Repository navigation
Create the index for INDEX name (...) inside CREATE TABLE to close #2607 - #2614
Merged
mathiasrw merged 2 commits intoOct 20, 2026
Merged
Conversation
…aSQL#2607 CreateTable.execute handled the constraint types PRIMARY KEY, CHECK, UNIQUE and FOREIGN KEY. A constraint of type INDEX was parsed and then skipped, so no index was created. Register it the way CREATE INDEX registers a non-unique index: table.inddefs, table.indices and db.indices. The key expression is built the same way too, so INDEX k (a, b(2)) inside CREATE TABLE gives the same index definition as CREATE INDEX k ON t (a, b(2)), and INSERT keeps it up to date. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2607
Problem
INDEX name (...)insideCREATE TABLEwas parsed, but no index was created. Reproduced ondevelop(c9e3b53):Cause
As described in the issue:
yy.CreateTable.prototype.execute(src/60createtable.js) handles the constraint typesPRIMARY KEY,CHECK,UNIQUEandFOREIGN KEY. The parser already produces{type: 'INDEX', indexid, columns, prefixes}for an inline index, and execution skipped it.Change
A new
INDEXbranch in the constraint loop registers the index the wayCREATE INDEXregisters a non-unique index:table.inddefs[name],table.indices[hh]anddb.indices[name]. INSERT then keeps it up to date through the existinginddefsloop intable.insert.The key expression is built the same way
CREATE INDEXbuilds it. A plain column goes throughyy.Column#toJS(r['a']). A column with a prefix length (#2606) goes throughcolumnPrefixToJS. SoINDEX k (a, b(2))insideCREATE TABLEgives exactly the sameinddefsentry and hash asCREATE INDEX k ON t (a, b(2)). The tests check this.No grammar or generated parser changes.
Tests
test/test2607.js:SHOW INDEXlists the index, anddb.indicesandtable.inddefscontain it.CREATE TABLEare found through the index.CREATE INDEXon an identical table.PRIMARY KEYin oneCREATE TABLE. Both indexes are created and the primary key is still enforced.Results:
bun test ./test/test2607.jsagainst the unchangedsrc/60createtable.js: 0 pass, 4 fail.bun test ./test/test2607.jswith this change: 4 pass, 0 fail.yarn test-only(full suite, aftersh build.sh): 2283 pass, 213 skip, 0 fail. Ondevelop(c9e3b53) before the change: 2279 pass, 213 skip, 0 fail.prettier --list-differenton both changed files: clean.I did not run
yarn test-browser.This does not touch
queryfn3, so it is independent of #2582.Note: I used Claude Code to help investigate this issue and draft the change and tests. I reviewed the result, checked that the new tests fail without the fix, and ran the checks above locally.
🤖 Generated with Claude Code