Repository navigation
Avoid quadratic rescans when deduplicating query column names - #913
Open
workstonedai-collab wants to merge 1 commit into
Open
workstonedai-collab wants to merge 1 commit into
workstonedai-collab 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.
The change
Optimize
sqlite_utils.utils.dedupe_keysby caching the next suffix to try for each repeated original key. This avoids repeatedly scanning already-reserved suffixes when many duplicate column names occur.The implementation preserves the existing behavior for duplicate aliases and adds coverage for generator inputs, repeated suffix bases, and a scaling regression.
Closes #912: #912
Before
The previous implementation restarted suffix search at
_2for every duplicate key. For a large number of duplicate names, this repeatedly formatted and checked suffixes that had already been rejected.After
The implementation remembers the next suffix for each repeated base key and continues from there. Candidate names are still checked against both existing names and names reserved by the original input, so the result remains unique.
Testing
The following results were reported for this change:
1501 passed, 16 skipped74 passedmypyover 10 source files: passed1,999,000format calls, exceeding the budget of2,000; the new implementation passes.The synthetic benchmark reported these medians over 5 runs on Python 3.12, macOS arm64:
These are helper microbenchmarks for
dedupe_keys, not end-to-end database performance measurements.Independent equivalence check: all 19,531 sequences of length 0–6 over
id,id_2,id_3,id_2_2, andxmatched the frozen baseline exactly.AI assistance: MiniMax-M3.1-Flash implemented the optimization, tests and benchmark, including repairs after test feedback. Codex reviewed the diff and ran the listed validation.
📚 Documentation preview 📚: https://sqlite-utils--913.org.readthedocs.build/en/913/