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 33b9cdd6878fa43aedca9ce33a149700dd890d74
Author: Ekta Khanna <[email protected]>
AuthorDate: Tue Apr 11 17:45:22 2023 -0700

    Update MDP tests and add test to ICG
---
 .../gporca/data/dxl/minidump/ArrayCoerceCast.mdp   |  25 +-
 .../data/dxl/minidump/ArrayCoerceImplicitCast.mdp  | 364 +++++++++++++++++++++
 .../data/dxl/minidump/SimpleArrayCoerceCast.mdp    |  25 +-
 .../gporca/data/dxl/parse_tests/q26-Metadata.xml   |   2 +-
 .../src/unittest/gpopt/minidump/CCastTest.cpp      |   1 +
 src/test/regress/expected/gporca.out               |  18 +
 src/test/regress/expected/gporca_optimizer.out     |  18 +
 src/test/regress/sql/gporca.sql                    |   7 +
 8 files changed, 455 insertions(+), 5 deletions(-)

diff --git a/src/backend/gporca/data/dxl/minidump/ArrayCoerceCast.mdp 
b/src/backend/gporca/data/dxl/minidump/ArrayCoerceCast.mdp
index 97e974cdac..8b2895ed41 100644
--- a/src/backend/gporca/data/dxl/minidump/ArrayCoerceCast.mdp
+++ b/src/backend/gporca/data/dxl/minidump/ArrayCoerceCast.mdp
@@ -88,7 +88,25 @@
         <dxl:SumAgg Mdid="0.2108.1.0"/>
         <dxl:CountAgg Mdid="0.2147.1.0"/>
       </dxl:Type>
-      <dxl:ArrayCoerceCast Mdid="3.1007.1.0;1022.1.0" Name="float8" 
CoercePathType="3" BinaryCoercible="false" SourceTypeId="0.1007.1.0" 
DestinationTypeId="0.1022.1.0" CastFuncId="0.316.1.0" IsExplicit="false" 
CoercionForm="2" Location="-1"/>
+      <dxl:Type Mdid="0.701.1.0" Name="float8" IsRedistributable="true" 
IsHashable="true" IsMergeJoinable="true" IsComposite="false" 
IsFixedLength="true" Length="8" PassByValue="true">
+        <dxl:EqualityOp Mdid="0.670.1.0"/>
+        <dxl:InequalityOp Mdid="0.671.1.0"/>
+        <dxl:LessThanOp Mdid="0.672.1.0"/>
+        <dxl:LessThanEqualsOp Mdid="0.673.1.0"/>
+        <dxl:GreaterThanOp Mdid="0.674.1.0"/>
+        <dxl:GreaterThanEqualsOp Mdid="0.675.1.0"/>
+        <dxl:ComparisonOp Mdid="0.355.1.0"/>
+        <dxl:ArrayType Mdid="0.1022.1.0"/>
+        <dxl:MinAgg Mdid="0.2136.1.0"/>
+        <dxl:MaxAgg Mdid="0.2120.1.0"/>
+        <dxl:AvgAgg Mdid="0.2105.1.0"/>
+        <dxl:SumAgg Mdid="0.2111.1.0"/>
+        <dxl:CountAgg Mdid="0.2147.1.0"/>
+      </dxl:Type>
+      <dxl:GPDBFunc Mdid="0.316.1.0" Name="float8" ReturnsSet="false" 
Stability="Immutable" DataAccess="NoSQL" IsStrict="true">
+        <dxl:ResultType Mdid="0.701.1.0"/>
+      </dxl:GPDBFunc>
+      <dxl:ArrayCoerceCast Mdid="3.1007.1.0;1022.1.0" Name="float8" 
CoercePathType="3" BinaryCoercible="false" SourceTypeId="0.1007.1.0" 
DestinationTypeId="0.1022.1.0" CastFuncId="0.316.1.0" IsExplicit="false" 
CoercionForm="2" Location="-1" SourceElemTypeId="0.23.1.0"/>
       <dxl:Type Mdid="0.26.1.0" Name="oid" IsRedistributable="true" 
IsHashable="true" IsMergeJoinable="true" IsComposite="false" 
IsFixedLength="true" Length="4" PassByValue="true">
         <dxl:EqualityOp Mdid="0.607.1.0"/>
         <dxl:InequalityOp Mdid="0.608.1.0"/>
@@ -282,7 +300,10 @@
               <dxl:ProjElem ColId="11" Alias="cont_features">
                 <dxl:ArrayCoerceExpr ElementFunc="0.316.1.0" 
TypeMdid="0.1022.1.0" IsExplicit="false" CoercionForm="2" Location="-1">
                   <dxl:Ident ColId="10" ColName="cont_features" 
TypeMdid="0.1007.1.0"/>
-                </dxl:ArrayCoerceExpr>
+                  <dxl:FuncExpr FuncId="0.316.1.0" FuncRetSet="false" 
TypeMdid="0.701.1.0">
+                    <dxl:CaseTest TypeMdid="0.23.1.0"/>
+                  </dxl:FuncExpr>
+               </dxl:ArrayCoerceExpr>
               </dxl:ProjElem>
             </dxl:ProjList>
             <dxl:Filter/>
diff --git a/src/backend/gporca/data/dxl/minidump/ArrayCoerceImplicitCast.mdp 
b/src/backend/gporca/data/dxl/minidump/ArrayCoerceImplicitCast.mdp
new file mode 100644
index 0000000000..c6583ac8bb
--- /dev/null
+++ b/src/backend/gporca/data/dxl/minidump/ArrayCoerceImplicitCast.mdp
@@ -0,0 +1,364 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/";>
+  <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="102001,102002,102003,102043,102074,102120,102144,103001,103014,103022,103026,103027,103029,103033,103038,103040,104002,104003,104004,104005,105000,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: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.1043.1.0" Name="varchar" IsRedistributable="true" 
IsHashable="true" IsMergeJoinable="true" IsComposite="false" 
IsTextRelated="true" IsFixedLength="false" Length="-1" PassByValue="false">
+        <dxl:DistrOpfamily Mdid="0.1995.1.0"/>
+        <dxl:LegacyDistrOpfamily Mdid="0.7105.1.0"/>
+        <dxl:EqualityOp Mdid="0.98.1.0"/>
+        <dxl:InequalityOp Mdid="0.531.1.0"/>
+        <dxl:LessThanOp Mdid="0.664.1.0"/>
+        <dxl:LessThanEqualsOp Mdid="0.665.1.0"/>
+        <dxl:GreaterThanOp Mdid="0.666.1.0"/>
+        <dxl:GreaterThanEqualsOp Mdid="0.667.1.0"/>
+        <dxl:ComparisonOp Mdid="0.360.1.0"/>
+        <dxl:ArrayType Mdid="0.1015.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: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: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: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:GPDBFunc Mdid="0.669.1.0" Name="varchar" ReturnsSet="false" 
Stability="Immutable" DataAccess="NoSQL" IsStrict="true" 
IsNDVPreserving="false" IsAllowedForPS="false">
+        <dxl:ResultType Mdid="0.1043.1.0"/>
+      </dxl:GPDBFunc>
+      <dxl:Relation Mdid="6.16387.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:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="b" Attno="2" Mdid="0.1015.1.0" TypeModifier="6" 
Nullable="true" ColWidth="8">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="ctid" Attno="-1" Mdid="0.27.1.0" Nullable="false" 
ColWidth="6">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="xmin" Attno="-2" Mdid="0.28.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="cmin" Attno="-3" Mdid="0.29.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="xmax" Attno="-4" Mdid="0.28.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="cmax" Attno="-5" Mdid="0.29.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="tableoid" Attno="-6" Mdid="0.26.1.0" 
Nullable="false" ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="gp_segment_id" Attno="-7" Mdid="0.23.1.0" 
Nullable="false" ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+        </dxl:Columns>
+        <dxl:IndexInfoList/>
+        <dxl:CheckConstraints/>
+        <dxl:DistrOpfamilies>
+          <dxl:DistrOpfamily Mdid="0.1977.1.0"/>
+        </dxl:DistrOpfamilies>
+      </dxl:Relation>
+      <dxl:RelationStatistics Mdid="2.16393.1.0" Name="bar" Rows="0.000000" 
RelPages="0" RelAllVisible="0" EmptyRelation="true"/>
+      <dxl:Relation Mdid="6.16393.1.0" Name="bar" 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:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="b" Attno="2" Mdid="0.1015.1.0" TypeModifier="14" 
Nullable="true" ColWidth="8">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="ctid" Attno="-1" Mdid="0.27.1.0" Nullable="false" 
ColWidth="6">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="xmin" Attno="-2" Mdid="0.28.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="cmin" Attno="-3" Mdid="0.29.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="xmax" Attno="-4" Mdid="0.28.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="cmax" Attno="-5" Mdid="0.29.1.0" Nullable="false" 
ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="tableoid" Attno="-6" Mdid="0.26.1.0" 
Nullable="false" ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+          <dxl:Column Name="gp_segment_id" Attno="-7" Mdid="0.23.1.0" 
Nullable="false" ColWidth="4">
+            <dxl:DefaultValue/>
+          </dxl:Column>
+        </dxl:Columns>
+        <dxl:IndexInfoList/>
+        <dxl:CheckConstraints/>
+        <dxl:DistrOpfamilies>
+          <dxl:DistrOpfamily Mdid="0.1977.1.0"/>
+        </dxl:DistrOpfamilies>
+      </dxl:Relation>
+      <dxl:RelationExtendedStatistics Mdid="10.16393.1.0" Name="bar"/>
+      <dxl:ColumnStatistics Mdid="1.16393.1.0.1" Name="b" Width="8.000000" 
NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" 
ColStatsMissing="true"/>
+      <dxl:ColumnStatistics Mdid="1.16393.1.0.0" Name="a" Width="4.000000" 
NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" 
ColStatsMissing="true"/>
+      <dxl:Type Mdid="0.1015.1.0" Name="_varchar" IsRedistributable="true" 
IsHashable="true" IsMergeJoinable="true" IsComposite="false" 
IsTextRelated="false" IsFixedLength="false" Length="-1" PassByValue="false">
+        <dxl:DistrOpfamily Mdid="0.627.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.0.0.0"/>
+        <dxl:CountAgg Mdid="0.2147.1.0"/>
+      </dxl:Type>
+    </dxl:Metadata>
+    <dxl:Query>
+      <dxl:OutputColumns>
+        <dxl:Ident ColId="1" ColName="a" TypeMdid="0.23.1.0"/>
+        <dxl:Ident ColId="10" ColName="b" TypeMdid="0.1015.1.0" 
TypeModifier="6"/>
+      </dxl:OutputColumns>
+      <dxl:CTEList/>
+      <dxl:LogicalInsert InsertColumns="1,10">
+        <dxl:TableDescriptor Mdid="6.16387.1.0" TableName="foo" LockMode="3" 
AssignedQueryIdForTargetRel="1">
+          <dxl:Columns>
+            <dxl:Column ColId="11" Attno="1" ColName="a" TypeMdid="0.23.1.0" 
ColWidth="4"/>
+            <dxl:Column ColId="12" Attno="2" ColName="b" TypeMdid="0.1015.1.0" 
TypeModifier="6" ColWidth="8"/>
+            <dxl:Column ColId="13" Attno="-1" ColName="ctid" 
TypeMdid="0.27.1.0" ColWidth="6"/>
+            <dxl:Column ColId="14" Attno="-2" ColName="xmin" 
TypeMdid="0.28.1.0" ColWidth="4"/>
+            <dxl:Column ColId="15" Attno="-3" ColName="cmin" 
TypeMdid="0.29.1.0" ColWidth="4"/>
+            <dxl:Column ColId="16" Attno="-4" ColName="xmax" 
TypeMdid="0.28.1.0" ColWidth="4"/>
+            <dxl:Column ColId="17" Attno="-5" ColName="cmax" 
TypeMdid="0.29.1.0" ColWidth="4"/>
+            <dxl:Column ColId="18" Attno="-6" ColName="tableoid" 
TypeMdid="0.26.1.0" ColWidth="4"/>
+            <dxl:Column ColId="19" Attno="-7" ColName="gp_segment_id" 
TypeMdid="0.23.1.0" ColWidth="4"/>
+          </dxl:Columns>
+        </dxl:TableDescriptor>
+        <dxl:LogicalProject>
+          <dxl:ProjList>
+            <dxl:ProjElem ColId="10" Alias="b">
+              <dxl:ArrayCoerceExpr TypeMdid="0.1015.1.0" TypeModifier="6" 
CoercionForm="2" Location="-1">
+                <dxl:Ident ColId="2" ColName="b" TypeMdid="0.1015.1.0" 
TypeModifier="14"/>
+                <dxl:FuncExpr FuncId="0.669.1.0" FuncRetSet="false" 
TypeMdid="0.1043.1.0" FuncVariadic="false" TypeModifier="6">
+                  <dxl:CaseTest TypeMdid="0.1043.1.0"/>
+                  <dxl:ConstValue TypeMdid="0.23.1.0" Value="6"/>
+                  <dxl:ConstValue TypeMdid="0.16.1.0" Value="false"/>
+                </dxl:FuncExpr>
+              </dxl:ArrayCoerceExpr>
+            </dxl:ProjElem>
+          </dxl:ProjList>
+          <dxl:LogicalGet>
+            <dxl:TableDescriptor Mdid="6.16393.1.0" TableName="bar" 
LockMode="1">
+              <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.1015.1.0" TypeModifier="14" ColWidth="8"/>
+                <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:LogicalInsert>
+    </dxl:Query>
+    <dxl:Plan Id="0" SpaceSize="5">
+      <dxl:DMLInsert Columns="0,9" ActionCol="10" CtidCol="0" SegmentIdCol="0">
+        <dxl:Properties>
+          <dxl:Cost StartupCost="0" TotalCost="431.020854" Rows="1.000000" 
Width="12"/>
+        </dxl:Properties>
+        <dxl:DirectDispatchInfo/>
+        <dxl:ProjList>
+          <dxl:ProjElem ColId="0" Alias="a">
+            <dxl:Ident ColId="0" ColName="a" TypeMdid="0.23.1.0"/>
+          </dxl:ProjElem>
+          <dxl:ProjElem ColId="9" Alias="b">
+            <dxl:Ident ColId="9" ColName="b" TypeMdid="0.1015.1.0" 
TypeModifier="6"/>
+          </dxl:ProjElem>
+        </dxl:ProjList>
+        <dxl:TableDescriptor Mdid="6.16387.1.0" TableName="foo" LockMode="3" 
AssignedQueryIdForTargetRel="1">
+          <dxl:Columns>
+            <dxl:Column ColId="11" Attno="1" ColName="a" TypeMdid="0.23.1.0" 
ColWidth="4"/>
+            <dxl:Column ColId="12" Attno="2" ColName="b" TypeMdid="0.1015.1.0" 
TypeModifier="6" ColWidth="8"/>
+            <dxl:Column ColId="13" Attno="-1" ColName="ctid" 
TypeMdid="0.27.1.0" ColWidth="6"/>
+            <dxl:Column ColId="14" Attno="-2" ColName="xmin" 
TypeMdid="0.28.1.0" ColWidth="4"/>
+            <dxl:Column ColId="15" Attno="-3" ColName="cmin" 
TypeMdid="0.29.1.0" ColWidth="4"/>
+            <dxl:Column ColId="16" Attno="-4" ColName="xmax" 
TypeMdid="0.28.1.0" ColWidth="4"/>
+            <dxl:Column ColId="17" Attno="-5" ColName="cmax" 
TypeMdid="0.29.1.0" ColWidth="4"/>
+            <dxl:Column ColId="18" Attno="-6" ColName="tableoid" 
TypeMdid="0.26.1.0" ColWidth="4"/>
+            <dxl:Column ColId="19" Attno="-7" ColName="gp_segment_id" 
TypeMdid="0.23.1.0" ColWidth="4"/>
+          </dxl:Columns>
+        </dxl:TableDescriptor>
+        <dxl:Result>
+          <dxl:Properties>
+            <dxl:Cost StartupCost="0" TotalCost="431.000020" Rows="1.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="9" Alias="b">
+              <dxl:ArrayCoerceExpr TypeMdid="0.1015.1.0" TypeModifier="6" 
CoercionForm="2" Location="-1">
+                <dxl:Ident ColId="1" ColName="b" TypeMdid="0.1015.1.0" 
TypeModifier="14"/>
+                <dxl:FuncExpr FuncId="0.669.1.0" FuncRetSet="false" 
TypeMdid="0.1043.1.0" FuncVariadic="false" TypeModifier="6">
+                  <dxl:CaseTest TypeMdid="0.1043.1.0"/>
+                  <dxl:ConstValue TypeMdid="0.23.1.0" Value="6"/>
+                  <dxl:ConstValue TypeMdid="0.16.1.0" Value="false"/>
+                </dxl:FuncExpr>
+              </dxl:ArrayCoerceExpr>
+            </dxl:ProjElem>
+            <dxl:ProjElem ColId="10" Alias="ColRef_0010">
+              <dxl:ConstValue TypeMdid="0.23.1.0" Value="1"/>
+            </dxl:ProjElem>
+          </dxl:ProjList>
+          <dxl:Filter/>
+          <dxl:OneTimeFilter/>
+          <dxl:TableScan>
+            <dxl:Properties>
+              <dxl:Cost StartupCost="0" TotalCost="431.000008" Rows="1.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.1015.1.0" 
TypeModifier="14"/>
+              </dxl:ProjElem>
+            </dxl:ProjList>
+            <dxl:Filter/>
+            <dxl:TableDescriptor Mdid="6.16393.1.0" TableName="bar" 
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.1015.1.0" TypeModifier="14" 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:TableScan>
+        </dxl:Result>
+      </dxl:DMLInsert>
+    </dxl:Plan>
+  </dxl:Thread>
+</dxl:DXLMessage>
diff --git a/src/backend/gporca/data/dxl/minidump/SimpleArrayCoerceCast.mdp 
b/src/backend/gporca/data/dxl/minidump/SimpleArrayCoerceCast.mdp
index fe7e0619bb..f4a23f2fd4 100644
--- a/src/backend/gporca/data/dxl/minidump/SimpleArrayCoerceCast.mdp
+++ b/src/backend/gporca/data/dxl/minidump/SimpleArrayCoerceCast.mdp
@@ -61,7 +61,25 @@
         <dxl:SumAgg Mdid="0.0.0.0"/>
         <dxl:CountAgg Mdid="0.2147.1.0"/>
       </dxl:Type>
-      <dxl:ArrayCoerceCast Mdid="3.1007.1.0;1231.1.0" Name="numeric" 
CoercePathType="3" BinaryCoercible="false" SourceTypeId="0.1007.1.0" 
DestinationTypeId="0.1231.1.0" CastFuncId="0.1740.1.0" IsExplicit="false" 
CoercionForm="2" Location="-1"/>
+      <dxl:Type Mdid="0.1700.1.0" Name="numeric" IsRedistributable="true" 
IsHashable="true" IsMergeJoinable="true" IsComposite="false" 
IsFixedLength="false" Length="-1" PassByValue="false">
+        <dxl:EqualityOp Mdid="0.1752.1.0"/>
+        <dxl:InequalityOp Mdid="0.1753.1.0"/>
+        <dxl:LessThanOp Mdid="0.1754.1.0"/>
+        <dxl:LessThanEqualsOp Mdid="0.1755.1.0"/>
+        <dxl:GreaterThanOp Mdid="0.1756.1.0"/>
+        <dxl:GreaterThanEqualsOp Mdid="0.1757.1.0"/>
+        <dxl:ComparisonOp Mdid="0.1769.1.0"/>
+        <dxl:ArrayType Mdid="0.1231.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.0.0.0"/>
+      </dxl:Type>
+      <dxl:GPDBFunc Mdid="0.1740.1.0" Name="numeric" ReturnsSet="false" 
Stability="Immutable" DataAccess="NoSQL" IsStrict="true">
+        <dxl:ResultType Mdid="0.1700.1.0"/>
+      </dxl:GPDBFunc>
+      <dxl:ArrayCoerceCast Mdid="3.1007.1.0;1231.1.0" Name="numeric" 
CoercePathType="3" BinaryCoercible="false" SourceTypeId="0.1007.1.0" 
DestinationTypeId="0.1231.1.0" CastFuncId="0.1740.1.0" IsExplicit="false" 
CoercionForm="2" Location="-1" SourceElemTypeId="0.23.1.0"/>
       <dxl:Type Mdid="0.1007.1.0" Name="_int4" IsRedistributable="true" 
