Skip to content

avoid quadratic string concatenation in FullTextSearch.toString - #2859

Open
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:fulltextsearch-tostring-linear
Open

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:fulltextsearch-tostring-linear

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor
  1. FullTextSearch.toString builds the MATCH column list with String += inside the loop, so every column copies the whole list built so far. The grammar's ColumnList puts no limit on the column count, which makes Statement.toString() on a parsed SELECT * FROM t WHERE MATCH (c0,c1,...,cN) AGAINST ('x') quadratic in N, and the parser timeout does not cover deparsing.
  2. Switched to a StringBuilder, the same way ExpressionDeParser.visit(FullTextSearch) already builds it. Output does not change.

On a 1.1 MB statement (160k columns), CCJSqlParserUtil.parse takes about 0.4 s both before and after. toString drops from 6.8 s to 25 ms (548 KB: 1.85 s to 16 ms). The new test renders 200k columns under a 2 second preemptive timeout. It times out before the change and passes after. ./gradlew check is green.

This branch has not been deployed

No deployments
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