-
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: index accelerate array overlap operator &&
#75477
Comments
Hi, I would like to take this up but I am fairly new to CockroachDB and would need some pointers to get started. Let me know if that's ok :) |
Hi @RajivTS! You're absolutely welcome to give this one a shot. Now that I think about it, I may have incorrectly labelled this a "good first issue" - it's a bit challenging for a newcomer. But not impossible, so don't let me deter you! This issue requires recognizing the |
Hi @mgartner! Thank you for the high level overview and the reference PR. Based on what I have seen so far, I have the following understanding of the changes needed to address this issue. I might be way off the mark here so please do correct me wherever I am wrong. The set of changes needed (except tests) are:
I also have a few open questions (and will probably have more as I progress):
|
This sounds right. Beware of
The logic might be as simple as this block of code: cockroach/pkg/sql/rowenc/index_encoding.go Lines 797 to 802 in 98bd5a8
Great question! We already have a normalization rule that commutes binary operators so that variables are always on the left, so that other rules and logic doesn't need to handle both cases.
You can extend this test to make sure it works properly: cockroach/pkg/sql/opt/norm/testdata/rules/scalar Lines 27 to 39 in a812e22
Feel free to submit that as a separate commit or even a separate PR. It's a simpler, self-contained change and it might be nice to make incremental progress towards the larger goal.
I'm not sure I understand the question, sorry. The In Postgres:
Another great question! You anticipate my warning about |
Thank you @mgartner for the clarifications! I do have a few remaining questions before I can complete my changes.
So does this mean the below structure (from cockroach/pkg/sql/opt/invertedidx/json_array.go Lines 374 to 384 in 30ee32c
I am sorry but I don't quite understand how the above tests need to be modified to validate the commutativity property of the
I am also having difficulty in following the cockroach/pkg/sql/opt/norm/testdata/rules/scalar Lines 213 to 218 in 3e0da46
Do I need to hardcode these? Or will these be generated via |
It shouldn't be after you update the Also, I forgot to mention any pointers about these
These are data driven tests with a command, query, and expected output. I've annotated a test to explain a bit more:
The supported optimizer data-driven test commands and options are documented here. The output of data driven tests can be regenerated with the
If you want to rewrite all test files in the
You can do the same for any package with datadriven tests.
The test won't validate that the operator is commutative, but it will validate that your changes to the |
Thanks a bunch @mgartner! I will send out a draft PR once I have the first working version of the changes ready. |
Hi @mgartner I have created the first draft version of the PR addressing this issue. Note that this does not contain the changes for Overlaps operator commutativity. That will be a separate PR. |
…dexes Previously, we did not support index acceleration for queries involving array overlaps (&&). This change adds support for using the inverted index with && expressions on Array columns. When there is an inverted index available, a scan will be done on the Array column using the spans found from the constant value. Fixes: cockroachdb#75477 Release note (performance improvement): Expressions using the overlaps (&&) operator for arrays now support index-acceleration for faster execution in some cases. Release justification: low risk, high benefit changes to existing functionality.
…dexes Previously, we did not support index acceleration for queries involving array overlaps (&&). This change adds support for using the inverted index with && expressions on Array columns. When there is an inverted index available, a scan will be done on the Array column using the spans found from the constant value. Fixes: cockroachdb#75477 Release note (performance improvement): Expressions using the overlaps (&&) operator for arrays now support index-acceleration for faster execution in some cases. Release justification: low risk, high benefit changes to existing functionality.
…dexes Previously, we did not support index acceleration for queries involving array overlaps (&&). This change adds support for using the inverted index with && expressions on Array columns. When there is an inverted index available, a scan will be done on the Array column using the spans found from the constant value. Fixes: cockroachdb#75477 Release note (performance improvement): Expressions using the overlaps (&&) operator for arrays now support index-acceleration for faster execution in some cases. Release justification: low risk, high benefit changes to existing functionality.
The array overlap operator,
&&
, provides a convenient syntax for filtering for arrays that have one more more elements in common with another array. However, the&&
operator is not index accelerated, so an efficient inverted index scan in not planned. The current workaround is to rewrite the query by combining the containment operator withOR
expressions:Jira issue: CRDB-12686
The text was updated successfully, but these errors were encountered: