-
Notifications
You must be signed in to change notification settings - Fork 25k
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
SQL: Fix wrong appliance of StackOverflow limit for IN #36724
Conversation
Pinging @elastic/es-search |
00bb58e
to
73a1e1c
Compare
Fix grammar so that each element inside the list of values for IN is a `valueExpression` and not a more generic `expression`. Also change some names in the grammar so that they match the primary rule name plus "Default". This helps so that the decrement of depth counts in the Parser's `CircuitBreakerListener` works correctly. For the list of values for `IN` don't count the `PrimaryExpressionContext` as this is not visited on exit due to the peculiarity in our gramamr with the `predicate` and `predicated`. Fixes: elastic#36592
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left few minor comments.
|
||
// Skip PrimaryExpressionContext for IN as it's not visited on exit due to | ||
// the grammar's peculiarity rule with "predicated" and "predicate". | ||
// Also skip the Identifiers as they are "cheap". | ||
if (ctx.getClass() != SqlBaseParser.UnquoteIdentifierContext.class && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you import static
all these classes to make the code a bit less crowded?
|
||
// Avoid having negative numbers | ||
if (depthCounts.containsKey(classNameToDecrement)) { | ||
depthCounts.putOrAdd(classNameToDecrement, (short) 0, (short) -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the scenario of negative counter even possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because currently some rules are not encountered on enter but only on exit.
I'll open an issue soon to track this and investigate more.
@@ -254,6 +261,40 @@ public void testLimitToPreventStackOverflowFromLargeComplexSubselectTree() { | |||
e.getMessage()); | |||
} | |||
|
|||
public void testLimitStackOverflowForInAndLiteralsIsNotApplied() { | |||
new SqlParser().createStatement("SELECT * FROM t WHERE a IN(" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the parser being invoked is enough here? Can you check that at least that a minimal plan is created correctly given the query? Also, there is already a method that creates the statement given a query String: parseStatement(String)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is only to check that we don't hit the limit, but I can add more assertions.
run the gradle build tests 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
run the gradle build tests 2 |
1 similar comment
run the gradle build tests 2 |
run the gradle build tests 1 |
run the gradle build tests 2 |
Fix grammar so that each element inside the list of values for IN is a valueExpression and not a more generic expression. Introduce a mapping for context names as some rules in the grammar are exited with a different rule from the one they entered.This helps so that the decrement of depth counts in the Parser's CircuitBreakerListener works correctly. For the list of values for IN, don't count the PrimaryExpressionContext as this is not visited on exitRule() due to the peculiarity in our gramamr with the predicate and predicated. Fixes: #36592
Backported to |
Fix grammar so that each element inside the list of values for IN is a valueExpression and not a more generic expression. Introduce a mapping for context names as some rules in the grammar are exited with a different rule from the one they entered.This helps so that the decrement of depth counts in the Parser's CircuitBreakerListener works correctly. For the list of values for IN, don't count the PrimaryExpressionContext as this is not visited on exitRule() due to the peculiarity in our gramamr with the predicate and predicated. Fixes: #36592
Backported to |
* elastic/master: (31 commits) enable bwc tests and switch transport serialization version to 6.6.0 for CAS features [DOCs] Adds ml-cpp PRs to alpha release notes (elastic#36790) Synchronize WriteReplicaResult callbacks (elastic#36770) Add CcrRestoreSourceService to track sessions (elastic#36578) [Painless] Add tests for boxed return types (elastic#36747) Internal: Remove originalSettings from Node (elastic#36569) [ILM][DOCS] Update ILM API authorization docs (elastic#36749) Core: Deprecate use of scientific notation in epoch time parsing (elastic#36691) [ML] Merge the Jindex master feature branch (elastic#36702) Tests: Mute SnapshotDisruptionIT.testDisruptionOnSnapshotInitialization Update versions in SearchSortValues transport serialization Update version in SearchHits transport serialization [Geo] Integrate Lucene's LatLonShape (BKD Backed GeoShapes) as default `geo_shape` indexing approach (elastic#36751) [Docs] Fix error in Common Grams Token Filter (elastic#36774) Fix rollup search statistics (elastic#36674) SQL: Fix wrong appliance of StackOverflow limit for IN (elastic#36724) [TEST] Added more logging Invalidate Token API enhancements - HLRC (elastic#36362) Deprecate types in index API (elastic#36575) Disable bwc tests until elastic#36555 backport is complete (elastic#36737) ...
Fix grammar so that each element inside the list of values for IN
is a
valueExpression
and not a more genericexpression
. Introduce amapping for context names as some rules in the grammar are exited with
a different rule from the one they entered.This helps so that the decrement
of depth counts in the Parser's
CircuitBreakerListener
works correctly.For the list of values for
IN
, don't count thePrimaryExpressionContext
as this is not visited onexitRule()
due tothe peculiarity in our gramamr with the
predicate
andpredicated
.Fixes: #36592