CContextDXLToPlStmt.h 5.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2011 Greenplum, Inc.
//
//	@filename:
//		CContextDXLToPlStmt.h
//
//	@doc:
//		Class providing access to CIdGenerators (needed to number initplans, motion
//		nodes as well as params), list of RangeTableEntires and Subplans
//		generated so far during DXL-->PlStmt translation.
//
//	@test:
//
//---------------------------------------------------------------------------

#ifndef GPDXL_CContextDXLToPlStmt_H
#define GPDXL_CContextDXLToPlStmt_H

#include "gpopt/translate/CDXLTranslateContext.h"
#include "gpopt/translate/CDXLTranslateContextBaseTable.h"
#include "gpos/base.h"

24 25 26
#include "naucrates/dxl/gpdb_types.h"
#include "naucrates/dxl/CIdGenerator.h"
#include "naucrates/dxl/operators/CDXLScalarIdent.h"
27 28 29 30 31 32 33 34 35 36 37 38 39 40

#include "gpopt/gpdbwrappers.h"

// fwd decl
struct RangeTblEntry;
struct Plan;

struct List;
struct Var;
struct ShareInputScan;
struct GpPolicy;

namespace gpdxl
{
J
Jesse Zhang 已提交
41 42 43 44 45 46 47
// fwd decl
class CDXLTranslateContext;

typedef CHashMap<ULONG, CDXLTranslateContext, gpos::HashValue<ULONG>,
				 gpos::Equals<ULONG>, CleanupDelete<ULONG>,
				 CleanupDelete<CDXLTranslateContext> >
	HMUlDxltrctx;
48

J
Jesse Zhang 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
//---------------------------------------------------------------------------
//	@class:
//		CContextDXLToPlStmt
//
//	@doc:
//		Class providing access to CIdGenerators (needed to number initplans, motion
//		nodes as well as params), list of RangeTableEntires and Subplans
//		generated so far during DXL-->PlStmt translation.
//
//---------------------------------------------------------------------------
class CContextDXLToPlStmt
{
private:
	// cte consumer information
	struct SCTEConsumerInfo
64
	{
J
Jesse Zhang 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
		// list of ShareInputScan represent cte consumers
		List *m_cte_consumer_list;

		// ctor
		SCTEConsumerInfo(List *plan_cte) : m_cte_consumer_list(plan_cte)
		{
		}

		void
		AddCTEPlan(ShareInputScan *share_input_scan)
		{
			GPOS_ASSERT(NULL != share_input_scan);
			m_cte_consumer_list =
				gpdb::LAppend(m_cte_consumer_list, share_input_scan);
		}

		~SCTEConsumerInfo()
		{
			gpdb::ListFree(m_cte_consumer_list);
		}
	};

	// hash maps mapping ULONG -> SCTEConsumerInfo
	typedef CHashMap<ULONG, SCTEConsumerInfo, gpos::HashValue<ULONG>,
					 gpos::Equals<ULONG>, CleanupDelete<ULONG>,
					 CleanupDelete<SCTEConsumerInfo> >
		HMUlCTEConsumerInfo;

	CMemoryPool *m_mp;

	// counter for generating plan ids
	CIdGenerator *m_plan_id_counter;

	// counter for generating motion ids
	CIdGenerator *m_motion_id_counter;

	// counter for generating unique param ids
	CIdGenerator *m_param_id_counter;

	// list of all rtable entries
	List **m_rtable_entries_list;

	// list of oids of partitioned tables
	List *m_partitioned_tables_list;

	// number of partition selectors for each dynamic scan
	ULongPtrArray *m_num_partition_selectors_array;

	// list of all subplan entries
	List **m_subplan_entries_list;

	// index of the target relation in the rtable or 0 if not a DML statement
	ULONG m_result_relation_index;

	// hash map of the cte identifiers and the cte consumers with the same cte identifier
	HMUlCTEConsumerInfo *m_cte_consumer_info;

	// into clause
	IntoClause *m_into_clause;

	// CTAS distribution policy
	GpPolicy *m_distribution_policy;

public:
	// ctor/dtor
	CContextDXLToPlStmt(CMemoryPool *mp, CIdGenerator *plan_id_counter,
131 132 133
						CIdGenerator *motion_id_counter,
						CIdGenerator *param_id_counter,
						List **rtable_entries_list,
J
Jesse Zhang 已提交
134
						List **subplan_entries_list);
135

J
Jesse Zhang 已提交
136 137
	// dtor
	~CContextDXLToPlStmt();
138

J
Jesse Zhang 已提交
139 140
	// retrieve the next plan id
	ULONG GetNextPlanId();
141

J
Jesse Zhang 已提交
142 143
	// retrieve the current motion id
	ULONG GetCurrentMotionId();
144

J
Jesse Zhang 已提交
145 146
	// retrieve the next motion id
	ULONG GetNextMotionId();
147

J
Jesse Zhang 已提交
148 149
	// retrieve the current parameter id
	ULONG GetCurrentParamId();
150

J
Jesse Zhang 已提交
151 152
	// retrieve the next parameter id
	ULONG GetNextParamId();
153

J
Jesse Zhang 已提交
154 155
	// add a newly found CTE consumer
	void AddCTEConsumerInfo(ULONG cte_id, ShareInputScan *share_input_scan);
156

J
Jesse Zhang 已提交
157 158
	// return the list of shared input scan plans representing the CTE consumers
	List *GetCTEConsumerList(ULONG cte_id) const;
159

J
Jesse Zhang 已提交
160 161
	// return list of range table entries
	List *GetRTableEntriesList();
162

J
Jesse Zhang 已提交
163 164 165 166 167 168
	// return list of partitioned table indexes
	List *
	GetPartitionedTablesList() const
	{
		return m_partitioned_tables_list;
	}
169

J
Jesse Zhang 已提交
170 171
	// return list containing number of partition selectors for every scan id
	List *GetNumPartitionSelectorsList() const;
172

J
Jesse Zhang 已提交
173
	List *GetSubplanEntriesList();
174

J
Jesse Zhang 已提交
175 176 177 178 179 180
	// index of result relation in the rtable
	ULONG
	GetResultRelationIndex() const
	{
		return m_result_relation_index;
	}
181

J
Jesse Zhang 已提交
182 183
	// add a range table entry
	void AddRTE(RangeTblEntry *rte, BOOL is_result_relation = false);
184

J
Jesse Zhang 已提交
185 186
	// add a partitioned table index
	void AddPartitionedTable(OID oid);
187

J
Jesse Zhang 已提交
188 189
	// increment the number of partition selectors for the given scan id
	void IncrementPartitionSelectors(ULONG scan_id);
190

J
Jesse Zhang 已提交
191
	void AddSubplan(Plan *);
192

J
Jesse Zhang 已提交
193 194
	// add CTAS information
	void AddCtasInfo(IntoClause *into_clause, GpPolicy *distribution_policy);
195

J
Jesse Zhang 已提交
196 197 198 199 200 201
	// into clause
	IntoClause *
	GetIntoClause() const
	{
		return m_into_clause;
	}
202

J
Jesse Zhang 已提交
203 204 205 206 207
	// CTAS distribution policy
	GpPolicy *
	GetDistributionPolicy() const
	{
		return m_distribution_policy;
208
	}
J
Jesse Zhang 已提交
209 210 211 212
};

}  // namespace gpdxl
#endif	// !GPDXL_CContextDXLToPlStmt_H
213 214

//EOF