CConfigParamMapping.cpp 11.7 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
//---------------------------------------------------------------------------
//	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
CConfigParamMapping::SConfigMappingElem CConfigParamMapping::m_elem[] =
{
		{
		EopttracePrintQuery,
		&optimizer_print_query,
		false, // m_fNegate
		GPOS_WSZ_LIT("Prints the optimizer's input query expression tree.")
		},

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

		{
		EopttracePrintXform,
		&optimizer_print_xform,
		false, // m_fNegate
		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_fNegate
V
Venkatesh Raghavan 已提交
54
		GPOS_WSZ_LIT("Print input and output of xforms.")
55 56 57
		},

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

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

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

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

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

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

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

		{
V
Venkatesh Raghavan 已提交
107
		EopttracePrintOptimizationStatistics,
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
		&optimizer_print_optimization_stats,
		false, // m_fNegate
		GPOS_WSZ_LIT("Prints optimization stats.")
		},

		{
		EopttraceMinidump,
		&optimizer_minidump,
		false, // m_fNegate
		GPOS_WSZ_LIT("Generate optimizer minidump.")
		},
             	
		{
		EopttraceDisableMotions,
		&optimizer_enable_motions,
		true, // m_fNegate
		GPOS_WSZ_LIT("Disable motion nodes in optimizer.")
		},

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

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

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

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

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

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

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

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

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

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

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

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

		{
V
Venkatesh Raghavan 已提交
212 213
		EopttraceForceMultiStageAgg,
		&optimizer_force_multistage_agg,
214
		false, // m_fNegate
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_fNegate
V
Venkatesh Raghavan 已提交
222
		GPOS_WSZ_LIT("Print columns with missing statistics.")
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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
		},

		{
		EopttraceEnableRedistributeBroadcastHashJoin,
		&optimizer_enable_hashjoin_redistribute_broadcast_children,
		false, // m_fNegate
		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_fNegate
		GPOS_WSZ_LIT("Extract plan stats in dxl.")
		},

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

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

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

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

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

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

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

		{
		EopttraceApplyLeftOuter2InnerUnionAllLeftAntiSemiJoinDisregardingStats,
		&optimizer_apply_left_outer_to_union_all_disregarding_stats,
		false,  // m_fNegate
		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_fNegate
		GPOS_WSZ_LIT("Remove OrderBy below a DML operation")
		},

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

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

		{
V
Venkatesh Raghavan 已提交
317 318
		EopttraceForceExpandedMDQAs,
		&optimizer_force_expanded_distinct_aggs,
319
		false,  // m_fNegate
V
Venkatesh Raghavan 已提交
320
		GPOS_WSZ_LIT("Always pick plans that expand multiple distinct aggregates into join of single distinct aggregate in the optimizer")
321 322 323 324 325 326 327 328 329 330 331 332 333 334
		},

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

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

		{
V
Venkatesh Raghavan 已提交
338 339
		EopttraceForceThreeStageScalarDQA,
		&optimizer_force_three_stage_scalar_dqa,
340
		false, // m_fNegate
V
Venkatesh Raghavan 已提交
341
		GPOS_WSZ_LIT("Force optimizer to always pick 3 stage aggregate plan for scalar distinct qualified aggregate.")
342
		},
343

344 345 346 347 348
		{
		EopttraceEnableParallelAppend,
		&optimizer_parallel_union,
		false, // m_fNegate
		GPOS_WSZ_LIT("Enable parallel execution for UNION/UNION ALL queries.")
349 350 351
		},

		{
352 353
		EopttraceArrayConstraints,
		&optimizer_array_constraints,
354 355
		false, // m_fNegate
		GPOS_WSZ_LIT("Allows the constraint framework to derive array constraints in the optimizer.")
356
		}
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
};

