ORCA优化器浅析——CDXLScalarFilter Class for DXL filter operators
  5b99XfAwWKiH 2023年11月02日 61 0


ORCA优化器浅析——CDXLScalarFilter Class for DXL filter operators_scala

CDXLScalarFilter

CDXLScalarFilter为Class for representing DXL filter operators。CDXLScalarFilter相对于CDXLScalar没有增加其他数据成员。

class CDXLScalarFilter : public CDXLScalar{
private: CDXLScalarFilter(CDXLScalarFilter &); // private copy ctor
public:	
	explicit CDXLScalarFilter(CMemoryPool *mp); // ctor/dtor	
	Edxlopid GetDXLOperator() const; // accessors
	const CWStringConst *GetOpNameStr() const;
	// serialize operator in DXL format
	virtual void SerializeToDXL(CXMLSerializer *xml_serializer, const CDXLNode *node) const;
	// conversion function
	static CDXLScalarFilter *Cast(CDXLOperator *dxl_op) { return dynamic_cast<CDXLScalarFilter *>(dxl_op); }

	// does the operator return a boolean result
	virtual BOOL HasBoolResult(CMDAccessor *	 //md_accessor) const { return false; }
};

CDXLScalarFilter类有三个子类,它们的成员函数和CDXLScalarFilter父类一致:

