Skip to content

fix(restore): eliminate O(N^2) linear scan in getTableListByPatternLocal#1430

Open
ruslanen wants to merge 1 commit into
Altinity:masterfrom
ruslanen:fix/restore-tablelist-o-n2
Open

fix(restore): eliminate O(N^2) linear scan in getTableListByPatternLocal#1430
ruslanen wants to merge 1 commit into
Altinity:masterfrom
ruslanen:fix/restore-tablelist-o-n2

Conversation

@ruslanen

Copy link
Copy Markdown

addTableToListIfNotExistsOrEnrichQueryAndParts iterated the full result slice for every file processed during filepath.Walk. With 550K tables this produced N*(N-1)/2 ~ 151 billion string comparisons (~2 hours).

Fix: maintain a tableIndex map[TableTitle]int alongside the result slice. Lookup and enrich are now O(1); total restore init phase drops from O(N^2) to O(N). The inline addToResult closure replaces the two local call sites; the original function is kept for the remote-restore path which operates on far fewer tables in practice.

addTableToListIfNotExistsOrEnrichQueryAndParts iterated the full result
slice for every file processed during filepath.Walk. With 550K tables
this produced N*(N-1)/2 ~ 151 billion string comparisons (~2 hours).

Fix: maintain a tableIndex map[TableTitle]int alongside the result slice.
Lookup and enrich are now O(1); total restore init phase drops from O(N^2)
to O(N). The inline addToResult closure replaces the two local call sites;
the original function is kept for the remote-restore path which operates on
far fewer tables in practice.
@ruslanen ruslanen force-pushed the fix/restore-tablelist-o-n2 branch from a806ef5 to 5964ab7 Compare June 19, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant