Repository navigation
fix(plan): support enum and prefix text indexes - #24809
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
I found a substantive issue in the current prefix-index implementation.
Prefix length is persisted in metadata, but SHOW CREATE TABLE still drops it, so the feature does not round-trip.
- Prefix lengths are stored in
indexDef.IndexAlgoParamsviaprefix_lengths(pkg/catalog/secondary_index_utils.go:187-203,pkg/sql/plan/build_ddl.go:2076-2079,2456-2459). - But when
SHOW CREATE TABLErenders index definitions, it only prints raw part names and then appendscatalog.IndexParamsToStringList(...)(pkg/sql/plan/build_show_util.go:278-303). That renderer never reconstructs key-part suffixes like(100), andIndexParamsToStringListdoes not outputprefix_lengthseither (pkg/catalog/secondary_index_utils.go:104-160).
So a table created as INDEX x3(a(100)) will still be shown as if it were just INDEX x3(a). That is not just cosmetic: SHOW CREATE TABLE no longer reproduces the original schema, and MatrixOne's snapshot/PITR/restore flows fetch DDL through show create table (pkg/frontend/snapshot_restore_with_ts.go:252-268, pkg/frontend/pitr.go:1583-1592, pkg/frontend/snapshot.go:2072-2080). In other words, a restored table can silently lose its prefix-index semantics or even fail when replaying the downgraded DDL on TEXT/BLOB keys.
I think this needs to be fixed before approval: SHOW CREATE TABLE / restoreDDL must reconstruct key-part lengths from prefix_lengths and emit col(length) again.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Requesting changes for a prefix-index maintenance bug on the delete/update path.
The backfill / insert / unique-lock paths were updated to materialize prefix index keys with substring(..., 1, n), but appendDeleteIndexTablePlan in build_dml_util.go still builds the lookup key from the full source column value (or serial(...) of full values).
That means for any indexed value longer than the prefix length, DELETE / UPDATE will fail to match the old hidden index row. On secondary indexes that leaves stale index rows behind; on unique prefix indexes it can later surface as false duplicate conflicts.
I think the delete-maintenance path needs to apply the same prefix expression/cast as the insert/backfill path before joining to the index table, and it would be good to add an end-to-end UPDATE/DELETE case with values longer than the prefix length.
XuPeng-SH
left a comment
There was a problem hiding this comment.
✅ APPROVED after comprehensive multi-angle review
Analysis Summary: 2576 lines across 25 files • 21-item systematic checklist • Zero blocking issues
Key Strengths:
- ✅ Excellent refactoring - centralized validation in checkIndexColumnSupportability()
- ✅ Comprehensive test coverage - 87 planner + 64 BVT lines covering happy/unhappy paths
- ✅ First-principles correctness - substring/cast applied at all DML entry points (INSERT/UPDATE/DELETE)
- ✅ Robust error handling - validates prefix lengths at parse/serialization/execution
- ✅ Backward compatible - existing indexes continue working, no migration required
- ✅ Critical bug fix - preinsertunique.go now uses PreInsertCtx.UkType (prevents type mismatches)
Unhappy Path Validation:
- ✅ Zero/negative prefix lengths → rejected at parse time
- ✅ Prefix > data length → substring() handles gracefully
- ✅ NULL values → filtered in index maintenance
- ✅ Mixed prefix/non-prefix columns → each checked independently
- ✅ Upgrade scenario → (nil, nil) return for old metadata
- ✅ GEOMETRY32 → RTREE validation preserved
First-Principles Check:
- Core design: PREFIX INDEX stores substring(col, 1, len) instead of full TEXT/BLOB
- Type safety: TEXT→VARCHAR(65535), BLOB→VARBINARY(65535) with proper casts
- Metadata: JSON extensible format in IndexAlgoParams
- DML completeness: 12 function usages across INSERT/DELETE/UPDATE paths
See full review document: /tmp/pr_review_24809.md
This PR is production-ready and represents a significant feature addition with excellent quality.
Add unit tests for the prefix-length param helpers in catalog and the pure index helpers in build_index_util, raising their coverage to 100%. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Merge Queue Status
This pull request spent 1 hour 56 minutes 3 seconds in the queue, including 1 hour 5 minutes 57 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #24740
Fixes #24729
What this PR does / why we need it:
Validation:
go test ./pkg/sql/plan -run 'TestBuildIndexAllowsEnumAndTextBlobPrefix|TestBuildIndexRejectsTextBlobPlainIndex' -count=1go test ./pkg/sql/compile -run 'TestGenInsertIndexTableSql_UsesPrefixExpression|TestBuildCreateUniqueIndexDuplicateCheckSQL' -count=1go test ./pkg/sql/colexec/preinsertunique ./pkg/sql/colexec/preinsertsecondaryindex -count=1./run.sh -p /Users/LoveYY/Develop/matrixorigin/matrixone/.worktrees/issue-24740/test/distributed/cases/ddl/create_index.sql -g -n./run.sh -p /Users/LoveYY/Develop/matrixorigin/matrixone/.worktrees/issue-24740/test/distributed/cases/dtype/enum.sql -g -ngit diff --checkmakemake static-check