-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: like_escape is slower than SELECT LIKE #30192
Comments
As you found via EXPLAIN, when you use ESCAPE the query optimization that narrows the search on the index is disabled. This is a limitation of the current query engine. |
Currently, the optimizer only recognizes the cc @RaduBerinde |
To propagate my offline comments here: the A LIKE B ESCAPE C is the first/only 3-way operator. It's not completely trivial to introduce 3-way operators throughout the entire SQL layer. However we could perhaps specialize the code to treat a literal/constant C as a 2-way special LIKE operator. |
@andy-kimball FYI this is a rather uncommonly used feature. I'm not sure about the "high priority" label. |
That just means it's a backlog that I review more frequently, not that issues in it are necessarily high priority (i.e. it's "higher priority" than the lower priority backlog, not "high priority"). Maybe I'll rename to reduce confusion. |
it's ok, I just didn't know. Thanks for explaining. |
@andy-kimball Can I get a quick blurb describing this known limitation w/r/t the impact to user experience? Ideally, we need it by Friday 10/26 for the 2.1 Known Limitations page. Posting it on this issue and/or pinging me would be great. |
Sean: """ CockroachDB tries to optimize most comparisons operators in WHERE and HAVING clauses into constraints on SQL indexes so that only the selected rows are accessed. This is done for LIKE clauses when a common prefix for all selected rows can be determined in the search pattern (e.g. `... LIKE 'Joe%''). However, this optimization is not yet available if the ESCAPE keyword is also used. |
Thanks for providing, @knz. |
We have marked this issue as stale because it has been inactive for |
This problem still exists in v21.1. Moreover, even the LIKE operator behaves strangely: with However the generated span is It looks like the span generation for LIKE gets confused by cc @rytaft for re-triage. |
Without any escaping, |
Oh i didn't know this. TIL thanks |
This issue made me realize we also have a bug in our index constraint generation code for LIKE. I've opened #66144 to track that issue. |
I'm dealing with an issue on Is this a bug or am I doing something wrong? |
@bladefist is this the right place to ask this question? I don't think this particular github issue is related to it. |
@knz I thought I was responding to the original post which commented on a bug with ESCAPE being slow, and/or the escape character Maybe I'm doing something wrong but my intention was report bug |
The concern you're having is unrelated to the issue at top. You want to report a new bug, not contribute to the conversation about the fact that like_escape is slower. So you can file a new issue and/or discuss the new bug on the community slack. |
We just ran into this issue in production. The query took the form After we removed the unnecessary redundant specification of the escape character used, the query was Documentation says that So our solution is to just remove the |
We have marked this issue as stale because it has been inactive for |
still relevant |
BUG REPORT
Please describe the issue you observed, and any steps we can take to reproduce it:
v2.1.0-beta.20180910
It seems that SELECT ... LIKE is a lot faster than SELECT ... LIKE ... ESCAPE
Example timing on a few million row table:
Time: 24.575054ms
Time: 3m37.614735676s
Jira issue: CRDB-7884
The text was updated successfully, but these errors were encountered: