> While that's all a *bit* convoluted to work around the fact that Teiid doesn't allow a translator to declare a maximum number of AND clauses is supported (similar to setMaxDependentInPredicates), that's not my real issue... - See more at: https://developer.jboss.org/message/926558?et=watches.email.thread#926558
> result in two queries pushed to translator when it should be easy to detect that the second is always going to be a subset of the first and, thus, only one query is necessary. - See more at: https://developer.jboss.org/message/926558?et=watches.email.thread#926558
We have some logic for detecting repeated queries within a plan, but it's pretty rudimentary. I'd like for it to be expanded so that differences in projection and filtering were allowed as well. But it's not always straight forward as to when the combination is beneficial - such as when potentially removing indexed access. Reusing the results will typically imply that the results will need to be cached (rather than just streaming) and it also may increase latency. Vote or update [TEIID-2139] Factor out common table expressions - JBoss Issue Tracker to make a little more progress on this.
> We have some logic for detecting repeated queries within a plan, but it's pretty rudimentary
In this case, the issue isn't so much around the repeated query but the logic of sets: "select * from x" is always a superset of "select * from x where y=a" so the planner can eliminate the first clause.
Sorry I wasn't reading this literally enough. I thought you were looking for something more general. Yes in this specific case you can simply eliminate the first branch. Do you often have queries of this form such that an optimization like that would be helpful?
> Do you often have queries of this form such that an optimization like that would be helpful?
It's not a big concern, no.