Repository navigation
fix: support empty subjects in regexp functions - #27579
mergify[bot] merged 3 commits into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
4d8db5a to
1cdcafa
Compare
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head 1cdcafad743deac4ad3bf401d8052d319b08664e against merge base e866c535f5723fca6a8522c8338f7277e4b9e40f.
The new predicate admits exactly position 1 for an empty subject and preserves the existing [1,len(subject)] domain for non-empty subjects. This lets zero-width regular expressions reach the engine while positions 0 and 2 remain errors. I checked matching and non-matching zero-width patterns, explicit/default position, occurrence and return-option validation, NULL propagation, and the distinct no-match contracts of INSTR and SUBSTR. The unit and SQL fixtures provide direct result oracles. I found no blocking issue.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head 1cdcafad743deac4ad3bf401d8052d319b08664e.
Blocking unhappy path: regularInstr("^$", "", 1, 1, -1) panics at matches[occurrence-1][retOption] with index -1 instead of returning an invalid-input error. This is reachable from SQL as REGEXP_INSTR(empty_subject, anchor_pattern, 1, 1, -1); MySQL 8.4 returns an argument error. The PR description says invalid return options remain errors, but the new test covers only 2, while the validator still checks only retOption > 1.
Please reject both sides of the domain (retOption < 0 || retOption > 1) before indexing and add a regression for the negative case, preferably through the evaluator/SQL path. The empty-subject position rule itself matches MySQL, existing unit tests pass, focused race tests pass, and the helper adds no meaningful hot-path overhead.
aptend
left a comment
There was a problem hiding this comment.
Blocking — pkg/sql/plan/function/func_builtin_regexp.go:859-873: regularInstr rejects only retOption > 1, so a negative int8 value passes validation and is then used as matches[occurrence-1][retOption]. On this head, REGEXP_INSTR('', '^$', 1, 1, -1) reaches the newly enabled empty-subject path and panics with runtime error: index out of range [-1] instead of returning an invalid-input error; the same defect is reachable with a non-empty matching subject. This can abort SQL evaluation rather than report bad input. I reproduced it at exact head with a temporary counterexample test. Please validate both bounds (retOption < 0 || retOption > 1) before indexing and add a negative-option regression through the evaluator or SQL fixture. The empty-subject position predicate itself and the matching/no-match/NULL cases passed package tests, 100x focused tests, 10x race tests, and vet.
1cdcafa to
82b6db3
Compare
aptend
left a comment
There was a problem hiding this comment.
Deep re-review of exact head 82b6db33278f267fc51617d538003eb5214689da against exact base 428ce80cb88368b2436a7445a9016c5e6aa021e5. I read the complete review/discussion history and compared the follow-up with the previously reviewed head 1cdcafad743deac4ad3bf401d8052d319b08664e, then rechecked the complete current diff.
The prior blocker is closed: regularInstr now rejects return_option < 0 || return_option > 1 before indexing match bounds, and the new evaluator regressions cover negative options for both empty and non-empty matching subjects. The empty-subject predicate admits only position 1, preserves the existing non-empty position domain, and maintains the INSTR/SUBSTR match, no-match, invalid-position, invalid-occurrence, invalid-pattern, and NULL contracts. I found no blocking issue.
Validation on the unmodified head: go test ./pkg/sql/plan/function -count=1; the focused empty-subject test 100x; focused race test 10x; go vet ./pkg/sql/plan/function; and git diff --check. A temporary boundary matrix covering positions -1/0/1/2/large, occurrences -1/0/1, return options -128/-1/0/1/2/127, zero-width matches, and no-match cases passed 10x and was removed.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review completed on exact head 82b6db33278f267fc51617d538003eb5214689da against base 428ce80cb88368b2436a7445a9016c5e6aa021e5.
The previous blocker is closed: regularInstr rejects every return option outside [0,1] before using it as the match-bound index, and evaluator-level regressions cover negative options for both empty and non-empty matching subjects. The new empty-subject predicate admits exactly position 1, preserves the pre-existing non-empty domain, and keeps NULL, no-match, occurrence, invalid-pattern, and INSTR/SUBSTR result contracts unchanged.
I rechecked every production/test/BVT hunk and the boundary interactions. This is a focused sequential compatibility fix, so the feature-design and lifecycle/Q1-Q3 gates are not triggered. The helper adds constant work only; regexp compilation/matching still dominates the path. Exact-head build, UT, SCA, coverage, and service BVT checks are terminal green. No blocking correctness, compatibility, performance, or unhappy-path issue remains.
Merge Queue Status
This pull request spent 50 minutes 32 seconds in the queue, including 50 minutes 11 seconds running CI. Required conditions to merge
|
Allow position 1 as the sole valid search start for an empty subject in `REGEXP_INSTR` and `REGEXP_SUBSTR`. This lets zero-length patterns such as `^$` reach the regular expression engine while preserving errors for position 0, position 2, and other out-of-range positions. The change keeps the existing semantics for non-empty subjects, NULL propagation, no-match results (`0` for `REGEXP_INSTR`, NULL for `REGEXP_SUBSTR`), invalid occurrences, invalid return options, and invalid patterns. Regression coverage includes matching and non-matching patterns, default and explicit positions, NULL inputs, invalid positions, and `REGEXP_LIKE` controls. Distributed SQL fixtures and expected result files are updated in matching command order. Validation: - Reproduced the original rejection twice on an unmodified latest `origin/main` worktree. - `go test ./... -count=1` in `pkg/sql/plan/function` - `go test -race ./... -count=1` in `pkg/sql/plan/function` - `go vet ./...` in `pkg/sql/plan/function` - Changed functions have 100% statement coverage. - `make config` - `make err-check` - `git diff --check` - Two rounds of 16 focused SQL assertions against an isolated MatrixOne process built from this head. The full Java `mo-tester` BVT harness was not run locally because the host has no JRE and dependencies were intentionally not downloaded. The corresponding BVT SQL and result fixtures are included for CI execution. Approved by: @aunjgr, @XuPeng-SH, @aptend
Allow position 1 as the sole valid search start for an empty subject in `REGEXP_INSTR` and `REGEXP_SUBSTR`. This lets zero-length patterns such as `^$` reach the regular expression engine while preserving errors for position 0, position 2, and other out-of-range positions. The change keeps the existing semantics for non-empty subjects, NULL propagation, no-match results (`0` for `REGEXP_INSTR`, NULL for `REGEXP_SUBSTR`), invalid occurrences, invalid return options, and invalid patterns. Regression coverage includes matching and non-matching patterns, default and explicit positions, NULL inputs, invalid positions, and `REGEXP_LIKE` controls. Distributed SQL fixtures and expected result files are updated in matching command order. Validation: - Reproduced the original rejection twice on an unmodified latest `origin/main` worktree. - `go test ./... -count=1` in `pkg/sql/plan/function` - `go test -race ./... -count=1` in `pkg/sql/plan/function` - `go vet ./...` in `pkg/sql/plan/function` - Changed functions have 100% statement coverage. - `make config` - `make err-check` - `git diff --check` - Two rounds of 16 focused SQL assertions against an isolated MatrixOne process built from this head. The full Java `mo-tester` BVT harness was not run locally because the host has no JRE and dependencies were intentionally not downloaded. The corresponding BVT SQL and result fixtures are included for CI execution. Approved by: @aunjgr, @XuPeng-SH, @aptend
Allow position 1 as the sole valid search start for an empty subject in `REGEXP_INSTR` and `REGEXP_SUBSTR`. This lets zero-length patterns such as `^$` reach the regular expression engine while preserving errors for position 0, position 2, and other out-of-range positions. The change keeps the existing semantics for non-empty subjects, NULL propagation, no-match results (`0` for `REGEXP_INSTR`, NULL for `REGEXP_SUBSTR`), invalid occurrences, invalid return options, and invalid patterns. Regression coverage includes matching and non-matching patterns, default and explicit positions, NULL inputs, invalid positions, and `REGEXP_LIKE` controls. Distributed SQL fixtures and expected result files are updated in matching command order. Validation: - Reproduced the original rejection twice on an unmodified latest `origin/main` worktree. - `go test ./... -count=1` in `pkg/sql/plan/function` - `go test -race ./... -count=1` in `pkg/sql/plan/function` - `go vet ./...` in `pkg/sql/plan/function` - Changed functions have 100% statement coverage. - `make config` - `make err-check` - `git diff --check` - Two rounds of 16 focused SQL assertions against an isolated MatrixOne process built from this head. The full Java `mo-tester` BVT harness was not run locally because the host has no JRE and dependencies were intentionally not downloaded. The corresponding BVT SQL and result fixtures are included for CI execution. Approved by: @aunjgr, @XuPeng-SH, @aptend
What type of PR is this?
Which issue(s) this PR fixes:
issue #27573
What this PR does / why we need it:
Allow position 1 as the sole valid search start for an empty subject in
REGEXP_INSTRandREGEXP_SUBSTR. This lets zero-length patterns such as^$reach the regular expression engine while preserving errors for position 0, position 2, and other out-of-range positions.The change keeps the existing semantics for non-empty subjects, NULL propagation, no-match results (
0forREGEXP_INSTR, NULL forREGEXP_SUBSTR), invalid occurrences, invalid return options, and invalid patterns.Regression coverage includes matching and non-matching patterns, default and explicit positions, NULL inputs, invalid positions, and
REGEXP_LIKEcontrols. Distributed SQL fixtures and expected result files are updated in matching command order.Validation:
origin/mainworktree.go test ./... -count=1inpkg/sql/plan/functiongo test -race ./... -count=1inpkg/sql/plan/functiongo vet ./...inpkg/sql/plan/functionmake configmake err-checkgit diff --checkThe full Java
mo-testerBVT harness was not run locally because the host has no JRE and dependencies were intentionally not downloaded. The corresponding BVT SQL and result fixtures are included for CI execution.