IsHashable="false" IsMergeJoinable="false" IsComposite="false" 
IsFixedLength="false" Length="-1" PassByValue="false">
         <dxl:EqualityOp Mdid="0.1070.1.0"/>
         <dxl:InequalityOp Mdid="0.1071.1.0"/>
@@ -162,7 +180,10 @@
             <dxl:ProjElem ColId="4" Alias="array">
               <dxl:ArrayCoerceExpr ElementFunc="0.1740.1.0" 
TypeMdid="0.1231.1.0" IsExplicit="false" CoercionForm="2" Location="-1">
                 <dxl:Ident ColId="3" ColName="array" TypeMdid="0.1007.1.0"/>
-              </dxl:ArrayCoerceExpr>
+                <dxl:FuncExpr FuncId="0.1740.1.0" FuncRetSet="false" 
TypeMdid="0.1700.1.0">
+                  <dxl:CaseTest TypeMdid="0.23.1.0"/>
+                </dxl:FuncExpr>
+             </dxl:ArrayCoerceExpr>
             </dxl:ProjElem>
           </dxl:ProjList>
           <dxl:Filter/>
diff --git a/src/backend/gporca/data/dxl/parse_tests/q26-Metadata.xml 
b/src/backend/gporca/data/dxl/parse_tests/q26-Metadata.xml
index 6d2cdd630e..2d6ed7c2c5 100644
--- a/src/backend/gporca/data/dxl/parse_tests/q26-Metadata.xml
+++ b/src/backend/gporca/data/dxl/parse_tests/q26-Metadata.xml
@@ -3,7 +3,7 @@
   <dxl:Metadata>
     <dxl:MDCast Mdid="3.23.1.0;20.1.0" Name="int8" BinaryCoercible="false" 
