Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Complex Parsing of Functions #1200

Merged
merged 5 commits into from
May 26, 2021

Conversation

manticore-projects
Copy link
Contributor

@manticore-projects manticore-projects commented May 20, 2021

This PR will determine the nested brackets "(" ")" and configure the Parser in order to parse Complex Function Parameters like to_char( a = b) and Named Function Parameters like trim(BOTH ' ' from 'foo bar ') ONLY WHEN the level of nesting functions is below a threshold = 7. Although this is a configurable Parser Feature.

This massively speeds up the parser. The whole NestedBracketsPerformanceTest Suite takes less than 3 seconds now, with 50! iterations for the concat test.

At the same time we can parse Complex Expression Parameters for all Functions (but only when there is no deep recursion of more than 9 levels although this detail is mood because it would not work in anyway because of the slowdown).

Fixes issues #1190 #1103

This is a CLEAN PR handcrafted against the latest Upstream MASTER, containing only the minimal changes.

@manticore-projects
Copy link
Contributor Author

LOL! The CI server is too slow for the performance test timeouts.

@coveralls
Copy link

coveralls commented May 20, 2021

Coverage Status

Coverage increased (+0.001%) to 88.531% when pulling cb1cb16 on manticore-projects:AllowComplexParsingClean into a5204f6 on JSQLParser:master.

@wumpz
Copy link
Member

wumpz commented May 25, 2021

Building an upper boundary is quite a good idea. Could you please resolve the conflicts. I already merged your case when pr. My first changes for adaption the ValuesStatement are included as well. Maybe we could skip those MultiExpressionLists, because they are handles now by SimpleExpressonLists as well.

…plexParsingClean

Conflicts:
	src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
	src/test/java/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.java
	src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
@manticore-projects
Copy link
Contributor Author

Merged the latest Master Branch.

@wumpz wumpz merged commit 3a5da44 into JSQLParser:master May 26, 2021
@wumpz
Copy link
Member

wumpz commented May 26, 2021

So could you somehow better document, how the nesting depth is calculated or modified?

@wumpz
Copy link
Member

wumpz commented May 26, 2021

BTW I check your modifications. Since complex parsing is now allowed for functions I removed FunctionWithCondParams. But now your depth of seven is not enough for multiple tests. Unfortunately I have problems for accepting one test.

@manticore-projects
Copy link
Contributor Author

So could you somehow better document, how the nesting depth is calculated or modified?

It is a simple count of the maximum Open Bracket (. If there are more than 7 Open Brackets we assume deep nesting and do not allow complex parsing.

BTW I check your modifications. Since complex parsing is now allowed for functions I removed FunctionWithCondParams. But now your depth of seven is not enough for multiple tests. Unfortunately I have problems for accepting one test.

Out of my head, I foresee a situation where you have a deep nesting on a function (without complex expressions) and one complex expression somewhere else (without deep nesting). That would fail because Complex Parsing and Deep Nesting are now mutual exclusive.

However, I kept experimenting when addressing the CASE WHEN expressions.
Instead of counting the Open Brackets, we can define a Nested Expression Counter in the Grammar File and increment it when ever we enter a Primary Expression and decrement it whenever we leave a Primary Expression. If this worked we would have much better granularity on when to give up Complex Parsing.

Please let me know your particular failing test case and I will have a look at it promptly.

@manticore-projects
Copy link
Contributor Author

@wumpz: You have modified the Brackets Threshold for Complex Parsing from 7 to 10. Unfortunately, the 7 has been selected for a purpose:

old duration 1565 new duration time 6873 for SELECT concat(concat(concat(concat(concat(concat(concat(concat(concat('A','B'),'B'),'B'),'B'),'B'),'B'),'B'),'B'),'B') FROM mytbl

It is the point when the performance impact LOOKAHEAD amplifies too much. This was also the reason why I have had defined timeout for the unit tests and I would like to recommend to leave it at 2000 and not to accept any change that breaks these constraints again. (2 seconds for parsing 1 single statement is too much already).

So, can we set the Threshold back to 7 again please? I am still working on a more fine granular solution, where the nesting is determined as per expression.

@wumpz
Copy link
Member

wumpz commented Jun 2, 2021

Understand. The problem is, you are calculating the "complexity" of a statement via running through the parenthesis. So you are taking parenthesises into account that have nothing to do with complex expressions. Somehow we should count the deepness within the productions. I don't know, if that is even possible and limit there to a level of 7 or 10.

@manticore-projects
Copy link
Contributor Author

manticore-projects commented Jun 2, 2021 via email

@wumpz
Copy link
Member

wumpz commented Jun 2, 2021

Critics acknowledged. I try to improve.

@wumpz
Copy link
Member

wumpz commented Jun 2, 2021

Does this case counting work for lookaheads as well? If I remember right, this case deepness was never checked, or am I wrong?

@manticore-projects
Copy link
Contributor Author

manticore-projects commented Jun 2, 2021 via email

@manticore-projects manticore-projects deleted the AllowComplexParsingClean branch November 28, 2021 07:44
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.

None yet

3 participants