CConfigParamMapping.cpp 14.5 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 24 25 26
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2012 EMC Corp.
//
//	@filename:
//		CConfigParamMapping.cpp
//
//	@doc:
//		Implementation of GPDB config params->trace flags mapping
//
//	@test:
//
//
//---------------------------------------------------------------------------

#include "postgres.h"
#include "utils/guc.h"

#include "gpopt/config/CConfigParamMapping.h"
#include "gpopt/xforms/CXform.h"

using namespace gpos;
using namespace gpdxl;
using namespace gpopt;

// array mapping GUCs to traceflags
J
Jesse Zhang 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
CConfigParamMapping::SConfigMappingElem CConfigParamMapping::m_elements[] = {
	{EopttracePrintQuery, &optimizer_print_query,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints the optimizer's input query expression tree.")},

	{EopttracePrintPlan, &optimizer_print_plan,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Prints the plan expression tree produced by the optimizer.")},

	{EopttracePrintXform, &optimizer_print_xform,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Prints the input and output expression trees of the optimizer transformations.")},

	{EopttracePrintXformResults, &optimizer_print_xform_results,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Print input and output of xforms.")},

	{EopttracePrintMemoAfterExploration,
	 &optimizer_print_memo_after_exploration,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints MEMO after exploration.")},

	{EopttracePrintMemoAfterImplementation,
	 &optimizer_print_memo_after_implementation,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints MEMO after implementation.")},

	{EopttracePrintMemoAfterOptimization,
	 &optimizer_print_memo_after_optimization,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints MEMO after optimization.")},

	{EopttracePrintJobScheduler, &optimizer_print_job_scheduler,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints jobs in scheduler on each job completion.")},

	{EopttracePrintExpressionProperties, &optimizer_print_expression_properties,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints expression properties.")},

	{EopttracePrintGroupProperties, &optimizer_print_group_properties,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints group properties.")},

	{EopttracePrintOptimizationContext, &optimizer_print_optimization_context,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints optimization context.")},

	{EopttracePrintOptimizationStatistics, &optimizer_print_optimization_stats,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Prints optimization stats.")},

	{EopttraceMinidump, &optimizer_minidump,
	 false,	 // m_fNegate
	 GPOS_WSZ_LIT("Generate optimizer minidump.")},

	{EopttraceDisableMotions, &optimizer_enable_motions,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable motion nodes in optimizer.")},

	{EopttraceDisableMotionBroadcast, &optimizer_enable_motion_broadcast,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable motion broadcast nodes in optimizer.")},

	{EopttraceDisableMotionGather, &optimizer_enable_motion_gather,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable motion gather nodes in optimizer.")},

	{EopttraceDisableMotionHashDistribute,
	 &optimizer_enable_motion_redistribute,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable motion hash-distribute nodes in optimizer.")},

	{EopttraceDisableMotionRandom, &optimizer_enable_motion_redistribute,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable motion random nodes in optimizer.")},

	{EopttraceDisableMotionRountedDistribute,
	 &optimizer_enable_motion_redistribute,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable motion routed-distribute nodes in optimizer.")},

	{EopttraceDisableSort, &optimizer_enable_sort,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable sort nodes in optimizer.")},

	{EopttraceDisableSpool, &optimizer_enable_materialize,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable spool nodes in optimizer.")},

	{EopttraceDisablePartPropagation, &optimizer_enable_partition_propagation,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable partition propagation nodes in optimizer.")},

	{EopttraceDisablePartSelection, &optimizer_enable_partition_selection,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable partition selection in optimizer.")},

	{EopttraceDisableOuterJoin2InnerJoinRewrite,
	 &optimizer_enable_outerjoin_rewrite,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable outer join to inner join rewrite in optimizer.")},

	{EopttraceDonotDeriveStatsForAllGroups,
	 &optimizer_enable_derive_stats_all_groups,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Disable deriving stats for all groups after exploration.")},

	{EopttraceEnableSpacePruning, &optimizer_enable_space_pruning,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enable space pruning in optimizer.")},

	{EopttraceForceMultiStageAgg, &optimizer_force_multistage_agg,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Force optimizer to always pick multistage aggregates when such a plan alternative is generated.")},

	{EopttracePrintColsWithMissingStats, &optimizer_print_missing_stats,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Print columns with missing statistics.")},

	{EopttraceEnableRedistributeBroadcastHashJoin,
	 &optimizer_enable_hashjoin_redistribute_broadcast_children,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Enable generating hash join plan where outer child is Redistribute and inner child is Broadcast.")},

	{EopttraceExtractDXLStats, &optimizer_extract_dxl_stats,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Extract plan stats in dxl.")},

	{EopttraceExtractDXLStatsAllNodes, &optimizer_extract_dxl_stats_all_nodes,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Extract plan stats for all physical dxl nodes.")},

	{EopttraceDeriveStatsForDPE, &optimizer_dpe_stats,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Enable stats derivation of partitioned tables with dynamic partition elimination.")},

	{EopttraceEnumeratePlans, &optimizer_enumerate_plans,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enable plan enumeration.")},

	{EopttraceSamplePlans, &optimizer_sample_plans,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enable plan sampling.")},

	{EopttraceEnableCTEInlining, &optimizer_cte_inlining,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enable CTE inlining.")},

	{EopttraceEnableConstantExpressionEvaluation,
	 &optimizer_enable_constant_expression_evaluation,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enable constant expression evaluation in the optimizer")},

	{EopttraceUseExternalConstantExpressionEvaluationForInts,
	 &optimizer_use_external_constant_expression_evaluation_for_ints,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Enable constant expression evaluation for integers in the optimizer")},

	{EopttraceApplyLeftOuter2InnerUnionAllLeftAntiSemiJoinDisregardingStats,
	 &optimizer_apply_left_outer_to_union_all_disregarding_stats,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Always apply Left Outer Join to Inner Join UnionAll Left Anti Semi Join without looking at stats")},

	{EopttraceRemoveOrderBelowDML, &optimizer_remove_order_below_dml,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Remove OrderBy below a DML operation")},

	{EopttraceDisableReplicateInnerNLJOuterChild,
	 &optimizer_enable_broadcast_nestloop_outer_child,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT(
		 "Enable plan alternatives where NLJ's outer child is replicated")},

	{EopttraceMotionHazardHandling, &optimizer_enable_streaming_material,
	 false,	 // m_fNegate
	 GPOS_WSZ_LIT(
		 "Enable motion hazard handling during NLJ optimization and generate streaming material when appropriate")},

	{EopttraceDisableNonMasterGatherForDML,
	 &optimizer_enable_gather_on_segment_for_dml,
	 true,	// m_fNegate
	 GPOS_WSZ_LIT(
		 "Enable DML optimization by enforcing a non-master gather when appropriate")},

	{EopttraceEnforceCorrelatedExecution, &optimizer_enforce_subplans,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enforce correlated execution in the optimizer")},

	{EopttraceForceExpandedMDQAs, &optimizer_force_expanded_distinct_aggs,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Always pick plans that expand multiple distinct aggregates into join of single distinct aggregate in the optimizer")},

	{EopttraceDisablePushingCTEConsumerReqsToCTEProducer,
	 &optimizer_push_requirements_from_consumer_to_producer,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT(
		 "Optimize CTE producer plan on requirements enforced on top of CTE consumer")},

	{EopttraceDisablePruneUnusedComputedColumns,
	 &optimizer_prune_computed_columns,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Prune unused computed columns when pre-processing query")},

	{EopttraceForceThreeStageScalarDQA, &optimizer_force_three_stage_scalar_dqa,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Force optimizer to always pick 3 stage aggregate plan for scalar distinct qualified aggregate.")},

	{EopttraceEnableParallelAppend, &optimizer_parallel_union,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT("Enable parallel execution for UNION/UNION ALL queries.")},

	{EopttraceArrayConstraints, &optimizer_array_constraints,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Allows the constraint framework to derive array constraints in the optimizer.")},

	{EopttraceForceAggSkewAvoidance, &optimizer_force_agg_skew_avoidance,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Always pick a plan for aggregate distinct that minimizes skew.")},

	{EopttraceExpandFullJoin, &optimizer_enable_full_join,
	 false,	 // m_negate_param
	 GPOS_WSZ_LIT(
		 "Enable Expand Full Join transform for converting FULL JOIN into UNION ALL.")},
	{EopttracePenalizeSkewedHashJoin, &optimizer_penalize_skew,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT(
		 "Penalize a hash join with a skewed redistribute as a child.")},
	{EopttraceTranslateUnusedColrefs, &optimizer_prune_unused_columns,
	 true,	// m_negate_param
	 GPOS_WSZ_LIT("Prune unused columns from the query.")}
269 270 271 272 273

};

//---------------------------------------------------------------------------
//	@function:
274
//		CConfigParamMapping::PackConfigParamInBitset
275 276 277 278 279 280
//
//	@doc:
//		Pack the GPDB config params into a bitset
//
//---------------------------------------------------------------------------
CBitSet *
J
Jesse Zhang 已提交
281
CConfigParamMapping::PackConfigParamInBitset(
282
	CMemoryPool *mp,
J
Jesse Zhang 已提交
283 284
	ULONG xform_id	// number of available xforms
)
285
{
286
	CBitSet *traceflag_bitset = GPOS_NEW(mp) CBitSet(mp, EopttraceSentinel);
287

288
	for (ULONG ul = 0; ul < GPOS_ARRAY_SIZE(m_elements); ul++)
289
	{
290 291
		SConfigMappingElem elem = m_elements[ul];
		GPOS_ASSERT(!traceflag_bitset->Get((ULONG) elem.m_trace_flag) &&
292 293
					"trace flag already set");

294 295
		BOOL value = *elem.m_is_param;
		if (elem.m_negate_param)
296 297
		{
			// negate the value of config param
298
			value = !value;
299 300
		}

301
		if (value)
302 303
		{
#ifdef GPOS_DEBUG
304
			BOOL is_traceflag_set =
J
Jesse Zhang 已提交
305
#endif	// GPOS_DEBUG
306 307
				traceflag_bitset->ExchangeSet((ULONG) elem.m_trace_flag);
			GPOS_ASSERT(!is_traceflag_set);
308 309 310 311
		}
	}

	// pack disable flags of xforms
312
	for (ULONG ul = 0; ul < xform_id; ul++)
313
	{
314
		GPOS_ASSERT(!traceflag_bitset->Get(EopttraceDisableXformBase + ul) &&
315 316 317 318 319
					"xform trace flag already set");

		if (optimizer_xforms[ul])
		{
#ifdef GPOS_DEBUG
320
			BOOL is_traceflag_set =
J
Jesse Zhang 已提交
321
#endif	// GPOS_DEBUG
322 323
				traceflag_bitset->ExchangeSet(EopttraceDisableXformBase + ul);
			GPOS_ASSERT(!is_traceflag_set);
324 325 326 327 328 329
		}
	}

	// disable index-join if the corresponding GUC is turned off
	if (!optimizer_enable_indexjoin)
	{
330 331 332
		CBitSet *index_join_bitset = CXform::PbsIndexJoinXforms(mp);
		traceflag_bitset->Union(index_join_bitset);
		index_join_bitset->Release();
333 334 335 336 337
	}

	// disable bitmap scan if the corresponding GUC is turned off
	if (!optimizer_enable_bitmapscan)
	{
338 339 340
		CBitSet *bitmap_index_bitset = CXform::PbsBitmapIndexXforms(mp);
		traceflag_bitset->Union(bitmap_index_bitset);
		bitmap_index_bitset->Release();
341 342 343 344 345
	}

	// disable outerjoin to unionall transformation if GUC is turned off
	if (!optimizer_enable_outerjoin_to_unionall_rewrite)
	{
J
Jesse Zhang 已提交
346 347
		traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(
			CXform::ExfLeftOuter2InnerUnionAllLeftAntiSemiJoin));
348 349 350 351 352
	}

	// disable Assert MaxOneRow plans if GUC is turned off
	if (!optimizer_enable_assert_maxonerow)
	{
J
Jesse Zhang 已提交
353 354
		traceflag_bitset->ExchangeSet(
			GPOPT_DISABLE_XFORM_TF(CXform::ExfMaxOneRow2Assert));
355 356
	}

357 358
	if (!optimizer_enable_partial_index)
	{
J
Jesse Zhang 已提交
359 360
		CBitSet *heterogeneous_index_bitset =
			CXform::PbsHeterogeneousIndexXforms(mp);
361 362
		traceflag_bitset->Union(heterogeneous_index_bitset);
		heterogeneous_index_bitset->Release();
363
	}
364

365 366 367
	if (!optimizer_enable_hashjoin)
	{
		// disable hash-join if the corresponding GUC is turned off
368 369 370
		CBitSet *hash_join_bitste = CXform::PbsHashJoinXforms(mp);
		traceflag_bitset->Union(hash_join_bitste);
		hash_join_bitste->Release();
371 372 373 374 375
	}

	if (!optimizer_enable_dynamictablescan)
	{
		// disable dynamic table scan if the corresponding GUC is turned off
J
Jesse Zhang 已提交
376 377
		traceflag_bitset->ExchangeSet(
			GPOPT_DISABLE_XFORM_TF(CXform::ExfDynamicGet2DynamicTableScan));
378 379
	}

380 381 382
	if (!optimizer_enable_tablescan)
	{
		// disable table scan if the corresponding GUC is turned off
J
Jesse Zhang 已提交
383 384
		traceflag_bitset->ExchangeSet(
			GPOPT_DISABLE_XFORM_TF(CXform::ExfGet2TableScan));
385 386
	}

387 388 389
	if (!optimizer_enable_indexscan)
	{
		// disable index scan if the corresponding GUC is turned off
J
Jesse Zhang 已提交
390 391
		traceflag_bitset->ExchangeSet(
			GPOPT_DISABLE_XFORM_TF(CXform::ExfIndexGet2IndexScan));
392 393
	}

394
	CBitSet *join_heuristic_bitset = NULL;
395 396 397
	switch (optimizer_join_order)
	{
		case JOIN_ORDER_IN_QUERY:
398
			join_heuristic_bitset = CXform::PbsJoinOrderInQueryXforms(mp);
399 400
			break;
		case JOIN_ORDER_GREEDY_SEARCH:
401
			join_heuristic_bitset = CXform::PbsJoinOrderOnGreedyXforms(mp);
402 403
			break;
		case JOIN_ORDER_EXHAUSTIVE_SEARCH:
404
			join_heuristic_bitset = CXform::PbsJoinOrderOnExhaustiveXforms(mp);
405
			break;
S
Sambitesh Dash 已提交
406 407 408
		case JOIN_ORDER_EXHAUSTIVE2_SEARCH:
			join_heuristic_bitset = CXform::PbsJoinOrderOnExhaustive2Xforms(mp);
			break;
409
		default:
J
Jesse Zhang 已提交
410 411
			elog(ERROR,
				 "Invalid value for optimizer_join_order, must \
412 413 414
				 not come here");
			break;
	}
415 416
	traceflag_bitset->Union(join_heuristic_bitset);
	join_heuristic_bitset->Release();
417

418 419 420 421
	// disable join associativity transform if the corresponding GUC
	// is turned off independent of the join order algorithm chosen
	if (!optimizer_enable_associativity)
	{
J
Jesse Zhang 已提交
422 423
		traceflag_bitset->ExchangeSet(
			GPOPT_DISABLE_XFORM_TF(CXform::ExfJoinAssociativity));
424 425
	}

A
Ashuka Xue 已提交
426
	// full merge join is disabled in 5x
J
Jesse Zhang 已提交
427 428
	traceflag_bitset->ExchangeSet(
		GPOPT_DISABLE_XFORM_TF(CXform::ExfImplementFullOuterMergeJoin));
A
Ashuka Xue 已提交
429

430 431
	if (!optimizer_enable_full_join)
	{
J
Jesse Zhang 已提交
432 433
		traceflag_bitset->ExchangeSet(
			GPOPT_DISABLE_XFORM_TF(CXform::ExfExpandFullOuterJoin));
434 435
	}

C
Chris Hajas 已提交
436 437 438 439 440
	if (OPTIMIZER_GPDB_EXPERIMENTAL == optimizer_cost_model)
	{
		traceflag_bitset->ExchangeSet(EopttraceCalibratedBitmapIndexCostModel);
	}

441 442 443
	// Keep current behavior for range predicates in DPE for 5x
	traceflag_bitset->ExchangeSet(EopttraceAllowGeneralPredicatesforDPE);

444
	return traceflag_bitset;
445 446 447
}

// EOF