Skip to content

Commit

Permalink
[ORCA] Avoid pushdown of predicate with set-returning function (#14201)
Browse files Browse the repository at this point in the history
Issue is that if a predicate with a set-returning function is pushed
down then it can lead to bad execution because there exist cases where
the below context cannot accept a set. Logic already existed to prevent
such a case, but it wasn't sufficient.

Following example demonstrates such a case:
  ```sql
  CREATE TABLE t(a int[]) ;
  INSERT INTO t VALUES (ARRAY[1, 2]);

  SELECT * FROM (SELECT unnest(t1.a) a_unnest FROM t t1, t t2) s WHERE a_unnest IS NOT NULL;
  ```

Also similarly, do not push down a filter through a projected column
containing a subquery.
  • Loading branch information
dgkimura authored and leborchuk committed Nov 10, 2024
1 parent 30b8446 commit 4298c29
Show file tree
Hide file tree
Showing 8 changed files with 959 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
<dxl:Plan Id="0" SpaceSize="6">
<dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="862.000682" Rows="1.000000" Width="16"/>
<dxl:Cost StartupCost="0" TotalCost="862.000660" Rows="1.000000" Width="16"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="18" Alias="x">
Expand All @@ -338,14 +338,11 @@
<dxl:SortingColumnList/>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="862.000622" Rows="1.000000" Width="16"/>
<dxl:Cost StartupCost="0" TotalCost="862.000600" Rows="1.000000" Width="16"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="18" Alias="x">
<dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0">
<dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:FuncExpr>
<dxl:Ident ColId="18" ColName="x" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
Expand All @@ -357,19 +354,27 @@
<dxl:Ident ColId="10" ColName="d" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:Filter>
<dxl:Comparison ComparisonOperator="&lt;" OperatorMdid="0.97.1.0">
<dxl:Ident ColId="18" ColName="x" TypeMdid="0.23.1.0"/>
<dxl:ConstValue TypeMdid="0.23.1.0" Value="3"/>
</dxl:Comparison>
</dxl:Filter>
<dxl:OneTimeFilter/>
<dxl:HashJoin JoinType="Inner">
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="862.000583" Rows="1.000000" Width="16"/>
<dxl:Cost StartupCost="0" TotalCost="862.000589" Rows="1.000000" Width="16"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="18" Alias="x">
<dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0">
<dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:FuncExpr>
</dxl:ProjElem>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="9" Alias="c">
<dxl:Ident ColId="9" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
Expand All @@ -378,16 +383,10 @@
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:JoinFilter/>
<dxl:HashCondList>
<dxl:Comparison ComparisonOperator="=" OperatorMdid="0.96.1.0">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Ident ColId="9" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:Comparison>
</dxl:HashCondList>
<dxl:TableScan>
<dxl:OneTimeFilter/>
<dxl:HashJoin JoinType="Inner">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000069" Rows="1.000000" Width="8"/>
<dxl:Cost StartupCost="0" TotalCost="862.000550" Rows="1.000000" Width="16"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
Expand All @@ -396,35 +395,6 @@
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter>
<dxl:Comparison ComparisonOperator="&lt;" OperatorMdid="0.97.1.0">
<dxl:FuncExpr FuncId="0.1067.1.0" FuncRetSet="true" TypeMdid="0.23.1.0">
<dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:FuncExpr>
<dxl:ConstValue TypeMdid="0.23.1.0" Value="3"/>
</dxl:Comparison>
</dxl:Filter>
<dxl:TableDescriptor Mdid="0.81920.1.0" TableName="foo" ExecuteAsUser="10" LockMode="1">
<dxl:Columns>
<dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="1" Attno="2" ColName="b" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="2" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/>
<dxl:Column ColId="3" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="4" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="5" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="6" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="7" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/>
<dxl:Column ColId="8" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000021" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="9" Alias="c">
<dxl:Ident ColId="9" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
Expand All @@ -433,21 +403,69 @@
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableDescriptor Mdid="0.81923.1.0" TableName="bar" ExecuteAsUser="10" LockMode="1">
<dxl:Columns>
<dxl:Column ColId="9" Attno="1" ColName="c" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="10" Attno="2" ColName="d" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="11" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/>
<dxl:Column ColId="12" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="13" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="14" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="15" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="16" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/>
<dxl:Column ColId="17" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
</dxl:HashJoin>
<dxl:JoinFilter/>
<dxl:HashCondList>
<dxl:Comparison ComparisonOperator="=" OperatorMdid="0.96.1.0">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Ident ColId="9" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:Comparison>
</dxl:HashCondList>
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000021" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="0" Alias="a">
<dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableDescriptor Mdid="0.81920.1.0" TableName="foo" ExecuteAsUser="10" LockMode="1">
<dxl:Columns>
<dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="1" Attno="2" ColName="b" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="2" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/>
<dxl:Column ColId="3" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="4" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="5" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="6" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="7" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/>
<dxl:Column ColId="8" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000021" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="9" Alias="c">
<dxl:Ident ColId="9" ColName="c" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
<dxl:ProjElem ColId="10" Alias="d">
<dxl:Ident ColId="10" ColName="d" TypeMdid="0.23.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableDescriptor Mdid="0.81923.1.0" TableName="bar" ExecuteAsUser="10" LockMode="1">
<dxl:Columns>
<dxl:Column ColId="9" Attno="1" ColName="c" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="10" Attno="2" ColName="d" TypeMdid="0.23.1.0" ColWidth="4"/>
<dxl:Column ColId="11" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/>
<dxl:Column ColId="12" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="13" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="14" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="15" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="16" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/>
<dxl:Column ColId="17" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
</dxl:HashJoin>
</dxl:Result>
</dxl:Result>
</dxl:GatherMotion>
</dxl:Plan>
Expand Down
Loading

0 comments on commit 4298c29

Please sign in to comment.