[jira] [Updated] (CALCITE-6193) SubstitutionVisitor stop trying incorrect subtree because of wrong parent relationship when replace query

2024-01-08 Thread Julian Hyde (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6193?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Julian Hyde updated CALCITE-6193:
-
Fix Version/s: 1.37.0

> SubstitutionVisitor stop trying incorrect subtree because of wrong parent 
> relationship when replace query
> -
>
> Key: CALCITE-6193
> URL: https://issues.apache.org/jira/browse/CALCITE-6193
> Project: Calcite
>  Issue Type: Bug
>Reporter: Mou Wu
>Assignee: Mou Wu
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.37.0
>
>
> {code:java}
> @Test void testStopTryIncorrectSubtree() {
>   final String mv = ""
>   + "select \"empid\", \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"empid\", \"deptno\"";
>   final String query = ""
>   + "select t1.\"deptno\"\n"
>   + "from (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "union all\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t1 inner join (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t2 on t1.\"deptno\" = t2.\"deptno\"\n";
>   sql(mv, query)
>   .checkingThatResultContains(""
>   + "LogicalCalc(expr#0..1=[{inputs}], deptno=[$t0])\n"
>   + "  LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n"
>   + "LogicalUnion(all=[true])\n"
>   + "  LogicalCalc(expr#0..4=[{inputs}], expr#5=[1000], 
> expr#6=[>($t3, $t5)], deptno=[$t1], $condition=[$t6])\n"
>   + "LogicalTableScan(table=[[hr, emps]])\n"
>   + "  LogicalAggregate(group=[{1}])\n"
>   + "EnumerableTableScan(table=[[hr, MV0]])\n"
>   + "LogicalAggregate(group=[{1}])\n"
>   + "  EnumerableTableScan(table=[[hr, MV0]])"
>   ).ok();
> }{code}
> The test case above will fail because the second mv0 not be matched.
> The root cause is that SubstitutionVisitor replace child nodes with 
> targetDescendant node itself, not a deep-copy replica, so they may share the 
> same node and the same parent node, thus the incorrect parent relationship 
> may occur, it will make stopTrying be wrong.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (CALCITE-6193) SubstitutionVisitor stop trying incorrect subtree because of wrong parent relationship when replace query

2024-01-08 Thread ASF GitHub Bot (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6193?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated CALCITE-6193:

Labels: pull-request-available  (was: )

> SubstitutionVisitor stop trying incorrect subtree because of wrong parent 
> relationship when replace query
> -
>
> Key: CALCITE-6193
> URL: https://issues.apache.org/jira/browse/CALCITE-6193
> Project: Calcite
>  Issue Type: Bug
>Reporter: Mou Wu
>Assignee: Mou Wu
>Priority: Major
>  Labels: pull-request-available
>
> {code:java}
> @Test void testStopTryIncorrectSubtree() {
>   final String mv = ""
>   + "select \"empid\", \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"empid\", \"deptno\"";
>   final String query = ""
>   + "select t1.\"deptno\"\n"
>   + "from (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "union all\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t1 inner join (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t2 on t1.\"deptno\" = t2.\"deptno\"\n";
>   sql(mv, query)
>   .checkingThatResultContains(""
>   + "LogicalCalc(expr#0..1=[{inputs}], deptno=[$t0])\n"
>   + "  LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n"
>   + "LogicalUnion(all=[true])\n"
>   + "  LogicalCalc(expr#0..4=[{inputs}], expr#5=[1000], 
> expr#6=[>($t3, $t5)], deptno=[$t1], $condition=[$t6])\n"
>   + "LogicalTableScan(table=[[hr, emps]])\n"
>   + "  LogicalAggregate(group=[{1}])\n"
>   + "EnumerableTableScan(table=[[hr, MV0]])\n"
>   + "LogicalAggregate(group=[{1}])\n"
>   + "  EnumerableTableScan(table=[[hr, MV0]])"
>   ).ok();
> }{code}
> The test case above will fail because the second mv0 not be matched.
> The root cause is that SubstitutionVisitor replace child nodes with 
> targetDescendant node itself, not a deep-copy replica, so they may share the 
> same node and the same parent node, thus the incorrect parent relationship 
> may occur, it will make stopTrying be wrong.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (CALCITE-6193) SubstitutionVisitor stop trying incorrect subtree because of wrong parent relationship when replace query

2024-01-08 Thread Mou Wu (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6193?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mou Wu updated CALCITE-6193:

Description: 
{code:java}
@Test void testStopTryIncorrectSubtree() {
  final String mv = ""
  + "select \"empid\", \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "group by \"empid\", \"deptno\"";
  final String query = ""
  + "select t1.\"deptno\"\n"
  + "from (\n"
  + "select \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "union all\n"
  + "select \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "group by \"deptno\"\n"
  + ") as t1 inner join (\n"
  + "select \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "group by \"deptno\"\n"
  + ") as t2 on t1.\"deptno\" = t2.\"deptno\"\n";
  sql(mv, query)
  .checkingThatResultContains(""
  + "LogicalCalc(expr#0..1=[{inputs}], deptno=[$t0])\n"
  + "  LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n"
  + "LogicalUnion(all=[true])\n"
  + "  LogicalCalc(expr#0..4=[{inputs}], expr#5=[1000], 
expr#6=[>($t3, $t5)], deptno=[$t1], $condition=[$t6])\n"
  + "LogicalTableScan(table=[[hr, emps]])\n"
  + "  LogicalAggregate(group=[{1}])\n"
  + "EnumerableTableScan(table=[[hr, MV0]])\n"
  + "LogicalAggregate(group=[{1}])\n"
  + "  EnumerableTableScan(table=[[hr, MV0]])"
  ).ok();
}{code}
The test case above will fail because the second mv0 not be matched.

The root cause is that SubstitutionVisitor replace child nodes with 
targetDescendant node itself, not a deep-copy replica, so they may share the 
same node and the same parent node, thus the incorrect parent relationship may 
occur, it will make stopTrying be wrong.

  was:
{code:java}
@Test void testStopTryIncorrectSubtree() {
  final String mv = ""
  + "select \"empid\", \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "group by \"empid\", \"deptno\"";
  final String query = ""
  + "select t1.\"deptno\"\n"
  + "from (\n"
  + "select \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "union all\n"
  + "select \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "group by \"deptno\"\n"
  + ") as t1 inner join (\n"
  + "select \"deptno\"\n"
  + "from \"emps\"\n"
  + "where \"salary\" > 1000\n"
  + "group by \"deptno\"\n"
  + ") as t2 on t1.\"deptno\" = t2.\"deptno\"\n";
  sql(mv, query)
  .checkingThatResultContains(""
  + "LogicalCalc(expr#0..1=[{inputs}], deptno=[$t0])\n"
  + "  LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n"
  + "LogicalUnion(all=[true])\n"
  + "  LogicalCalc(expr#0..4=[{inputs}], expr#5=[1000], 
expr#6=[>($t3, $t5)], deptno=[$t1], $condition=[$t6])\n"
  + "LogicalTableScan(table=[[hr, emps]])\n"
  + "  LogicalAggregate(group=[{1}])\n"
  + "EnumerableTableScan(table=[[hr, MV0]])\n"
  + "LogicalAggregate(group=[{1}])\n"
  + "  EnumerableTableScan(table=[[hr, MV0]])"
  ).ok();
}{code}
The test case above will fail because the second mv0 not be matched.

The root cause is that SubstitutionVisitor replace child nodes with 
targetDescendant node itself, not a deep-copy replica, so they may share the 
same node and the same parent node, so the incorrect parent relationship may 
occur, it will make stopTrying be wrong.


> SubstitutionVisitor stop trying incorrect subtree because of wrong parent 
> relationship when replace query
> -
>
> Key: CALCITE-6193
> URL: https://issues.apache.org/jira/browse/CALCITE-6193
> Project: Calcite
>  Issue Type: Bug
>Reporter: Mou Wu
>Assignee: Mou Wu
>Priority: Major
>
> {code:java}
> @Test void testStopTryIncorrectSubtree() {
>   final String mv = ""
>   + "select \"empid\", \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"empid\", \"deptno\"";
>   final String query = ""
>   + "select t1.\"deptno\"\n"
>   + "from (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "union all\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t1 inner join (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t2 on t1.\"deptno\" = t2.\"deptno\"\

[jira] [Updated] (CALCITE-6193) SubstitutionVisitor stop trying incorrect subtree because of wrong parent relationship when replace query

2024-01-08 Thread Mou Wu (Jira)


 [ 
https://issues.apache.org/jira/browse/CALCITE-6193?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mou Wu updated CALCITE-6193:

Summary: SubstitutionVisitor stop trying incorrect subtree because of wrong 
parent relationship when replace query  (was: SubstitutionVisitor stop trying 
incorrect subtree because wrong parent relationship when replace query)

> SubstitutionVisitor stop trying incorrect subtree because of wrong parent 
> relationship when replace query
> -
>
> Key: CALCITE-6193
> URL: https://issues.apache.org/jira/browse/CALCITE-6193
> Project: Calcite
>  Issue Type: Bug
>Reporter: Mou Wu
>Assignee: Mou Wu
>Priority: Major
>
> {code:java}
> @Test void testStopTryIncorrectSubtree() {
>   final String mv = ""
>   + "select \"empid\", \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"empid\", \"deptno\"";
>   final String query = ""
>   + "select t1.\"deptno\"\n"
>   + "from (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "union all\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t1 inner join (\n"
>   + "select \"deptno\"\n"
>   + "from \"emps\"\n"
>   + "where \"salary\" > 1000\n"
>   + "group by \"deptno\"\n"
>   + ") as t2 on t1.\"deptno\" = t2.\"deptno\"\n";
>   sql(mv, query)
>   .checkingThatResultContains(""
>   + "LogicalCalc(expr#0..1=[{inputs}], deptno=[$t0])\n"
>   + "  LogicalJoin(condition=[=($0, $1)], joinType=[inner])\n"
>   + "LogicalUnion(all=[true])\n"
>   + "  LogicalCalc(expr#0..4=[{inputs}], expr#5=[1000], 
> expr#6=[>($t3, $t5)], deptno=[$t1], $condition=[$t6])\n"
>   + "LogicalTableScan(table=[[hr, emps]])\n"
>   + "  LogicalAggregate(group=[{1}])\n"
>   + "EnumerableTableScan(table=[[hr, MV0]])\n"
>   + "LogicalAggregate(group=[{1}])\n"
>   + "  EnumerableTableScan(table=[[hr, MV0]])"
>   ).ok();
> }{code}
> The test case above will fail because the second mv0 not be matched.
> The root cause is that SubstitutionVisitor replace child nodes with 
> targetDescendant node itself, not a deep-copy replica, so they may share the 
> same node and the same parent node, so the incorrect parent relationship may 
> occur, it will make stopTrying be wrong.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)