SourceTypeId="0.23.1.0" DestinationTypeId="0.20.1.0" CastFuncId="0.481.1.0" 
CoercePathType="1"/>
     <dxl:MDCast Mdid="3.23.1.0;26.1.0" Name="int" BinaryCoercible="true" 
SourceTypeId="0.23.1.0" DestinationTypeId="0.26.1.0" CastFuncId="0.0.0.0" 
CoercePathType="0"/>
-    <dxl:ArrayCoerceCast Mdid="3.1007.1.0;1022.1.0" Name="float8" 
CoercePathType="3" BinaryCoercible="false" SourceTypeId="0.1007.1.0" 
DestinationTypeId="0.1022.1.0" CastFuncId="0.316.1.0" IsExplicit="false" 
CoercionForm="2" Location="-1"/>
+    <dxl:ArrayCoerceCast Mdid="3.1007.1.0;1022.1.0" Name="float8" 
CoercePathType="3" BinaryCoercible="false" SourceTypeId="0.1007.1.0" 
DestinationTypeId="0.1022.1.0" CastFuncId="0.316.1.0" 
SourceElemTypeId="0.23.1.0" IsExplicit="false" CoercionForm="2" Location="-1"/>
     <dxl:MDScalarComparison Mdid="4.23.1.0;20.1.0;0" Name="=" 
