CXform
CXforml类作为所有transformation的基础类,其包含了pattern成员m_pexpr。主要是在exploration和implementation expression流程中使用,主要调用Transform函数。其还包含返回相关xforms的集合函数,比如PbsIndexJoinXforms等。
class CXform : public CRefCount {
private: CExpression *m_pexpr; // pattern
CXform(CXform &); // private copy ctor
public:
explicit CXform(CExpression *pexpr); virtual ~CXform();
CExpression *PexprPattern() const { return m_pexpr; } // accessor
static BOOL FEqualIds(const CHAR *szIdOne, const CHAR *szIdTwo); // equality function over xform ids
virtual EXformId Exfid() const = 0; // ident accessors
virtual const CHAR *SzId() const = 0; // return a string for xform name
// the following functions check xform type
virtual BOOL FSubstitution() const { return false; } // is xform substitution?
virtual BOOL FExploration() const { return false; } // is xform exploration?
virtual BOOL FImplementation() const { return false; } // is xform implementation?
virtual BOOL FCompatible(CXform::EXformId) { return true; } // check compatibility with another xform
// actual transformation
virtual void Transform(CXformContext *pxfctxt, CXformResult *pxfres, CExpression *pexpr) const = 0;
// compute xform promise for a given expression handle
virtual EXformPromise Exfp(CExpressionHandle &exprhdl) const = 0;
// return true if xform should be applied only once.
// for expression of type CPatternTree, in deep trees, the number
// of expressions generated for group expression can be significantly
// large causing the Xform to be applied many times. This can lead to
// significantly long planning time, so such Xform should only be applied once
virtual BOOL IsApplyOnce();
// returns a set containing all xforms related to index join
// caller takes ownership of the returned set
static CBitSet *PbsIndexJoinXforms(CMemoryPool *mp);
// returns a set containing all xforms related to bitmap indexes
// caller takes ownership of the returned set
static CBitSet *PbsBitmapIndexXforms(CMemoryPool *mp);
// returns a set containing all xforms related to heterogeneous indexes
// caller takes ownership of the returned set
static CBitSet *PbsHeterogeneousIndexXforms(CMemoryPool *mp);
// returns a set containing all xforms that generate a plan with a hash join
// caller takes ownership of the returned set
static CBitSet *PbsHashJoinXforms(CMemoryPool *mp);
// returns a set containing xforms to use only the join order as available
// in the query
static CBitSet *PbsJoinOrderInQueryXforms(CMemoryPool *mp);
// returns a set containing xforms to use combination of greedy xforms
// for join order
static CBitSet *PbsJoinOrderOnGreedyXforms(CMemoryPool *mp);
// returns a set containing xforms to use for exhaustive join order
static CBitSet *PbsJoinOrderOnExhaustiveXforms(CMemoryPool *mp);
// returns a set containing xforms to use for exhaustive2 join order
static CBitSet *PbsJoinOrderOnExhaustive2Xforms(CMemoryPool *mp);
}; // class CXform
CXformExploration和CXformImplementation
CXformExploration类作为Base class for all explorations,其定义如下所示:
class CXformExploration : public CXform {
private: CXformExploration(const CXformExploration &); // private copy ctor
public:
explicit CXformExploration(CExpression *pexpr); // ctor
virtual ~CXformExploration(); // dtor
virtual BOOL FExploration() const { return true; } // type of operator
// is transformation a subquery unnesting (Subquery To Apply) xform?
virtual BOOL FSubqueryUnnesting() const { return false; }
// is transformation an Apply decorrelation (Apply To Join) xform?
virtual BOOL FApplyDecorrelating() const { return false; }
// do stats need to be computed before applying xform?
virtual BOOL FNeedsStats() const { return false; }
// conversion function
static CXformExploration *Pxformexp(CXform *pxform) {
return dynamic_cast<CXformExploration *>(pxform);
}
}; // class CXformExploration
CXformImplementation类作为base class for all implementations,其定义如下所示:
class CXformImplementation : public CXform {
private: CXformImplementation(const CXformImplementation &); // private copy ctor
public:
explicit CXformImplementation(CExpression *); // ctor
virtual ~CXformImplementation(); // dtor
virtual BOOL FImplementation() const { // type of operator
return true;
}
}; // class CXformImplementation
CLogical | EXformId | CXform subclass | Phase |
---|---|---|---|
CLogicalAssert | CXform::ExfImplementAssert | ||
CLogicalBitmapTableGet | CXform::ExfImplementBitmapTableGet | ||
CLogicalConstTableGet | CXform::ExfImplementConstTableGet | ||
CLogicalCTEAnchor | CXform::ExfCTEAnchor2Sequence、CXform::ExfCTEAnchor2TrivialSelect | ||
CLogicalCTEConsumer | CXform::ExfInlineCTEConsumer、CXform::ExfImplementCTEConsumer | ||
CLogicalCTEProducer | CXform::ExfImplementCTEProducer | ||
CLogicalDelete | CXform::ExfDelete2DML | ||
CLogicalDifference | CXform::ExfDifference2LeftAntiSemiJoin | ||
CLogicalDifferenceAll | CXform::ExfDifferenceAll2LeftAntiSemiJoin | ||
CLogicalDML | CXform::ExfImplementDML | ||
CLogicalDynamicBitmapTableGet | CXform::ExfImplementDynamicBitmapTableGet | ||
CLogicalDynamicGet | CXform::ExfDynamicGet2DynamicTableScan、CXform::ExfExpandDynamicGetWithExternalPartitions | ||
CLogicalDynamicIndexGet | CXform::ExfDynamicIndexGet2DynamicIndexScan | ||
CLogicalExternalGet | CXform::ExfExternalGet2ExternalScan | ||
CLogicalFullOuterJoin | CXform::ExfExpandFullOuterJoin、CXform::ExfImplementFullOuterMergeJoin | ||
CLogicalGbAgg | CXform::ExfSimplifyGbAgg)、CXform::ExfGbAggWithMDQA2Join、CXform::ExfCollapseGbAgg、CXform::ExfPushGbBelowJoin、CXform::ExfPushGbBelowUnion、CXform::ExfPushGbBelowUnionAll、CXform::ExfSplitGbAgg、CXform::ExfSplitDQA、CXform::ExfGbAgg2Apply、CXform::ExfGbAgg2HashAgg、CXform::ExfGbAgg2StreamAgg、CXform::ExfGbAgg2ScalarAgg、CXform::ExfEagerAgg | ||
CLogicalGbAggDeduplicate | CXform::ExfPushGbDedupBelowJoin、CXform::ExfSplitGbAggDedup、CXform::ExfGbAggDedup2HashAggDedup、CXform::ExfGbAggDedup2StreamAggDedup | ||
CLogicalGet | CXform::ExfGet2TableScan | ||
CLogicalIndexApply | CXform::ExfImplementIndexApply | ||
CLogicalIndexGet | CXform::ExfIndexGet2IndexScan、CXform::ExfIndexGet2IndexOnlyScan | ||
CLogicalInnerApply | CXform::ExfInnerApply2InnerJoin、CXform::ExfInnerApply2InnerJoinNoCorrelations、CXform::ExfInnerApplyWithOuterKey2InnerJoin | ||
CLogicalInnerCorrelatedApply | CXform::ExfImplementInnerCorrelatedApply | ||
CLogicalInnerJoin | CXform::ExfInnerJoin2NLJoin、CXform::ExfInnerJoin2HashJoin、CXform::ExfSubqJoin2Apply、CXform::ExfInnerJoin2PartialDynamicIndexGetApply、CXform::ExfInnerJoinWithInnerSelect2PartialDynamicIndexGetApply、CXform::ExfJoin2BitmapIndexGetApply、CXform::ExfJoin2IndexGetApply、CXform::ExfJoinCommutativity、CXform::ExfJoinAssociativity、CXform::ExfInnerJoinSemiJoinSwap、CXform::ExfInnerJoinAntiSemiJoinSwap、CXform::ExfInnerJoinAntiSemiJoinNotInSwap | ||
CLogicalInsert | CXform::ExfInsert2DML | ||
CLogicalIntersect | CXform::ExfIntersect2Join | ||
CLogicalIntersectAll | CXform::ExfIntersectAll2LeftSemiJoin | ||
CLogicalLeftAntiSemiApply | CXform::ExfLeftAntiSemiApply2LeftAntiSemiJoin、CXform::ExfLeftAntiSemiApply2LeftAntiSemiJoinNoCorrelations | ||
CLogicalLeftAntiSemiApplyNotIn | CXform::ExfLeftAntiSemiApplyNotIn2LeftAntiSemiJoinNotIn、CXform::ExfLeftAntiSemiApplyNotIn2LeftAntiSemiJoinNotInNoCorrelations | ||
CLogicalLeftAntiSemiCorrelatedApply | CXform::ExfImplementLeftAntiSemiCorrelatedApply | ||
CLogicalLeftAntiSemiCorrelatedApplyNotIn | CXform::ExfImplementLeftAntiSemiCorrelatedApplyNotIn | ||
CLogicalLeftAntiSemiJoin | CXform::ExfAntiSemiJoinAntiSemiJoinSwap、CXform::ExfAntiSemiJoinAntiSemiJoinNotInSwap、CXform::ExfAntiSemiJoinSemiJoinSwap、CXform::ExfAntiSemiJoinInnerJoinSwap、CXform::ExfLeftAntiSemiJoin2CrossProduct、CXform::ExfLeftAntiSemiJoin2NLJoin、CXform::ExfLeftAntiSemiJoin2HashJoin | ||
CLogicalLeftAntiSemiJoinNotIn | CXform::ExfAntiSemiJoinNotInAntiSemiJoinNotInSwap、CXform::ExfAntiSemiJoinNotInAntiSemiJoinSwap、CXform::ExfAntiSemiJoinNotInSemiJoinSwap、CXform::ExfAntiSemiJoinNotInInnerJoinSwap、CXform::ExfLeftAntiSemiJoinNotIn2CrossProduct、CXform::ExfLeftAntiSemiJoinNotIn2NLJoinNotIn、CXform::ExfLeftAntiSemiJoinNotIn2HashJoinNotIn | ||
CLogicalLeftOuterApply | CXform::ExfLeftOuterApply2LeftOuterJoin、CXform::ExfLeftOuterApply2LeftOuterJoinNoCorrelations | ||
CLogicalLeftOuterCorrelatedApply | CXform::ExfImplementLeftOuterCorrelatedApply | ||
CLogicalLeftOuterJoin | CXform::ExfPushDownLeftOuterJoin、CXform::ExfSimplifyLeftOuterJoin、CXform::ExfLeftOuterJoin2NLJoin、CXform::ExfLeftOuterJoin2HashJoin、CXform::ExfLeftOuter2InnerUnionAllLeftAntiSemiJoin、CXform::ExfJoin2BitmapIndexGetApply、CXform::ExfJoin2IndexGetApply、CXform::ExfLeftJoin2RightJoin | ||
CLogicalLeftSemiApply | CXform::ExfLeftSemiApply2LeftSemiJoin、CXform::ExfLeftSemiApplyWithExternalCorrs2InnerJoin、CXform::ExfLeftSemiApply2LeftSemiJoinNoCorrelations | ||
CLogicalLeftSemiApplyIn | CXform::ExfLeftSemiApplyIn2LeftSemiJoin、CXform::ExfLeftSemiApplyInWithExternalCorrs2InnerJoin、CXform::ExfLeftSemiApplyIn2LeftSemiJoinNoCorrelations | ||
CLogicalLeftSemiCorrelatedApply | CXform::ExfImplementLeftSemiCorrelatedApply | ||
CLogicalLeftSemiCorrelatedApplyIn | CXform::ExfImplementLeftSemiCorrelatedApplyIn | ||
CLogicalLeftSemiJoin | CXform::ExfSemiJoinSemiJoinSwap、CXform::ExfSemiJoinAntiSemiJoinSwap、CXform::ExfSemiJoinAntiSemiJoinNotInSwap、CXform::ExfSemiJoinInnerJoinSwap、CXform::ExfLeftSemiJoin2InnerJoin、CXform::ExfLeftSemiJoin2InnerJoinUnderGb、CXform::ExfLeftSemiJoin2CrossProduct、CXform::ExfLeftSemiJoin2NLJoin、CXform::ExfLeftSemiJoin2HashJoin | ||
CLogicalLimit | CXform::ExfImplementLimit、CXform::ExfSplitLimit | ||
CLogicalMaxOneRow | CXform::ExfMaxOneRow2Assert | ||
CLogicalMultiExternalGet | CXform::ExfMultiExternalGet2MultiExternalScan | ||
CLogicalNAryJoin | CXform::ExfSubqNAryJoin2Apply、CXform::ExfExpandNAryJoin、CXform::ExfExpandNAryJoinMinCard、CXform::ExfExpandNAryJoinDP、CXform::ExfExpandNAryJoinGreedy、CXform::ExfExpandNAryJoinDPv2 | ||
CLogicalPartitionSelector | CXform::ExfImplementPartitionSelector | ||
CLogicalProject | CXform::ExfSimplifyProjectWithSubquery、CXform::ExfProject2Apply、CXform::ExfProject2ComputeScalar、CXform::ExfCollapseProject | ||
CLogicalRightOuterJoin | CXform::ExfRightOuterJoin2HashJoin | ||
CLogicalRowTrigger | CXform::ExfImplementRowTrigger | ||
CLogicalSelect | CXform::ExfSelect2Apply、CXform::ExfRemoveSubqDistinct、CXform::ExfInlineCTEConsumerUnderSelect、CXform::ExfPushGbWithHavingBelowJoin、CXform::ExfSelect2IndexGet、CXform::ExfSelect2DynamicIndexGet、CXform::ExfSelect2PartialDynamicIndexGet、CXform::ExfSelect2BitmapBoolOp、CXform::ExfSelect2DynamicBitmapBoolOp、CXform::ExfSimplifySelectWithSubquery、CXform::ExfSelect2Filter | ||
CLogicalSequence | CXform::ExfImplementSequence | ||
CLogicalSequenceProject | CXform::ExfSequenceProject2Apply、CXform::ExfImplementSequenceProject | ||
CLogicalSplit | CXform::ExfImplementSplit | ||
CLogicalTVF | CXform::ExfUnnestTVF、CXform::ExfImplementTVF、CXform::ExfImplementTVFNoArgs | ||
CLogicalUnion | CXform::ExfUnion2UnionAll | ||
CLogicalUnionAll | CXform::ExfImplementUnionAll | ||
CLogicalUpdate | CXform::ExfUpdate2DML |