//---------------------------------------------------------------------------
//	@function:
//		CConfigParamMapping::PbsPack
//
//	@doc:
//		Pack the GPDB config params into a bitset
//
//---------------------------------------------------------------------------
CBitSet *
CConfigParamMapping::PbsPack
	(
	IMemoryPool *pmp,
	ULONG ulXforms // number of available xforms
	)
{
374
	CBitSet *pbs = GPOS_NEW(pmp) CBitSet(pmp, EopttraceSentinel);
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

	for (ULONG ul = 0; ul < GPOS_ARRAY_SIZE(m_elem); ul++)
	{
		SConfigMappingElem elem = m_elem[ul];
		GPOS_ASSERT(!pbs->FBit((ULONG) elem.m_etf) &&
					"trace flag already set");

		BOOL fVal = *elem.m_pfParam;
		if (elem.m_fNegate)
		{
			// negate the value of config param
			fVal = !fVal;
		}

		if (fVal)
		{
#ifdef GPOS_DEBUG
			BOOL fSet =
#endif // GPOS_DEBUG
				pbs->FExchangeSet((ULONG) elem.m_etf);
			GPOS_ASSERT(!fSet);
		}
	}

	// pack disable flags of xforms
	for (ULONG ul = 0; ul < ulXforms; ul++)
	{
		GPOS_ASSERT(!pbs->FBit(EopttraceDisableXformBase + ul) &&
					"xform trace flag already set");

		if (optimizer_xforms[ul])
		{
#ifdef GPOS_DEBUG
			BOOL fSet =
#endif // GPOS_DEBUG
				pbs->FExchangeSet(EopttraceDisableXformBase + ul);
			GPOS_ASSERT(!fSet);
		}
	}

	// disable index-join if the corresponding GUC is turned off
	if (!optimizer_enable_indexjoin)
	{
		CBitSet *pbsIndexJoin = CXform::PbsIndexJoinXforms(pmp);
		pbs->Union(pbsIndexJoin);
		pbsIndexJoin->Release();
	}

	// disable bitmap scan if the corresponding GUC is turned off
	if (!optimizer_enable_bitmapscan)
	{
		CBitSet *pbsBitmapScan = CXform::PbsBitmapIndexXforms(pmp);
		pbs->Union(pbsBitmapScan);
		pbsBitmapScan->Release();
	}

	// disable outerjoin to unionall transformation if GUC is turned off
	if (!optimizer_enable_outerjoin_to_unionall_rewrite)
	{
		 pbs->FExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfLeftOuter2InnerUnionAllLeftAntiSemiJoin));
	}

	// disable Assert MaxOneRow plans if GUC is turned off
	if (!optimizer_enable_assert_maxonerow)
	{
		 pbs->FExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfMaxOneRow2Assert));
	}

443 444 445 446 447 448
	if (!optimizer_enable_partial_index)
	{
		CBitSet *pbsHeterogeneousIndex = CXform::PbsHeterogeneousIndexXforms(pmp);
		pbs->Union(pbsHeterogeneousIndex);
		pbsHeterogeneousIndex->Release();
	}
449

450 451 452 453 454 455 456 457 458 459 460 461 462 463
	if (!optimizer_enable_hashjoin)
	{
		// disable hash-join if the corresponding GUC is turned off
		CBitSet *pbsHashJoin = CXform::PbsHashJoinXforms(pmp);
		pbs->Union(pbsHashJoin);
		pbsHashJoin->Release();
	}

	if (!optimizer_enable_dynamictablescan)
	{
		// disable dynamic table scan if the corresponding GUC is turned off
		pbs->FExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfDynamicGet2DynamicTableScan));
	}

464 465 466 467 468 469
	if (!optimizer_enable_tablescan)
	{
		// disable table scan if the corresponding GUC is turned off
		pbs->FExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfGet2TableScan));
	}

470 471 472 473 474 475
	if (!optimizer_enable_indexscan)
	{
		// disable index scan if the corresponding GUC is turned off
		pbs->FExchangeSet(GPOPT_DISABLE_XFORM_TF(CXform::ExfIndexGet2IndexScan));
	}

476 477 478 479
	return pbs;
}

// EOF