提交 5bcd44f6 编写于 作者: D Dhanashree Kashid 提交者: Bhuvnesh

Add new Array Coerce Cast Metadata object

Currently executor crashes for following query with ORCA ON :
```
CREATE TABLE FOO(a
integer NOT NULL, b double precision[]); SELECT b FROM foo UNION ALL SELECT
ARRAY[90, 90] as Cont_features;
```

In this query, we are appending an integer array (ARRAY[90, 90]) to a double
precision array (foo.b) and hence we need to apply a cast on ARRAY[90, 90] to
generate ARRAY[90, 90]::double precision[].
In gpdb5 there is not direct function available that can cast array of any type
to array of any other type. So in relcache to dxl translator we look into the
array elements and get their type and try to find a cast function for them.
For this query, source type is 23 (integer) and dest type is 701 (double precision)
 and we try to find if we have a conversion function for 23 -> 701.
Since that is available we send that function to ORCA as follows:
```
<dxl:MDCast
Mdid="3.1007.1.0;1022.1.0" Name="float8" BinaryCoercible="false"
SourceTypeId="0.1007.1.0" DestinationTypeId="0.1022.1.0"
CastFuncId="0.316.1.0"/>
```
Here we are misinforming ORCA by specifying that function with id 316 is available
to convert type 1007 (integer array) to 1022 (double precision) array.
However Function id 316 is simple int4 to float8 conversion function and it CAN NOT
convert an array of int4 to array of double precision.
ORCA generates a plan using this function but executor crashes while executing this
function because this function can not handle arrays.

This commit adds a new ArrayCoerceCast MetaData object which will be constructed
when we need to convert an array of one type to another; instead of constructing
Cast Metadata.

`CMDArrayCoerceCastGPDB` extends `CMDCastGPDB` in that it includes necessary information
to generate `CScalarArrayCoerceExpr`.

In Relcache Translator on GPDB, we will construct an object of `CMDArrayCoerceCastGPDB`
instead of `CMDCastGPDB` depending on the coercion path determined by `FCastFunc`.

Added relevant test cases.

Ref [#149524459]
Signed-off-by: NEkta Khanna <ekhanna@pivotal.io>
上级 ee5ef334
<?xml version="1.0" encoding="UTF-8"?>
<!--
CREATE TABLE FOO(a integer NOT NULL, b double precision[]);
SELECT b FROM foo
UNION ALL
SELECT ARRAY[90, 90] as Cont_features;
-->
<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.010000" DampingFactorGroupBy="0.750000"/>
<dxl:CTEConfig CTEInliningCutoff="0"/>
<dxl:CostModelConfig CostModelType="1" SegmentsForCosting="3"/>
<dxl:Hint MinNumOfPartsToRequireSortOnInsert="2147483647" JoinArityForAssociativityCommutativity="2147483647" ArrayExpansionThreshold="25" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="10000000"/>
<dxl:TraceFlags Value="102120,103001,103014,103015,103022,104003,104004,104005,105000"/>
</dxl:OptimizerConfig>
<dxl:Metadata SystemIds="0.GPDB">
<dxl:RelationStatistics Mdid="2.98304.1.0" Name="foo" Rows="0.000000" EmptyRelation="true"/>
<dxl:Relation Mdid="0.98304.1.0" Name="foo" IsTemporary="false" HasOids="false" StorageType="Heap" DistributionPolicy="Hash" DistributionColumns="0" Keys="8,2" NumberLeafPartitions="0">
<dxl:Columns>
<dxl:Column Name="a" Attno="1" Mdid="0.23.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="b" Attno="2" Mdid="0.1022.1.0" Nullable="true">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="ctid" Attno="-1" Mdid="0.27.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="xmin" Attno="-3" Mdid="0.28.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="cmin" Attno="-4" Mdid="0.29.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="xmax" Attno="-5" Mdid="0.28.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="cmax" Attno="-6" Mdid="0.29.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="tableoid" Attno="-7" Mdid="0.26.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="gp_segment_id" Attno="-8" Mdid="0.23.1.0" Nullable="false">
<dxl:DefaultValue/>
</dxl:Column>
</dxl:Columns>
<dxl:Indexes/>
<dxl:Triggers/>
<dxl:CheckConstraints/>
</dxl:Relation>
<dxl:ColumnStatistics Mdid="1.98304.1.0.3" Name="xmin" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.2" Name="ctid" Width="6.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:Type Mdid="0.16.1.0" Name="bool" IsRedistributable="true" IsHashable="true" IsComposite="false" IsFixedLength="true" Length="1" PassByValue="true">
<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" IsComposite="false" IsFixedLength="true" Length="4" PassByValue="true">
<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: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" TypeModification="-1" IsExplicit="false" CoercionForm="2" Location="-1"/>
<dxl:Type Mdid="0.26.1.0" Name="oid" IsRedistributable="true" IsHashable="true" IsComposite="false" IsFixedLength="true" Length="4" PassByValue="true">
<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.2118.1.0"/>
<dxl:MaxAgg Mdid="0.2134.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="false" IsComposite="false" IsFixedLength="true" Length="6" PassByValue="false">
<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="false" IsHashable="true" IsComposite="false" IsFixedLength="true" Length="4" PassByValue="true">
<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="false" IsHashable="true" IsComposite="false" IsFixedLength="true" Length="4" PassByValue="true">
<dxl:EqualityOp Mdid="0.352.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.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.98304.1.0.8" Name="gp_segment_id" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.1" Name="b" Width="8.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.0" Name="a" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.7" Name="tableoid" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.6" Name="cmax" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.5" Name="xmax" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:ColumnStatistics Mdid="1.98304.1.0.4" Name="cmin" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="true"/>
<dxl:Type Mdid="0.1007.1.0" Name="_int4" IsRedistributable="true" IsHashable="false" IsComposite="false" IsFixedLength="false" PassByValue="false">
<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.3217.1.0"/>
<dxl:CountAgg Mdid="0.2147.1.0"/>
</dxl:Type>
<dxl:Type Mdid="0.1022.1.0" Name="_float8" IsRedistributable="true" IsHashable="false" IsComposite="false" IsFixedLength="false" PassByValue="false">
<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.3219.1.0"/>
<dxl:CountAgg Mdid="0.2147.1.0"/>
</dxl:Type>
</dxl:Metadata>
<dxl:Query>
<dxl:OutputColumns>
<dxl:Ident ColId="2" ColName="b" TypeMdid="0.1022.1.0"/>
</dxl:OutputColumns>
<dxl:CTEList/>
<dxl:UnionAll InputColumns="2;11" CastAcrossInputs="true">
<dxl:Columns>
<dxl:Column ColId="2" Attno="1" ColName="b" TypeMdid="0.1022.1.0"/>
</dxl:Columns>
<dxl:LogicalGet>
<dxl:TableDescriptor Mdid="0.98304.1.0" TableName="foo">
<dxl:Columns>
<dxl:Column ColId="1" Attno="1" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="2" Attno="2" ColName="b" TypeMdid="0.1022.1.0"/>
<dxl:Column ColId="3" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0"/>
<dxl:Column ColId="4" Attno="-3" ColName="xmin" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="5" Attno="-4" ColName="cmin" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="6" Attno="-5" ColName="xmax" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="7" Attno="-6" ColName="cmax" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="8" Attno="-7" ColName="tableoid" TypeMdid="0.26.1.0"/>
<dxl:Column ColId="9" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:LogicalGet>
<dxl:LogicalProject>
<dxl:ProjList>
<dxl:ProjElem ColId="11" Alias="cont_features">
<dxl:ConstValue TypeMdid="0.1007.1.0" IsNull="false" IsByValue="false" Value="AAAAIAEAAAAAAAAAFwAAAAIAAAABAAAAWgAAAFoAAAA="/>
</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" IsNull="false" IsByValue="true" Value="true"/>
</dxl:ConstTuple>
</dxl:LogicalConstTable>
</dxl:LogicalProject>
</dxl:UnionAll>
</dxl:Query>
<dxl:Plan Id="0" SpaceSize="1">
<dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000087" Rows="2.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.1022.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:SortingColumnList/>
<dxl:Append IsTarget="false" IsZapped="false">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000027" Rows="2.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.1022.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000008" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="1" Alias="b">
<dxl:Ident ColId="1" ColName="b" TypeMdid="0.1022.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:TableDescriptor Mdid="0.98304.1.0" TableName="foo">
<dxl:Columns>
<dxl:Column ColId="0" Attno="1" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Column ColId="1" Attno="2" ColName="b" TypeMdid="0.1022.1.0"/>
<dxl:Column ColId="2" Attno="-1" ColName="ctid" TypeMdid="0.27.1.0"/>
<dxl:Column ColId="3" Attno="-3" ColName="xmin" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="4" Attno="-4" ColName="cmin" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="5" Attno="-5" ColName="xmax" TypeMdid="0.28.1.0"/>
<dxl:Column ColId="6" Attno="-6" ColName="cmax" TypeMdid="0.29.1.0"/>
<dxl:Column ColId="7" Attno="-7" ColName="tableoid" TypeMdid="0.26.1.0"/>
<dxl:Column ColId="8" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000009" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="11" Alias="cont_features">
<dxl:ArrayCoerceExpr ElementFunc="0.316.1.0" TypeMdid="0.1022.1.0" TypeModification="-1" IsExplicit="false" CoercionForm="2" Location="-1">
<dxl:Ident ColId="10" ColName="cont_features" TypeMdid="0.1007.1.0"/>
</dxl:ArrayCoerceExpr>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:OneTimeFilter/>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000006" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="10" Alias="cont_features">
<dxl:ConstValue TypeMdid="0.1007.1.0" IsNull="false" IsByValue="false" Value="AAAAIAEAAAAAAAAAFwAAAAIAAAABAAAAWgAAAFoAAAA="/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:OneTimeFilter/>
<dxl:RandomMotion InputSegments="0" OutputSegments="0,1,2" DuplicateSensitive="true">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000004" Rows="1.000000" Width="1"/>
</dxl:Properties>
<dxl:ProjList/>
<dxl:Filter/>
<dxl:SortingColumnList/>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000001" Rows="1.000000" Width="1"/>
</dxl:Properties>
<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" IsNull="false" IsByValue="true" Value="true"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:OneTimeFilter/>
</dxl:Result>
</dxl:Result>
</dxl:RandomMotion>
</dxl:Result>
</dxl:Result>
</dxl:Append>
</dxl:GatherMotion>
</dxl:Plan>
</dxl:Thread>
</dxl:DXLMessage>
<?xml version="1.0" encoding="UTF-8"?>
<!--
SELECT ARRAY[1.11, 2.11] UNION ALL SELECT ARRAY[1, 2];
-->
<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.010000" DampingFactorGroupBy="0.750000"/>
<dxl:CTEConfig CTEInliningCutoff="0"/>
<dxl:CostModelConfig CostModelType="1" SegmentsForCosting="3"/>
<dxl:Hint MinNumOfPartsToRequireSortOnInsert="2147483647" JoinArityForAssociativityCommutativity="2147483647" ArrayExpansionThreshold="25" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="10000000"/>
<dxl:TraceFlags Value="102120,103001,103003,103014,103015,103022,104003,104004,104005,105000"/>
</dxl:OptimizerConfig>
<dxl:Metadata SystemIds="0.GPDB">
<dxl:Type Mdid="0.16.1.0" Name="bool" IsRedistributable="true" IsHashable="true" IsComposite="false" IsFixedLength="true" Length="1" PassByValue="true">
<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:GPDBScalarOp Mdid="0.1070.1.0" Name="=" ComparisonType="Eq" ReturnsNullOnNullInput="true">
<dxl:LeftType Mdid="0.2277.1.0"/>
<dxl:RightType Mdid="0.2277.1.0"/>
<dxl:ResultType Mdid="0.16.1.0"/>
<dxl:OpFunc Mdid="0.744.1.0"/>
<dxl:Commutator Mdid="0.1070.1.0"/>
<dxl:InverseOp Mdid="0.1071.1.0"/>
<dxl:OpClasses>
<dxl:OpClass Mdid="0.397.1.0"/>
<dxl:OpClass Mdid="0.2745.1.0"/>
<dxl:OpClass Mdid="0.3015.1.0"/>
</dxl:OpClasses>
</dxl:GPDBScalarOp>
<dxl:Type Mdid="0.1231.1.0" Name="_numeric" IsRedistributable="true" IsHashable="false" IsComposite="false" IsFixedLength="false" PassByValue="false">
<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: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" TypeModification="-1" IsExplicit="false" CoercionForm="2" Location="-1"/>
<dxl:Type Mdid="0.1007.1.0" Name="_int4" IsRedistributable="true" IsHashable="false" IsComposite="false" IsFixedLength="false" PassByValue="false">
<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.3217.1.0"/>
<dxl:CountAgg Mdid="0.2147.1.0"/>
</dxl:Type>
</dxl:Metadata>
<dxl:Query>
<dxl:OutputColumns>
<dxl:Ident ColId="2" ColName="array" TypeMdid="0.1231.1.0"/>
</dxl:OutputColumns>
<dxl:CTEList/>
<dxl:UnionAll InputColumns="2;4" CastAcrossInputs="true">
<dxl:Columns>
<dxl:Column ColId="2" Attno="1" ColName="array" TypeMdid="0.1231.1.0"/>
</dxl:Columns>
<dxl:LogicalProject>
<dxl:ProjList>
<dxl:ProjElem ColId="2" Alias="array">
<dxl:ConstValue TypeMdid="0.1231.1.0" IsNull="false" IsByValue="false" Value="AAAAMAEAAAAAAAAApAYAAAIAAAABAAAAAAAADAIAAAABAEwEAAAADAIAAAAC&#10;AEwE"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:LogicalConstTable>
<dxl:Columns>
<dxl:Column ColId="1" Attno="1" ColName="" TypeMdid="0.16.1.0"/>
</dxl:Columns>
<dxl:ConstTuple>
<dxl:Datum TypeMdid="0.16.1.0" IsNull="false" IsByValue="true" Value="true"/>
</dxl:ConstTuple>
</dxl:LogicalConstTable>
</dxl:LogicalProject>
<dxl:LogicalProject>
<dxl:ProjList>
<dxl:ProjElem ColId="4" Alias="array">
<dxl:ConstValue TypeMdid="0.1007.1.0" IsNull="false" IsByValue="false" Value="AAAAIAEAAAAAAAAAFwAAAAIAAAABAAAAAQAAAAIAAAA="/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:LogicalConstTable>
<dxl:Columns>
<dxl:Column ColId="3" Attno="1" ColName="" TypeMdid="0.16.1.0"/>
</dxl:Columns>
<dxl:ConstTuple>
<dxl:Datum TypeMdid="0.16.1.0" IsNull="false" IsByValue="true" Value="true"/>
</dxl:ConstTuple>
</dxl:LogicalConstTable>
</dxl:LogicalProject>
</dxl:UnionAll>
</dxl:Query>
<dxl:Plan Id="0" SpaceSize="3">
<dxl:Append IsTarget="false" IsZapped="false">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000042" Rows="2.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="1" Alias="array">
<dxl:Ident ColId="1" ColName="array" TypeMdid="0.1231.1.0"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000009" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="1" Alias="array">
<dxl:ConstValue TypeMdid="0.1231.1.0" IsNull="false" IsByValue="false" Value="AAAAMAEAAAAAAAAApAYAAAIAAAABAAAAAAAADAIAAAABAEwEAAAADAIAAAAC&#10;AEwE"/>
</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="0" Alias="">
<dxl:ConstValue TypeMdid="0.16.1.0" IsNull="false" IsByValue="true" Value="true"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:OneTimeFilter/>
</dxl:Result>
</dxl:Result>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000017" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="4" Alias="array">
<dxl:ArrayCoerceExpr ElementFunc="0.1740.1.0" TypeMdid="0.1231.1.0" TypeModification="-1" IsExplicit="false" CoercionForm="2" Location="-1">
<dxl:Ident ColId="3" ColName="array" TypeMdid="0.1007.1.0"/>
</dxl:ArrayCoerceExpr>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:OneTimeFilter/>
<dxl:Result>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="0.000009" Rows="1.000000" Width="8"/>
</dxl:Properties>
<dxl:ProjList>
<dxl:ProjElem ColId="3" Alias="array">
<dxl:ConstValue TypeMdid="0.1007.1.0" IsNull="false" IsByValue="false" Value="AAAAIAEAAAAAAAAAFwAAAAIAAAABAAAAAQAAAAIAAAA="/>
</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="2" Alias="">
<dxl:ConstValue TypeMdid="0.16.1.0" IsNull="false" IsByValue="true" Value="true"/>
</dxl:ProjElem>
</dxl:ProjList>
<dxl:Filter/>
<dxl:OneTimeFilter/>
</dxl:Result>
</dxl:Result>
</dxl:Result>
</dxl:Append>
</dxl:Plan>
</dxl:Thread>
</dxl:DXLMessage>
<?xml version="1.0" encoding="UTF-8"?>
<dxl:DXLMessage xmlns:dxl="http://greenplum.com/dxl/2010/12/">
<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"/>
<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"/>
<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" TypeModification="-1" 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" 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">
......
......@@ -47,6 +47,7 @@
#include "naucrates/md/IMDTypeOid.h"
#include "naucrates/md/CMDIdGPDB.h"
#include "naucrates/md/IMDCast.h"
#include "naucrates/md/CMDArrayCoerceCastGPDB.h"
#include "naucrates/md/CMDIdScCmp.h"
#include "naucrates/traceflags/traceflags.h"
......@@ -4224,9 +4225,34 @@ CUtils::PexprCast
pmdidDest->AddRef();
pmdcast->PmdidCastFunc()->AddRef();
CScalarCast *popCast = GPOS_NEW(pmp) CScalarCast(pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible());
return GPOS_NEW(pmp) CExpression(pmp, popCast, PexprScalarIdent(pmp, pcr));
CExpression *pexpr;
if(pmdcast->EmdPathType() == IMDCast::EmdtArrayCoerce)
{
CMDArrayCoerceCastGPDB *parrayCoerceCast = (CMDArrayCoerceCastGPDB *) pmdcast;
pexpr = GPOS_NEW(pmp) CExpression
(
pmp,
GPOS_NEW(pmp) CScalarArrayCoerceExpr
(
pmp,
parrayCoerceCast->PmdidCastFunc(),
pmdidDest,
parrayCoerceCast->IMod(),
parrayCoerceCast->FIsExplicit(),
(COperator::ECoercionForm) parrayCoerceCast->Ecf(),
parrayCoerceCast->ILoc()
),
PexprScalarIdent(pmp, pcr)
);
}
else
{
CScalarCast *popCast = GPOS_NEW(pmp) CScalarCast(pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible());
pexpr = GPOS_NEW(pmp) CExpression(pmp, popCast, PexprScalarIdent(pmp, pcr));
}
return pexpr;
}
// cast the input expression to the destination mdid
......@@ -4247,9 +4273,35 @@ CUtils::PexprCast
pmdidDest->AddRef();
pmdcast->PmdidCastFunc()->AddRef();
CExpression *pexprCast;
if(pmdcast->EmdPathType() == IMDCast::EmdtArrayCoerce)
{
CMDArrayCoerceCastGPDB *parrayCoerceCast = (CMDArrayCoerceCastGPDB *) pmdcast;
pexprCast = GPOS_NEW(pmp) CExpression
(
pmp,
GPOS_NEW(pmp) CScalarArrayCoerceExpr
(
pmp,
parrayCoerceCast->PmdidCastFunc(),
pmdidDest,
parrayCoerceCast->IMod(),
parrayCoerceCast->FIsExplicit(),
(COperator::ECoercionForm) parrayCoerceCast->Ecf(),
parrayCoerceCast->ILoc()
),
pexpr
);
}
else
{
CScalarCast *popCast = GPOS_NEW(pmp) CScalarCast(pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible());
pexprCast = GPOS_NEW(pmp) CExpression(pmp, popCast, pexpr);
}
CScalarCast *popCast = GPOS_NEW(pmp) CScalarCast(pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible());
return GPOS_NEW(pmp) CExpression(pmp, popCast, pexpr);
return pexprCast;
}
// check whether the given expression is a binary coercible cast of something
......
......@@ -30,6 +30,7 @@
#include "naucrates/md/IMDType.h"
#include "naucrates/md/CMDIdGPDB.h"
#include "naucrates/md/IMDCast.h"
#include "naucrates/md/CMDArrayCoerceCastGPDB.h"
#include "naucrates/dxl/gpdb_types.h"
#include "naucrates/statistics/CStatistics.h"
......@@ -2012,9 +2013,25 @@ CPredicateUtils::PexprCast
pmdidDest->AddRef();
pmdcast->PmdidCastFunc()->AddRef();
CScalarCast *popCast = GPOS_NEW(pmp) CScalarCast(pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible());
return GPOS_NEW(pmp) CExpression(pmp, popCast, pexpr);
CExpression *pexprCast;
if (pmdcast->EmdPathType() == IMDCast::EmdtArrayCoerce)
{
CMDArrayCoerceCastGPDB *parrayCoerceCast = (CMDArrayCoerceCastGPDB *) pmdcast;
pexprCast = GPOS_NEW(pmp) CExpression
(
pmp,
GPOS_NEW(pmp) CScalarArrayCoerceExpr(pmp, parrayCoerceCast->PmdidCastFunc(), pmdidDest, parrayCoerceCast->IMod(), parrayCoerceCast->FIsExplicit(), (COperator::ECoercionForm) parrayCoerceCast->Ecf(), parrayCoerceCast->ILoc()),
pexpr
);
}
else
{
CScalarCast *popCast = GPOS_NEW(pmp) CScalarCast(pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible());
pexprCast = GPOS_NEW(pmp) CExpression(pmp, popCast, pexpr);
}
return pexprCast;
}
// add explicit casting to equality operations between compatible types
......
......@@ -19,6 +19,7 @@
#include "naucrates/md/IMDScalarOp.h"
#include "naucrates/md/IMDAggregate.h"
#include "naucrates/md/IMDCast.h"
#include "naucrates/md/CMDArrayCoerceCastGPDB.h"
#include "naucrates/md/CMDRelationCtasGPDB.h"
#include "naucrates/md/CMDProviderMemory.h"
......@@ -724,14 +725,29 @@ CTranslatorDXLToExpr::PexprCastPrjElem
const IMDCast *pmdcast = m_pmda->Pmdcast(pmdidSource, pmdidDest);
pmdidDest->AddRef();
pmdcast->PmdidCastFunc()->AddRef();
CExpression *pexprCast;
CExpression *pexprCast =
if (pmdcast->EmdPathType() == IMDCast::EmdtArrayCoerce)
{
CMDArrayCoerceCastGPDB *parrayCoerceCast = (CMDArrayCoerceCastGPDB *) pmdcast;
pexprCast =
GPOS_NEW(m_pmp) CExpression
(
(
m_pmp,
GPOS_NEW(m_pmp) CScalarCast(m_pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible()),
GPOS_NEW(m_pmp) CScalarArrayCoerceExpr(m_pmp, parrayCoerceCast->PmdidCastFunc(), pmdidDest, parrayCoerceCast->IMod(), parrayCoerceCast->FIsExplicit(), (COperator::ECoercionForm) parrayCoerceCast->Ecf(), parrayCoerceCast->ILoc()),
GPOS_NEW(m_pmp) CExpression(m_pmp, GPOS_NEW(m_pmp) CScalarIdent(m_pmp, pcrToCast))
);
}
else
{
pexprCast =
GPOS_NEW(m_pmp) CExpression
(
m_pmp,
GPOS_NEW(m_pmp) CScalarCast(m_pmp, pmdidDest, pmdcast->PmdidCastFunc(), pmdcast->FBinaryCoercible()),
GPOS_NEW(m_pmp) CExpression(m_pmp, GPOS_NEW(m_pmp) CScalarIdent(m_pmp, pcrToCast))
);
}
return
GPOS_NEW(m_pmp) CExpression
......@@ -2870,13 +2886,31 @@ CTranslatorDXLToExpr::PexprScalarFunc
if (CTranslatorDXLToExprUtils::FCastFunc(m_pmda, pdxlnFunc, pmdidInput))
{
const IMDCast *pmdcast = m_pmda->Pmdcast(pmdidInput, pmdidRetType);
pop = GPOS_NEW(m_pmp) CScalarCast
(
m_pmp,
pmdidRetType,
pmdidFunc,
pmdcast->FBinaryCoercible()
);
if (pmdcast->EmdPathType() == IMDCast::EmdtArrayCoerce)
{
CMDArrayCoerceCastGPDB *parrayCoerceCast = (CMDArrayCoerceCastGPDB *) pmdcast;
pop = GPOS_NEW(m_pmp) CScalarArrayCoerceExpr
(
m_pmp,
parrayCoerceCast->PmdidCastFunc(),
pmdidRetType,
parrayCoerceCast->IMod(),
parrayCoerceCast->FIsExplicit(),
(COperator::ECoercionForm) parrayCoerceCast->Ecf(),
parrayCoerceCast->ILoc()
);
}
else
{
pop = GPOS_NEW(m_pmp) CScalarCast
(
m_pmp,
pmdidRetType,
pmdidFunc,
pmdcast->FBinaryCoercible()
);
}
}
else
{
......@@ -3572,12 +3606,37 @@ CTranslatorDXLToExpr::PexprScalarCast
const IMDCast *pmdcast = m_pmda->Pmdcast(pmdidInput, pmdidType);
BOOL fRelabel = pmdcast->FBinaryCoercible();
CExpression *pexpr = GPOS_NEW(m_pmp) CExpression
CExpression *pexpr;
if (pmdcast->EmdPathType() == IMDCast::EmdtArrayCoerce)
{
CMDArrayCoerceCastGPDB *parrayCoerceCast = (CMDArrayCoerceCastGPDB *) pmdcast;
pexpr = GPOS_NEW(m_pmp) CExpression
(
m_pmp,
GPOS_NEW(m_pmp) CScalarArrayCoerceExpr
(
m_pmp,
parrayCoerceCast->PmdidCastFunc(),
pmdidType,
parrayCoerceCast->IMod(),
parrayCoerceCast->FIsExplicit(),
(COperator::ECoercionForm) parrayCoerceCast->Ecf(),
parrayCoerceCast->ILoc()
),
pexprChild
);
}
else
{
pexpr= GPOS_NEW(m_pmp) CExpression
(
m_pmp,
GPOS_NEW(m_pmp) CScalarCast(m_pmp, pmdidType, pmdidFunc, fRelabel),
pexprChild
);
}
return pexpr;
}
......
......@@ -88,6 +88,8 @@ add_library(naucrates
src/md/CMDAggregateGPDB.cpp
include/naucrates/md/CMDCastGPDB.h
src/md/CMDCastGPDB.cpp
include/naucrates/md/CMDArrayCoerceCastGPDB.h
src/md/CMDArrayCoerceCastGPDB.cpp
include/naucrates/md/CMDCheckConstraintGPDB.h
src/md/CMDCheckConstraintGPDB.cpp
include/naucrates/md/CMDColumn.h
......@@ -572,6 +574,8 @@ add_library(naucrates
src/parser/CParseHandlerMaterialize.cpp
include/naucrates/dxl/parser/CParseHandlerMDCast.h
src/parser/CParseHandlerMDCast.cpp
include/naucrates/dxl/parser/CParseHandlerMDArrayCoerceCast.h
src/parser/CParseHandlerMDArrayCoerceCast.cpp
include/naucrates/dxl/parser/CParseHandlerMDGPDBAgg.h
src/parser/CParseHandlerMDGPDBAgg.cpp
include/naucrates/dxl/parser/CParseHandlerMDGPDBCheckConstraint.h
......
......@@ -1622,6 +1622,15 @@ namespace gpdxl
CParseHandlerBase *pphRoot
);
// construct a values scan parse handler
static
CParseHandlerBase *PphMDArrayCoerceCast
(
IMemoryPool *pmp,
CParseHandlerManager *pphm,
CParseHandlerBase *pphRoot
);
public:
// initialize mappings of tokens to parse handlers
......
//---------------------------------------------------------------------------
// Greenplum Database
// Copyright (C) 2017 Pivotal Software, Inc.
//
// @filename:
// CParseHandlerMDArrayCoerceCast.h
//
// @doc:
// SAX parse handler class for GPDB array coerce cast metadata
//---------------------------------------------------------------------------
#ifndef GPDXL_CParseHandlerMDArrayCoerceCast_H
#define GPDXL_CParseHandlerMDArrayCoerceCast_H
#include "gpos/base.h"
#include "naucrates/dxl/parser/CParseHandlerMetadataObject.h"
#include "naucrates/md/CMDFunctionGPDB.h"
namespace gpdxl
{
using namespace gpos;
using namespace gpmd;
XERCES_CPP_NAMESPACE_USE
// parse handler for GPDB array coerce cast function metadata
class CParseHandlerMDArrayCoerceCast : public CParseHandlerMetadataObject
{
private:
// private copy ctor
CParseHandlerMDArrayCoerceCast(const CParseHandlerMDArrayCoerceCast &);
// process the start of an element
void StartElement
(
const XMLCh* const xmlszUri, // URI of element's namespace
const XMLCh* const xmlszLocalname, // local part of element's name
const XMLCh* const xmlszQname, // element's qname
const Attributes& attr // element's attributes
);
// process the end of an element
void EndElement
(
const XMLCh* const xmlszUri, // URI of element's namespace
const XMLCh* const xmlszLocalname, // local part of element's name
const XMLCh* const xmlszQname // element's qname
);
public:
// ctor
CParseHandlerMDArrayCoerceCast
(
IMemoryPool *pmp,
CParseHandlerManager *pphm,
CParseHandlerBase *pphRoot
);
};
}
#endif // !GPDXL_CParseHandlerMDArrayCoerceCast_H
// EOF
......@@ -39,6 +39,7 @@
#include "naucrates/dxl/parser/CParseHandlerColStatsBucket.h"
#include "naucrates/dxl/parser/CParseHandlerMDCast.h"
#include "naucrates/dxl/parser/CParseHandlerMDScCmp.h"
#include "naucrates/dxl/parser/CParseHandlerMDArrayCoerceCast.h"
#include "naucrates/dxl/parser/CParseHandlerPhysicalOp.h"
#include "naucrates/dxl/parser/CParseHandlerScalarOp.h"
......
......@@ -578,6 +578,8 @@ namespace gpdxl
EdxltokenGPDBCastSrcType,
EdxltokenGPDBCastDestType,
EdxltokenGPDBCastFuncId,
EdxltokenGPDBCastCoercePathType,
EdxltokenGPDBArrayCoerceCast,
EdxltokenGPDBMDScCmp,
......
//---------------------------------------------------------------------------
// Greenplum Database
// Copyright (C) 2017 Pivotal Software, Inc.
//
// @filename:
// CMDArrayCoerceCastGPDB.h
//
// @doc:
// Implementation of GPDB-specific array coerce cast functions in the
// metadata cache
//---------------------------------------------------------------------------
#ifndef GPMD_CMDArrayCoerceCastGPDB_H
#define GPMD_CMDArrayCoerceCastGPDB_H
#include "gpos/base.h"
#include "naucrates/md/CMDCastGPDB.h"
#include "naucrates/dxl/operators/CDXLScalar.h"
namespace gpmd
{
using namespace gpdxl;
class CMDArrayCoerceCastGPDB : public CMDCastGPDB
{
private:
// DXL for object
const CWStringDynamic *m_pstr;
// type mod
INT m_iMod;
// is explicit
BOOL m_fIsExplicit;
// CoercionForm
EdxlCoercionForm m_edxlcf;
// iLoc
INT m_iLoc;
// private copy ctor
CMDArrayCoerceCastGPDB(const CMDArrayCoerceCastGPDB &);
public:
// ctor
CMDArrayCoerceCastGPDB
(
IMemoryPool *pmp,
IMDId *pmdid,
CMDName *pmdname,
IMDId *pmdidSrc,
IMDId *pmdidDest,
BOOL fBinaryCoercible,
IMDId *pmdidCastFunc,
EmdCoercepathType emdPathType,
INT iMod,
BOOL fIsExplicit,
EdxlCoercionForm edxlcf,
INT iLoc
);
// dtor
virtual
~CMDArrayCoerceCastGPDB();
// accessors
virtual
const CWStringDynamic *Pstr() const
{
return m_pstr;
}
// return type modification
virtual
INT IMod() const;
virtual
BOOL FIsExplicit() const;
// return coercion form
virtual
EdxlCoercionForm Ecf() const;
// return token location
virtual
INT ILoc() const;
// serialize object in DXL format
virtual
void Serialize(gpdxl::CXMLSerializer *pxmlser) const;
#ifdef GPOS_DEBUG
// debug print of the type in the provided stream
virtual
void DebugPrint(IOstream &os) const;
#endif
};
}
#endif // !GPMD_CMDArrayCoerceCastGPDB_H
// EOF
......@@ -33,6 +33,10 @@ namespace gpmd
class CMDCastGPDB : public IMDCast
{
private:
// private copy ctor
CMDCastGPDB(const CMDCastGPDB &);
protected:
// memory pool
IMemoryPool *m_pmp;
......@@ -56,9 +60,9 @@ namespace gpmd
// cast func id
IMDId *m_pmdidCastFunc;
// private copy ctor
CMDCastGPDB(const CMDCastGPDB &);
// coercion path type
EmdCoercepathType m_emdPathType;
public:
// ctor
......@@ -70,7 +74,8 @@ namespace gpmd
IMDId *pmdidSrc,
IMDId *pmdidDest,
BOOL fBinaryCoercible,
IMDId *pmdidCastFunc
IMDId *pmdidCastFunc,
EmdCoercepathType emdPathType = EmdtNone
);
// dtor
......@@ -103,7 +108,11 @@ namespace gpmd
// is this a cast between binary coeercible types, i.e. the types are binary compatible
virtual
BOOL FBinaryCoercible() const;
// return the coercion path type
virtual
EmdCoercepathType EmdPathType() const;
// cast function id
virtual
IMDId *PmdidCastFunc() const;
......
......@@ -35,6 +35,15 @@ namespace gpmd
{
public:
// type of coercion pathway
enum EmdCoercepathType
{
EmdtNone, /* failed to find any coercion pathway */
EmdtFunc, /* apply the specified coercion function */
EmdtRelabelType, /* binary-compatible cast, no function */
EmdtArrayCoerce /* need an ArrayCoerceExpr node */
};
// object type
virtual
Emdtype Emdt() const
......@@ -57,6 +66,10 @@ namespace gpmd
// cast function id
virtual
IMDId *PmdidCastFunc() const = 0;
// return the coercion path type
virtual
EmdCoercepathType EmdPathType() const = 0;
};
}
......
//---------------------------------------------------------------------------
// Greenplum Database
// Copyright (C) 2013 EMC Corp.
//
// @filename:
// CMDArrayCoerceCastGPDB.cpp
//
// @doc:
// Implementation of the class for representing GPDB-specific array coerce
// casts in the MD cache
//---------------------------------------------------------------------------
#include "gpos/string/CWStringDynamic.h"
#include "naucrates/md/CMDArrayCoerceCastGPDB.h"
#include "naucrates/dxl/xml/CXMLSerializer.h"
#include "naucrates/dxl/CDXLUtils.h"
using namespace gpmd;
using namespace gpdxl;
// ctor
CMDArrayCoerceCastGPDB::CMDArrayCoerceCastGPDB
(
IMemoryPool *pmp,
IMDId *pmdid,
CMDName *pmdname,
IMDId *pmdidSrc,
IMDId *pmdidDest,
BOOL fBinaryCoercible,
IMDId *pmdidCastFunc,
EmdCoercepathType emdPathType,
INT iMod,
BOOL fIsExplicit,
EdxlCoercionForm edxlcf,
INT iLoc
)
:
CMDCastGPDB(pmp, pmdid, pmdname, pmdidSrc, pmdidDest, fBinaryCoercible, pmdidCastFunc, emdPathType),
m_iMod(iMod),
m_fIsExplicit(fIsExplicit),
m_edxlcf(edxlcf),
m_iLoc(iLoc)
{
m_pstr = CDXLUtils::PstrSerializeMDObj(pmp, this, false /*fSerializeHeader*/, false /*fIndent*/);
}
// dtor
CMDArrayCoerceCastGPDB::~CMDArrayCoerceCastGPDB()
{
GPOS_DELETE(m_pstr);
}
// return type modification
INT
CMDArrayCoerceCastGPDB::IMod() const
{
return m_iMod;
}
// return is explicit cast
BOOL
CMDArrayCoerceCastGPDB::FIsExplicit() const
{
return m_fIsExplicit;
}
// return coercion form
EdxlCoercionForm
CMDArrayCoerceCastGPDB::Ecf() const
{
return m_edxlcf;
}
// return token location
INT
CMDArrayCoerceCastGPDB::ILoc() const
{
return m_iLoc;
}
// serialize function metadata in DXL format
void
CMDArrayCoerceCastGPDB::Serialize
(
CXMLSerializer *pxmlser
)
const
{
pxmlser->OpenElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix),
CDXLTokens::PstrToken(EdxltokenGPDBArrayCoerceCast));
m_pmdid->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenMdid));
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenName), m_pmdname->Pstr());
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenGPDBCastCoercePathType), m_emdPathType);
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenGPDBCastBinaryCoercible), m_fBinaryCoercible);
m_pmdidSrc->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenGPDBCastSrcType));
m_pmdidDest->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenGPDBCastDestType));
m_pmdidCastFunc->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenGPDBCastFuncId));
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenTypeMod), m_iMod);
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenIsExplicit), m_fIsExplicit);
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenCoercionForm), (ULONG) m_edxlcf);
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenLocation), m_iLoc);
pxmlser->CloseElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix),
CDXLTokens::PstrToken(EdxltokenGPDBArrayCoerceCast));
}
#ifdef GPOS_DEBUG
// prints a metadata cache relation to the provided output
void
CMDArrayCoerceCastGPDB::DebugPrint
(
IOstream &os
)
const
{
CMDCastGPDB::DebugPrint(os);
os << ", Result Type Mod: ";
os << m_iMod;
os << ", isExplicit: ";
os << m_fIsExplicit;
os << ", coercion form: ";
os << m_edxlcf;
os << std::endl;
}
#endif // GPOS_DEBUG
// EOF
......@@ -36,7 +36,8 @@ CMDCastGPDB::CMDCastGPDB
IMDId *pmdidSrc,
IMDId *pmdidDest,
BOOL fBinaryCoercible,
IMDId *pmdidCastFunc
IMDId *pmdidCastFunc,
EmdCoercepathType emdPathType
)
:
m_pmp(pmp),
......@@ -45,7 +46,8 @@ CMDCastGPDB::CMDCastGPDB
m_pmdidSrc(pmdidSrc),
m_pmdidDest(pmdidDest),
m_fBinaryCoercible(fBinaryCoercible),
m_pmdidCastFunc(pmdidCastFunc)
m_pmdidCastFunc(pmdidCastFunc),
m_emdPathType(emdPathType)
{
GPOS_ASSERT(m_pmdid->FValid());
GPOS_ASSERT(m_pmdidSrc->FValid());
......@@ -159,6 +161,13 @@ CMDCastGPDB::FBinaryCoercible() const
return m_fBinaryCoercible;
}
// returns coercion path type
IMDCast::EmdCoercepathType
CMDCastGPDB::EmdPathType() const
{
return m_emdPathType;
}
//---------------------------------------------------------------------------
// @function:
// CMDCastGPDB::Serialize
......@@ -180,12 +189,12 @@ CMDCastGPDB::Serialize
m_pmdid->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenMdid));
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenName), m_pmdname->Pstr());
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenGPDBCastBinaryCoercible), m_fBinaryCoercible);
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenGPDBCastBinaryCoercible), m_fBinaryCoercible);
m_pmdidSrc->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenGPDBCastSrcType));
m_pmdidDest->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenGPDBCastDestType));
m_pmdidCastFunc->Serialize(pxmlser, CDXLTokens::PstrToken(EdxltokenGPDBCastFuncId));
pxmlser->AddAttribute(CDXLTokens::PstrToken(EdxltokenGPDBCastCoercePathType), m_emdPathType);
pxmlser->CloseElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix),
CDXLTokens::PstrToken(EdxltokenGPDBCast));
......
......@@ -102,6 +102,7 @@ CParseHandlerFactory::Init
{EdxltokenColumnStatsBucket, &PphColStatsBucket},
{EdxltokenGPDBCast, &PphMDCast},
{EdxltokenGPDBMDScCmp, &PphMDScCmp},
{EdxltokenGPDBArrayCoerceCast, &PphMDArrayCoerceCast},
{EdxltokenPhysical, &PphPhysOp},
......@@ -3587,7 +3588,7 @@ CParseHandlerFactory::PphScalarValuesList
// creates a parse handler for parsing a Values Scan operator
CParseHandlerBase *
CParseHandlerFactory::PphValuesScan
(
(
IMemoryPool *pmp,
CParseHandlerManager *pphm,
CParseHandlerBase *pphRoot
......@@ -3596,4 +3597,16 @@ CParseHandlerFactory::PphValuesScan
return GPOS_NEW(pmp) CParseHandlerValuesScan(pmp, pphm, pphRoot);
}
// creates a parse handler for parsing GPDB-specific array coerce cast metadata
CParseHandlerBase *
CParseHandlerFactory::PphMDArrayCoerceCast
(
IMemoryPool *pmp,
CParseHandlerManager *pphm,
CParseHandlerBase *pphRoot
)
{
return GPOS_NEW(pmp) CParseHandlerMDArrayCoerceCast(pmp, pphm, pphRoot);
}
// EOF
//---------------------------------------------------------------------------
// Greenplum Database
// Copyright (C) 2017 Pivotal Software, Inc.
//
// @filename:
// CParseHandlerMDArrayCoerceCast.cpp
//
// @doc:
// Implementation of the SAX parse handler class for parsing metadata for
// GPDB array coerce cast functions
//---------------------------------------------------------------------------
#include "naucrates/md/CMDArrayCoerceCastGPDB.h"
#include "naucrates/dxl/parser/CParseHandlerMDArrayCoerceCast.h"
#include "naucrates/dxl/parser/CParseHandlerManager.h"
#include "naucrates/dxl/parser/CParseHandlerFactory.h"
#include "naucrates/dxl/operators/CDXLOperatorFactory.h"
using namespace gpdxl;
XERCES_CPP_NAMESPACE_USE
// ctor
CParseHandlerMDArrayCoerceCast::CParseHandlerMDArrayCoerceCast
(
IMemoryPool *pmp,
CParseHandlerManager *pphm,
CParseHandlerBase *pphRoot
)
:
CParseHandlerMetadataObject(pmp, pphm, pphRoot)
{}
// invoked by Xerces to process an opening tag
void
CParseHandlerMDArrayCoerceCast::StartElement
(
const XMLCh* const, // xmlszUri,
const XMLCh* const xmlszLocalname,
const XMLCh* const, // xmlszQname
const Attributes& attrs
)
{
if (0 != XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenGPDBArrayCoerceCast), xmlszLocalname))
{
CWStringDynamic *pstr = CDXLUtils::PstrFromXMLCh(m_pphm->Pmm(), xmlszLocalname);
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXLUnexpectedTag, pstr->Wsz());
}
// parse func name
const XMLCh *xmlszFuncName = CDXLOperatorFactory::XmlstrFromAttrs
(
attrs,
EdxltokenName,
EdxltokenGPDBArrayCoerceCast
);
CMDName *pmdname = CDXLUtils::PmdnameFromXmlsz(m_pphm->Pmm(), xmlszFuncName);
// parse cast properties
IMDId *pmdid = CDXLOperatorFactory::PmdidFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenMdid,
EdxltokenGPDBArrayCoerceCast
);
IMDId *pmdidSrc = CDXLOperatorFactory::PmdidFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenGPDBCastSrcType,
EdxltokenGPDBArrayCoerceCast
);
IMDId *pmdidDest = CDXLOperatorFactory::PmdidFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenGPDBCastDestType,
EdxltokenGPDBArrayCoerceCast
);
IMDId *pmdidCastFunc = CDXLOperatorFactory::PmdidFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenGPDBCastFuncId,
EdxltokenGPDBArrayCoerceCast
);
// parse whether func returns a set
BOOL fBinaryCoercible = CDXLOperatorFactory::FValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenGPDBCastBinaryCoercible,
EdxltokenGPDBArrayCoerceCast
);
// parse coercion path type
IMDCast::EmdCoercepathType eCoercePathType = (IMDCast::EmdCoercepathType)
CDXLOperatorFactory::IValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenGPDBCastCoercePathType,
EdxltokenGPDBArrayCoerceCast
);
INT iMod = CDXLOperatorFactory::IValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenTypeMod,
EdxltokenGPDBArrayCoerceCast
);
BOOL fIsExplicit =CDXLOperatorFactory::FValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenIsExplicit,
EdxltokenGPDBArrayCoerceCast
);
EdxlCoercionForm edcf = (EdxlCoercionForm) CDXLOperatorFactory::IValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenCoercionForm,
EdxltokenGPDBArrayCoerceCast
);
INT iLoc = CDXLOperatorFactory::IValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenLocation,
EdxltokenGPDBArrayCoerceCast
);
m_pimdobj = GPOS_NEW(m_pmp) CMDArrayCoerceCastGPDB(m_pmp, pmdid, pmdname, pmdidSrc, pmdidDest, fBinaryCoercible, pmdidCastFunc, eCoercePathType, iMod, fIsExplicit, edcf, iLoc);
}
// invoked by Xerces to process a closing tag
void
CParseHandlerMDArrayCoerceCast::EndElement
(
const XMLCh* const, // xmlszUri,
const XMLCh* const xmlszLocalname,
const XMLCh* const // xmlszQname
)
{
if (0 != XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenGPDBArrayCoerceCast), xmlszLocalname))
{
CWStringDynamic *pstr = CDXLUtils::PstrFromXMLCh(m_pphm->Pmm(), xmlszLocalname);
GPOS_RAISE(gpdxl::ExmaDXL, gpdxl::ExmiDXLUnexpectedTag, pstr->Wsz());
}
// deactivate handler
m_pphm->DeactivateHandler();
}
// EOF
......@@ -108,7 +108,7 @@ CParseHandlerMDCast::StartElement
EdxltokenGPDBCastFuncId,
EdxltokenGPDBCast
);
// parse whether func returns a set
BOOL fBinaryCoercible = CDXLOperatorFactory::FValueFromAttrs
(
......@@ -117,8 +117,18 @@ CParseHandlerMDCast::StartElement
EdxltokenGPDBCastBinaryCoercible,
EdxltokenGPDBCast
);
m_pimdobj = GPOS_NEW(m_pmp) CMDCastGPDB(m_pmp, pmdid, pmdname, pmdidSrc, pmdidDest, fBinaryCoercible, pmdidCastFunc);
IMDCast::EmdCoercepathType eCoercePathType = (IMDCast::EmdCoercepathType)
CDXLOperatorFactory::IValueFromAttrs
(
m_pphm->Pmm(),
attrs,
EdxltokenGPDBCastCoercePathType,
EdxltokenGPDBCast,
true // eCoercePathType is optional
);
m_pimdobj = GPOS_NEW(m_pmp) CMDCastGPDB(m_pmp, pmdid, pmdname, pmdidSrc, pmdidDest, fBinaryCoercible, pmdidCastFunc, eCoercePathType);
}
//---------------------------------------------------------------------------
......
......@@ -630,6 +630,8 @@ CDXLTokens::Init
{EdxltokenGPDBCastSrcType, GPOS_WSZ_LIT("SourceTypeId")},
{EdxltokenGPDBCastDestType, GPOS_WSZ_LIT("DestinationTypeId")},
{EdxltokenGPDBCastFuncId, GPOS_WSZ_LIT("CastFuncId")},
{EdxltokenGPDBCastCoercePathType, GPOS_WSZ_LIT("CoercePathType")},
{EdxltokenGPDBArrayCoerceCast, GPOS_WSZ_LIT("ArrayCoerceCast")},
{EdxltokenGPDBMDScCmp, GPOS_WSZ_LIT("MDScalarComparison")},
......
......@@ -221,6 +221,8 @@ const CHAR *rgszFileNames[] =
"../data/dxl/minidump/SemiJoin2Select-EnforceSubplan.mdp",
"../data/dxl/minidump/EstimateJoinRowsForCastPredicates.mdp",
"../data/dxl/minidump/MissingBoolColStats.mdp",
"../data/dxl/minidump/ArrayCoerceCast.mdp",
"../data/dxl/minidump/SimpleArrayCoerceCast.mdp",
#ifndef GPOS_DEBUG
// TODO: - 06/29/2015: the row estimate for 32-bit rhel is off in the 6th decimel place
"../data/dxl/minidump/retail_28.mdp",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册