gpdb
gpdb copied to clipboard
[ORCA] Support join type hints
This work is a continuation of plan hints in commit https://github.com/greenplum-db/gpdb/commit/e781fe0db4e3cb24b38be0b8497fc2ebafdd2b7a.
This change allows the user to specify join type hints that coerce the optimizer to generate a plan that uses the specified join type.
Following hints are supported:
NestLoop
HashJoin
MergeJoin
NoNestLoop
NoHashJoin
NoMergeJoin
Example usage:
LOAD 'pg_hint_plan';
CREATE TABLE t(a int, b int);
CREATE INDEX i ON t(a);
/*+
NestLoop(t1 t2)
IndexScan(t1)
*/
EXPLAIN (costs off) SELECT * FROM t t1 JOIN t t2 ON t1.a=t2.a;
QUERY PLAN
------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
Join Filter: true
-> Seq Scan on t t2
-> Index Scan using i on t t1
Index Cond: (a = t2.a)
Optimizer: GPORCA
Above query would produce MDP format with JoinTypeHint entry:
<dxl:PlanHint>
<dxl:ScanHint Alias="t1" OperatorName="IndexScan"/>
<dxl:JoinTypeHint Alias="t1,t2" JoinType="NestedLoopJoin"/>
</dxl:PlanHint>
This feature is implemented by filtering out plan alternatives that do not satisfy the specified join type hint. The filtering is done during the implementation phase of optimization when xforms consider plans for physical operators based on hash, merge, or nest loop join.
Dev pipeline: https://dev.ci.gpdb.pivotal.io/teams/main/pipelines/gpdb-dev-orca-join-hints-type-rocky8