Skip to content

fix: support empty subjects in regexp functions - #27579

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
Lundomn:fix/issue-27573-empty-regexp-subject-codex
Aug 26, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
Lundomn:fix/issue-27573-empty-regexp-subject-codex

Conversation

@Lundomn

@Lundomn Lundomn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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_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.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Aug 25, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Aug 25, 2026
@Lundomn
Lundomn force-pushed the fix/issue-27573-empty-regexp-subject-codex branch from 4d8db5a to 1cdcafa Compare August 25, 2026 09:17

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Lundomn
Lundomn force-pushed the fix/issue-27573-empty-regexp-subject-codex branch from 1cdcafa to 82b6db3 Compare August 26, 2026 02:36

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@mergify mergify Bot added the queued label Aug 26, 2026
@mergify

mergify Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-26 05:46 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-26 06:37 UTC · at 8ea97357696f8c539d948ae2543784d507507efc · squash

This pull request spent 50 minutes 32 seconds in the queue, including 50 minutes 11 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit a5877b6 into matrixorigin:main Aug 26, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Aug 26, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
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

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants