ORCA优化器浅析——CXform base class for all transformations
  5b99XfAwWKiH 2023年11月02日 108 0


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

ORCA优化器浅析——CXform base class for all transformations_bc

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


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  f18CFixvrKz8   2024年05月20日   90   0   0 JavaScript
  fxrR9b8fJ5Wh   2024年05月17日   52   0   0 JavaScript
  2xk0JyO908yA   2024年04月28日   40   0   0 JavaScript
5b99XfAwWKiH