Skip to content

avoid quadratic positional access over linked-list column lists - #2860

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:linkedlist-positional-deparse
Oct 27, 2026
Merged

manticore-projects merged 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:linkedlist-positional-deparse

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

Select.appendStringListTo builds a comma-separated list by reading its argument positionally with list.get(i). Join stores its USING columns in a LinkedList, so deparsing SELECT ... JOIN ... USING (c0, ..., cN) through Join.toString is O(N^2), and the USING column list has no bound in the grammar. Parsing a 200k-column clause and then calling Statement.toString does not finish within 5 s here, against about 55 ms after the change, and the parser timeout does not cover deparsing. ConnectExpressionsVisitor has the same shape: it connects the select items it collected into a LinkedList by indexing them with get(i) in a loop, so joining a select with many items is quadratic too. Both now walk the list once with an iterator instead of by index; the deparsed text and the built expression tree are unchanged. I added regression tests over 200k elements under a 5 s preemptive timeout, which hang before the change and pass after.

@manticore-projects
manticore-projects merged commit cfedd31 into JSQLParser:master Oct 27, 2026
9 of 10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

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.

2 participants