This is an automated email from the ASF dual-hosted git repository. dlych pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push: new 6dc0f84 [NO ISSUE][COMP] No subquery coercion in EXISTS clause 6dc0f84 is described below commit 6dc0f84985fde15017d14b316db2ce2c590c3e15 Author: Dmitry Lychagin <dmitry.lycha...@couchbase.com> AuthorDate: Fri Nov 19 14:30:16 2021 -0800 [NO ISSUE][COMP] No subquery coercion in EXISTS clause - user model changes: no - storage format changes: no - interface changes: no Details: - In SQL-compat mode do not perform subquery coecrion if the subquery is in EXISTS or NOT EXISTS clause - Add testscases Change-Id: If4ae567fc449e5fa6bb040555325f429e8953256 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/14145 Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Dmitry Lychagin <dmitry.lycha...@couchbase.com> Reviewed-by: Ali Alsuliman <ali.al.solai...@gmail.com> --- .../subquery_coercion_08_misc.1.query.sqlpp} | 2 +- .../subquery_coercion_08_misc.2.query.sqlpp} | 4 ++-- .../subquery_coercion_08_misc.3.query.sqlpp} | 7 +++---- .../subquery_coercion_08_misc.4.query.sqlpp} | 7 +++---- .../subquery_coercion_08_misc.1.adm} | 0 .../subquery_coercion_08_misc.2.adm | 3 +++ .../subquery_coercion_08_misc.3.adm | 2 ++ .../subquery_coercion_08_misc.4.adm | 1 + .../src/test/resources/runtimets/testsuite_sqlpp.xml | 5 +++++ .../rewrites/visitor/SqlCompatRewriteVisitor.java | 18 +++++++++++++++++- 10 files changed, 37 insertions(+), 12 deletions(-) diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.1.query.sqlpp similarity index 96% copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.1.query.sqlpp index 833d06e..689d5d5 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.1.query.sqlpp @@ -20,7 +20,7 @@ /* * SQL-compat mode. * Test no subquery coercion if the subquery is in the IN clause - * of a quantified expression + * of a quantified expression (SOME) */ // requesttype=application/json diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.2.query.sqlpp similarity index 89% copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.2.query.sqlpp index 833d06e..c96057e 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.2.query.sqlpp @@ -20,7 +20,7 @@ /* * SQL-compat mode. * Test no subquery coercion if the subquery is in the IN clause - * of a quantified expression + * of a quantified expression (EVERY) */ // requesttype=application/json @@ -28,5 +28,5 @@ select r2.r1 from (select r1 from range(1, 3) r1) r2 -where some r3 in (select r4 from range(0, 2) r4) satisfies r3.r4 = r2.r1 +where every r3 in (select r4 from range(r2.r1, r2.r1) r4) satisfies r3.r4 = r2.r1 order by r2.r1; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.3.query.sqlpp similarity index 80% copy from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp copy to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.3.query.sqlpp index 833d06e..01b1b40 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.3.query.sqlpp @@ -19,14 +19,13 @@ /* * SQL-compat mode. - * Test no subquery coercion if the subquery is in the IN clause - * of a quantified expression + * Test no subquery coercion if the subquery is in the EXISTS clause */ // requesttype=application/json // param sql-compat:json=true -select r2.r1 +select r2.r1, (select value { "a": r4, "b": r4 + 1 } from range(2, r2.r1) r4) x from (select r1 from range(1, 3) r1) r2 -where some r3 in (select r4 from range(0, 2) r4) satisfies r3.r4 = r2.r1 +where exists (select r4 a, r4 + 1 b from range(2, r2.r1) r4) -- 0, 1, or 2 tuples order by r2.r1; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.4.query.sqlpp similarity index 80% rename from asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp rename to asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.4.query.sqlpp index 833d06e..6709b34 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.query.sqlpp +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.4.query.sqlpp @@ -19,14 +19,13 @@ /* * SQL-compat mode. - * Test no subquery coercion if the subquery is in the IN clause - * of a quantified expression + * Test no subquery coercion if the subquery is in the NOT EXISTS clause */ // requesttype=application/json // param sql-compat:json=true -select r2.r1 +select r2.r1, (select value { "a": r4, "b": r4 + 1 } from range(2, r2.r1) r4) x from (select r1 from range(1, 3) r1) r2 -where some r3 in (select r4 from range(0, 2) r4) satisfies r3.r4 = r2.r1 +where not exists (select r4 a, r4 + 1 b from range(2, r2.r1) r4) -- 0, 1, or 2 tuples order by r2.r1; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.1.adm similarity index 100% rename from asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_07_from/subquery_coercion_07_from.4.adm rename to asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.1.adm diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.2.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.2.adm new file mode 100644 index 0000000..572906d --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.2.adm @@ -0,0 +1,3 @@ +{ "r1": 1 } +{ "r1": 2 } +{ "r1": 3 } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.3.adm new file mode 100644 index 0000000..6cd767c --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.3.adm @@ -0,0 +1,2 @@ +{ "r1": 2, "x": [ { "a": 2, "b": 3 } ] } +{ "r1": 3, "x": [ { "a": 2, "b": 3 }, { "a": 3, "b": 4 } ] } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.4.adm new file mode 100644 index 0000000..82978d9 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/sql-compat/subquery_coercion_08_misc/subquery_coercion_08_misc.4.adm @@ -0,0 +1 @@ +{ "r1": 1, "x": [ ] } \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index b992c4c..cca0d63 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -10222,6 +10222,11 @@ <output-dir compare="Text">subquery_coercion_07_from</output-dir> </compilation-unit> </test-case> + <test-case FilePath="sql-compat"> + <compilation-unit name="subquery_coercion_08_misc"> + <output-dir compare="Text">subquery_coercion_08_misc</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="statement-params"> <test-case FilePath="statement-params"> diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlCompatRewriteVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlCompatRewriteVisitor.java index 0c6732d..1b44377 100644 --- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlCompatRewriteVisitor.java +++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/rewrites/visitor/SqlCompatRewriteVisitor.java @@ -36,6 +36,7 @@ import org.apache.asterix.lang.common.expression.ListConstructor; import org.apache.asterix.lang.common.expression.LiteralExpr; import org.apache.asterix.lang.common.expression.OperatorExpr; import org.apache.asterix.lang.common.expression.QuantifiedExpression; +import org.apache.asterix.lang.common.expression.UnaryExpr; import org.apache.asterix.lang.common.expression.VariableExpr; import org.apache.asterix.lang.common.literal.IntegerLiteral; import org.apache.asterix.lang.common.rewrites.LangRewritingContext; @@ -72,7 +73,8 @@ import org.apache.hyracks.api.exceptions.SourceLocation; * <ol> * <li> FROM/JOIN/UNNEST (subquery) --> no subquery coercion * <li> WITH/LET v = (subquery) --> no subquery coercion - * <li> SOME v IN (subquery) --> no subquery coercion + * <li> SOME/EVERY v IN (subquery) --> no subquery coercion + * <li> [NOT] EXISTS (subquery) --> no subquery coercion * <li> WHERE (x,y) = (subquery) --> coerce the subquery into a single array * <li> WHERE x IN (subquery) --> coerce the subquery into a collection of values * <li> WHERE (x,y) IN (subquery) --> coerce the subquery into a collection of arrays @@ -185,6 +187,20 @@ public final class SqlCompatRewriteVisitor extends AbstractSqlppSimpleExpression } @Override + public Expression visit(UnaryExpr u, ILangExpression arg) throws CompilationException { + switch (u.getExprType()) { + case EXISTS: + case NOT_EXISTS: + Expression expr = u.getExpr(); + if (expr.getKind() == Expression.Kind.SELECT_EXPRESSION) { + annotateSubqueryNoCoercion((SelectExpression) expr); + } + break; + } + return super.visit(u, arg); + } + + @Override public Expression visit(SelectExpression selectExpr, ILangExpression arg) throws CompilationException { SqlCompatSelectExpressionCoercionAnnotation selectExprAnn = null; if (selectExpr.isSubquery()) {