Skip to content

feat(dialect): add index prefix length hook - #407

Merged
KKould merged 6 commits into
KipData:mainfrom
alexskinner:upstream/dialect-prefix-index
Nov 22, 2026
Merged

KKould merged 6 commits into
KipData:mainfrom
alexskinner:upstream/dialect-prefix-index

Conversation

@alexskinner

@alexskinner alexskinner commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Part of #403.

Depends on #404 (please review only the last commit; I'll rebase once #404 lands).

What

  • Adds SqlDialect::supports_index_prefix_length() -> bool, defaulting to false.
  • When a dialect returns true, a key part written col(n) with a positive integer n is accepted as col in PRIMARY KEY and UNIQUE constraints and in CREATE INDEX. The parser reads col(n) as a function call. The length isn't stored: the whole value is indexed, and a unique key compares whole values.
  • Anything else in that position (col(0), col(other_col), upper(col), an unknown column) is rejected as before.
  • With GenericSqlDialect, such key parts are rejected with the same errors as today.
  • Rustdoc on the hook and a line in the dialect section of docs/features.md.

Why

Schemas written for some dialects routinely use prefix key parts such as UNIQUE (name(191)). This lets a dialect crate accept them without changing what core stores or how indexes behave. See #403.

Testing

  • One unit test in src/dialect/mod.rs: the generic dialect still rejects a prefix key part, and a test-only dialect accepts UNIQUE (b(4)) and CREATE INDEX .. (b(2)), rejects a zero length, and enforces uniqueness on the whole value.
  • make test (650 passed, 2 ignored), make test-async (595 passed), make test-slt and make test-slt-async (198 files each), make fmt and all four make clippy invocations pass. make test-wasm passes too.

Notes for review

  • One commit on top of feat(dialect): add pluggable SqlDialect trait and DynDialect #404, no new dependencies. It's independent of the coercion PR.
  • I chose to ignore the length rather than store it, because KiteSQL indexes whole values. If you'd prefer to keep rejecting the length until real prefix indexes exist, the hook can simply stay false by default, as it is now.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.55959% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.99%. Comparing base (2610d5a) to head (ee1cc70).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/binder/parser.rs 87.35% 11 Missing ⚠️
...rc/optimizer/rule/implementation/dql/table_scan.rs 88.23% 2 Missing ⚠️
...ptimizer/rule/normalization/pushdown_predicates.rs 92.85% 2 Missing ⚠️
src/types/value.rs 93.33% 2 Missing ⚠️
...ptimizer/rule/normalization/parameterized_index.rs 88.88% 1 Missing ⚠️
src/planner/operator/create_table.rs 0.00% 1 Missing ⚠️
src/storage/mod.rs 97.43% 1 Missing ⚠️
src/types/index.rs 97.87% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #407      +/-   ##
==========================================
+ Coverage   92.98%   92.99%   +0.01%     
==========================================
  Files         275      275              
  Lines       39360    39538     +178     
==========================================
+ Hits        36598    36768     +170     
- Misses       2762     2770       +8     
Flag Coverage Δ
rust 92.99% <94.55%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/binder/create_index.rs 75.00% <ø> (-14.48%) ⬇️
src/binder/create_table.rs 78.12% <100.00%> (ø)
src/catalog/table.rs 98.04% <100.00%> (+0.29%) ⬆️
src/db/program.rs 82.60% <ø> (ø)
src/execution/ddl/create_index.rs 85.55% <100.00%> (+1.83%) ⬆️
src/execution/dml/analyze.rs 87.58% <100.00%> (+0.33%) ⬆️
src/execution/dml/delete.rs 85.13% <100.00%> (-0.20%) ⬇️
src/execution/dml/insert.rs 89.15% <100.00%> (ø)
src/execution/dml/update.rs 88.77% <100.00%> (ø)
src/expression/range_detacher.rs 90.43% <100.00%> (ø)
... and 20 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cursor
cursor Bot force-pushed the upstream/dialect-prefix-index branch from d1a9ee9 to 0a141f2 Compare November 21, 2026 13:38
@cursor
cursor Bot force-pushed the upstream/dialect-prefix-index branch 3 times, most recently from 9fca456 to 02997eb Compare November 21, 2026 19:08
@KKould
KKould force-pushed the upstream/dialect-prefix-index branch 2 times, most recently from eebee1b to 4f34d2b Compare November 21, 2026 20:27
@KKould KKould added the enhancement New feature or request label Nov 21, 2026
@KKould
KKould self-requested a review November 21, 2026 20:46
@KKould
KKould force-pushed the upstream/dialect-prefix-index branch from 061d6e8 to 7de5d36 Compare November 22, 2026 08:11

@KKould KKould left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This pull request was originally just for parser compatibility. I added KiteSQL's index implementation logic to the pull request to achieve compatibility, and enabled the default dialect option.

@KKould
KKould merged commit 2c5fb1c into KipData:main Nov 22, 2026
12 checks passed
cursoragent and others added 6 commits November 23, 2026 00:08
Add SqlDialect::supports_index_prefix_length(), defaulting to false.
When a dialect returns true, a key part written `col(n)` with a positive
integer length `n` (which the parser reads as a call) is accepted as
`col` in PRIMARY KEY and UNIQUE constraints and in CREATE INDEX. The
length is not stored: the whole value is indexed, and a unique key
compares whole values.

GenericSqlDialect keeps rejecting such key parts with the same errors
as before, and DynDialect forwards the hook to its current dialect.
A unit test in src/dialect/mod.rs covers both dialects.

Co-authored-by: Alex Skinner <alexskinner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants