Repository navigation
evalengine: report a bad regexp pattern when another argument is NULL - #22133
Pranav-error wants to merge 2 commits into
Conversation
REGEXP, REGEXP_LIKE, REGEXP_INSTR, REGEXP_SUBSTR and REGEXP_REPLACE
returned NULL as soon as the subject, the replacement, the position,
the occurrence or the return option was NULL, without looking at the
pattern. MySQL compiles the pattern first and fails the statement when
it is invalid: on MySQL 8.4, NULL REGEXP '[' fails with
ER_REGEXP_MISSING_CLOSE_BRACKET, NULL REGEXP '' with
ER_REGEXP_ILLEGAL_ARGUMENT, and REGEXP_REPLACE('a', '[', NULL) and
REGEXP_SUBSTR('dog cat dog', '[', 1, NULL, 'i') fail the same way, also
when the pattern comes from a column. A NULL pattern or a NULL match type still
gives NULL.
Check those arguments for NULL only after the pattern and the match
type, and compile the pattern before returning NULL, in both the AST
evaluator and the compiled program. The compiled program only compiles
the pattern at run time when it could not be compiled ahead of time.
Signed-off-by: sai pranav <rajasaipranav0@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
mattlord
left a comment
There was a problem hiding this comment.
Blocking: The match type parse on the new NULL paths has no test. In go/vt/vtgate/evalengine/fn_regexp.go:293 (regexpNullArg) and go/vt/vtgate/evalengine/compiler_asm.go:4892 (Fn_REGEXP_NULLCHECK), the match type is now parsed before NULL is returned, so a bad match type with a NULL subject or another NULL argument is now an error where main returns NULL. That matches MySQL: on 8.0.46 and 8.4.9, REGEXP_LIKE(NULL, 'a', 'x'), REGEXP_INSTR(NULL, 'a', 1, 1, 1, 'x'), REGEXP_SUBSTR(NULL, 'a', 1, 1, 'x') and REGEXP_REPLACE(NULL, 'DOG', 'bar', 1, 1, 0) all fail with ERROR 1210 (HY000): Incorrect arguments to ..., and REGEXP_INSTR(NULL, '[', 1, 1, 1, 'x') reports the match type rather than the bracket. But removing either regexpFlags call leaves the whole evalengine package passing, so this second behavior change could regress without notice. I think that we should add a couple of cases to TestRegexpNullArgumentWithBadPattern that expect vterrors.WrongArguments, such as REGEXP_LIKE(:s, 'a', 'x') and REGEXP_INSTR(:s, '[', 1, 1, 1, 'x') (for the ordering), and mention the match type case in the description next to the pattern case. What do you think?
Locally, the evalengine package tests pass.
Thanks for the fix!
A bad match type is now reported when another argument is NULL, as on MySQL 8.4, so cover it, including its order before a bad pattern. Signed-off-by: sai pranav <rajasaipranav0@gmail.com>
|
Thanks, agreed. I checked your cases on MySQL 8.4.13 and they all fail with 1210, including One related difference I left out of this PR: with a NULL pattern, |
mattlord
left a comment
There was a problem hiding this comment.
Thanks for adding these. The five new cases cover both NULL paths: removing the regexpFlags call in either regexpNullArg or Fn_REGEXP_NULLCHECK now fails them, and the evalengine package tests pass locally.
On the NULL pattern case, I see the same on MySQL 8.0.46 and 8.4.9: REGEXP_LIKE('a', NULL, 'x'), REGEXP_LIKE(NULL, NULL, 'x') and REGEXP_INSTR('a', NULL, 1, 1, 0, 'x') all fail with ERROR 1210, while REGEXP_LIKE('a', NULL, NULL) gives NULL. I think that a separate PR is the right place for it, along with the return option and position cases that you already listed, since it's a different check.
The description doesn't mention the match type change yet. It seems worth a sentence next to the pattern case saying that a bad match type now fails with ERROR 1210 when the subject or another argument is NULL, where main returns NULL.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22133 +/- ##
===========================================
+ Coverage 69.67% 86.81% +17.14%
===========================================
Files 1614 59 -1555
Lines 216793 15823 -200970
===========================================
- Hits 151044 13737 -137307
+ Misses 65749 2086 -63663
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
REGEXP,REGEXP_LIKE,REGEXP_INSTR,REGEXP_SUBSTRandREGEXP_REPLACEreturnNULLas soon as the subject, the replacement, the position, the occurrence or the return option isNULL, without looking at the pattern. MySQL compiles the pattern first and fails the statement when it is invalid. On MySQL 8.4.13,NULL REGEXP '[',REGEXP_INSTR('dog', '[', NULL),REGEXP_SUBSTR(NULL, '[', 1, 1, 'i'),REGEXP_REPLACE('a', '[', NULL)andREGEXP_REPLACE('dog cat dog', '[', 'bar', 1, NULL, 'i')all returnERROR 3696 (HY000): The regular expression contains an unclosed bracket expression., andNULL REGEXP ''returnsERROR 3685 (HY000): Illegal argument to a regular expression.This also happens when the pattern comes from a column or a prepared statement parameter. ANULLpattern or aNULLmatch type still givesNULL, for exampleREGEXP_LIKE(NULL, '[', NULL)andNULL REGEXP NULL.The match type is parsed before
NULLis returned as well, so a bad match type now fails withERROR 1210 (HY000): Incorrect arguments to ...when the subject or another argument isNULL, wheremainreturnsNULL. For exampleREGEXP_LIKE(NULL, 'a', 'x')andREGEXP_INSTR(NULL, '[', 1, 1, 1, 'x'); the latter reports the match type, not the bracket, as on MySQL.This PR checks those arguments for
NULLonly after the pattern and the match type, and compiles the pattern before returningNULL:evalmethods of the four builtins call a newregexpNullArghelper when one of those arguments isNULL.NULLjumps on those arguments are replaced by a newFn_REGEXP_NULLCHECKinstruction that runs once all arguments are on the stack. It compiles the pattern only when it could not be compiled ahead of time, so a constant valid pattern costs nothing extra. The integer conversions of position, occurrence and return option are now skipped forNULLvalues instead of jumping out.Left out on purpose, since they are separate checks: MySQL also fails
REGEXP_LIKE('a', NULL, 'x')(bad match type with aNULLpattern) andREGEXP_INSTR(NULL, 'a', 1, 1, 5)/REGEXP_SUBSTR(NULL, 'a', 0)(bad return option or position with aNULLsubject), where the evalengine still returnsNULL.Motivation
How do you use Vitess? (pick one)
Did you run this change against a real Vitess deployment? No. These inputs were among the cases hidden by
knownErrors(#22107): 27 of them inRegexpLike,RegexpSubstrandRegexpReplace. I ran them against MySQL 8.4.13 to confirm the errors. The newTestRegexpNullArgumentWithBadPatternchecks both the interpreter and the compiled path with bind variables, so nothing is folded away; it fails on the current code and passes with this change. Theevalenginepackage tests andTestMySQL/Regexp*against MySQL 8.4 pass, and with the strict comparison from #22107 the 27 hidden cases go to 0.Related Issue(s)
Found with the strict comparison described in #22107. Same kind of fix as #22130 and #22131.
Checklist