Updated on 2023-10-23 GMT+08:00

Stream Operation Hints

Function

These hints specify a stream operation, which can be broadcast or redistribute. You can also directly specify a method to generate a gather plan.

Syntax

1
2
[no] broadcast|redistribute(table_list)
gather(REL|JOIN|ALL)

Parameter Description

  • broadcast and redistribute
    • no specifies that the specified hint will not be used for a stream operation.
    • table_list specifies the table on which a stream operation is to be performed or the tables to be joined. For details, see Parameter Description.
  • gather
    The gather hint can specify the following plan generation modes:
    • REL: Only the gather path based on the base table is generated, and then the remaining plan is executed on the CN.
    • JOIN: A join-based gather path is generated as much as possible and is added to the join subplan that can be pushed down (the join subplan does not contain the redistribution node), and the remaining plan is executed on the CN. For a join plan that requires node redistribution, such a join-based gather path cannot be generated. Instead, a base table-based gather path is generated.

      After Hint(JOIN) is specified, the plan expected by Hint(JOIN) cannot be generated if the distribution table and replication table are joined, because the optimizer has found a better plan for replacement.

    • ALL: The Gather Rel or Gather Join path is selected based on the optimal mode.

Example

Hint the query plan in Example as follows:

1
2
explain
select /*+ no redistribute(store_sales store_returns item store) leading(((store_sales store_returns item store) customer)) */ i_product_name product_name ...

In the original plan, the join result of store_sales, store_returns, item, and store is redistributed before it is joined with customer. After the hinting, the redistribution is disabled and the join order is retained. The optimized plan is as follows:

Specify the gather hint for a statement.

  1. Generate the gather plan /* + GATHER(REL)*/ based on the base table.
    openGauss=# explain select /*+ GATHER(REL)*/* from t1, t2, t3 where t1.c2 = t2.c2 and t2.c2 = t3.c2;
    QUERY PLAN
    -------------------------------------------------------------------------------
    Hash Join  (cost=3.29..5.08 rows=10 width=24)
    Hash Cond: (t1.c2 = t3.c2)
    ->  Hash Join  (cost=1.64..3.30 rows=10 width=16)
    Hash Cond: (t1.c2 = t2.c2)
    ->  Streaming (type: GATHER)  (cost=0.31..1.52 rows=10 width=8)
    Node/s: All datanodes
    ->  Seq Scan on t1  (cost=0.00..1.05 rows=10 width=8)
    ->  Hash  (cost=1.52..1.52 rows=10 width=8)
    ->  Streaming (type: GATHER)  (cost=0.31..1.52 rows=10 width=8)
    Node/s: All datanodes
    ->  Seq Scan on t2  (cost=0.00..1.05 rows=10 width=8)
    ->  Hash  (cost=1.52..1.52 rows=10 width=8)
    ->  Streaming (type: GATHER)  (cost=0.31..1.52 rows=10 width=8)
    Node/s: All datanodes
    ->  Seq Scan on t3  (cost=0.00..1.05 rows=10 width=8)
    (15 rows)
  2. Generate the join gather plan /*+ GATHER(REL)*/ that can be pushed down.
    openGauss=# explain select /*+ GATHER(JOIN)*/* from t1, t2, t3 where t1.c1 = t2.c1 and t2.c2 = t3.c2;
    QUERY PLAN
    ---------------------------------------------------------------------------
    Hash Join  (cost=2.76..4.48 rows=10 width=24)
    Hash Cond: (t2.c2 = t3.c2)
    ->  Streaming (type: GATHER)  (cost=1.43..2.70 rows=10 width=16)
    Node/s: All datanodes
    ->  Hash Join  (cost=1.11..2.23 rows=10 width=16)
    Hash Cond: (t1.c1 = t2.c1)
    ->  Seq Scan on t1  (cost=0.00..1.05 rows=10 width=8)
    ->  Hash  (cost=1.05..1.05 rows=10 width=8)
    ->  Seq Scan on t2  (cost=0.00..1.05 rows=10 width=8)
    ->  Hash  (cost=1.52..1.52 rows=10 width=8)
    ->  Streaming (type: GATHER)  (cost=0.31..1.52 rows=10 width=8)
    Node/s: All datanodes
    ->  Seq Scan on t3  (cost=0.00..1.05 rows=10 width=8)
    (13 rows)
  3. Generate the gather plan /*+ GATHER(ALL)*/ based on the optimal mode.
    The GATHER(REL) or GATHER(JOIN) path is selected based on the optimal mode and rules.
    openGauss=# explain select /*+ GATHER(ALL)*/* from t1, t2, t3 where t1.c1 = t2.c1 and t2.c2 = t3.c2;
    QUERY PLAN
    ---------------------------------------------------------------------------
    Hash Join  (cost=2.76..4.48 rows=10 width=24)
    Hash Cond: (t2.c2 = t3.c2)
    ->  Streaming (type: GATHER)  (cost=1.43..2.70 rows=10 width=16)
    Node/s: All datanodes
    ->  Hash Join  (cost=1.11..2.23 rows=10 width=16)
    Hash Cond: (t1.c1 = t2.c1)
    ->  Seq Scan on t1  (cost=0.00..1.05 rows=10 width=8)
    ->  Hash  (cost=1.05..1.05 rows=10 width=8)
    ->  Seq Scan on t2  (cost=0.00..1.05 rows=10 width=8)
    ->  Hash  (cost=1.52..1.52 rows=10 width=8)
    ->  Streaming (type: GATHER)  (cost=0.31..1.52 rows=10 width=8)
    Node/s: All datanodes
    ->  Seq Scan on t3  (cost=0.00..1.05 rows=10 width=8)
    (13 rows)