-
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: suboptimal behavior related to predicate evaluation #58283
Comments
Hello, I am Blathers. I am here to help you get the issue triaged. It looks like you have not filled out the issue in the format of any of our templates. To best assist you, we advise you to use one of these templates. I have CC'd a few people who may be able to assist you:
If we have not gotten back to your issue within a few business days, you can try the following:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
One thing to note is that in general, with a boolean variable However, I'm not sure if there is any difference between the two expressions when it is used as a filter condition like this. For example, these two queries return the same thing.
|
In the fast case the optimizer is able to prove that the filter is always
I'm curious to know why the optimizer isn't able to deduce the same thing in the latter case. |
Looks like a missing rule. I think there could be a rule for selects and joins that normalizes |
Previously, a filter in the condition of a `Select` or `Join` could not simplify an expression of the following form: `<expr> IS (True | False)` This could prevent other rules from firing - contradiction detection, for example. This patch allows the SimplifyFilters logic to effect the following transformation on `IS` expressions in the filters of a `Select` or `Join`: ``` <expr> IS True => <expr> <expr> IS False => NOT <expr> ``` Note that the original `IS` expression would return `False` on a null input, whereas the replacement expression could return `Null`. In the case when the `IS` expression is a `Select` or `Join` condition, this does not matter, because `False` and `Null` conditions are treated the same way (no rows returned). However, the same logic does not apply to `IS NOT`, because then `True` values would become `Null`, since `Null IS NOT True` returns `True`. This would result in less rows being returned. Currently, only IS expressions that are top-level conjuncts of the filters are simplified for the sake of simplicity. Fixes cockroachdb#58283 Release note: None
58321: opt: simplify IS filters for selects and joins r=rytaft a=DrewKimball Previously, a filter in the condition of a `Select` or `Join` could not simplify an expression of the following form: `<expr> IS (True | False)` This could prevent other rules from firing - contradiction detection, for example. This patch allows the SimplifyFilters logic to effect the following transformation on `IS` expressions in the filters of a `Select` or `Join`: ``` <expr> IS True => <expr> <expr> IS False => NOT <expr> ``` Note that the original `IS` expression would return `False` on a null input, whereas the replacement expression could return `Null`. In the case when the `IS` expression is a `Select` or `Join` condition, this does not matter, because `False` and `Null` conditions are treated the same way (no rows returned). However, the same logic does not apply to `IS NOT`, because then `True` values would become `Null`, since `Null IS NOT True` returns `True`. This would result in less rows being returned. Currently, only IS expressions that are top-level conjuncts of the filters are simplified for the sake of simplicity. Fixes #58283 Release note: None Co-authored-by: Andrew Kimball <[email protected]>
Hello everyone!
First off, I am sorry for gestures vaguely all of this. Second, I think we may have found a suboptimal behavior related to predicate evaluation.
Here is a pair of TPC-H queries that exhibit this behavior.
Actual Behavior
The first query takes 49 milliseconds on the latest release v20.2.0-alpha.1, while the second query only takes 1 milliseconds.
The first query's
EXPLAIN ANALYZE (DEBUG)
result isstmt-bundle-firstquery.zip
The second query's
EXPLAIN ANALYZE (DEBUG)
result isstmt-bundle-secondquery.zip
Expected Behavior
I would have expected the database system run these two queries with similar execution time, given that their filters look almost identical to me. However, I am not certain whether these two filters have the same semantics in this case.
Here are the steps for reproducing our observations:
Test environment
Reproduce Bug
Download the dataset from the link: https://drive.google.com/file/d/1MLVFPKdRQhlRgmeRIumyIj8NBMRSQ3um/view?usp=sharing
$ cockroach sql --insecure --host=localhost:26257
In CockroachDB's built-in SQL client to create database:
$ cockroach sql --insecure --host=localhost:26257 -d tpch5 < dss.ddl
$ cockroach sql --insecure --host=localhost:26257 -d tpch5
The text was updated successfully, but these errors were encountered: