This is an automated email from the ASF dual-hosted git repository. alexpl pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new f1af53169cb IGNITE-22738 Sql: Fix nested subquery optimization - Fixes #11437. f1af53169cb is described below commit f1af53169cbd068b8ec4266a5754d42728d9a17e Author: Aleksey Plekhanov <plehanov.a...@gmail.com> AuthorDate: Wed Jul 24 18:20:13 2024 +0300 IGNITE-22738 Sql: Fix nested subquery optimization - Fixes #11437. Signed-off-by: Aleksey Plekhanov <plehanov.a...@gmail.com> --- .../processors/query/h2/GridSubqueryJoinOptimizer.java | 6 ++++-- .../query/h2/GridSubqueryJoinOptimizerSelfTest.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizer.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizer.java index 875284dd631..c3ca1376a93 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizer.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizer.java @@ -412,8 +412,10 @@ public class GridSubqueryJoinOptimizer { remapColumns( parent, subSel, - // reference equality used intentionally here - col -> wrappedSubQry == col.expressionInFrom(), + // In case of several nested subqueries, inner subqueries are wrapped into alias of outer subqueries, + // to check column belonging correctly we should unwrap aliases. + // Reference equality used intentionally here. + col -> GridSqlAlias.unwrap(wrappedSubQry) == GridSqlAlias.unwrap(col.expressionInFrom()), subTbl ); diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizerSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizerSelfTest.java index 5849d1b8aea..9cd984af0c1 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizerSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridSubqueryJoinOptimizerSelfTest.java @@ -953,6 +953,22 @@ public class GridSubqueryJoinOptimizerSelfTest extends GridCommonAbstractTest { } } + /** + * Case when select subquery from another subquery, which is select from another subquery. + */ + @Test + public void testSeveralNestedSubqueries() { + String innerSql = "SELECT id as id0, name as name0 FROM dep"; + String outerSqlTemplate = "SELECT id%d as id%d, name%d as name%d FROM %s WHERE id%d > %d"; + + String curSql = innerSql; + + for (int i = 0; i < 5; i++) { + curSql = String.format(outerSqlTemplate, i, i + 1, i, i + 1, '(' + curSql + ')', i, i); + check(curSql, 1); + } + } + /** * @param sql Sql. * @param expSelectClauses Expected select clauses.