提交 f55b0fac 编写于 作者: D David Kimura

Allow direct dispatch in Orca if predicate on column gp_segment_id (#10679)

This approach special cases gp_segment_id enough to include the column
as a distributed column constraint. It also updates direct dispatch info
to be aware of gp_segment_id which represents the raw value of the
segment where the data resides. This is different than other columns
which hash the datum value to decide where the data resides.

After this change the following DDL shows Gather Motion from 2 segments
on a 3 segment demo cluster.

```
CREATE TABLE t(a int, b int) DISTRIBUTED BY (a);
EXPLAIN SELECT gp_segment_id, * FROM t WHERE gp_segment_id=1 or gp_segment_id=2;
                                  QUERY PLAN
-------------------------------------------------------------------------------
 Gather Motion 2:1  (slice1; segments: 2)  (cost=0.00..431.00 rows=1 width=12)
   ->  Seq Scan on t  (cost=0.00..431.00 rows=1 width=12)
         Filter: ((gp_segment_id = 1) OR (gp_segment_id = 2))
 Optimizer: Pivotal Optimizer (GPORCA)
(4 rows)

```

(cherry picked from commit 10e2b2d9)
上级 0ade3e4e
...@@ -4180,12 +4180,44 @@ CTranslatorDXLToPlStmt::TranslateDXLDirectDispatchInfo ...@@ -4180,12 +4180,44 @@ CTranslatorDXLToPlStmt::TranslateDXLDirectDispatchInfo
{ {
return NIL; return NIL;
} }
CDXLDatumArray *dxl_datum_array = (*dispatch_identifier_datum_arrays)[0]; CDXLDatumArray *dxl_datum_array = (*dispatch_identifier_datum_arrays)[0];
GPOS_ASSERT(0 < dxl_datum_array->Size()); GPOS_ASSERT(0 < dxl_datum_array->Size());
ULONG hash_code = GetDXLDatumGPDBHash(dxl_datum_array);
const ULONG length = dispatch_identifier_datum_arrays->Size(); const ULONG length = dispatch_identifier_datum_arrays->Size();
if (dxl_direct_dispatch_info->FContainsRawValues()) {
List *segids_list = NIL;
INT segid;
Const *const_expr = NULL;
for (ULONG ul = 0; ul < length; ul++)
{
CDXLDatumArray *dispatch_identifier_datum_array = (*dispatch_identifier_datum_arrays)[ul];
GPOS_ASSERT(1 == dispatch_identifier_datum_array->Size());
const_expr = (Const *) m_translator_dxl_to_scalar->TranslateDXLDatumToScalar(
(*dispatch_identifier_datum_array)[0]
);
segid = DatumGetInt32(const_expr->constvalue);
if (segid >= -1 && segid < (INT)m_num_of_segments)
{
segids_list = gpdb::LAppendInt(segids_list, segid);
}
}
if (segids_list == NIL && const_expr)
{
// If no valid segids were found, and there were items in the
// dispatch identifier array, then append the last item to behave
// in same manner as Planner for consistency. Currently this will
// lead to a FATAL in the backend when we dispatch.
segids_list = gpdb::LAppendInt(segids_list, segid);
}
return segids_list;
}
ULONG hash_code = GetDXLDatumGPDBHash(dxl_datum_array);
for (ULONG ul = 0; ul < length; ul++) for (ULONG ul = 0; ul < length; ul++)
{ {
CDXLDatumArray *dispatch_identifier_datum_array = (*dispatch_identifier_datum_arrays)[ul]; CDXLDatumArray *dispatch_identifier_datum_array = (*dispatch_identifier_datum_arrays)[ul];
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
create table foo(a int, b int);
select * from foo where gp_segment_id=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" 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 MinNumOfPartsToRequireSortOnInsert="2147483647" JoinArityForAssociativityCommutativity="18" ArrayExpansionThreshold="100" JoinOrderDynamicProgThreshold="10" BroadcastThreshold="100000" EnforceConstraintsOnDML="false" PushGroupByBelowSetopThreshold="10"/>
<dxl:TraceFlags Value="102074,102120,102146,102152,103001,103014,103022,103027,103029,103038,104002,104003,104004,104005,105000,106000"/>
</dxl:OptimizerConfig>
<dxl:Metadata SystemIds="0.GPDB">
<dxl:RelationStatistics Mdid="2.16385.1.0" Name="foo" Rows="20.000000" EmptyRelation="false"/>
<dxl:Relation Mdid="0.16385.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="true" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="b" Attno="2" Mdid="0.23.1.0" Nullable="true" ColWidth="4">
<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="-3" Mdid="0.28.1.0" Nullable="false" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="cmin" Attno="-4" Mdid="0.29.1.0" Nullable="false" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="xmax" Attno="-5" Mdid="0.28.1.0" Nullable="false" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="cmax" Attno="-6" Mdid="0.29.1.0" Nullable="false" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="tableoid" Attno="-7" Mdid="0.26.1.0" Nullable="false" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
<dxl:Column Name="gp_segment_id" Attno="-8" Mdid="0.23.1.0" Nullable="false" ColWidth="4">
<dxl:DefaultValue/>
</dxl:Column>
</dxl:Columns>
<dxl:IndexInfoList/>
<dxl:Triggers/>
<dxl:CheckConstraints/>
<dxl:DistrOpfamilies>
<dxl:DistrOpfamily Mdid="0.1977.1.0"/>
</dxl:DistrOpfamilies>
</dxl:Relation>
<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.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:ColumnStatistics Mdid="1.16385.1.0.8" Name="gp_segment_id" Width="4.000000" NullFreq="0.000000" NdvRemain="3.000000" FreqRemain="1.000000" ColStatsMissing="false"/>
<dxl:ColumnStatistics Mdid="1.16385.1.0.0" Name="a" Width="4.000000" NullFreq="0.000000" NdvRemain="0.000000" FreqRemain="0.000000" ColStatsMissing="false">
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="1"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="2"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="2"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="3"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="3"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="4"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="4"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="5"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="5"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="6"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="6"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="7"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="7"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="8"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="8"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="9"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="9"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="10"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="10"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="11"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="11"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="12"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="12"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="13"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="13"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="14"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="14"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="15"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="15"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="16"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="16"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="17"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="17"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="18"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="18"/>
<dxl:UpperBound Closed="false" TypeMdid="0.23.1.0" Value="19"/>
</dxl:StatsBucket>
<dxl:StatsBucket Frequency="0.052632" DistinctValues="1.052632">
<dxl:LowerBound Closed="true" TypeMdid="0.23.1.0" Value="19"/>
<dxl:UpperBound Closed="true" TypeMdid="0.23.1.0" Value="20"/>
</dxl:StatsBucket>
</dxl:ColumnStatistics>
<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.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="true" IsMergeJoinable="true" IsComposite="false" IsTextRelated="false" IsFixedLength="true" Length="6" PassByValue="false">
<dxl:DistrOpfamily Mdid="0.7077.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:GPDBScalarOp Mdid="0.96.1.0" Name="=" ComparisonType="Eq" ReturnsNullOnNullInput="true" IsNDVPreserving="false">
<dxl:LeftType Mdid="0.23.1.0"/>
<dxl:RightType Mdid="0.23.1.0"/>
<dxl:ResultType Mdid="0.16.1.0"/>
<dxl:OpFunc Mdid="0.65.1.0"/>
<dxl:Commutator Mdid="0.96.1.0"/>
<dxl:InverseOp Mdid="0.518.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.12738.1.0"/>
</dxl:Opfamilies>
</dxl:GPDBScalarOp>
</dxl:Metadata>
<dxl:Query>
<dxl:OutputColumns>
<dxl:Ident ColId="1" ColName="a" TypeMdid="0.23.1.0"/>
<dxl:Ident ColId="2" ColName="b" TypeMdid="0.23.1.0"/>
</dxl:OutputColumns>
<dxl:CTEList/>
<dxl:LogicalSelect>
<dxl:Comparison ComparisonOperator="=" OperatorMdid="0.96.1.0">
<dxl:Ident ColId="9" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
<dxl:ConstValue TypeMdid="0.23.1.0" Value="2"/>
</dxl:Comparison>
<dxl:LogicalGet>
<dxl:TableDescriptor Mdid="0.16385.1.0" TableName="foo">
<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="-3" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="5" Attno="-4" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="6" Attno="-5" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="7" Attno="-6" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="8" Attno="-7" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/>
<dxl:Column ColId="9" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:LogicalGet>
</dxl:LogicalSelect>
</dxl:Query>
<dxl:Plan Id="0" SpaceSize="1">
<dxl:GatherMotion InputSegments="0,1,2" OutputSegments="-1">
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000607" Rows="6.666667" 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:SortingColumnList/>
<dxl:TableScan>
<dxl:Properties>
<dxl:Cost StartupCost="0" TotalCost="431.000408" Rows="6.666667" 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:Comparison ComparisonOperator="=" OperatorMdid="0.96.1.0">
<dxl:Ident ColId="8" ColName="gp_segment_id" TypeMdid="0.23.1.0"/>
<dxl:ConstValue TypeMdid="0.23.1.0" Value="2"/>
</dxl:Comparison>
</dxl:Filter>
<dxl:TableDescriptor Mdid="0.16385.1.0" TableName="foo">
<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="-3" ColName="xmin" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="4" Attno="-4" ColName="cmin" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="5" Attno="-5" ColName="xmax" TypeMdid="0.28.1.0" ColWidth="4"/>
<dxl:Column ColId="6" Attno="-6" ColName="cmax" TypeMdid="0.29.1.0" ColWidth="4"/>
<dxl:Column ColId="7" Attno="-7" ColName="tableoid" TypeMdid="0.26.1.0" ColWidth="4"/>
<dxl:Column ColId="8" Attno="-8" ColName="gp_segment_id" TypeMdid="0.23.1.0" ColWidth="4"/>
</dxl:Columns>
</dxl:TableDescriptor>
</dxl:TableScan>
</dxl:GatherMotion>
<dxl:DirectDispatchInfo IsRaw="true">
<dxl:KeyValue>
<dxl:Datum TypeMdid="0.23.1.0" Value="2"/>
</dxl:KeyValue>
</dxl:DirectDispatchInfo>
</dxl:Plan>
</dxl:Thread>
</dxl:DXLMessage>
...@@ -213,6 +213,12 @@ namespace gpopt ...@@ -213,6 +213,12 @@ namespace gpopt
virtual virtual
BOOL FConstraint(const CColRef *colref) const = 0; BOOL FConstraint(const CColRef *colref) const = 0;
virtual
BOOL FConstraintOnSegmentId() const
{
return false;
}
// return a copy of the constraint with remapped columns // return a copy of the constraint with remapped columns
virtual virtual
CConstraint *PcnstrCopyWithRemappedColumns(CMemoryPool *mp, UlongToColRefMap *colref_mapping, BOOL must_exist) = 0; CConstraint *PcnstrCopyWithRemappedColumns(CMemoryPool *mp, UlongToColRefMap *colref_mapping, BOOL must_exist) = 0;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "gpos/base.h" #include "gpos/base.h"
#include "gpos/task/CAutoTraceFlag.h" #include "gpos/task/CAutoTraceFlag.h"
#include "gpos/error/CAutoTrace.h" #include "gpos/error/CAutoTrace.h"
#include "naucrates/dxl/xml/dxltokens.h"
#include "naucrates/traceflags/traceflags.h" #include "naucrates/traceflags/traceflags.h"
#include "gpopt/base/CConstraint.h" #include "gpopt/base/CConstraint.h"
...@@ -217,6 +218,13 @@ namespace gpopt ...@@ -217,6 +218,13 @@ namespace gpopt
return m_pcr == colref; return m_pcr == colref;
} }
// check if constraint is on the gp_segment_id column
virtual
BOOL FConstraintOnSegmentId() const
{
return m_pcr->IsSystemCol() && m_pcr->Name().Equals(CDXLTokens::GetDXLTokenStr(EdxltokenGpSegmentIdColName));
}
// return a copy of the constraint with remapped columns // return a copy of the constraint with remapped columns
virtual virtual
CConstraint *PcnstrCopyWithRemappedColumns(CMemoryPool *mp, UlongToColRefMap *colref_mapping, BOOL must_exist); CConstraint *PcnstrCopyWithRemappedColumns(CMemoryPool *mp, UlongToColRefMap *colref_mapping, BOOL must_exist);
......
...@@ -71,10 +71,8 @@ namespace gpopt ...@@ -71,10 +71,8 @@ namespace gpopt
return m_str_name->Length(); return m_str_name->Length();
} }
#ifdef GPOS_DEBUG
// comparison // comparison
BOOL Equals(const CName &) const; BOOL Equals(const CName &) const;
#endif // GPOS_DEBUG
// debug print // debug print
IOstream &OsPrint(IOstream &) const; IOstream &OsPrint(IOstream &) const;
......
...@@ -176,7 +176,6 @@ CName::DeepCopy ...@@ -176,7 +176,6 @@ CName::DeepCopy
} }
#ifdef GPOS_DEBUG
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// @function: // @function:
// CName::Equals // CName::Equals
...@@ -195,7 +194,6 @@ CName::Equals ...@@ -195,7 +194,6 @@ CName::Equals
return m_str_name->Equals((name.Pstr())); return m_str_name->Equals((name.Pstr()));
} }
#endif // GPOS_DEBUG
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
......
...@@ -5872,7 +5872,7 @@ CTranslatorExprToDXL::GetDXLDirectDispatchInfo ...@@ -5872,7 +5872,7 @@ CTranslatorExprToDXL::GetDXLDirectDispatchInfo
CDXLDatum2dArray *pdrgpdrgpdxldatum = GPOS_NEW(m_mp) CDXLDatum2dArray(m_mp); CDXLDatum2dArray *pdrgpdrgpdxldatum = GPOS_NEW(m_mp) CDXLDatum2dArray(m_mp);
pdrgpdrgpdxldatum->Append(pdrgpdxldatum); pdrgpdrgpdxldatum->Append(pdrgpdxldatum);
return GPOS_NEW(m_mp) CDXLDirectDispatchInfo(pdrgpdrgpdxldatum); return GPOS_NEW(m_mp) CDXLDirectDispatchInfo(pdrgpdrgpdxldatum, false);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
......
...@@ -2176,7 +2176,7 @@ CTranslatorExprToDXLUtils::GetDXLDirectDispatchInfo ...@@ -2176,7 +2176,7 @@ CTranslatorExprToDXLUtils::GetDXLDirectDispatchInfo
CDXLDatum2dArray *pdrgpdrgpdxldatum = GPOS_NEW(mp) CDXLDatum2dArray(mp); CDXLDatum2dArray *pdrgpdrgpdxldatum = GPOS_NEW(mp) CDXLDatum2dArray(mp);
pdrgpdrgpdxldatum->Append(pdrgpdxldatum); pdrgpdrgpdxldatum->Append(pdrgpdxldatum);
return GPOS_NEW(mp) CDXLDirectDispatchInfo(pdrgpdrgpdxldatum); return GPOS_NEW(mp) CDXLDirectDispatchInfo(pdrgpdrgpdxldatum, false);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
...@@ -2205,7 +2205,21 @@ CTranslatorExprToDXLUtils::PdxlddinfoSingleDistrKey ...@@ -2205,7 +2205,21 @@ CTranslatorExprToDXLUtils::PdxlddinfoSingleDistrKey
const CColRef *pcrDistrCol = CScalarIdent::PopConvert(pexprHashed->Pop())->Pcr(); const CColRef *pcrDistrCol = CScalarIdent::PopConvert(pexprHashed->Pop())->Pcr();
BOOL useRawValues = false;
CConstraint *pcnstrDistrCol = pcnstr->Pcnstr(mp, pcrDistrCol); CConstraint *pcnstrDistrCol = pcnstr->Pcnstr(mp, pcrDistrCol);
CConstraintInterval *pcnstrInterval;
if (pcnstrDistrCol == NULL && (pcnstrInterval = dynamic_cast<CConstraintInterval *>(pcnstr)))
{
if (pcnstrInterval->FConstraintOnSegmentId())
{
// If the constraint is on gp_segment_id then we trick ourselves into
// considering the constraint as being on a distribution column.
pcnstrDistrCol = pcnstr;
pcnstrDistrCol->AddRef();
pcrDistrCol = pcnstrInterval->Pcr();
useRawValues = true;
}
}
CDXLDatum2dArray *pdrgpdrgpdxldatum = NULL; CDXLDatum2dArray *pdrgpdrgpdxldatum = NULL;
...@@ -2231,7 +2245,7 @@ CTranslatorExprToDXLUtils::PdxlddinfoSingleDistrKey ...@@ -2231,7 +2245,7 @@ CTranslatorExprToDXLUtils::PdxlddinfoSingleDistrKey
{ {
pdrgpdrgpdxldatum = PdrgpdrgpdxldatumFromDisjPointConstraint(mp, md_accessor, pcrDistrCol, pcnstrDistrCol); pdrgpdrgpdxldatum = PdrgpdrgpdxldatumFromDisjPointConstraint(mp, md_accessor, pcrDistrCol, pcnstrDistrCol);
} }
CRefCount::SafeRelease(pcnstrDistrCol); CRefCount::SafeRelease(pcnstrDistrCol);
if (NULL == pdrgpdrgpdxldatum) if (NULL == pdrgpdrgpdxldatum)
...@@ -2239,7 +2253,7 @@ CTranslatorExprToDXLUtils::PdxlddinfoSingleDistrKey ...@@ -2239,7 +2253,7 @@ CTranslatorExprToDXLUtils::PdxlddinfoSingleDistrKey
return NULL; return NULL;
} }
return GPOS_NEW(mp) CDXLDirectDispatchInfo(pdrgpdrgpdxldatum); return GPOS_NEW(mp) CDXLDirectDispatchInfo(pdrgpdrgpdxldatum, useRawValues);
} }
......
...@@ -42,19 +42,28 @@ namespace gpdxl ...@@ -42,19 +42,28 @@ namespace gpdxl
// constants for determining segments to dispatch to // constants for determining segments to dispatch to
CDXLDatum2dArray *m_dispatch_identifer_datum_array; CDXLDatum2dArray *m_dispatch_identifer_datum_array;
// true indicates m_dispatch_identifer_datum_array contains raw
// gp_segment_id values rather than hashable datums
BOOL m_contains_raw_values;
// private copy ctor // private copy ctor
CDXLDirectDispatchInfo(const CDXLDirectDispatchInfo &); CDXLDirectDispatchInfo(const CDXLDirectDispatchInfo &);
public: public:
// ctor // ctor
explicit explicit
CDXLDirectDispatchInfo(CDXLDatum2dArray *dispatch_identifer_datum_array); CDXLDirectDispatchInfo(CDXLDatum2dArray *dispatch_identifer_datum_array, BOOL contains_raw_values);
// dtor // dtor
virtual virtual
~CDXLDirectDispatchInfo(); ~CDXLDirectDispatchInfo();
BOOL FContainsRawValues() const
{
return m_contains_raw_values;
}
// accessor to array of datums // accessor to array of datums
CDXLDatum2dArray *GetDispatchIdentifierDatumArray() const CDXLDatum2dArray *GetDispatchIdentifierDatumArray() const
{ {
......
...@@ -44,6 +44,10 @@ namespace gpdxl ...@@ -44,6 +44,10 @@ namespace gpdxl
// direct dispatch spec // direct dispatch spec
CDXLDirectDispatchInfo *m_direct_dispatch_info; CDXLDirectDispatchInfo *m_direct_dispatch_info;
// true indicates m_dispatch_identifer_datum_array contains raw
// gp_segment_id values rather than hashable datums
BOOL m_dispatch_is_raw;
// private copy ctor // private copy ctor
CParseHandlerDirectDispatchInfo(const CParseHandlerDirectDispatchInfo &); CParseHandlerDirectDispatchInfo(const CParseHandlerDirectDispatchInfo &);
......
...@@ -652,6 +652,7 @@ namespace gpdxl ...@@ -652,6 +652,7 @@ namespace gpdxl
EdxltokenPhysicalDMLDelete, EdxltokenPhysicalDMLDelete,
EdxltokenPhysicalDMLUpdate, EdxltokenPhysicalDMLUpdate,
EdxltokenDirectDispatchInfo, EdxltokenDirectDispatchInfo,
EdxltokenDirectDispatchIsRaw,
EdxltokenDirectDispatchKeyValue, EdxltokenDirectDispatchKeyValue,
EdxltokenPhysicalSplit, EdxltokenPhysicalSplit,
EdxltokenPhysicalRowTrigger, EdxltokenPhysicalRowTrigger,
......
...@@ -32,10 +32,12 @@ using namespace gpdxl; ...@@ -32,10 +32,12 @@ using namespace gpdxl;
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
CDXLDirectDispatchInfo::CDXLDirectDispatchInfo CDXLDirectDispatchInfo::CDXLDirectDispatchInfo
( (
CDXLDatum2dArray *dispatch_identifer_datum_array CDXLDatum2dArray *dispatch_identifer_datum_array,
BOOL contains_raw_values
) )
: :
m_dispatch_identifer_datum_array(dispatch_identifer_datum_array) m_dispatch_identifer_datum_array(dispatch_identifer_datum_array),
m_contains_raw_values(contains_raw_values)
{ {
GPOS_ASSERT(NULL != dispatch_identifer_datum_array); GPOS_ASSERT(NULL != dispatch_identifer_datum_array);
...@@ -80,9 +82,15 @@ CDXLDirectDispatchInfo::Serialize ...@@ -80,9 +82,15 @@ CDXLDirectDispatchInfo::Serialize
) )
{ {
xml_serializer->OpenElement(CDXLTokens::GetDXLTokenStr(EdxltokenNamespacePrefix), CDXLTokens::GetDXLTokenStr(EdxltokenDirectDispatchInfo)); xml_serializer->OpenElement(CDXLTokens::GetDXLTokenStr(EdxltokenNamespacePrefix), CDXLTokens::GetDXLTokenStr(EdxltokenDirectDispatchInfo));
if (m_contains_raw_values)
{
// Output attribute iff true. Default false keeps backward compatability
xml_serializer->AddAttribute(CDXLTokens::GetDXLTokenStr(EdxltokenDirectDispatchIsRaw), m_contains_raw_values);
}
const ULONG num_of_dispatch_identifiers = (m_dispatch_identifer_datum_array == NULL) ? 0 : m_dispatch_identifer_datum_array->Size(); const ULONG num_of_dispatch_identifiers = (m_dispatch_identifer_datum_array == NULL) ? 0 : m_dispatch_identifer_datum_array->Size();
for (ULONG idx1 = 0; idx1 < num_of_dispatch_identifiers; idx1++) for (ULONG idx1 = 0; idx1 < num_of_dispatch_identifiers; idx1++)
{ {
xml_serializer->OpenElement(CDXLTokens::GetDXLTokenStr(EdxltokenNamespacePrefix), CDXLTokens::GetDXLTokenStr(EdxltokenDirectDispatchKeyValue)); xml_serializer->OpenElement(CDXLTokens::GetDXLTokenStr(EdxltokenNamespacePrefix), CDXLTokens::GetDXLTokenStr(EdxltokenDirectDispatchKeyValue));
......
...@@ -43,7 +43,8 @@ CParseHandlerDirectDispatchInfo::CParseHandlerDirectDispatchInfo ...@@ -43,7 +43,8 @@ CParseHandlerDirectDispatchInfo::CParseHandlerDirectDispatchInfo
CParseHandlerBase(mp, parse_handler_mgr, parse_handler_root), CParseHandlerBase(mp, parse_handler_mgr, parse_handler_root),
m_dxl_datum_array(NULL), m_dxl_datum_array(NULL),
m_datum_array_combination(NULL), m_datum_array_combination(NULL),
m_direct_dispatch_info(NULL) m_direct_dispatch_info(NULL),
m_dispatch_is_raw(false)
{} {}
...@@ -81,6 +82,16 @@ CParseHandlerDirectDispatchInfo::StartElement ...@@ -81,6 +82,16 @@ CParseHandlerDirectDispatchInfo::StartElement
{ {
if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchInfo), element_local_name)) if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchInfo), element_local_name))
{ {
m_dispatch_is_raw = CDXLOperatorFactory::ExtractConvertAttrValueToBool
(
m_parse_handler_mgr->GetDXLMemoryManager(),
attrs,
EdxltokenDirectDispatchIsRaw,
EdxltokenDirectDispatchInfo,
true, // optional
false // default
);
m_datum_array_combination = GPOS_NEW(m_mp) CDXLDatum2dArray(m_mp); m_datum_array_combination = GPOS_NEW(m_mp) CDXLDatum2dArray(m_mp);
} }
else if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchKeyValue), element_local_name)) else if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchKeyValue), element_local_name))
...@@ -120,7 +131,7 @@ CParseHandlerDirectDispatchInfo::EndElement ...@@ -120,7 +131,7 @@ CParseHandlerDirectDispatchInfo::EndElement
{ {
if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchInfo), element_local_name)) if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchInfo), element_local_name))
{ {
m_direct_dispatch_info = GPOS_NEW(m_mp) CDXLDirectDispatchInfo(m_datum_array_combination); m_direct_dispatch_info = GPOS_NEW(m_mp) CDXLDirectDispatchInfo(m_datum_array_combination, m_dispatch_is_raw);
m_parse_handler_mgr->DeactivateHandler(); m_parse_handler_mgr->DeactivateHandler();
} }
else if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchKeyValue), element_local_name)) else if (0 == XMLString::compareString(CDXLTokens::XmlstrToken(EdxltokenDirectDispatchKeyValue), element_local_name))
......
...@@ -138,6 +138,7 @@ CDXLTokens::Init ...@@ -138,6 +138,7 @@ CDXLTokens::Init
{EdxltokenPhysicalDMLDelete, GPOS_WSZ_LIT("DMLDelete")}, {EdxltokenPhysicalDMLDelete, GPOS_WSZ_LIT("DMLDelete")},
{EdxltokenPhysicalDMLUpdate, GPOS_WSZ_LIT("DMLUpdate")}, {EdxltokenPhysicalDMLUpdate, GPOS_WSZ_LIT("DMLUpdate")},
{EdxltokenDirectDispatchInfo, GPOS_WSZ_LIT("DirectDispatchInfo")}, {EdxltokenDirectDispatchInfo, GPOS_WSZ_LIT("DirectDispatchInfo")},
{EdxltokenDirectDispatchIsRaw, GPOS_WSZ_LIT("IsRaw")},
{EdxltokenDirectDispatchKeyValue, GPOS_WSZ_LIT("KeyValue")}, {EdxltokenDirectDispatchKeyValue, GPOS_WSZ_LIT("KeyValue")},
{EdxltokenPhysicalPartitionSelector, GPOS_WSZ_LIT("PartitionSelector")}, {EdxltokenPhysicalPartitionSelector, GPOS_WSZ_LIT("PartitionSelector")},
......
...@@ -29,6 +29,7 @@ ULONG CDirectDispatchTest::m_ulDirectDispatchCounter = 0; // start from first t ...@@ -29,6 +29,7 @@ ULONG CDirectDispatchTest::m_ulDirectDispatchCounter = 0; // start from first t
const CHAR *rgszDirectDispatchFileNames[] = const CHAR *rgszDirectDispatchFileNames[] =
{ {
"../data/dxl/minidump/DirectDispatch-SingleCol.mdp", "../data/dxl/minidump/DirectDispatch-SingleCol.mdp",
"../data/dxl/minidump/DirectDispatch-GpSegmentId.mdp",
"../data/dxl/minidump/DirectDispatch-SingleCol-Disjunction.mdp", "../data/dxl/minidump/DirectDispatch-SingleCol-Disjunction.mdp",
"../data/dxl/minidump/DirectDispatch-SingleCol-Disjunction-IsNull.mdp", "../data/dxl/minidump/DirectDispatch-SingleCol-Disjunction-IsNull.mdp",
"../data/dxl/minidump/DirectDispatch-SingleCol-Disjunction-Negative.mdp", "../data/dxl/minidump/DirectDispatch-SingleCol-Disjunction-Negative.mdp",
......
...@@ -650,6 +650,104 @@ INFO: (slice 1) Dispatch command to SINGLE content ...@@ -650,6 +650,104 @@ INFO: (slice 1) Dispatch command to SINGLE content
drop table test_prepare; drop table test_prepare;
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2 INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2 INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
-- test direct dispatch via gp_segment_id qual
create table t_test_dd_via_segid(id int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' 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.
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
insert into t_test_dd_via_segid select * from generate_series(1, 6);
INFO: (slice 0) Dispatch command to ALL contents: 0 1 2
INFO: (slice 1) Dispatch command to SINGLE content
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=0;
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t_test_dd_via_segid
Filter: (gp_segment_id = 0)
Optimizer: Postgres query optimizer
(4 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=0;
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | id
---------------+----
0 | 2
0 | 3
0 | 4
(3 rows)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1;
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t_test_dd_via_segid
Filter: (gp_segment_id = 1)
Optimizer: Postgres query optimizer
(4 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1;
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | id
---------------+----
1 | 1
(1 row)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=2;
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t_test_dd_via_segid
Filter: (gp_segment_id = 2)
Optimizer: Postgres query optimizer
(4 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=2;
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | id
---------------+----
2 | 5
2 | 6
(2 rows)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2;
QUERY PLAN
--------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t_test_dd_via_segid
Filter: ((gp_segment_id = 1) OR (gp_segment_id = 2))
Optimizer: Postgres query optimizer
(4 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2;
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | id
---------------+----
1 | 1
2 | 5
2 | 6
(3 rows)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2 or gp_segment_id=3;
QUERY PLAN
-------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Seq Scan on t_test_dd_via_segid
Filter: ((gp_segment_id = 1) OR (gp_segment_id = 2) OR (gp_segment_id = 3))
Optimizer: Postgres query optimizer
(4 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2 or gp_segment_id=3;
INFO: (slice 1) Dispatch command to ALL contents: 0 1 2
gp_segment_id | id
---------------+----
2 | 5
2 | 6
1 | 1
(3 rows)
-- cleanup -- cleanup
set test_print_direct_dispatch_info=off; set test_print_direct_dispatch_info=off;
begin; begin;
......
...@@ -671,6 +671,108 @@ INFO: (slice 1) Dispatch command to SINGLE content ...@@ -671,6 +671,108 @@ INFO: (slice 1) Dispatch command to SINGLE content
drop table test_prepare; drop table test_prepare;
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2 INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2 INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
-- test direct dispatch via gp_segment_id qual
create table t_test_dd_via_segid(id int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'id' 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.
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
insert into t_test_dd_via_segid select * from generate_series(1, 6);
INFO: (slice 0) Dispatch command to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Prepare' to ALL contents: 0 1 2
INFO: Distributed transaction command 'Distributed Commit Prepared' to ALL contents: 0 1 2
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=0;
QUERY PLAN
---------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Result
-> Seq Scan on t_test_dd_via_segid
Filter: (gp_segment_id = 0)
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=0;
INFO: (slice 1) Dispatch command to SINGLE content
gp_segment_id | id
---------------+----
0 | 2
0 | 3
0 | 4
(3 rows)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1;
QUERY PLAN
---------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Result
-> Seq Scan on t_test_dd_via_segid
Filter: (gp_segment_id = 1)
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1;
INFO: (slice 1) Dispatch command to SINGLE content
gp_segment_id | id
---------------+----
1 | 1
(1 row)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=2;
QUERY PLAN
---------------------------------------------
Gather Motion 1:1 (slice1; segments: 1)
-> Result
-> Seq Scan on t_test_dd_via_segid
Filter: (gp_segment_id = 2)
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=2;
INFO: (slice 1) Dispatch command to SINGLE content
gp_segment_id | id
---------------+----
2 | 5
2 | 6
(2 rows)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2;
QUERY PLAN
--------------------------------------------------------------------
Gather Motion 2:1 (slice1; segments: 2)
-> Result
-> Seq Scan on t_test_dd_via_segid
Filter: ((gp_segment_id = 1) OR (gp_segment_id = 2))
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2;
INFO: (slice 1) Dispatch command to PARTIAL contents: 1 2
gp_segment_id | id
---------------+----
1 | 1
2 | 5
2 | 6
(3 rows)
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2 or gp_segment_id=3;
QUERY PLAN
-------------------------------------------------------------------------------------------
Gather Motion 2:1 (slice1; segments: 2)
-> Result
-> Seq Scan on t_test_dd_via_segid
Filter: ((gp_segment_id = 1) OR (gp_segment_id = 2) OR (gp_segment_id = 3))
Optimizer: Pivotal Optimizer (GPORCA)
(5 rows)
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2 or gp_segment_id=3;
INFO: (slice 1) Dispatch command to PARTIAL contents: 1 2
gp_segment_id | id
---------------+----
1 | 1
2 | 5
2 | 6
(3 rows)
-- cleanup -- cleanup
set test_print_direct_dispatch_info=off; set test_print_direct_dispatch_info=off;
begin; begin;
......
...@@ -289,6 +289,25 @@ execute p3(1); ...@@ -289,6 +289,25 @@ execute p3(1);
execute p3(1); execute p3(1);
drop table test_prepare; drop table test_prepare;
-- test direct dispatch via gp_segment_id qual
create table t_test_dd_via_segid(id int);
insert into t_test_dd_via_segid select * from generate_series(1, 6);
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=0;
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=0;
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1;
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1;
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=2;
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=2;
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2;
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2;
explain (costs off) select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2 or gp_segment_id=3;
select gp_segment_id, id from t_test_dd_via_segid where gp_segment_id=1 or gp_segment_id=2 or gp_segment_id=3;
-- cleanup -- cleanup
set test_print_direct_dispatch_info=off; set test_print_direct_dispatch_info=off;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册