| First I think it is important to nail down the interpretation of how we know when to (1) restrict the hierarchy in the SQL FROM clause versus (2) restrict the hierarchy local to the SQL predicate (make it a CONJUNCTION) IMO this distinction boils down the SQM concept of a from-element's "intrinsic subclass indicator". From there we can look at situations and whether they indicate "flipping" the from-element's "intrinsic subclass indicator":
- Certainly use of the TREAT in the FROM element defines the "intrinsic subclass indicator" of the generated from-element
- I'd argue that use of TREAT in any other clause used in a predicate (the main thing with predicates is that they could be part of a DISJUNCTION/OR branch which means the restriction would need to be local to the predicate by composing a CONJUNCTION/AND predicate grouping the original predicate plus the restrictive predicate).
- That means use of TREAT in the SELECT, WHERE, GROUP BY and ORDER BY clauses would indicate an "intrinsic subclass indicator" for the TREATed from-element. "intrinsic subclass indicator" can also be made more resitrictive (in terms of more conrete subclass) throughout these clauses
- Use of TREAT in the WHERE and HAVING clauses would indicate using predicate-local resitrictions unles the source from-element already indicates an "intrinsic subclass indicator".
- we need to decide whether a CASE statement falls into the predicate-local case or the "intrinsic subclass indicator" case.
Look at Christian's examples and assertions (the link GitHub project) to see how they stack up with that generalizable algorithm. |