-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opt: rewrite const OP ANY(subquery) as EXISTS(subquery WHERE ... OP const) #37241
Comments
Perhaps the cleaner way to do this would be to hoist the subquery and then add a rule that simplifies that kind of join with a |
We have marked this issue as stale because it has been inactive for |
still exists in 21.1 |
Unfortunately, The Postgres docs explain this:
Here's how this plays out in practice:
I'm motivated to make a rewrite like this work - it'll vastly simplify the optimizer and execution engine if we can get rid of bespoke support for One of the most difficult hurdles to overcome is supporting this bizarre behavior (which I've extracted from the results above):
If the contents of the |
I think the following is a valid rewrite:
Here's some tests showing its equivalence (in Postgres): https://gist.github.com/mgartner/9dac0b802c087329a8e2ee4ff0204bbd |
I used this transformation in #98375. I don't think we should use it yet universally, though, because it can lead to plans with slow apply-joins. Also, it doesn't provide the benefit originally described in this issue - it won't allow constrained scans to be performed. If columns can be prove to be non-NULL then a simpler transformation may be possible. For now I'm going to close this issue. |
These two queries are equivalent:
However, the first is significantly better since it can generate spans.
It might be the case that it's better to address this by instead hoisting the subquery, which would be a more general solution, but wouldn't generate spans at plan time which might be valuable (and is also blocked in the common case by #37240).
Jira issue: CRDB-4443
The text was updated successfully, but these errors were encountered: