Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes

PARALLEL(num) -- Global level, the level of the Query BlockPARALLEL(@qbname num) -- the level of the Query BlockPARALLEL(tablename) -- the level of the TablePARALLEL(tablename num) -- the level of the TableNO_PARALLEL -- Global level, the level of the Query BlockNO_PARALLEL(@qbname) -- the level of the Query BlockNO_PARALLEL(tablename) -- Table level
-- Global levelEXPLAIN select /*+ PARALLEL(4) */ * from t1 where a > 4;-- Query block level, which takes effect only at the top-level query.EXPLAIN select /*+ QB_NAME(q1) PARALLEL(@q1 4) */ * from t1 where a > 4;-- Query block level, which takes effect only in subqueries.explain select * from t3 where a = (select /*+ PARALLEL(2) */ count(a) from t3);-- Table levelEXPLAIN select /*+ PARALLEL(t1 4) */ from t1 where a > 4;-- Table levelEXPLAIN select /*+ PARALLEL(t3@q2 4) */ * from t3 where a = (select /*+ QB_NAME(q2) */ count(a) from t3);-- Table levelEXPLAIN select /*+ PARALLEL(@q2 t3 4) */ * from t3 where a = (select /*+ QB_NAME(q2) */ count(a) from t3);

-- Basic syntaxPQ_DISTRIBUTE(tablespec strategy1 strategy2)PQ_DISTRIBUTE(tablespec strategy)-- For specific operation typesPQ_DISTRIBUTE(target strategy1 strategy2)
target: Operation target, which supports AGGREGATE, SORT, and WINDOW. It specifies the distribution policy for GROUP BY, ORDER BY, and WINDOW functions respectively. WINDOW can be followed by the name of the WINDOW.strategy1, strategy2: Redistribution policy, which supports NONE, GATHER, HASH, BROADCAST.PQ_DISTRIBUTE(t1 HASH, HASH), PQ_DISTRIBUTE(t1@qb1 HASH, HASH), or PQ_DISTRIBUTE(@qb1 t1 HASH HASH): Specifies that when a JOIN is performed between t1 and its preceding table, HASH redistribution is applied first, followed by JOIN operations on each node.PQ_DISTRIBUTE(t1 BROADCAST, NONE): Specifies that when a JOIN is performed between t1 and its preceding table, the preceding table (outer table) is broadcasted before being joined with t1.PQ_DISTRIBUTE(t1 GATHER): Specifies that table t1 is gathered first before being joined with other tables.-- Both tables undergo HASH redistribution before JOINSELECT /*+ PQ_DISTRIBUTE(t1 HASH, HASH) */ *FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id;-- Outer table broadcast, inner table not redistributedSELECT /*+ PQ_DISTRIBUTE(t1 BROADCAST, NONE) */ *FROM small_table t1 JOIN large_table t2 ON t1.id = t2.id;-- Perform JOIN after the table data is gathered to the LeaderSELECT /*+ PQ_DISTRIBUTE(t1 GATHER) */ *FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id;
PQ_DISTRIBUTE(AGGREGATE NONE): Fully pushes down the operation in a single phase.PQ_DISTRIBUTE(AGGREGATE NONE, GATHER): Two phases for Worker and Leader.PQ_DISTRIBUTE(AGGREGATE NONE HASH): Two-phase operation between Workers.PQ_DISTRIBUTE(AGGREGATE GATHER): Performed solely on the Leader in a single phase.-- Fully pushed down single-phase aggregationSELECT /*+ PQ_DISTRIBUTE(AGGREGATE NONE) */department, AVG(salary)FROM employeesGROUP BY department;-- Two-phase aggregation between Worker and LeaderSELECT /*+ PQ_DISTRIBUTE(AGGREGATE NONE, GATHER) */department, AVG(salary)FROM employeesGROUP BY department;-- Two-phase aggregation between WorkersSELECT /*+ PQ_DISTRIBUTE(AGGREGATE NONE HASH) */department, AVG(salary)FROM employeesGROUP BY department;-- Single-phase aggregation performed solely on the LeaderSELECT /*+ PQ_DISTRIBUTE(AGGREGATE GATHER) */department, AVG(salary)FROM employeesGROUP BY department;
PQ_DISTRIBUTE(SORT NONE, GATHER): Merge Sort performed by Worker + Leader.PQ_DISTRIBUTE(SORT GATHER): Sort is performed solely on the Leader.-- Partial sorting by Workers + Merge sort by the LeaderSELECT /*+ PQ_DISTRIBUTE(SORT NONE, GATHER) */ *FROM large_tableORDER BY create_time DESC;-- Global sorting performed solely on the LeaderSELECT /*+ PQ_DISTRIBUTE(SORT GATHER) */ *FROM large_tableORDER BY create_time DESC;
-- Compute global ranking on the Leader nodeSELECT /*+ PQ_DISTRIBUTE(WINDOW GATHER) */student_id,score,RANK() OVER (ORDER BY score DESC) as global_rankFROM exam_scores;-- Calculate the trend of grade changes for each student (data volume is small)SELECT /*+ PQ_DISTRIBUTE(WINDOW GATHER) */student_id,exam_date,score,LAG(score) OVER (PARTITION BY student_id ORDER BY exam_date) as prev_scoreFROM student_scores;
-- Rankings are computed in parallel by subject partition.SELECT /*+ PQ_DISTRIBUTE(WINDOW HASH) */subject,student_id,score,RANK() OVER (PARTITION BY subject ORDER BY score DESC) as subject_rankFROM exam_scores;-- Calculate the cumulative salary sum by department partition.SELECT /*+ PQ_DISTRIBUTE(WINDOW HASH) */department,employee_id,salary,SUM(salary) OVER (PARTITION BY department ORDER BY hire_date) as cumulative_salaryFROM employees;
-- Apply the GATHER policy to specifically named windows.SELECT /*+ PQ_DISTRIBUTE(WINDOW win1 GATHER) */student_id,subject,score,AVG(score) OVER win1 as avg_score,RANK() OVER (PARTITION BY subject ORDER BY score DESC) as rankFROM exam_scoresWINDOW win1 AS (PARTITION BY student_id);-- Different policies for multiple named windowsSELECT /*+ PQ_DISTRIBUTE(WINDOW win1 GATHER) PQ_DISTRIBUTE(WINDOW win2 HASH) */department,employee_id,salary,AVG(salary) OVER win1 as dept_avg,SUM(salary) OVER win2 as running_totalFROM employeesWINDOW win1 AS (PARTITION BY department),win2 AS (PARTITION BY department ORDER BY hire_date);
-- Use HASH distribution for specific windows.SELECT /*+ PQ_DISTRIBUTE(WINDOW win1 HASH) */product_category,product_id,sales_amount,SUM(sales_amount) OVER win1 as category_total,RANK() OVER (ORDER BY sales_amount DESC) as global_rankFROM sales_dataWINDOW win1 AS (PARTITION BY product_category);-- Mixed policy: one window GATHER, another window HASH.SELECT /*+ PQ_DISTRIBUTE(WINDOW win1 GATHER) PQ_DISTRIBUTE(WINDOW win2 HASH) */customer_id,order_date,amount,AVG(amount) OVER win1 as cust_avg, -- For small data volumes, use GATHER.SUM(amount) OVER win2 as running_sum -- For large data volumes, use HASH.FROM ordersWINDOW win1 AS (PARTITION BY customer_id),win2 AS (PARTITION BY customer_id ORDER BY order_date);
-- Specify that this IN subquery uses the MATERIALIZATION policy and does not employ the pre-evaluation policy in the parallel plan.EXPLAIN FORMAT=TREESELECT * FROM t1WHERE t1.a IN (SELECT /*+ SUBQUERY(MATERIALIZATION, PQ_INLINE_EVALUATION) */ aFROM t2);-- Specify that the Derived Table subquery t uses the pre-evaluation policy.EXPLAIN FORMAT=TREESELECT /*+ NO_MERGE(t) pq_distribute(t1 none) */ t1.aFROM t1, (SELECT /*+ subquery(pq_inline_evaluation) */ aFROM t2) tWHERE t1.a = t.a;
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan