CConfigParamMapping.cpp 13.8 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
27
CConfigParamMapping::SConfigMappingElem CConfigParamMapping::m_elements[] =
28 29 30 31
{
		{
		EopttracePrintQuery,
		&optimizer_print_query,
32
		false, // m_negate_param
33 34 35 36 37 38
		GPOS_WSZ_LIT("Prints the optimizer's input query expression tree.")
		},

		{
		EopttracePrintPlan,
		&optimizer_print_plan,
39
		false, // m_negate_param
40 41 42 43 44 45
		GPOS_WSZ_LIT("Prints the plan expression tree produced by the optimizer.")
		},

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

		{
V
Venkatesh Raghavan 已提交
51 52
		EopttracePrintXformResults,
		&optimizer_print_xform_results,
53
		false, // m_negate_param
V
Venkatesh Raghavan 已提交
54
		GPOS_WSZ_LIT("Print input and output of xforms.")
55 56 57
		},

		{
V
Venkatesh Raghavan 已提交
58
		EopttracePrintMemoAfterExploration,
59
		&optimizer_print_memo_after_exploration,
60
		false, // m_negate_param
61 62 63 64
		GPOS_WSZ_LIT("Prints MEMO after exploration.")
		},

		{
V
Venkatesh Raghavan 已提交
65
		EopttracePrintMemoAfterImplementation,
66
		&optimizer_print_memo_after_implementation,
67
		false, // m_negate_param
68 69 70 71
		GPOS_WSZ_LIT("Prints MEMO after implementation.")
		},

		{
V
Venkatesh Raghavan 已提交
72
		EopttracePrintMemoAfterOptimization,
73
		&optimizer_print_memo_after_optimization,
74
		false, // m_negate_param
75 76 77 78
		GPOS_WSZ_LIT("Prints MEMO after optimization.")
		},

		{
V
Venkatesh Raghavan 已提交
79
		EopttracePrintJobScheduler,
80
		&optimizer_print_job_scheduler,
81
		false, // m_negate_param
82 83 84 85
		GPOS_WSZ_LIT("Prints jobs in scheduler on each job completion.")
		},

		{
V
Venkatesh Raghavan 已提交
86
		EopttracePrintExpressionProperties,
87
		&optimizer_print_expression_properties,
88
		false, // m_negate_param
89 90 91 92
		GPOS_WSZ_LIT("Prints expression properties.")
		},

		{
V
Venkatesh Raghavan 已提交
93
		EopttracePrintGroupProperties,
94
		&optimizer_print_group_properties,
95
		false, // m_negate_param
96 97 98 99
		GPOS_WSZ_LIT("Prints group properties.")
		},

		{
V
Venkatesh Raghavan 已提交
100
		EopttracePrintOptimizationContext,
101
		&optimizer_print_optimization_context,
102
		false, // m_negate_param
103 104 105 106
		GPOS_WSZ_LIT("Prints optimization context.")
		},

		{
V
Venkatesh Raghavan 已提交
107
		EopttracePrintOptimizationStatistics,
108
		&optimizer_print_optimization_stats,
109
		false, // m_negate_param
110 111 112 113 114 115 116 117 118 119 120 121 122
		GPOS_WSZ_LIT("Prints optimization stats.")
		},

		{
		EopttraceMinidump,
		&optimizer_minidump,
		false, // m_fNegate
		GPOS_WSZ_LIT("Generate optimizer minidump.")
		},
             	
		{
		EopttraceDisableMotions,
		&optimizer_enable_motions,
123
		true, // m_negate_param
124 125 126 127 128 129
		GPOS_WSZ_LIT("Disable motion nodes in optimizer.")
		},

		{
		EopttraceDisableMotionBroadcast,
		&optimizer_enable_motion_broadcast,
130
		true, // m_negate_param
131 132 133 134 135 136
		GPOS_WSZ_LIT("Disable motion broadcast nodes in optimizer.")
		},

		{
		EopttraceDisableMotionGather,
		&optimizer_enable_motion_gather,
137
		true, // m_negate_param
138 139 140 141 142 143
		GPOS_WSZ_LIT("Disable motion gather nodes in optimizer.")
		},

		{
		EopttraceDisableMotionHashDistribute,
		&optimizer_enable_motion_redistribute,
144
		true, // m_negate_param
145 146 147 148 149 150
		GPOS_WSZ_LIT("Disable motion hash-distribute nodes in optimizer.")
		},

		{
		EopttraceDisableMotionRandom,
		&optimizer_enable_motion_redistribute,
151
		true, // m_negate_param
152 153 154 155 156 157
		GPOS_WSZ_LIT("Disable motion random nodes in optimizer.")
		},

		{
		EopttraceDisableMotionRountedDistribute,
		&optimizer_enable_motion_redistribute,
158
		true, // m_negate_param
159 160 161 162 163 164
		GPOS_WSZ_LIT("Disable motion routed-distribute nodes in optimizer.")
		},

		{
		EopttraceDisableSort,
		&optimizer_enable_sort,
165
		true, // m_negate_param
166 167 168 169 170 171
		GPOS_WSZ_LIT("Disable sort nodes in optimizer.")
		},

		{
		EopttraceDisableSpool,
		&optimizer_enable_materialize,
172
		true, // m_negate_param
173 174 175 176 177 178
		GPOS_WSZ_LIT("Disable spool nodes in optimizer.")
		},

		{
		EopttraceDisablePartPropagation,
		&optimizer_enable_partition_propagation,
179
		true, // m_negate_param
180 181 182 183 184 185
		GPOS_WSZ_LIT("Disable partition propagation nodes in optimizer.")
		},

		{
		EopttraceDisablePartSelection,
		&optimizer_enable_partition_selection,
186
		true, // m_negate_param
187 188 189 190 191 192
		GPOS_WSZ_LIT("Disable partition selection in optimizer.")
		},

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

197 198 199
		{
		EopttraceDonotDeriveStatsForAllGroups,
		&optimizer_enable_derive_stats_all_groups,
200
		true, // m_negate_param
201 202 203
		GPOS_WSZ_LIT("Disable deriving stats for all groups after exploration.")
		},

204 205 206
		{
		EopttraceEnableSpacePruning,
		&optimizer_enable_space_pruning,
207
		false, // m_negate_param
208 209 210 211
		GPOS_WSZ_LIT("Enable space pruning in optimizer.")
		},

		{
V
Venkatesh Raghavan 已提交
212 213
		EopttraceForceMultiStageAgg,
		&optimizer_force_multistage_agg,
214
		false, // m_negate_param
V
Venkatesh Raghavan 已提交
215
		GPOS_WSZ_LIT("Force optimizer to always pick multistage aggregates when such a plan alternative is generated.")
216 217 218
		},

		{
V
Venkatesh Raghavan 已提交
219 220
		EopttracePrintColsWithMissingStats,
		&optimizer_print_missing_stats,
221
		false, // m_negate_param
V
Venkatesh Raghavan 已提交
222
		GPOS_WSZ_LIT("Print columns with missing statistics.")
223 224 225 226 227
		},

		{
		EopttraceEnableRedistributeBroadcastHashJoin,
		&optimizer_enable_hashjoin_redistribute_broadcast_children,
228
		false, // m_negate_param
229 230 231 232 233 234
		GPOS_WSZ_LIT("Enable generating hash join plan where outer child is Redistribute and inner child is Broadcast.")
		},

		{
		EopttraceExtractDXLStats,
		&optimizer_extract_dxl_stats,
235
		false, // m_negate_param
236 237 238 239 240 241
		GPOS_WSZ_LIT("Extract plan stats in dxl.")
		},

		{
		EopttraceExtractDXLStatsAllNodes,
		&optimizer_extract_dxl_stats_all_nodes,
242
		false, // m_negate_param
243 244 245 246 247 248
		GPOS_WSZ_LIT("Extract plan stats for all physical dxl nodes.")
		},

		{
		EopttraceDeriveStatsForDPE,
		&optimizer_dpe_stats,
249
		false, // m_negate_param
250 251 252 253 254 255
		GPOS_WSZ_LIT("Enable stats derivation of partitioned tables with dynamic partition elimination.")
		},

		{
		EopttraceEnumeratePlans,
		&optimizer_enumerate_plans,
256
		false, // m_negate_param
257 258 259 260 261 262
		GPOS_WSZ_LIT("Enable plan enumeration.")
		},

		{
		EopttraceSamplePlans,
		&optimizer_sample_plans,
263
		false, // m_negate_param
264 265 266 267 268 269
		GPOS_WSZ_LIT("Enable plan sampling.")
		},

		{
		EopttraceEnableCTEInlining,
		&optimizer_cte_inlining,
270
		false, // m_negate_param
271 272 273 274 275 276
		GPOS_WSZ_LIT("Enable CTE inlining.")
		},

		{
		EopttraceEnableConstantExpressionEvaluation,
		&optimizer_enable_constant_expression_evaluation,
277
		false,  // m_negate_param
278 279 280 281 282 283
		GPOS_WSZ_LIT("Enable constant expression evaluation in the optimizer")
		},

		{
		EopttraceUseExternalConstantExpressionEvaluationForInts,
		&optimizer_use_external_constant_expression_evaluation_for_ints,
284
		false,  // m_negate_param
285 286 287 288 289 290
		GPOS_WSZ_LIT("Enable constant expression evaluation for integers in the optimizer")
		},

		{
		EopttraceApplyLeftOuter2InnerUnionAllLeftAntiSemiJoinDisregardingStats,
		&optimizer_apply_left_outer_to_union_all_disregarding_stats,
291
		false,  // m_negate_param
292 293 294 295 296 297
		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,
298
		false,  // m_negate_param
299 300 301 302 303 304
		GPOS_WSZ_LIT("Remove OrderBy below a DML operation")
		},

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

309 310 311 312 313 314 315
		{
		EopttraceMotionHazardHandling,
		&optimizer_enable_streaming_material,
		false,  // m_fNegate
		GPOS_WSZ_LIT("Enable motion hazard handling during NLJ optimization and generate streaming material when appropriate")
		},

316 317 318 319 320 321 322
		{
		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")
		},

323 324 325
		{
		EopttraceEnforceCorrelatedExecution,
		&optimizer_enforce_subplans,
326
		false,  // m_negate_param
327 328 329 330
		GPOS_WSZ_LIT("Enforce correlated execution in the optimizer")
		},

		{
V
Venkatesh Raghavan 已提交
331 332
		EopttraceForceExpandedMDQAs,
		&optimizer_force_expanded_distinct_aggs,
333
		false,  // m_negate_param
V
Venkatesh Raghavan 已提交
334
		GPOS_WSZ_LIT("Always pick plans that expand multiple distinct aggregates into join of single distinct aggregate in the optimizer")
335 336 337 338 339
		},

		{
		EopttraceDisablePushingCTEConsumerReqsToCTEProducer,
		&optimizer_push_requirements_from_consumer_to_producer,
340
		true,  // m_negate_param
341 342 343 344 345 346
		GPOS_WSZ_LIT("Optimize CTE producer plan on requirements enforced on top of CTE consumer")
		},

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

		{
V
Venkatesh Raghavan 已提交
352 353
		EopttraceForceThreeStageScalarDQA,
		&optimizer_force_three_stage_scalar_dqa,
354
		false, // m_negate_param
V
Venkatesh Raghavan 已提交
355
		GPOS_WSZ_LIT("Force optimizer to always pick 3 stage aggregate plan for scalar distinct qualified aggregate.")
356
		},
357

358 359 360
		{
		EopttraceEnableParallelAppend,
		&optimizer_parallel_union,
361
		false, // m_negate_param
362
		GPOS_WSZ_LIT("Enable parallel execution for UNION/UNION ALL queries.")
363 364 365
		},

		{
366 367
		EopttraceArrayConstraints,
		&optimizer_array_constraints,
368
		false, // m_negate_param
369
		GPOS_WSZ_LIT("Allows the constraint framework to derive array constraints in the optimizer.")
370 371 372 373 374 375 376
		},

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

//---------------------------------------------------------------------------
//	@function:
382
//		CConfigParamMapping::PackConfigParamInBitset
383 384 385 386 387 388
//
//	@doc:
//		Pack the GPDB config params into a bitset
//
//---------------------------------------------------------------------------
CBitSet *
389
CConfigParamMapping::PackConfigParamInBitset
390
	(
391 392
	IMemoryPool *mp,
	ULONG xform_id // number of available xforms
393 394
	)
{
395
	CBitSet *traceflag_bitset = GPOS_NEW(mp) CBitSet(mp, EopttraceSentinel);
396

397
	for (ULONG ul = 0; ul < GPOS_ARRAY_SIZE(m_elements); ul++)
398
	{
399 400
		SConfigMappingElem elem = m_elements[ul];
		GPOS_ASSERT(!traceflag_bitset->Get((ULONG) elem.m_trace_flag) &&
401 402
					"trace flag already set");

403 404
		BOOL value = *elem.m_is_param;
		if (elem.m_negate_param)
405 406
		{
			// negate the value of config param
407
			value = !value;
408 409
		}

410
		if (value)
411 412
		{
#ifdef GPOS_DEBUG
413
			BOOL is_traceflag_set =
414
#endif // GPOS_DEBUG
415 416
				traceflag_bitset->ExchangeSet((ULONG) elem.m_trace_flag);
			GPOS_ASSERT(!is_traceflag_set);
417 418 419 420
		}
	}

	// pack disable flags of xforms
421
	for (ULONG ul = 0; ul < xform_id; ul++)
422
	{
423
		GPOS_ASSERT(!traceflag_bitset->Get(EopttraceDisableXformBase + ul) &&
424 425 426 427 428
					"xform trace flag already set");

		if (optimizer_xforms[ul])
		{
#ifdef GPOS_DEBUG
429
			BOOL is_traceflag_set =
430
#endif // GPOS_DEBUG
431 432
				traceflag_bitset->ExchangeSet(EopttraceDisableXformBase + ul);
			GPOS_ASSERT(!is_traceflag_set);
433 434 435 436 437 438
		}
	}

	// disable index-join if the corresponding GUC is turned off
	if (!optimizer_enable_indexjoin)
	{
439 440 441
		CBitSet *index_join_bitset = CXform::PbsIndexJoinXforms(mp);
		traceflag_bitset->Union(index_join_bitset);
		index_join_bitset->Release();
442 443 444 445 446
	}

	// disable bitmap scan if the corresponding GUC is turned off
	if (!optimizer_enable_bitmapscan)
	{
447 448 449
		CBitSet *bitmap_index_bitset = CXform::PbsBitmapIndexXforms(mp);
		traceflag_bitset->Union(bitmap_index_bitset);
		bitmap_index_bitset->Release();
450 451 452 453 454
	}

	// disable outerjoin to unionall transformation if GUC is turned off
	if (!optimizer_enable_outerjoin_to_unionall_rewrite)
	{
455
		 traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfLeftOuter2InnerUnionAllLeftAntiSemiJoin));
456 457 458 459 460
	}

	// disable Assert MaxOneRow plans if GUC is turned off
	if (!optimizer_enable_assert_maxonerow)
	{
461
		 traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfMaxOneRow2Assert));
462 463
	}

464 465
	if (!optimizer_enable_partial_index)
	{
466 467 468
		CBitSet *heterogeneous_index_bitset = CXform::PbsHeterogeneousIndexXforms(mp);
		traceflag_bitset->Union(heterogeneous_index_bitset);
		heterogeneous_index_bitset->Release();
469
	}
470

471 472 473
	if (!optimizer_enable_hashjoin)
	{
		// disable hash-join if the corresponding GUC is turned off
474 475 476
		CBitSet *hash_join_bitste = CXform::PbsHashJoinXforms(mp);
		traceflag_bitset->Union(hash_join_bitste);
		hash_join_bitste->Release();
477 478 479 480 481
	}

	if (!optimizer_enable_dynamictablescan)
	{
		// disable dynamic table scan if the corresponding GUC is turned off
482
		traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfDynamicGet2DynamicTableScan));
483 484
	}

485 486 487
	if (!optimizer_enable_tablescan)
	{
		// disable table scan if the corresponding GUC is turned off
488
		traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfGet2TableScan));
489 490
	}

491 492 493
	if (!optimizer_enable_indexscan)
	{
		// disable index scan if the corresponding GUC is turned off
494
		traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfIndexGet2IndexScan));
495 496
	}

497
	CBitSet *join_heuristic_bitset = NULL;
498 499 500
	switch (optimizer_join_order)
	{
		case JOIN_ORDER_IN_QUERY:
501
			join_heuristic_bitset = CXform::PbsJoinOrderInQueryXforms(mp);
502 503
			break;
		case JOIN_ORDER_GREEDY_SEARCH:
504
			join_heuristic_bitset = CXform::PbsJoinOrderOnGreedyXforms(mp);
505 506
			break;
		case JOIN_ORDER_EXHAUSTIVE_SEARCH:
507
			join_heuristic_bitset = CXform::PbsJoinOrderOnExhaustiveXforms(mp);
508 509 510 511 512 513
			break;
		default:
			elog(ERROR, "Invalid value for optimizer_join_order, must \
				 not come here");
			break;
	}
514 515
	traceflag_bitset->Union(join_heuristic_bitset);
	join_heuristic_bitset->Release();
516

517 518 519 520
	// disable join associativity transform if the corresponding GUC
	// is turned off independent of the join order algorithm chosen
	if (!optimizer_enable_associativity)
	{
521
		traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfJoinAssociativity));
522 523
	}

524 525 526 527 528
	if (!optimizer_enable_full_join)
	{
		traceflag_bitset->ExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfExpandFullOuterJoin));
	}

529
	return traceflag_bitset;
530 531 532
}

// EOF