Skip to content

fix: maintain covering secondary indexes - #25342

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:fix-25341-covering-secondary-index
Jul 2, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
XuPeng-SH:fix-25341-covering-secondary-index

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Jul 1, 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:

fixes #25341

What this PR does / why we need it:

This fixes the inconsistent secondary-index path for tables whose regular secondary index covers the full composite primary key.

The root invariant is: if a regular hidden index table exists and the optimizer can read it, DML must maintain it. Previously getValidIndexes skipped some regular indexes when the index parts covered the full primary key, but the optimizer could still choose the existing hidden index table for predicates such as status = 'active' or status IN (...), producing empty results from a stale index table.

Changes:

  • Keep regular secondary indexes maintainable whenever their hidden table exists, even when the index covers the full composite primary key.
  • Use the same serialized lookup shape as the DML/index table encoding: serial_full for non-unique multi-part regular indexes, and serial for unique or single-part lookups.
  • Restrict the regular secondary-index rewrite to regular index algorithms so vector/fulltext/master index definitions cannot be consumed by this path.
  • Add planner unit coverage for covering regular indexes, irregular-index guards, serial_full lookup rewrites, equality/IN/range predicates, and unique-index behavior.
  • Add an optimizer regression case for the issue shape, covering equality, IN, range, null-safe equality, row projection, update, delete, replace, and ON DUPLICATE KEY UPDATE.

Local validation:

  • git diff --check
  • make cgo
  • CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib -lusearch_c" DYLD_LIBRARY_PATH="$(pwd)/cgo:$(pwd)/thirdparties/install/lib" go test -ldflags="-extldflags '-L$(pwd)/cgo -lmo -L$(pwd)/thirdparties/install/lib -Wl,-rpath,@executable_path/lib'" -count=1 -timeout 180s ./pkg/sql/plan
  • CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib -lusearch_c" DYLD_LIBRARY_PATH="$(pwd)/cgo:$(pwd)/thirdparties/install/lib" go test -ldflags="-extldflags '-L$(pwd)/cgo -lmo -L$(pwd)/thirdparties/install/lib -Wl,-rpath,@executable_path/lib'" -count=1 -timeout 120s ./pkg/sql/colexec/multi_update
  • CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib -lusearch_c" DYLD_LIBRARY_PATH="$(pwd)/cgo:$(pwd)/thirdparties/install/lib" go build -ldflags="-extldflags '-L$(pwd)/cgo -lmo -L$(pwd)/thirdparties/install/lib -Wl,-rpath,@executable_path/lib'" ./pkg/sql/plan
  • CGO_CFLAGS="-I$(pwd)/cgo -I$(pwd)/thirdparties/install/include" CGO_LDFLAGS="-L$(pwd)/thirdparties/install/lib -lusearch_c" DYLD_LIBRARY_PATH="$(pwd)/cgo:$(pwd)/thirdparties/install/lib" go vet -ldflags="-extldflags '-L$(pwd)/cgo -lmo -L$(pwd)/thirdparties/install/lib -Wl,-rpath,@executable_path/lib'" ./pkg/sql/plan

@XuPeng-SH
XuPeng-SH requested a review from a user July 1, 2026 15:27
@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 →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Re-reviewing the latest head: the earlier blockers look resolved now.

  • The NULL-semantics problem on covering index-only scans is fixed: the latest tryIndexOnlyScan() keeps the original leading predicate as a residual recheck when serial_full is involved and the lookup can compare against runtime NULL.
  • The missing regular-index guard in the join/runtime-filter path is also fixed: applyIndicesForJoins() now excludes non-regular and spatial/rtree indexes from the generic hidden-index rewrite path.

At this point I don’t see a remaining substantive correctness issue. The remaining gaps are at most nice-to-have extra coverage, not blockers.

LGTM.

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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: VARCHAR equality predicate returns zero rows with owner-bound PK and covering secondary index

2 participants