  • class CDXLScalarJoinFilter : public CDXLScalarFilter Class for representing DXL join condition operators
  • class CDXLScalarOneTimeFilter : public CDXLScalarFilter Class for representing DXL filter operators
  • class CDXLScalarRecheckCondFilter : public CDXLScalarFilter Filter for rechecking an index condition on the operator upstream of the bitmap index scan

CreateFilterFromQual

CreateFilterFromQual函数是定义在src/include/gpopt/translate/CTranslatorScalarToDXL.h的CTranslatorScalarToDXL类的成员函数,用于create a DXL scalar filter node from a GPDB qual list。但是该函数在greeplum使用orca优化器流程中都没有调用,因为ScalarFilter是在Expr Tree转化为DXL Tree的流程中创建的,而非在QueryToDXL流程中调用,因此Query树中的qual表达式是被转化为其他CDXLScalar子类,而不是CDXLScalarFilter。

//---------------------------------------------------------------------------
//	@function:
//		CTranslatorScalarToDXL::CreateFilterFromQual
//	@doc:
//		Create a DXL scalar filter node from a GPDB qual list.
//		The function allocates memory in the translator memory pool, and the caller
//		is responsible for freeing it
//---------------------------------------------------------------------------
CDXLNode *CTranslatorScalarToDXL::CreateFilterFromQual(List *quals, const CMappingVarColId *var_colid_mapping, Edxlopid filter_type) {
	CDXLScalarFilter *dxlop = NULL;
	switch (filter_type) {
		case EdxlopScalarFilter: dxlop = GPOS_NEW(m_mp) CDXLScalarFilter(m_mp); break;
		case EdxlopScalarJoinFilter: dxlop = GPOS_NEW(m_mp) CDXLScalarJoinFilter(m_mp); break;
		case EdxlopScalarOneTimeFilter: dxlop = GPOS_NEW(m_mp) CDXLScalarOneTimeFilter(m_mp); break;
		default: GPOS_ASSERT(!"Unrecognized filter type");
	}

	CDXLNode *filter_dxlnode = GPOS_NEW(m_mp) CDXLNode(m_mp, dxlop); // 创建CDXLNode,m_dxl_op设置为dxlop
	CDXLNode *cond_node = CreateScalarCondFromQual(quals, var_colid_mapping);
	if (NULL != cond_node){ filter_dxlnode->AddChild(cond_node); // 将子节点添加到m_dxl_array }

	return filter_dxlnode;
}

CreateScalarCondFromQual函数从GPDB qual列表创建DXL标量布尔运算符节点。Create a DXL scalar boolean operator node from a GPDB qual list. The function allocates memory in the translator memory pool, and the caller is responsible for freeing it. 其最终流程就是调用CTranslatorScalarToDXL类的TranslateScalarToDXL函数(Create a DXL node for a scalar expression from a GPDB expression node.)。

//---------------------------------------------------------------------------
//	@function:
//		CTranslatorScalarToDXL::CreateScalarCondFromQual
//	@doc:
//		Create a DXL scalar boolean operator node from a GPDB qual list.
//		The function allocates memory in the translator memory pool, and the caller
//		is responsible for freeing it
//---------------------------------------------------------------------------
CDXLNode *CTranslatorScalarToDXL::CreateScalarCondFromQual(List *quals, const CMappingVarColId *var_colid_mapping) {
	if (NULL == quals || 0 == gpdb::ListLength(quals)){ return NULL; }

	if (1 == gpdb::ListLength(quals)) {
		Expr *expr = (Expr *) gpdb::ListNth(quals, 0);
		return TranslateScalarToDXL(expr, var_colid_mapping);
	}else{
		// GPDB assumes that if there are a list of qual conditions then it is an implicit AND operation Here we build the left deep AND tree
		CDXLNode *dxlnode = GPOS_NEW(m_mp) CDXLNode(m_mp, GPOS_NEW(m_mp) CDXLScalarBoolExpr(m_mp, Edxland));
		TranslateScalarChildren(dxlnode, quals, var_colid_mapping);

		return dxlnode;
	}
}
//---------------------------------------------------------------------------
//	@function:
//		CTranslatorScalarToDXL::TranslateScalarChildren
//	@doc:
//		Translate list elements and add them as children of the DXL node
//---------------------------------------------------------------------------
void CTranslatorScalarToDXL::TranslateScalarChildren(CDXLNode *dxlnode, List *list, const CMappingVarColId *var_colid_mapping) {
	ListCell *lc = NULL;
	ForEach(lc, list){
		Expr *child_expr = (Expr *) lfirst(lc);
		CDXLNode *child_node = TranslateScalarToDXL(child_expr, var_colid_mapping);
		dxlnode->AddChild(child_node);
	}
}

CTranslatorExprToDXL

CDXLScalarFilter及其子类在CTranslatorExprToDXL流程中实例化,调用流程如下所示。
CDXLScalarFilter类的创建流程:

  • CTranslatorExprToDXL类的PdxlnResultFromFilter函数用于Create a DXL result node from an optimizer filter node
  • CTranslatorExprToDXL类的PdxlnAggregate函数用于Create a DXL aggregate node from an optimizer agg expression
  • CTranslatorExprToDXL类的PdxlnFilter函数用于Create a DXL filter node containing the given scalar node as a child. If the scalar node is NULL, a filter node with no children is returned

CDXLScalarJoinFilter类的创建流程:

  • CTranslatorExprToDXL类的PdxlnNLJoin函数用于Create a DXL nested loop join node from an optimizer nested loop join expression
  • CTranslatorExprToDXL类的PdxlnMergeJoin函数
  • CTranslatorExprToDXL类的PdxlnHashJoin函数用于Create a DXL hash join node from an optimizer hash join expression

CDXLScalarOneTimeFilter类的创建流程:

  • CTranslatorExprToDXL类的PdxlnAddScalarFilterOnRelationalChild函数
  • CTranslatorExprToDXL类的PdxlnResultFromFilter函数用于Create a DXL result node from an optimizer filter node.
  • CTranslatorExprToDXL类的PdxlnResultFromConstTableGet函数用于Create a DXL result node from an optimizer const table get node
  • CTranslatorExprToDXL类的PdxlnRestrictResult函数用于Helper to build a Result expression with project list restricted to required column
  • CTranslatorExprToDXL类的PdxlnProjectBoolConst函数用于Helper to add a project of bool constant on top of given DXL node
  • CTranslatorExprToDXL类的PdxlnBooleanScalarWithSubPlan函数用于Construct a boolean scalar dxl node with a subplan as its child. The sublan has a boolean output column, and has the given relational child under it
  • CTranslatorExprToDXL类的PdxlnResult函数用于A wrapper around CTranslatorExprToDXLUtils::PdxlnResult to check if the project list imposes a motion hazard, eventually leading to a deadlock. If yes, add a Materialize on the Result child to break the deadlock cycle

CDXLScalarRecheckCondFilter类的创建流程:

  • CTranslatorExprToDXL类的PdxlnBitmapTableScan函数用于Create a DXL physical bitmap table scan from an optimizer physical bitmap table scan operator.
  • CTranslatorExprToDXL类的PdxlnDynamicBitmapTableScan函数用于Create a DXL dynamic bitmap table scan node from an optimizer dynamic bitmap table scan node.


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

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

暂无评论

推荐阅读
  rvP2pqm8fEoB   2023年12月24日   27   0   0 ListJavaListJava
5b99XfAwWKiH