ComparisonType="Eq" LeftType="0.23.1.0" RightType="0.20.1.0" 
OperatorMdid="0.416.1.0"/>
     <dxl:RelationStatistics Mdid="2.1234.1.2" Name="T" Rows="1234.123400" 
RelPages="0" RelAllVisible="0" EmptyRelation="false"/>
     <dxl:ColumnStatistics Mdid="1.1234.1.2.1" Name="T.a" Width="4.000000" 
NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" 
ColStatsMissing="false">
diff --git 
a/src/backend/gporca/server/src/unittest/gpopt/minidump/CCastTest.cpp 
b/src/backend/gporca/server/src/unittest/gpopt/minidump/CCastTest.cpp
index 92dbb24388..06ae552a0a 100644
--- a/src/backend/gporca/server/src/unittest/gpopt/minidump/CCastTest.cpp
+++ b/src/backend/gporca/server/src/unittest/gpopt/minidump/CCastTest.cpp
@@ -35,6 +35,7 @@ const CHAR *rgszCastMdpFiles[] = {
        "../data/dxl/minidump/CoerceViaIO.mdp",
        "../data/dxl/minidump/ArrayCoerceCast.mdp",
        "../data/dxl/minidump/SimpleArrayCoerceCast.mdp",
+       "../data/dxl/minidump/ArrayCoerceImplicitCast.mdp",
        "../data/dxl/minidump/EstimateJoinRowsForCastPredicates.mdp",
        "../data/dxl/minidump/HashJoinOnRelabeledColumns.mdp",
        "../data/dxl/minidump/Correlation-With-Casting-1.mdp",
diff --git a/src/test/regress/expected/gporca.out 
b/src/test/regress/expected/gporca.out
index 94aeee9028..556536bb23 100644
--- a/src/test/regress/expected/gporca.out
+++ b/src/test/regress/expected/gporca.out
@@ -14590,3 +14590,21 @@ select * from conf;
 (1 row)
 
 reset optimizer_trace_fallback;
+-- Test ORCA support for implicit array coerce cast
+create table array_coerce_foo (a int, b varchar(2)[]);
+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.
+create table array_coerce_bar (a int, b varchar(10)[]);
+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.
+insert into array_coerce_bar values (1, ARRAY['abcde']);
+explain insert into array_coerce_foo select * from array_coerce_bar;
+                                 QUERY PLAN                                  
+-----------------------------------------------------------------------------
+ Insert on array_coerce_foo  (cost=0.00..654.00 rows=16533 width=36)
+   ->  Seq Scan on array_coerce_bar  (cost=0.00..654.00 rows=16533 width=36)
+ Optimizer: Postgres query optimizer
+(3 rows)
+
+insert into array_coerce_foo select * from array_coerce_bar;
+ERROR:  value too long for type character varying(2)  (seg1 127.0.0.1:7003 
pid=55908)
diff --git a/src/test/regress/expected/gporca_optimizer.out 
b/src/test/regress/expected/gporca_optimizer.out
index f443584318..85863735f5 100644
--- a/src/test/regress/expected/gporca_optimizer.out
+++ b/src/test/regress/expected/gporca_optimizer.out
@@ -14706,3 +14706,21 @@ select * from conf;
 (1 row)
 
 reset optimizer_trace_fallback;
+-- Test ORCA support for implicit array coerce cast
+create table array_coerce_foo (a int, b varchar(2)[]);
+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.
+create table array_coerce_bar (a int, b varchar(10)[]);
+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.
+insert into array_coerce_bar values (1, ARRAY['abcde']);
+explain insert into array_coerce_foo select * from array_coerce_bar;
+                               QUERY PLAN                                
+-------------------------------------------------------------------------
+ Insert on array_coerce_foo  (cost=0.00..431.02 rows=1 width=12)
+   ->  Seq Scan on array_coerce_bar  (cost=0.00..431.00 rows=1 width=12)
+ Optimizer: Pivotal Optimizer (GPORCA)
+(3 rows)
+
+insert into array_coerce_foo select * from array_coerce_bar;
+ERROR:  value too long for type character varying(2)  (seg1 127.0.0.1:7003 
pid=51460)
diff --git a/src/test/regress/sql/gporca.sql b/src/test/regress/sql/gporca.sql
index 32800ed277..ef071ff6d9 100644
--- a/src/test/regress/sql/gporca.sql
+++ b/src/test/regress/sql/gporca.sql
@@ -3575,6 +3575,13 @@ insert into ts_tbl select to_timestamp('99991231'::text, 
'YYYYMMDD'::text) from
 analyze ts_tbl;
 explain select * from ts_tbl where ts = to_timestamp('99991231'::text, 
'YYYYMMDD'::text);
 
+-- Test ORCA support for implicit array coerce cast
+create table array_coerce_foo (a int, b varchar(2)[]);
+create table array_coerce_bar (a int, b varchar(10)[]);
+
+insert into array_coerce_bar values (1, ARRAY['abcde']);
+explain insert into array_coerce_foo select * from array_coerce_bar;
+insert into array_coerce_foo select * from array_coerce_bar;
 
 WITH conf AS (
     SELECT setting


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to