Repository navigation
Run the subqueries of a where query before MongoDB and Neo4j compare with them - #16824
Closed
borinquenkid wants to merge 10 commits into
Closed
borinquenkid wants to merge 10 commits into
borinquenkid wants to merge 10 commits into
Conversation
…with them
A where query such as Person.where { age > avg(age) } puts a DetachedCriteria
in the comparison. MongoDB and Neo4j compared against that object and matched
no rows. Query.resolveSubqueries runs the subqueries first and returns a copy
of the criteria holding their results, so the query is correct and runs the
subquery again on every execution. Comparisons take the single value of the
subquery, in and notIn take every row, and exists, notExists and the all and
some forms throw an InvalidDataAccessResourceUsageException that names the
form.
Fixes #16809
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
…te-subquery-8.0.x
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16809
Stacked on #16823 (chain: #16816, #16817, #16818, #16820, #16821, #16822, #16823).
no ciuntil the chain reaches 8.0.x.Problem
Person.where { age > avg(age) }and the other aggregate subqueries documented forwhereput aDetachedCriteriain the comparison. SQL datastores run it as a subquery. MongoDB and Neo4j compared the property with the criteria object and returned no rows, without an error (the issue reports aMissingMethodExceptionfor some forms).inList/notInagainst a subquery,existsand theall/someforms had the same gap.Changes
Query.resolveSubqueries(Junction)(new, protected,@since 8.0.1) runs each subquery and returns a copy of the criteria that holds the results. The criteria passed in are not changed, so a reusedwherequery runs its subqueries again each time.==,!=,>,>=,<,<=take the one value the subquery returns (an empty result compares withnull);inListtakes every row, andnotInbecomes a negatedinList;exists,notExistsand theall/someforms throwInvalidDataAccessResourceUsageExceptionnaming the form or the property.MongoQuery.executeQueryandNeo4jQuery.executeQuerycall it first.wherereference and upgrade guide section 26.16.Two queries instead of one
$exprpipeline or a Cypher subquery: the result is a snapshot taken when the query runs, which is what awherequery already is on the SQL datastores' first read. A native$expr/CALLtranslation can replace the substitution later without changing behavior.Tests
AggregateSubquerySpecfor MongoDB (12) and Neo4j (9):avgwith>,>=,<,<=, the.of { }closure,max,min,sum,==,!=, negation,||,inList,notIn, the multi-row andexistserrors, and a repeat run that sees new data. All fail without the change (10 of 10 and 7 of 7 when I checked before adding the later cases).grails-data-mongodb-core1036 tests andgrails-data-neo4j-core623, 0 failures;grails-datastore-core348, 0 failures.codeStyle,validateRepositoryConventionsandratpass.Querycode, 43 killed.Not in this PR
$expr/ Cypher translation (see above).countas an aggregate comparison is untested here and not documented.