Repository navigation
Rebuild key indexes after table.data is assigned directly to close #2715 - #2956
Open
TheeCoderAhmed wants to merge 1 commit into
Open
TheeCoderAhmed wants to merge 1 commit into
TheeCoderAhmed wants to merge 1 commit into
Conversation
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.
Fixes #2715
After assigning
alasql.tables.t.dataon a table with a PRIMARY KEY or UNIQUE key, the key index still describes the old rows. INSERT stores a duplicate key and DELETE throwsSomething wrong with primary key index on table. UPDATE already worked, because it rebuilds the index when a key is missing.table.insert,table.deleteandtable.updatenow all callsyncKeyIndexesbefore they use a key index. It comparestable.datawith the array the indexes were last built from, and rebuilds them if the array has been replaced. The rebuild moved into a smallrebuildKeyIndexhelper, and UPDATE's existing rebuild on a missing key now uses it too, so rows pushed onto the same array still work there.Other things to check in review:
DELETE ... WHEREandTRUNCATEalso replacetable.data, so the next statement on that table does one rebuild, which is O(n). ADELETE ... WHEREalready walks every row, so I do not expect this to matter, but I did not runtest-perf.TRUNCATEleft its old keys in the index, so inserting a key again after it failed. The same check fixes this, andtest2715.jshas a case for it.table.data, so I left that as it is.What I ran:
bun test --preload ./test/bun-setup.js ./test/test2715.js: 6 of the 7 cases failed before the source change (Missing expected exception,Something wrong with primary key index on table). All 7 pass after it.bun test --dots --preload ./test/bun-setup.js ./test/test[0-9]*.jsaftersh build.sh: 2550 pass, 213 skip, 0 failprettier --checkon the two changed files: cleanI did not run the browser test suite,
test-perfor the older Node versions in CI.