This is an automated email from the ASF dual-hosted git repository. maxyang pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit 5389e3d7886af68cdae3ea17824ef394055fd915 Author: Hari krishna <[email protected]> AuthorDate: Fri Dec 1 12:29:46 2023 +0530 Fix query fallback when subqury present within LEAST()/GREATEST() (#16777) * Fix query fallback when Subqury present within LEAST()/GREATEST() Currently, Query fallsback to the planner when a subquery is present in a ScalarMinMax (LEAST, or GREATEST) expression. In This PR, I am addressing the situation by incorporating the ScalarMinMax operator when processing scalar operators with subqueries. support subquery within ScalarArrayRef/ScalarArrayRefINdexList --- .../data/dxl/minidump/Least-Greatest-Subselect.mdp | 415 ++++++++++++++++ .../data/dxl/minidump/SubqueryInsideArrayRef.mdp | 464 ++++++++++++++++++ .../minidump/SubqueryInsideArrayRefIndexList.mdp | 536 +++++++++++++++++++++ .../libgpopt/src/xforms/CSubqueryHandler.cpp | 3 + .../src/unittest/gpopt/minidump/CICGTest.cpp | 1 + .../src/unittest/gpopt/minidump/CSubqueryTest.cpp | 2 + src/test/regress/expected/subselect_gp.out | 154 ++++++ .../regress/expected/subselect_gp_optimizer.out | 186 +++++++ src/test/regress/sql/subselect_gp.sql | 46 ++ 9 files changed, 1807 insertions(+) diff --git a/src/backend/gporca/data/dxl/minidump/Least-Greatest-Subselect.mdp b/src/backend/gporca/data/dxl/minidump/Least-Greatest-Subselect.mdp new file mode 100644 index 0000000000..64185ad815 --- /dev/null +++ b/src/backend/gporca/data/dxl/minidump/Least-Greatest-Subselect.mdp @@ -0,0 +1,415 @@ +<?xml version="1.0" encoding="UTF-8"?> +<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/"> + <dxl:Comment><![CDATA[ + Objective: Orca should generate plan when there is a subquery is present within the LEAST() or GREATEST() + + create table foo (a int, b int) distributed by(a); + insert into foo values(1, 2); + + explain select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + QUERY PLAN + ------------------------------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..904314361.77 rows=10 width=4) + -> Nested Loop Left Join (cost=0.00..904314361.77 rows=14 width=16) + Join Filter: true + -> Nested Loop Left Join (cost=0.00..882688.49 rows=7 width=12) + Join Filter: true + -> Seq Scan on foo (cost=0.00..431.00 rows=4 width=8) + -> Materialize (cost=0.00..0.00 rows=1 width=4) + -> Result (cost=0.00..0.00 rows=1 width=1) + -> Materialize (cost=0.00..0.00 rows=1 width=4) + -> Result (cost=0.00..0.00 rows=1 width=1) + Optimizer: GPORCA + + select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + least + ------- + 1 + ]]> + </dxl:Comment> + <dxl:Thread Id="0"> + <dxl:OptimizerConfig> + <dxl:EnumeratorConfig Id="0" PlanSamples="0" CostThreshold="0"/> + <dxl:StatisticsConfig DampingFactorFilter="0.750000" DampingFactorJoin="0.000000" DampingFactorGroupBy="0.750000" MaxStatsBuckets="100"/> + <dxl:CTEConfig CTEInliningCutoff="0"/> + <dxl:WindowOids RowNumber="3100" Rank="3101"/> + <dxl:CostModelConfig CostModelType="1" SegmentsForCosting="3"> + <dxl:CostParams> + <dxl:CostParam Name="NLJFactor" Value="1024.000000" LowerBound="1023.500000" UpperBound="1024.500000"/> + </dxl:CostParams> + </dxl:CostModelConfig> + <dxl:Hint JoinArityForAssociativityCommutativity="18" ArrayExpansionThreshold="20" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="100000" EnforceConstraintsOnDML="false" PushGroupByBelowSetopThreshold="10" XformBindThreshold="0" SkewFactor="0"/> + <dxl:TraceFlags Value="101013,102001,102002,102003,102043,102074,102120,102144,102162,102163,103001,103014,103022,103026,103027,103029,103033,103038,103040,104002,104003,104004,104005,106000"/> + </dxl:OptimizerConfig> + <dxl:Metadata SystemIds="0.GPDB"> + <dxl:RelationExtendedStatistics Mdid="10.36574.1.0" Name="foo"/> + <dxl:Type Mdid="0.16.1.0" Name="bool" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="1" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2222.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7124.1.0"/> + <dxl:PartOpfamily Mdid="0.424.1.0"/> + <dxl:EqualityOp Mdid="0.91.1.0"/> + <dxl:InequalityOp Mdid="0.85.1.0"/> + <dxl:LessThanOp Mdid="0.58.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.1694.1.0"/> + <dxl:GreaterThanOp Mdid="0.59.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.1695.1.0"/> + <dxl:ComparisonOp Mdid="0.1693.1.0"/> + <dxl:ArrayType Mdid="0.1000.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.23.1.0" Name="int4" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/> + <dxl:PartOpfamily Mdid="0.1976.1.0"/> + <dxl:EqualityOp Mdid="0.96.1.0"/> + <dxl:InequalityOp Mdid="0.518.1.0"/> + <dxl:LessThanOp Mdid="0.97.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.523.1.0"/> + <dxl:GreaterThanOp Mdid="0.521.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.525.1.0"/> + <dxl:ComparisonOp Mdid="0.351.1.0"/> + <dxl:ArrayType Mdid="0.1007.1.0"/> + <dxl:MinAgg Mdid="0.2132.1.0"/> + <dxl:MaxAgg Mdid="0.2116.1.0"/> + <dxl:AvgAgg Mdid="0.2101.1.0"/> + <dxl:SumAgg Mdid="0.2108.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.26.1.0" Name="oid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1990.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7109.1.0"/> + <dxl:PartOpfamily Mdid="0.1989.1.0"/> + <dxl:EqualityOp Mdid="0.607.1.0"/> + <dxl:InequalityOp Mdid="0.608.1.0"/> + <dxl:LessThanOp Mdid="0.609.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.611.1.0"/> + <dxl:GreaterThanOp Mdid="0.610.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.612.1.0"/> + <dxl:ComparisonOp Mdid="0.356.1.0"/> + <dxl:ArrayType Mdid="0.1028.1.0"/> + <dxl:MinAgg Mdid="0.2134.1.0"/> + <dxl:MaxAgg Mdid="0.2118.1.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.27.1.0" Name="tid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="6" PassByValue="false"> + <dxl:DistrOpfamily Mdid="0.2227.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7110.1.0"/> + <dxl:PartOpfamily Mdid="0.2789.1.0"/> + <dxl:EqualityOp Mdid="0.387.1.0"/> + <dxl:InequalityOp Mdid="0.402.1.0"/> + <dxl:LessThanOp Mdid="0.2799.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.2801.1.0"/> + <dxl:GreaterThanOp Mdid="0.2800.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.2802.1.0"/> + <dxl:ComparisonOp Mdid="0.2794.1.0"/> + <dxl:ArrayType Mdid="0.1010.1.0"/> + <dxl:MinAgg Mdid="0.2798.1.0"/> + <dxl:MaxAgg Mdid="0.2797.1.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.29.1.0" Name="cid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="false" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2226.1.0"/> + <dxl:EqualityOp Mdid="0.385.1.0"/> + <dxl:InequalityOp Mdid="0.0.0.0"/> + <dxl:LessThanOp Mdid="0.0.0.0"/> + <dxl:LessThanEqualsOp Mdid="0.0.0.0"/> + <dxl:GreaterThanOp Mdid="0.0.0.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.0.0.0"/> + <dxl:ComparisonOp Mdid="0.0.0.0"/> + <dxl:ArrayType Mdid="0.1012.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.28.1.0" Name="xid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="false" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2225.1.0"/> + <dxl:EqualityOp Mdid="0.352.1.0"/> + <dxl:InequalityOp Mdid="0.3315.1.0"/> + <dxl:LessThanOp Mdid="0.0.0.0"/> + <dxl:LessThanEqualsOp Mdid="0.0.0.0"/> + <dxl:GreaterThanOp Mdid="0.0.0.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.0.0.0"/> + <dxl:ComparisonOp Mdid="0.0.0.0"/> + <dxl:ArrayType Mdid="0.1011.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:ColumnStatistics Mdid="1.36574.1.0.1" Name="b" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/> + <dxl:ColumnStatistics Mdid="1.36574.1.0.0" Name="a" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/> + <dxl:RelationStatistics Mdid="2.36574.1.0" Name="foo" Rows="0.000000" RelPages="0" RelAllVisible="0" EmptyRelation="true"/> + <dxl:Relation Mdid="6.36574.1.0" Name="foo" IsTemporary="false" StorageType="Heap" DistributionPolicy="Hash" DistributionColumns="0" Keys="8,2"> + <dxl:Columns> + <dxl:Column Name="a" Attno="1" Mdid="0.23.1.0" Nullable="true" ColWidth="4"/> + <dxl:Column Name="b" Attno="2" Mdid="0.23.1.0" Nullable="true" ColWidth="4"/> + <dxl:Column Name="ctid" Attno="-1" Mdid="0.27.1.0" Nullable="false" ColWidth="6"/> + <dxl:Column Name="xmin" Attno="-2" Mdid="0.28.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="cmin" Attno="-3" Mdid="0.29.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="xmax" Attno="-4" Mdid="0.28.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="cmax" Attno="-5" Mdid="0.29.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="tableoid" Attno="-6" Mdid="0.26.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="gp_segment_id" Attno="-7" Mdid="0.23.1.0" Nullable="false" ColWidth="4"/> + </dxl:Columns> + <dxl:IndexInfoList/> + <dxl:CheckConstraints/> + <dxl:DistrOpfamilies> + <dxl:DistrOpfamily Mdid="0.1977.1.0"/> + </dxl:DistrOpfamilies> + </dxl:Relation> + </dxl:Metadata> + <dxl:Query> + <dxl:OutputColumns> + <dxl:Ident ColId="14" ColName="least" TypeMdid="0.23.1.0"/> + </dxl:OutputColumns> + <dxl:CTEList/> + <dxl:LogicalProject> + <dxl:ProjList> + <dxl:ProjElem ColId="14" Alias="least"> + <dxl:Minimum TypeMdid="0.23.1.0"> + <dxl:ScalarSubquery ColId="11"> + <dxl:LogicalProject> + <dxl:ProjList> + <dxl:ProjElem ColId="11" Alias="?column?"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="5"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:LogicalConstTable> + <dxl:Columns> + <dxl:Column ColId="10" Attno="1" ColName="" TypeMdid="0.16.1.0"/> + </dxl:Columns> + <dxl:ConstTuple> + <dxl:Datum TypeMdid="0.16.1.0" Value="true"/> + </dxl:ConstTuple> + </dxl:LogicalConstTable> + </dxl:LogicalProject> + </dxl:ScalarSubquery> + <dxl:Maximum TypeMdid="0.23.1.0"> + <dxl:Ident ColId="2" ColName="b" TypeMdid="0.23.1.0"/> + <dxl:ConstValue TypeMdid="0.23.1.0" IsNull="true"/> + <dxl:ScalarSubquery ColId="13"> + <dxl:LogicalProject> + <dxl:ProjList> + <dxl:ProjElem ColId="13" Alias="?column?"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:LogicalConstTable> + <dxl:Columns> + <dxl:Column ColId="12" Attno="1" ColName="" TypeMdid="0.16.1.0"/> + </dxl:Columns> + <dxl:ConstTuple> + <dxl:Datum TypeMdid="0.16.1.0" Value="true"/> + </dxl:ConstTuple> + </dxl:LogicalConstTable> + </dxl:LogicalProject> + </dxl:ScalarSubquery> + </dxl:Maximum> + <dxl:Ident ColId="1" ColName="a" TypeMdid="0.23.1.0"/> + </dxl:Minimum> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:LogicalGet> + <dxl:TableDescriptor Mdid="6.36574.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="1" Attno="1" ColName="a" TypeMdid="0.23.1.0" ColWidth="4"/> + <dxl:Column ColId="2" Attno="2" ColName="b" TypeMdid="0.23.1.0" ColWidth="4"/> + <dxl:Column ColId="3" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/> + <dxl:Column ColId="4" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="5" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="6" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="7" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="8" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/> + <dxl:Column ColId="9" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/> + </dxl:Columns> + </dxl:TableDescriptor> + </dxl:LogicalGet> + </dxl:LogicalProject> + </dxl:Query> + <dxl:Plan Id="0" SpaceSize="8"> + <dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="904314014.342512" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="13" Alias="least"> + <dxl:Ident ColId="13" ColName="least" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="904314014.342497" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="13" Alias="least"> + <dxl:Minimum TypeMdid="0.23.1.0"> + <dxl:Ident ColId="10" ColName="?column?" TypeMdid="0.23.1.0"/> + <dxl:Maximum TypeMdid="0.23.1.0"> + <dxl:Ident ColId="1" ColName="b" TypeMdid="0.23.1.0"/> + <dxl:ConstValue TypeMdid="0.23.1.0" IsNull="true"/> + <dxl:Ident ColId="12" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:Maximum> + <dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/> + </dxl:Minimum> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:NestedLoopJoin JoinType="Left" IndexNestedLoopJoin="false" OuterRefAsParam="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="904314014.342496" Rows="4.000000" Width="16"/> + </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:ProjElem ColId="10" Alias="?column?"> + <dxl:Ident ColId="10" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="12" Alias="?column?"> + <dxl:Ident ColId="12" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:JoinFilter> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:JoinFilter> + <dxl:NestedLoopJoin JoinType="Left" IndexNestedLoopJoin="false" OuterRefAsParam="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="882688.154350" Rows="2.000000" Width="12"/> + </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:ProjElem ColId="10" Alias="?column?"> + <dxl:Ident ColId="10" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:JoinFilter> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:JoinFilter> + <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="6.36574.1.0" TableName="foo" LockMode="1" AclMode="2"> + <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:Materialize Eager="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000009" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="?column?"> + <dxl:Ident ColId="10" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000005" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="?column?"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="5"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000001" Rows="1.000000" Width="1"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="9" Alias=""> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + </dxl:Result> + </dxl:Result> + </dxl:Materialize> + </dxl:NestedLoopJoin> + <dxl:Materialize Eager="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000009" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="12" Alias="?column?"> + <dxl:Ident ColId="12" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000005" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="12" Alias="?column?"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000001" Rows="1.000000" Width="1"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="11" Alias=""> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + </dxl:Result> + </dxl:Result> + </dxl:Materialize> + </dxl:NestedLoopJoin> + </dxl:Result> + </dxl:GatherMotion> + </dxl:Plan> + </dxl:Thread> +</dxl:DXLMessage> diff --git a/src/backend/gporca/data/dxl/minidump/SubqueryInsideArrayRef.mdp b/src/backend/gporca/data/dxl/minidump/SubqueryInsideArrayRef.mdp new file mode 100644 index 0000000000..025782396b --- /dev/null +++ b/src/backend/gporca/data/dxl/minidump/SubqueryInsideArrayRef.mdp @@ -0,0 +1,464 @@ +<?xml version="1.0" encoding="UTF-8"?> +<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/"> + <dxl:Comment><![CDATA[ + Objective: Orca should generate plan when there is a subquery is present within the ScalarArrayRef + + create table foo(a int[]); + insert into foo values (ARRAY[1, 2, 3]); + analyze foo; + + explain select (select a from foo)[1] from foo; + QUERY PLAN + ------------------------------------------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1324033.07 rows=1 width=4) + -> Nested Loop Left Join (cost=0.00..1324033.07 rows=1 width=8) + Join Filter: true + -> Seq Scan on foo foo_1 (cost=0.00..431.00 rows=1 width=1) + -> Assert (cost=0.00..431.00 rows=1 width=8) + Assert Cond: ((row_number() OVER (?)) = 1) + -> Materialize (cost=0.00..431.00 rows=1 width=16) + -> Broadcast Motion 1:3 (slice2) (cost=0.00..431.00 rows=1 width=16) + -> WindowAgg (cost=0.00..431.00 rows=1 width=16) + -> Gather Motion 3:1 (slice3; segments: 3) (cost=0.00..431.00 rows=1 width=8) + -> Seq Scan on foo (cost=0.00..431.00 rows=1 width=8) + Optimizer: GPORCA + + select (select a from foo)[1] from foo; + a + --- + 1 + ]]> + </dxl:Comment> + <dxl:Thread Id="0"> + <dxl:OptimizerConfig> + <dxl:EnumeratorConfig Id="0" PlanSamples="0" CostThreshold="0"/> + <dxl:StatisticsConfig DampingFactorFilter="0.750000" DampingFactorJoin="0.000000" DampingFactorGroupBy="0.750000" MaxStatsBuckets="100"/> + <dxl:CTEConfig CTEInliningCutoff="0"/> + <dxl:WindowOids RowNumber="3100" Rank="3101"/> + <dxl:CostModelConfig CostModelType="1" SegmentsForCosting="3"> + <dxl:CostParams> + <dxl:CostParam Name="NLJFactor" Value="1024.000000" LowerBound="1023.500000" UpperBound="1024.500000"/> + </dxl:CostParams> + </dxl:CostModelConfig> + <dxl:Hint JoinArityForAssociativityCommutativity="18" ArrayExpansionThreshold="20" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="100000" EnforceConstraintsOnDML="false" PushGroupByBelowSetopThreshold="10" XformBindThreshold="0" SkewFactor="0"/> + <dxl:TraceFlags Value="101013,102001,102002,102003,102043,102074,102120,102144,102162,102163,103001,103014,103022,103026,103027,103029,103033,103038,103040,104002,104003,104004,104005,106000"/> + </dxl:OptimizerConfig> + <dxl:Metadata SystemIds="0.GPDB"> + <dxl:Type Mdid="0.16.1.0" Name="bool" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="1" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2222.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7124.1.0"/> + <dxl:PartOpfamily Mdid="0.424.1.0"/> + <dxl:EqualityOp Mdid="0.91.1.0"/> + <dxl:InequalityOp Mdid="0.85.1.0"/> + <dxl:LessThanOp Mdid="0.58.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.1694.1.0"/> + <dxl:GreaterThanOp Mdid="0.59.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.1695.1.0"/> + <dxl:ComparisonOp Mdid="0.1693.1.0"/> + <dxl:ArrayType Mdid="0.1000.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.20.1.0" Name="Int8" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="8" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/> + <dxl:PartOpfamily Mdid="0.1976.1.0"/> + <dxl:EqualityOp Mdid="0.410.1.0"/> + <dxl:InequalityOp Mdid="0.411.1.0"/> + <dxl:LessThanOp Mdid="0.412.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.414.1.0"/> + <dxl:GreaterThanOp Mdid="0.413.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.415.1.0"/> + <dxl:ComparisonOp Mdid="0.351.1.0"/> + <dxl:ArrayType Mdid="0.1016.1.0"/> + <dxl:MinAgg Mdid="0.2131.1.0"/> + <dxl:MaxAgg Mdid="0.2115.1.0"/> + <dxl:AvgAgg Mdid="0.2100.1.0"/> + <dxl:SumAgg Mdid="0.2107.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.23.1.0" Name="int4" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/> + <dxl:PartOpfamily Mdid="0.1976.1.0"/> + <dxl:EqualityOp Mdid="0.96.1.0"/> + <dxl:InequalityOp Mdid="0.518.1.0"/> + <dxl:LessThanOp Mdid="0.97.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.523.1.0"/> + <dxl:GreaterThanOp Mdid="0.521.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.525.1.0"/> + <dxl:ComparisonOp Mdid="0.351.1.0"/> + <dxl:ArrayType Mdid="0.1007.1.0"/> + <dxl:MinAgg Mdid="0.2132.1.0"/> + <dxl:MaxAgg Mdid="0.2116.1.0"/> + <dxl:AvgAgg Mdid="0.2101.1.0"/> + <dxl:SumAgg Mdid="0.2108.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.26.1.0" Name="oid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1990.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7109.1.0"/> + <dxl:PartOpfamily Mdid="0.1989.1.0"/> + <dxl:EqualityOp Mdid="0.607.1.0"/> + <dxl:InequalityOp Mdid="0.608.1.0"/> + <dxl:LessThanOp Mdid="0.609.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.611.1.0"/> + <dxl:GreaterThanOp Mdid="0.610.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.612.1.0"/> + <dxl:ComparisonOp Mdid="0.356.1.0"/> + <dxl:ArrayType Mdid="0.1028.1.0"/> + <dxl:MinAgg Mdid="0.2134.1.0"/> + <dxl:MaxAgg Mdid="0.2118.1.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.27.1.0" Name="tid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="6" PassByValue="false"> + <dxl:DistrOpfamily Mdid="0.2227.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7110.1.0"/> + <dxl:PartOpfamily Mdid="0.2789.1.0"/> + <dxl:EqualityOp Mdid="0.387.1.0"/> + <dxl:InequalityOp Mdid="0.402.1.0"/> + <dxl:LessThanOp Mdid="0.2799.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.2801.1.0"/> + <dxl:GreaterThanOp Mdid="0.2800.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.2802.1.0"/> + <dxl:ComparisonOp Mdid="0.2794.1.0"/> + <dxl:ArrayType Mdid="0.1010.1.0"/> + <dxl:MinAgg Mdid="0.2798.1.0"/> + <dxl:MaxAgg Mdid="0.2797.1.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:GPDBFunc Mdid="0.3100.1.0" Name="row_number" ReturnsSet="false" Stability="Immutable" IsStrict="false" IsNDVPreserving="false" IsAllowedForPS="false"> + <dxl:ResultType Mdid="0.20.1.0"/> + </dxl:GPDBFunc> + <dxl:Type Mdid="0.29.1.0" Name="cid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="false" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2226.1.0"/> + <dxl:EqualityOp Mdid="0.385.1.0"/> + <dxl:InequalityOp Mdid="0.0.0.0"/> + <dxl:LessThanOp Mdid="0.0.0.0"/> + <dxl:LessThanEqualsOp Mdid="0.0.0.0"/> + <dxl:GreaterThanOp Mdid="0.0.0.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.0.0.0"/> + <dxl:ComparisonOp Mdid="0.0.0.0"/> + <dxl:ArrayType Mdid="0.1012.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.28.1.0" Name="xid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="false" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2225.1.0"/> + <dxl:EqualityOp Mdid="0.352.1.0"/> + <dxl:InequalityOp Mdid="0.3315.1.0"/> + <dxl:LessThanOp Mdid="0.0.0.0"/> + <dxl:LessThanEqualsOp Mdid="0.0.0.0"/> + <dxl:GreaterThanOp Mdid="0.0.0.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.0.0.0"/> + <dxl:ComparisonOp Mdid="0.0.0.0"/> + <dxl:ArrayType Mdid="0.1011.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:GPDBScalarOp Mdid="0.416.1.0" Name="=" ComparisonType="Eq" ReturnsNullOnNullInput="true" IsNDVPreserving="false"> + <dxl:LeftType Mdid="0.20.1.0"/> + <dxl:RightType Mdid="0.23.1.0"/> + <dxl:ResultType Mdid="0.16.1.0"/> + <dxl:OpFunc Mdid="0.474.1.0"/> + <dxl:Commutator Mdid="0.15.1.0"/> + <dxl:InverseOp Mdid="0.417.1.0"/> + <dxl:HashOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyHashOpfamily Mdid="0.7100.1.0"/> + <dxl:Opfamilies> + <dxl:Opfamily Mdid="0.1976.1.0"/> + <dxl:Opfamily Mdid="0.1977.1.0"/> + <dxl:Opfamily Mdid="0.4054.1.0"/> + <dxl:Opfamily Mdid="0.7100.1.0"/> + <dxl:Opfamily Mdid="0.10009.1.0"/> + </dxl:Opfamilies> + </dxl:GPDBScalarOp> + <dxl:RelationExtendedStatistics Mdid="10.29311.1.0" Name="foo"/> + <dxl:MDScalarComparison Mdid="4.20.1.0;23.1.0;0" Name="=" ComparisonType="Eq" LeftType="0.20.1.0" RightType="0.23.1.0" OperatorMdid="0.416.1.0"/> + <dxl:RelationStatistics Mdid="2.29311.1.0" Name="foo" Rows="0.000000" RelPages="1" RelAllVisible="0" EmptyRelation="true"/> + <dxl:Relation Mdid="6.29311.1.0" Name="foo" IsTemporary="false" StorageType="Heap" DistributionPolicy="Hash" DistributionColumns="0" Keys="7,1"> + <dxl:Columns> + <dxl:Column Name="a" Attno="1" Mdid="0.1007.1.0" Nullable="true" ColWidth="8"/> + <dxl:Column Name="ctid" Attno="-1" Mdid="0.27.1.0" Nullable="false" ColWidth="6"/> + <dxl:Column Name="xmin" Attno="-2" Mdid="0.28.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="cmin" Attno="-3" Mdid="0.29.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="xmax" Attno="-4" Mdid="0.28.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="cmax" Attno="-5" Mdid="0.29.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="tableoid" Attno="-6" Mdid="0.26.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="gp_segment_id" Attno="-7" Mdid="0.23.1.0" Nullable="false" ColWidth="4"/> + </dxl:Columns> + <dxl:IndexInfoList/> + <dxl:CheckConstraints/> + <dxl:DistrOpfamilies> + <dxl:DistrOpfamily Mdid="0.627.1.0"/> + </dxl:DistrOpfamilies> + </dxl:Relation> + <dxl:ColumnStatistics Mdid="1.29311.1.0.0" Name="a" Width="8.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/> + <dxl:Type Mdid="0.1007.1.0" Name="_int4" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="false" Length="-1" PassByValue="false"> + <dxl:DistrOpfamily Mdid="0.627.1.0"/> + <dxl:PartOpfamily Mdid="0.397.1.0"/> + <dxl:EqualityOp Mdid="0.1070.1.0"/> + <dxl:InequalityOp Mdid="0.1071.1.0"/> + <dxl:LessThanOp Mdid="0.1072.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.1074.1.0"/> + <dxl:GreaterThanOp Mdid="0.1073.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.1075.1.0"/> + <dxl:ComparisonOp Mdid="0.382.1.0"/> + <dxl:ArrayType Mdid="0.0.0.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.6217.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + </dxl:Metadata> + <dxl:Query> + <dxl:OutputColumns> + <dxl:Ident ColId="17" ColName="a" TypeMdid="0.23.1.0"/> + </dxl:OutputColumns> + <dxl:CTEList/> + <dxl:LogicalProject> + <dxl:ProjList> + <dxl:ProjElem ColId="17" Alias="a"> + <dxl:ArrayRef ElementType="0.23.1.0" ArrayType="0.1007.1.0" TypeMdid="0.23.1.0"> + <dxl:ArrayIndexList Bound="Lower"/> + <dxl:ArrayIndexList Bound="Upper"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:ArrayIndexList> + <dxl:RefExpr> + <dxl:ScalarSubquery ColId="9"> + <dxl:LogicalGet> + <dxl:TableDescriptor Mdid="6.29311.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="9" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <dxl:Column ColId="10" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/> + <dxl:Column ColId="11" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="12" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="13" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="14" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="15" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/> + <dxl:Column ColId="16" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/> + </dxl:Columns> + </dxl:TableDescriptor> + </dxl:LogicalGet> + </dxl:ScalarSubquery> + </dxl:RefExpr> + <dxl:AssignExpr/> + </dxl:ArrayRef> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:LogicalGet> + <dxl:TableDescriptor Mdid="6.29311.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="1" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <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:LogicalGet> + </dxl:LogicalProject> + </dxl:Query> + <dxl:Plan Id="0" SpaceSize="2"> + <dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="1324033.071390" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="16" Alias="a"> + <dxl:Ident ColId="16" ColName="a" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="1324033.071375" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="16" Alias="a"> + <dxl:ArrayRef ElementType="0.23.1.0" ArrayType="0.1007.1.0" TypeMdid="0.23.1.0"> + <dxl:ArrayIndexList Bound="Lower"/> + <dxl:ArrayIndexList Bound="Upper"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:ArrayIndexList> + <dxl:RefExpr> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:RefExpr> + <dxl:AssignExpr/> + </dxl:ArrayRef> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:NestedLoopJoin JoinType="Left" IndexNestedLoopJoin="false" OuterRefAsParam="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="1324033.071373" Rows="2.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:JoinFilter> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:JoinFilter> + <dxl:TableScan> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000007" Rows="1.000000" Width="1"/> + </dxl:Properties> + <dxl:ProjList/> + <dxl:Filter/> + <dxl:TableDescriptor Mdid="6.29311.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <dxl:Column ColId="1" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/> + <dxl:Column ColId="2" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="3" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="4" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="5" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="6" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/> + <dxl:Column ColId="7" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/> + </dxl:Columns> + </dxl:TableDescriptor> + </dxl:TableScan> + <dxl:Assert ErrorCode="P0003"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.001008" Rows="3.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:AssertConstraintList> + <dxl:AssertConstraint ErrorMessage="Expected no more than one row to be returned by expression"> + <dxl:Comparison ComparisonOperator="=" OperatorMdid="0.416.1.0"> + <dxl:Ident ColId="17" ColName="row_number" TypeMdid="0.20.1.0"/> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:Comparison> + </dxl:AssertConstraint> + </dxl:AssertConstraintList> + <dxl:Materialize Eager="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.001000" Rows="3.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="17" Alias="row_number"> + <dxl:Ident ColId="17" ColName="row_number" TypeMdid="0.20.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:BroadcastMotion InputSegments="-1" OutputSegments="0,1,2"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000984" Rows="3.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="17" Alias="row_number"> + <dxl:Ident ColId="17" ColName="row_number" TypeMdid="0.20.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000125" Rows="1.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="17" Alias="row_number"> + <dxl:Ident ColId="17" ColName="row_number" TypeMdid="0.20.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:Window PartitionColumns=""> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000125" Rows="1.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="17" Alias="row_number"> + <dxl:WindowFunc Mdid="0.3100.1.0" TypeMdid="0.20.1.0" Distinct="false" WindowStarArg="false" WindowSimpleAgg="false" WindowStrategy="Immediate" WinSpecPos="0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000125" Rows="1.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:TableScan> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000021" Rows="1.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias="a"> + <dxl:Ident ColId="8" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:TableDescriptor Mdid="6.29311.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="8" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <dxl:Column ColId="9" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/> + <dxl:Column ColId="10" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="11" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="12" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="13" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="14" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/> + <dxl:Column ColId="15" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/> + </dxl:Columns> + </dxl:TableDescriptor> + </dxl:TableScan> + </dxl:GatherMotion> + <dxl:WindowKeyList> + <dxl:WindowKey> + <dxl:SortingColumnList/> + </dxl:WindowKey> + </dxl:WindowKeyList> + </dxl:Window> + </dxl:Result> + </dxl:BroadcastMotion> + </dxl:Materialize> + </dxl:Assert> + </dxl:NestedLoopJoin> + </dxl:Result> + </dxl:GatherMotion> + </dxl:Plan> + </dxl:Thread> +</dxl:DXLMessage> diff --git a/src/backend/gporca/data/dxl/minidump/SubqueryInsideArrayRefIndexList.mdp b/src/backend/gporca/data/dxl/minidump/SubqueryInsideArrayRefIndexList.mdp new file mode 100644 index 0000000000..9b70bdb799 --- /dev/null +++ b/src/backend/gporca/data/dxl/minidump/SubqueryInsideArrayRefIndexList.mdp @@ -0,0 +1,536 @@ +<?xml version="1.0" encoding="UTF-8"?> +<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/"> + <dxl:Comment><![CDATA[ + Objective: Orca should generate plan when there is a subquery is present within the ScalarArrayRefIndexList + + create table foo(a int[]); + insert into foo values (ARRAY[1, 2, 3]); + analyze foo; + + explain select (select a from foo)[(select 1)] from foo; + QUERY PLAN + ------------------------------------------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..904755234.48 rows=1 width=4) + -> Nested Loop Left Join (cost=0.00..904755234.48 rows=2 width=12) + Join Filter: true + -> Nested Loop Left Join (cost=0.00..882688.03 rows=1 width=4) + Join Filter: true + -> Seq Scan on foo foo_1 (cost=0.00..431.00 rows=1 width=1) + -> Materialize (cost=0.00..0.00 rows=1 width=4) + -> Result (cost=0.00..0.00 rows=1 width=1) + -> Assert (cost=0.00..431.00 rows=1 width=8) + Assert Cond: ((row_number() OVER (?)) = 1) + -> Materialize (cost=0.00..431.00 rows=1 width=16) + -> Broadcast Motion 1:3 (slice2) (cost=0.00..431.00 rows=1 width=16) + -> WindowAgg (cost=0.00..431.00 rows=1 width=16) + -> Gather Motion 3:1 (slice3; segments: 3) (cost=0.00..431.00 rows=1 width=8) + -> Seq Scan on foo (cost=0.00..431.00 rows=1 width=8) + Optimizer: GPORCA + + select (select a from foo)[(select 1)] from foo; + a + --- + 1 + ]]> + </dxl:Comment> + <dxl:Thread Id="0"> + <dxl:OptimizerConfig> + <dxl:EnumeratorConfig Id="0" PlanSamples="0" CostThreshold="0"/> + <dxl:StatisticsConfig DampingFactorFilter="0.750000" DampingFactorJoin="0.000000" DampingFactorGroupBy="0.750000" MaxStatsBuckets="100"/> + <dxl:CTEConfig CTEInliningCutoff="0"/> + <dxl:WindowOids RowNumber="3100" Rank="3101"/> + <dxl:CostModelConfig CostModelType="1" SegmentsForCosting="3"> + <dxl:CostParams> + <dxl:CostParam Name="NLJFactor" Value="1024.000000" LowerBound="1023.500000" UpperBound="1024.500000"/> + </dxl:CostParams> + </dxl:CostModelConfig> + <dxl:Hint JoinArityForAssociativityCommutativity="18" ArrayExpansionThreshold="20" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="100000" EnforceConstraintsOnDML="false" PushGroupByBelowSetopThreshold="10" XformBindThreshold="0" SkewFactor="0"/> + <dxl:TraceFlags Value="101013,102001,102002,102003,102043,102074,102120,102144,102162,102163,103001,103014,103022,103026,103027,103029,103033,103038,103040,104002,104003,104004,104005,106000"/> + </dxl:OptimizerConfig> + <dxl:Metadata SystemIds="0.GPDB"> + <dxl:RelationExtendedStatistics Mdid="10.41310.1.0" Name="foo"/> + <dxl:Type Mdid="0.16.1.0" Name="bool" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="1" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2222.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7124.1.0"/> + <dxl:PartOpfamily Mdid="0.424.1.0"/> + <dxl:EqualityOp Mdid="0.91.1.0"/> + <dxl:InequalityOp Mdid="0.85.1.0"/> + <dxl:LessThanOp Mdid="0.58.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.1694.1.0"/> + <dxl:GreaterThanOp Mdid="0.59.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.1695.1.0"/> + <dxl:ComparisonOp Mdid="0.1693.1.0"/> + <dxl:ArrayType Mdid="0.1000.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.20.1.0" Name="Int8" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="8" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/> + <dxl:PartOpfamily Mdid="0.1976.1.0"/> + <dxl:EqualityOp Mdid="0.410.1.0"/> + <dxl:InequalityOp Mdid="0.411.1.0"/> + <dxl:LessThanOp Mdid="0.412.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.414.1.0"/> + <dxl:GreaterThanOp Mdid="0.413.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.415.1.0"/> + <dxl:ComparisonOp Mdid="0.351.1.0"/> + <dxl:ArrayType Mdid="0.1016.1.0"/> + <dxl:MinAgg Mdid="0.2131.1.0"/> + <dxl:MaxAgg Mdid="0.2115.1.0"/> + <dxl:AvgAgg Mdid="0.2100.1.0"/> + <dxl:SumAgg Mdid="0.2107.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.23.1.0" Name="int4" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7100.1.0"/> + <dxl:PartOpfamily Mdid="0.1976.1.0"/> + <dxl:EqualityOp Mdid="0.96.1.0"/> + <dxl:InequalityOp Mdid="0.518.1.0"/> + <dxl:LessThanOp Mdid="0.97.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.523.1.0"/> + <dxl:GreaterThanOp Mdid="0.521.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.525.1.0"/> + <dxl:ComparisonOp Mdid="0.351.1.0"/> + <dxl:ArrayType Mdid="0.1007.1.0"/> + <dxl:MinAgg Mdid="0.2132.1.0"/> + <dxl:MaxAgg Mdid="0.2116.1.0"/> + <dxl:AvgAgg Mdid="0.2101.1.0"/> + <dxl:SumAgg Mdid="0.2108.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.26.1.0" Name="oid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.1990.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7109.1.0"/> + <dxl:PartOpfamily Mdid="0.1989.1.0"/> + <dxl:EqualityOp Mdid="0.607.1.0"/> + <dxl:InequalityOp Mdid="0.608.1.0"/> + <dxl:LessThanOp Mdid="0.609.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.611.1.0"/> + <dxl:GreaterThanOp Mdid="0.610.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.612.1.0"/> + <dxl:ComparisonOp Mdid="0.356.1.0"/> + <dxl:ArrayType Mdid="0.1028.1.0"/> + <dxl:MinAgg Mdid="0.2134.1.0"/> + <dxl:MaxAgg Mdid="0.2118.1.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.27.1.0" Name="tid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="6" PassByValue="false"> + <dxl:DistrOpfamily Mdid="0.2227.1.0"/> + <dxl:LegacyDistrOpfamily Mdid="0.7110.1.0"/> + <dxl:PartOpfamily Mdid="0.2789.1.0"/> + <dxl:EqualityOp Mdid="0.387.1.0"/> + <dxl:InequalityOp Mdid="0.402.1.0"/> + <dxl:LessThanOp Mdid="0.2799.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.2801.1.0"/> + <dxl:GreaterThanOp Mdid="0.2800.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.2802.1.0"/> + <dxl:ComparisonOp Mdid="0.2794.1.0"/> + <dxl:ArrayType Mdid="0.1010.1.0"/> + <dxl:MinAgg Mdid="0.2798.1.0"/> + <dxl:MaxAgg Mdid="0.2797.1.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:GPDBFunc Mdid="0.3100.1.0" Name="row_number" ReturnsSet="false" Stability="Immutable" IsStrict="false" IsNDVPreserving="false" IsAllowedForPS="false"> + <dxl:ResultType Mdid="0.20.1.0"/> + </dxl:GPDBFunc> + <dxl:Type Mdid="0.29.1.0" Name="cid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="false" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2226.1.0"/> + <dxl:EqualityOp Mdid="0.385.1.0"/> + <dxl:InequalityOp Mdid="0.0.0.0"/> + <dxl:LessThanOp Mdid="0.0.0.0"/> + <dxl:LessThanEqualsOp Mdid="0.0.0.0"/> + <dxl:GreaterThanOp Mdid="0.0.0.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.0.0.0"/> + <dxl:ComparisonOp Mdid="0.0.0.0"/> + <dxl:ArrayType Mdid="0.1012.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:Type Mdid="0.28.1.0" Name="xid" IsRedistributable="true" IsHashable="true" IsMergeJoinable="false" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="4" PassByValue="true"> + <dxl:DistrOpfamily Mdid="0.2225.1.0"/> + <dxl:EqualityOp Mdid="0.352.1.0"/> + <dxl:InequalityOp Mdid="0.3315.1.0"/> + <dxl:LessThanOp Mdid="0.0.0.0"/> + <dxl:LessThanEqualsOp Mdid="0.0.0.0"/> + <dxl:GreaterThanOp Mdid="0.0.0.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.0.0.0"/> + <dxl:ComparisonOp Mdid="0.0.0.0"/> + <dxl:ArrayType Mdid="0.1011.1.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.0.0.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:GPDBScalarOp Mdid="0.416.1.0" Name="=" ComparisonType="Eq" ReturnsNullOnNullInput="true" IsNDVPreserving="false"> + <dxl:LeftType Mdid="0.20.1.0"/> + <dxl:RightType Mdid="0.23.1.0"/> + <dxl:ResultType Mdid="0.16.1.0"/> + <dxl:OpFunc Mdid="0.474.1.0"/> + <dxl:Commutator Mdid="0.15.1.0"/> + <dxl:InverseOp Mdid="0.417.1.0"/> + <dxl:HashOpfamily Mdid="0.1977.1.0"/> + <dxl:LegacyHashOpfamily Mdid="0.7100.1.0"/> + <dxl:Opfamilies> + <dxl:Opfamily Mdid="0.1976.1.0"/> + <dxl:Opfamily Mdid="0.1977.1.0"/> + <dxl:Opfamily Mdid="0.4054.1.0"/> + <dxl:Opfamily Mdid="0.7100.1.0"/> + <dxl:Opfamily Mdid="0.10009.1.0"/> + </dxl:Opfamilies> + </dxl:GPDBScalarOp> + <dxl:MDScalarComparison Mdid="4.20.1.0;23.1.0;0" Name="=" ComparisonType="Eq" LeftType="0.20.1.0" RightType="0.23.1.0" OperatorMdid="0.416.1.0"/> + <dxl:RelationStatistics Mdid="2.41310.1.0" Name="foo" Rows="0.000000" RelPages="1" RelAllVisible="0" EmptyRelation="true"/> + <dxl:Relation Mdid="6.41310.1.0" Name="foo" IsTemporary="false" StorageType="Heap" DistributionPolicy="Hash" DistributionColumns="0" Keys="7,1"> + <dxl:Columns> + <dxl:Column Name="a" Attno="1" Mdid="0.1007.1.0" Nullable="true" ColWidth="8"/> + <dxl:Column Name="ctid" Attno="-1" Mdid="0.27.1.0" Nullable="false" ColWidth="6"/> + <dxl:Column Name="xmin" Attno="-2" Mdid="0.28.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="cmin" Attno="-3" Mdid="0.29.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="xmax" Attno="-4" Mdid="0.28.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="cmax" Attno="-5" Mdid="0.29.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="tableoid" Attno="-6" Mdid="0.26.1.0" Nullable="false" ColWidth="4"/> + <dxl:Column Name="gp_segment_id" Attno="-7" Mdid="0.23.1.0" Nullable="false" ColWidth="4"/> + </dxl:Columns> + <dxl:IndexInfoList/> + <dxl:CheckConstraints/> + <dxl:DistrOpfamilies> + <dxl:DistrOpfamily Mdid="0.627.1.0"/> + </dxl:DistrOpfamilies> + </dxl:Relation> + <dxl:Type Mdid="0.1007.1.0" Name="_int4" IsRedistributable="true" IsHashable="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="false" Length="-1" PassByValue="false"> + <dxl:DistrOpfamily Mdid="0.627.1.0"/> + <dxl:PartOpfamily Mdid="0.397.1.0"/> + <dxl:EqualityOp Mdid="0.1070.1.0"/> + <dxl:InequalityOp Mdid="0.1071.1.0"/> + <dxl:LessThanOp Mdid="0.1072.1.0"/> + <dxl:LessThanEqualsOp Mdid="0.1074.1.0"/> + <dxl:GreaterThanOp Mdid="0.1073.1.0"/> + <dxl:GreaterThanEqualsOp Mdid="0.1075.1.0"/> + <dxl:ComparisonOp Mdid="0.382.1.0"/> + <dxl:ArrayType Mdid="0.0.0.0"/> + <dxl:MinAgg Mdid="0.0.0.0"/> + <dxl:MaxAgg Mdid="0.0.0.0"/> + <dxl:AvgAgg Mdid="0.0.0.0"/> + <dxl:SumAgg Mdid="0.6217.1.0"/> + <dxl:CountAgg Mdid="0.2147.1.0"/> + </dxl:Type> + <dxl:ColumnStatistics Mdid="1.41310.1.0.0" Name="a" Width="8.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/> + </dxl:Metadata> + <dxl:Query> + <dxl:OutputColumns> + <dxl:Ident ColId="19" ColName="a" TypeMdid="0.23.1.0"/> + </dxl:OutputColumns> + <dxl:CTEList/> + <dxl:LogicalProject> + <dxl:ProjList> + <dxl:ProjElem ColId="19" Alias="a"> + <dxl:ArrayRef ElementType="0.23.1.0" ArrayType="0.1007.1.0" TypeMdid="0.23.1.0"> + <dxl:ArrayIndexList Bound="Lower"/> + <dxl:ArrayIndexList Bound="Upper"> + <dxl:ScalarSubquery ColId="10"> + <dxl:LogicalProject> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="?column?"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:LogicalConstTable> + <dxl:Columns> + <dxl:Column ColId="9" Attno="1" ColName="" TypeMdid="0.16.1.0"/> + </dxl:Columns> + <dxl:ConstTuple> + <dxl:Datum TypeMdid="0.16.1.0" Value="true"/> + </dxl:ConstTuple> + </dxl:LogicalConstTable> + </dxl:LogicalProject> + </dxl:ScalarSubquery> + </dxl:ArrayIndexList> + <dxl:RefExpr> + <dxl:ScalarSubquery ColId="11"> + <dxl:LogicalGet> + <dxl:TableDescriptor Mdid="6.41310.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="11" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <dxl:Column ColId="12" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/> + <dxl:Column ColId="13" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="14" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="15" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="16" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="17" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/> + <dxl:Column ColId="18" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/> + </dxl:Columns> + </dxl:TableDescriptor> + </dxl:LogicalGet> + </dxl:ScalarSubquery> + </dxl:RefExpr> + <dxl:AssignExpr/> + </dxl:ArrayRef> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:LogicalGet> + <dxl:TableDescriptor Mdid="6.41310.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="1" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <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:LogicalGet> + </dxl:LogicalProject> + </dxl:Query> + <dxl:Plan Id="0" SpaceSize="4"> + <dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="904755234.476809" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="18" Alias="a"> + <dxl:Ident ColId="18" ColName="a" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="904755234.476794" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="18" Alias="a"> + <dxl:ArrayRef ElementType="0.23.1.0" ArrayType="0.1007.1.0" TypeMdid="0.23.1.0"> + <dxl:ArrayIndexList Bound="Lower"/> + <dxl:ArrayIndexList Bound="Upper"> + <dxl:Ident ColId="9" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ArrayIndexList> + <dxl:RefExpr> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:RefExpr> + <dxl:AssignExpr/> + </dxl:ArrayRef> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:NestedLoopJoin JoinType="Left" IndexNestedLoopJoin="false" OuterRefAsParam="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="904755234.476792" Rows="4.000000" Width="12"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="9" Alias="?column?"> + <dxl:Ident ColId="9" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:JoinFilter> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:JoinFilter> + <dxl:NestedLoopJoin JoinType="Left" IndexNestedLoopJoin="false" OuterRefAsParam="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="882688.032580" Rows="2.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="9" Alias="?column?"> + <dxl:Ident ColId="9" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:JoinFilter> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:JoinFilter> + <dxl:TableScan> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000007" Rows="1.000000" Width="1"/> + </dxl:Properties> + <dxl:ProjList/> + <dxl:Filter/> + <dxl:TableDescriptor Mdid="6.41310.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <dxl:Column ColId="1" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0" ColWidth="6"/> + <dxl:Column ColId="2" Attno="-2" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="3" Attno="-3" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="4" Attno="-4" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/> + <dxl:Column ColId="5" Attno="-5" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/> + <dxl:Column ColId="6" Attno="-6" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/> + <dxl:Column ColId="7" Attno="-7" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/> + </dxl:Columns> + </dxl:TableDescriptor> + </dxl:TableScan> + <dxl:Materialize Eager="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000009" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="9" Alias="?column?"> + <dxl:Ident ColId="9" ColName="?column?" TypeMdid="0.23.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000005" Rows="1.000000" Width="4"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="9" Alias="?column?"> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="0.000001" Rows="1.000000" Width="1"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="8" Alias=""> + <dxl:ConstValue TypeMdid="0.16.1.0" Value="true"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + </dxl:Result> + </dxl:Result> + </dxl:Materialize> + </dxl:NestedLoopJoin> + <dxl:Assert ErrorCode="P0003"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.001008" Rows="3.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:AssertConstraintList> + <dxl:AssertConstraint ErrorMessage="Expected no more than one row to be returned by expression"> + <dxl:Comparison ComparisonOperator="=" OperatorMdid="0.416.1.0"> + <dxl:Ident ColId="19" ColName="row_number" TypeMdid="0.20.1.0"/> + <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/> + </dxl:Comparison> + </dxl:AssertConstraint> + </dxl:AssertConstraintList> + <dxl:Materialize Eager="false"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.001000" Rows="3.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="19" Alias="row_number"> + <dxl:Ident ColId="19" ColName="row_number" TypeMdid="0.20.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:BroadcastMotion InputSegments="-1" OutputSegments="0,1,2"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000984" Rows="3.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="19" Alias="row_number"> + <dxl:Ident ColId="19" ColName="row_number" TypeMdid="0.20.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:Result> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000125" Rows="1.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="19" Alias="row_number"> + <dxl:Ident ColId="19" ColName="row_number" TypeMdid="0.20.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:OneTimeFilter/> + <dxl:Window PartitionColumns=""> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000125" Rows="1.000000" Width="16"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="19" Alias="row_number"> + <dxl:WindowFunc Mdid="0.3100.1.0" TypeMdid="0.20.1.0" Distinct="false" WindowStarArg="false" WindowSimpleAgg="false" WindowStrategy="Immediate" WinSpecPos="0"/> + </dxl:ProjElem> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1"> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000125" Rows="1.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:SortingColumnList/> + <dxl:TableScan> + <dxl:Properties> + <dxl:Cost StartupCost="0" TotalCost="431.000021" Rows="1.000000" Width="8"/> + </dxl:Properties> + <dxl:ProjList> + <dxl:ProjElem ColId="10" Alias="a"> + <dxl:Ident ColId="10" ColName="a" TypeMdid="0.1007.1.0"/> + </dxl:ProjElem> + </dxl:ProjList> + <dxl:Filter/> + <dxl:TableDescriptor Mdid="6.41310.1.0" TableName="foo" LockMode="1" AclMode="2"> + <dxl:Columns> + <dxl:Column ColId="10" Attno="1" ColName="a" TypeMdid="0.1007.1.0" ColWidth="8"/> + <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:GatherMotion> + <dxl:WindowKeyList> + <dxl:WindowKey> + <dxl:SortingColumnList/> + </dxl:WindowKey> + </dxl:WindowKeyList> + </dxl:Window> + </dxl:Result> + </dxl:BroadcastMotion> + </dxl:Materialize> + </dxl:Assert> + </dxl:NestedLoopJoin> + </dxl:Result> + </dxl:GatherMotion> + </dxl:Plan> + </dxl:Thread> +</dxl:DXLMessage> diff --git a/src/backend/gporca/libgpopt/src/xforms/CSubqueryHandler.cpp b/src/backend/gporca/libgpopt/src/xforms/CSubqueryHandler.cpp index 6afbadd75b..f37a0ea512 100644 --- a/src/backend/gporca/libgpopt/src/xforms/CSubqueryHandler.cpp +++ b/src/backend/gporca/libgpopt/src/xforms/CSubqueryHandler.cpp @@ -2197,6 +2197,8 @@ CSubqueryHandler::FProcessScalarOperator(CExpression *pexprOuter, case COperator::EopScalarAggFunc: case COperator::EopScalarWindowFunc: case COperator::EopScalarArray: + case COperator::EopScalarArrayRef: + case COperator::EopScalarArrayRefIndexList: case COperator::EopScalarArrayCmp: case COperator::EopScalarCoalesce: case COperator::EopScalarCaseTest: @@ -2204,6 +2206,7 @@ CSubqueryHandler::FProcessScalarOperator(CExpression *pexprOuter, case COperator::EopScalarSwitch: case COperator::EopScalarSwitchCase: case COperator::EopScalarValuesList: + case COperator::EopScalarMinMax: fSuccess = FRecursiveHandler(pexprOuter, pexprScalar, esqctxt, ppexprNewOuter, ppexprResidualScalar); break; diff --git a/src/backend/gporca/server/src/unittest/gpopt/minidump/CICGTest.cpp b/src/backend/gporca/server/src/unittest/gpopt/minidump/CICGTest.cpp index 1f2b6fa896..b79a01aaa9 100644 --- a/src/backend/gporca/server/src/unittest/gpopt/minidump/CICGTest.cpp +++ b/src/backend/gporca/server/src/unittest/gpopt/minidump/CICGTest.cpp @@ -74,6 +74,7 @@ const CHAR *rgszFileNames[] = { // "../data/dxl/minidump/retail_28.mdp", "../data/dxl/minidump/JoinNDVRemain.mdp", "../data/dxl/minidump/Least-Greatest.mdp", + "../data/dxl/minidump/Least-Greatest-Subselect.mdp", }; struct UnSupportedTestCase diff --git a/src/backend/gporca/server/src/unittest/gpopt/minidump/CSubqueryTest.cpp b/src/backend/gporca/server/src/unittest/gpopt/minidump/CSubqueryTest.cpp index 7a4cb2d00f..2f330bcede 100644 --- a/src/backend/gporca/server/src/unittest/gpopt/minidump/CSubqueryTest.cpp +++ b/src/backend/gporca/server/src/unittest/gpopt/minidump/CSubqueryTest.cpp @@ -63,6 +63,8 @@ const CHAR *rgszSubqueryFileNames[] = { "../data/dxl/minidump/SubqAny-InsideScalarExpression.mdp", "../data/dxl/minidump/ExistentialSubquriesInsideScalarExpression.mdp", "../data/dxl/minidump/SubqueryInsideScalarIf.mdp", + "../data/dxl/minidump/SubqueryInsideArrayRef.mdp", + "../data/dxl/minidump/SubqueryInsideArrayRefIndexList.mdp", "../data/dxl/minidump/SubqueryNullTest.mdp", "../data/dxl/minidump/ExistsSubqInsideExpr.mdp", "../data/dxl/minidump/AnySubq-With-NonScalarSubqueryChild-1.mdp", diff --git a/src/test/regress/expected/subselect_gp.out b/src/test/regress/expected/subselect_gp.out index 29009a4553..2d723d5350 100644 --- a/src/test/regress/expected/subselect_gp.out +++ b/src/test/regress/expected/subselect_gp.out @@ -3721,3 +3721,157 @@ select * from table_left where exists (select 1 from table_right where l1 = r1); -- clean up drop table table_left; drop table table_right; +-- test cross params of initplan +-- https://github.com/greenplum-db/gpdb/issues/16268 +create table tmp (a varchar, b varchar, c varchar); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +select (SELECT EXISTS + (SELECT + FROM pg_views + WHERE schemaname = a)) from tmp; + exists +-------- +(0 rows) + +drop table tmp; +-- Test LEAST() and GREATEST() with an embedded subquery +drop table if exists foo; +create table foo (a int, b int) distributed by(a); +insert into foo values (1, 2), (2, 3), (3, 4); +analyze foo; +explain (costs off) select foo.a from foo where foo.a <= LEAST(foo.b, (SELECT 1), NULL); + QUERY PLAN +---------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Result + -> Seq Scan on foo + Filter: (a <= LEAST(b, $0, NULL::integer)) + Optimizer: Postgres-based planner +(6 rows) + +select foo.a from foo where foo.a <= LEAST(foo.b, (SELECT 1), NULL); + a +--- + 1 +(1 row) + +explain (costs off) select foo.a from foo where foo.a <= GREATEST(foo.b, (SELECT 1), NULL); + QUERY PLAN +------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Result + -> Seq Scan on foo + Filter: (a <= GREATEST(b, $0, NULL::integer)) + Optimizer: Postgres-based planner +(6 rows) + +select foo.a from foo where foo.a <= GREATEST(foo.b, (SELECT 1), NULL); + a +--- + 2 + 3 + 1 +(3 rows) + +explain (costs off) select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + QUERY PLAN +------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Result + InitPlan 2 (returns $1) (slice3) + -> Result + -> Seq Scan on foo + Optimizer: Postgres-based planner +(7 rows) + +select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + least +------- + 1 + 2 + 3 +(3 rows) + +drop table foo; +-- Test subquery within ScalarArrayRef or ScalarArrayRefIndexList +drop table if exists bar; +create table bar (a int[], b int[][]) distributed by(a); +insert into bar values (ARRAY[1, 2, 3], ARRAY[[1, 2, 3], [4, 5, 6]]); +analyze bar; +explain (costs off) select (select a from bar)[1] from bar; + QUERY PLAN +-------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Gather Motion 3:1 (slice3; segments: 3) + -> Seq Scan on bar bar_1 + -> Seq Scan on bar + Optimizer: Postgres-based planner +(6 rows) + +select (select a from bar)[1] from bar; + a +--- + 1 +(1 row) + +explain (costs off) select (select a from bar)[(select 1)] from bar; + QUERY PLAN +-------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Result + InitPlan 2 (returns $1) (slice3) + -> Gather Motion 3:1 (slice4; segments: 3) + -> Seq Scan on bar bar_1 + -> Seq Scan on bar + Optimizer: Postgres-based planner +(8 rows) + +select (select a from bar)[(select 1)] from bar; + a +--- + 1 +(1 row) + +explain (costs off) select (select b from bar)[1][1:3] from bar; + QUERY PLAN +-------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Gather Motion 3:1 (slice3; segments: 3) + -> Seq Scan on bar bar_1 + -> Seq Scan on bar + Optimizer: Postgres-based planner +(6 rows) + +select (select b from bar)[1][1:3] from bar; + b +----------- + {{1,2,3}} +(1 row) + +explain (costs off) select (select b from bar)[(select 1)][1:3] from bar; + QUERY PLAN +-------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + InitPlan 1 (returns $0) (slice2) + -> Result + InitPlan 2 (returns $1) (slice3) + -> Gather Motion 3:1 (slice4; segments: 3) + -> Seq Scan on bar bar_1 + -> Seq Scan on bar + Optimizer: Postgres-based planner +(8 rows) + +select (select b from bar)[(select 1)][1:3] from bar; + b +----------- + {{1,2,3}} +(1 row) + +drop table bar; diff --git a/src/test/regress/expected/subselect_gp_optimizer.out b/src/test/regress/expected/subselect_gp_optimizer.out index 4ce874d1fe..ab14862bbf 100644 --- a/src/test/regress/expected/subselect_gp_optimizer.out +++ b/src/test/regress/expected/subselect_gp_optimizer.out @@ -3828,3 +3828,189 @@ select * from table_left where exists (select 1 from table_right where l1 = r1); -- clean up drop table table_left; drop table table_right; +-- test cross params of initplan +-- https://github.com/greenplum-db/gpdb/issues/16268 +create table tmp (a varchar, b varchar, c varchar); +NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table. +HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. +select (SELECT EXISTS + (SELECT + FROM pg_views + WHERE schemaname = a)) from tmp; + exists +-------- +(0 rows) + +drop table tmp; +-- Test LEAST() and GREATEST() with an embedded subquery +drop table if exists foo; +create table foo (a int, b int) distributed by(a); +insert into foo values (1, 2), (2, 3), (3, 4); +analyze foo; +explain (costs off) select foo.a from foo where foo.a <= LEAST(foo.b, (SELECT 1), NULL); + QUERY PLAN +------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + -> Seq Scan on foo + Filter: (a <= LEAST(b, (SubPlan 1), NULL::integer)) + SubPlan 1 + -> Result + Optimizer: GPORCA +(6 rows) + +select foo.a from foo where foo.a <= LEAST(foo.b, (SELECT 1), NULL); + a +--- + 1 +(1 row) + +explain (costs off) select foo.a from foo where foo.a <= GREATEST(foo.b, (SELECT 1), NULL); + QUERY PLAN +---------------------------------------------------------------- + Gather Motion 3:1 (slice1; segments: 3) + -> Seq Scan on foo + Filter: (a <= GREATEST(b, (SubPlan 1), NULL::integer)) + SubPlan 1 + -> Result + Optimizer: GPORCA +(6 rows) + +select foo.a from foo where foo.a <= GREATEST(foo.b, (SELECT 1), NULL); + a +--- + 2 + 3 + 1 +(3 rows) + +explain (costs off) select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + QUERY PLAN +------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop Left Join + Join Filter: true + -> Nested Loop Left Join + Join Filter: true + -> Seq Scan on foo + -> Materialize + -> Result + -> Materialize + -> Result + Optimizer: GPORCA +(11 rows) + +select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + least +------- + 2 + 3 + 1 +(3 rows) + +drop table foo; +-- Test subquery within ScalarArrayRef or ScalarArrayRefIndexList +drop table if exists bar; +create table bar (a int[], b int[][]) distributed by(a); +insert into bar values (ARRAY[1, 2, 3], ARRAY[[1, 2, 3], [4, 5, 6]]); +analyze bar; +explain (costs off) select (select a from bar)[1] from bar; + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop Left Join + Join Filter: true + -> Seq Scan on bar bar_1 + -> Assert + Assert Cond: ((row_number() OVER (?)) = 1) + -> Materialize + -> Broadcast Motion 1:3 (slice2) + -> WindowAgg + -> Gather Motion 3:1 (slice3; segments: 3) + -> Seq Scan on bar + Optimizer: GPORCA +(12 rows) + +select (select a from bar)[1] from bar; + a +--- + 1 +(1 row) + +explain (costs off) select (select a from bar)[(select 1)] from bar; + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop Left Join + Join Filter: true + -> Nested Loop Left Join + Join Filter: true + -> Seq Scan on bar bar_1 + -> Materialize + -> Result + -> Assert + Assert Cond: ((row_number() OVER (?)) = 1) + -> Materialize + -> Broadcast Motion 1:3 (slice2) + -> WindowAgg + -> Gather Motion 3:1 (slice3; segments: 3) + -> Seq Scan on bar + Optimizer: GPORCA +(16 rows) + +select (select a from bar)[(select 1)] from bar; + a +--- + 1 +(1 row) + +explain (costs off) select (select b from bar)[1][1:3] from bar; + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop Left Join + Join Filter: true + -> Seq Scan on bar bar_1 + -> Assert + Assert Cond: ((row_number() OVER (?)) = 1) + -> Materialize + -> Broadcast Motion 1:3 (slice2) + -> WindowAgg + -> Gather Motion 3:1 (slice3; segments: 3) + -> Seq Scan on bar + Optimizer: GPORCA +(12 rows) + +select (select b from bar)[1][1:3] from bar; + b +----------- + {{1,2,3}} +(1 row) + +explain (costs off) select (select b from bar)[(select 1)][1:3] from bar; + QUERY PLAN +------------------------------------------------------------------------------ + Gather Motion 3:1 (slice1; segments: 3) + -> Nested Loop Left Join + Join Filter: true + -> Nested Loop Left Join + Join Filter: true + -> Seq Scan on bar bar_1 + -> Materialize + -> Result + -> Assert + Assert Cond: ((row_number() OVER (?)) = 1) + -> Materialize + -> Broadcast Motion 1:3 (slice2) + -> WindowAgg + -> Gather Motion 3:1 (slice3; segments: 3) + -> Seq Scan on bar + Optimizer: GPORCA +(16 rows) + +select (select b from bar)[(select 1)][1:3] from bar; + b +----------- + {{1,2,3}} +(1 row) + +drop table bar; diff --git a/src/test/regress/sql/subselect_gp.sql b/src/test/regress/sql/subselect_gp.sql index f6e2549771..982a6ff88b 100644 --- a/src/test/regress/sql/subselect_gp.sql +++ b/src/test/regress/sql/subselect_gp.sql @@ -1447,3 +1447,49 @@ select * from table_left where exists (select 1 from table_right where l1 = r1); -- clean up drop table table_left; drop table table_right; +-- test cross params of initplan +-- https://github.com/greenplum-db/gpdb/issues/16268 +create table tmp (a varchar, b varchar, c varchar); +select (SELECT EXISTS + (SELECT + FROM pg_views + WHERE schemaname = a)) from tmp; +drop table tmp; + +-- Test LEAST() and GREATEST() with an embedded subquery +drop table if exists foo; + +create table foo (a int, b int) distributed by(a); +insert into foo values (1, 2), (2, 3), (3, 4); +analyze foo; + +explain (costs off) select foo.a from foo where foo.a <= LEAST(foo.b, (SELECT 1), NULL); +select foo.a from foo where foo.a <= LEAST(foo.b, (SELECT 1), NULL); + +explain (costs off) select foo.a from foo where foo.a <= GREATEST(foo.b, (SELECT 1), NULL); +select foo.a from foo where foo.a <= GREATEST(foo.b, (SELECT 1), NULL); + +explain (costs off) select least((select 5), greatest(b, NULL, (select 1)), a) from foo; +select least((select 5), greatest(b, NULL, (select 1)), a) from foo; + +drop table foo; +-- Test subquery within ScalarArrayRef or ScalarArrayRefIndexList +drop table if exists bar; + +create table bar (a int[], b int[][]) distributed by(a); +insert into bar values (ARRAY[1, 2, 3], ARRAY[[1, 2, 3], [4, 5, 6]]); +analyze bar; + +explain (costs off) select (select a from bar)[1] from bar; +select (select a from bar)[1] from bar; + +explain (costs off) select (select a from bar)[(select 1)] from bar; +select (select a from bar)[(select 1)] from bar; + +explain (costs off) select (select b from bar)[1][1:3] from bar; +select (select b from bar)[1][1:3] from bar; + +explain (costs off) select (select b from bar)[(select 1)][1:3] from bar; +select (select b from bar)[(select 1)][1:3] from bar; + +drop table bar; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
