Skip to content
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

eval: add LIKE patterns without wildcards to optimizedLikeFunc #91895

Merged
merged 1 commit into from
Nov 16, 2022

Conversation

michae2
Copy link
Collaborator

@michae2 michae2 commented Nov 15, 2022

eval.optimizedLikeFunc has special cases for LIKE patterns that start and end with wildcards % or _ which can be evaluated without regular expressions. Add support for patterns with no wildcards at all.

Fixes: #91887
Assists: #89749

Epic: None

Release note (performance improvement): Performance of the LIKE and ILIKE operators using patterns without any wildcards has been improved.

@michae2 michae2 requested review from yuzefovich, DrewKimball and a team November 15, 2022 06:22
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Nice find! Might be worth having a sanity test for a couple simple patterns to ensure they get properly optimized. Also, is LIKE without wildcards the same as =?

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :lgtm:

I agree that adding some tests to assert that optimizedLikeFunc returns non-nil for the expected patterns would be great.

Without the wildcards and without the escape characters LIKE is the same to the direct comparison - if we have escape characters, then it's not.

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @michae2)


pkg/sql/sem/eval/match.go line 255 at r1 (raw file):

				}, nil

			default:

nit: maybe add a comment that this default case is handling both singleAnyStart || singleAnyEnd as well as the case when there are no wildcard characters in the pattern at all, and in the latter we just get a direct string comparison (modulo case insensitivity).

`eval.optimizedLikeFunc` has special cases for LIKE patterns that start and
end with wildcards `%` or `_` which can be evaluated without regular
expressions. Add support for patterns with no wildcards at all.

Fixes: cockroachdb#91887
Assists: cockroachdb#89749

Epic: None

Release note (performance improvement): Performance of the `LIKE` and
`ILIKE` operators using patterns without any wildcards has been
improved.
Copy link
Collaborator Author

@michae2 michae2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on the tests, they made me realize I was missing the length 1 case!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @yuzefovich)


pkg/sql/sem/eval/match.go line 255 at r1 (raw file):

Previously, yuzefovich (Yahor Yuzefovich) wrote…

nit: maybe add a comment that this default case is handling both singleAnyStart || singleAnyEnd as well as the case when there are no wildcard characters in the pattern at all, and in the latter we just get a direct string comparison (modulo case insensitivity).

Done.

@michae2
Copy link
Collaborator Author

michae2 commented Nov 16, 2022

bors r=DrewKimball,yuzefovich

@craig
Copy link
Contributor

craig bot commented Nov 16, 2022

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: LIKE and ILIKE with exact match strangely slow
4 participants