max_parallel_workers must be greater than 0, and max_parallel_degree must be valid or a PARALLEL Hint must be present; otherwise, the process exits immediately.parallel_plan_cost_threshold. This check is skipped when force=on in parallel_query_switch or when a PARALLEL Hint is present.parallel_scan_records_threshold). In a sharded system, an additional hashed (hash distribution) path is generated.parallel_plan_compare_serial_cost parameter controls whether the serial path participates in the comparison.SELECT * FROM t1 WHERE a > 0:SELECT * FROM t1 JOIN t2:WHERE id BETWEEN X AND Y, the optimizer can further prune irrelevant shards.max_parallel_degree.WHERE partition_key = XSELECT /*+ PARALLEL(PARTITION) */ or SELECT /*+ PARALLEL(DYNAMIC_RANGE) */Mode | Applicable Scenarios | Description |
Normal Gather | Order not required | Simply collects results from each Worker row by row and passes them to the upper-level operator. |
Merge Sort | ORDER BY output required | Performs merge sorting on the sorted results from each Worker during collection. The Worker side performs partial sorting, and the Leader side performs the merge. |
full_grouping_pushdown option in parallel_query_switch has been enabled (enabled by default).SELECT * FROM t1 WHERE t1.dept_id IN (SELECT id FROM departments WHERE region = 'ASIA');
SELECT id FROM departments WHERE region = 'ASIA' is first executed in parallel, and its result is shared with the Workers scanning table t1.subquery_pushdown option must be enabled (enabled by default).PQ_INLINE_EVALUATION Hint.tdsql> EXPLAIN SELECT DISTINCT (COUNT(b) + 1) AS c FROM t1 GROUP BY a;+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+--------------------------------------------+| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+--------------------------------------------+| 1 | SIMPLE | t1 | NULL | ALL | PRIMARY | NULL | NULL | NULL | 43 | 100.00 | Parallel scan (4 workers); Using temporary |+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+--------------------------------------------+tdsql> SHOW WARNINGS;+-------+------+--------------------------------------------------------------------------------------------------+| Level | Code | Message |+-------+------+--------------------------------------------------------------------------------------------------+| Note | 1003 | /* select#1 */ select distinct (count(`b`) + 1) AS `c` from `test`.`t1` group by `test`.`t1`.`a` || Note | 1003 | Query is executed in a parallel plan; explain with tree format to see the plan details. |+-------+------+--------------------------------------------------------------------------------------------------+
Parallel scan (N workers), it indicates that parallel execution is active. Concurrently, a WARNING message appears: "Query is executed in a parallel plan; explain with tree format to see the plan details." It is recommended to use the tree format to view the complete parallel plan.tdsql> EXPLAIN FORMAT=TREE-> SELECT-> t2.a,-> (SELECT SUM(t1.a) FROM t1) as total_sum,-> (SELECT COUNT(t1.a) FROM t1) as total_count-> FROM t2-> ORDER BY t2.a;+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| EXPLAIN |+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| -> Gather (slice: 1, workers: 4) (cost=2310.16..2312.04 rows=5)Merge sort: t2.a-> Sort: t2.a (cost=5.54..5.54 rows=1)-> Table scan on t2, with range parallel scan (cost=2.78..3.48 rows=1)-> Select #2 (subquery in projection; run only once)-> Aggregate: sum(t1.a) (cost=2309.05..2309.05 rows=1)-> Gather (slice: 1, workers: 4) (cost=2308.65..2308.65 rows=1)-> Aggregate: sum(t1.a) (cost=4.14..4.14 rows=1)-> Table scan on t1, with range parallel scan (cost=2.60..3.25 rows=1)-> Select #3 (subquery in projection; run only once)-> Aggregate: count(t1.a) (cost=2306.05..2306.05 rows=1)-> Gather (slice: 1, workers: 4) (cost=2304.43..2305.27 rows=4)-> Count rows in t1 (cost=0.83..0.83 rows=1)Table scan on t1, with pushed projection, with range parallel scan|+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Node | Description |
Gather (slice: 1, workers: 4) | Four workers execute Slice 1 in parallel, and the Leader collects the results. |
with range parallel scan or with partition parallel scan | Scans table data using the Dynamic Range Scan/Partition Scan method. |
Merge sort: col_name | Performs merge sorting during collection by Gather to ensure the output is ordered by col_name. |
Merge sort with duplicate removal: col | Performs merge sorting and duplicate removal during collection by Gather. |
Pre-evaluated subqueries: select #N | Pre-executed subqueries in parallel (subquery results are ready). |
tdsql> explain analyze verbose select * from t1, t2 where t1.a = t2.a;+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| EXPLAIN |+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| -> Inner hash join (t2.a = t1.a) (cost=6.28 rows=3) (actual time=0.511..0.533 rows=3 loops=1)Chunk pair files: 0, memory usage: 16kB-> Table scan on t2 (cost=0.88 rows=3) (actual time=0.167..0.185 rows=3 loops=1)-> Hash-> Table scan on t1 (cost=2.84 rows=3) (actual time=0.262..0.283 rows=3 loops=1)RPC statistics: leader-> LocalScanRecord=latency(ms): 2,0.266323,0.081208...0.185115, retry_count: 0, retry_interval_all(ms): 0.000000, failure_count: 0 |+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
EXPLAIN ANALYZE VERBOSE is suitable for scenarios that require further analysis of RPC overhead, memory usage, and operator execution details.SET optimizer_trace_features = 'parallel_plan_optimization=on';SET optimizer_trace = 'enabled=on';EXPLAIN SELECT * FROM t1 WHERE a > 4;SELECT * FROM information_schema.optimizer_trace \\G
considering.chosen: true/false — indicates whether parallel execution is selected.considering.optimization.enumerating_paths — indicates which parallel paths the optimizer evaluated.cause (when PQ is not selected) — specific reasons, such as plan_cost_less_than_threshold and disabled_by_limitVariable Name | Level | Default Value | Description |
max_parallel_degree | Session | 4 | Maximum number of workers for a single query. Set to 0 to disable parallelism. |
max_parallel_workers | Global | 10000 | Maximum total number of workers for the entire node. Set to 0 to disable parallelism globally. |
Variable Name | Level | Default Value | Description |
parallel_plan_cost_threshold | Session | 50000 | Consider generating a parallel plan only when the serial execution cost exceeds this threshold. |
parallel_scan_records_threshold | Session | 10000 | Consider a table as a candidate for parallel scanning only when the number of scanned rows exceeds this threshold. |
parallel_scan_ranges_threshold | Session | 2 | Use a parallel plan only when the number of splittable scan ranges exceeds this threshold. |
Variable Name | Level | Default Value | Description |
parallel_query_switch | Session | For details, see Description. | The switch for the PQ feature, in bitmask format, supporting the simultaneous setting of multiple options. |
parallel_query_switch Option Description:Option | Default Value | Description |
force | off | Forces the use of parallel plans, skipping all cost and row quantity threshold checks. |
subquery_pushdown | on | Supports pushing down correlated subqueries as a whole to workers for parallel execution. |
full_grouping_pushdown | on | When GROUP BY keys are non-duplicate across Workers, the aggregation is fully pushed down to Workers. |
group_min_max_pushdown, partition_group_min_max_pushdown, dynamic_range_parallel_scan, and partition_parallel_scan, are also enabled by default.parallel_query_switch is a developer option used for debugging. The content of the switch (including additions or deletions) may be adjusted with each release. Do not use it in management tools or formal maintenance scripts.-- View the current switch value.SHOW VARIABLES LIKE 'parallel_query_switch';-- Force parallel execution (bypassing all threshold checks).SET parallel_query_switch = 'force=on';-- Disable subquery pushdown (queries containing correlated subqueries will not be executed in parallel).SET parallel_query_switch = 'subquery_pushdown=off';
Limit | Description |
Dynamic Range Scan | Can only be executed on the Leader. |
Index Merge Scan | Does not support parallel scanning. |
Rollup | Exclude |
Correlated Subquery in SELECT List | Not supported (for example, when the SELECT list references columns from the outer query). |
Non-Parallel Safe Expressions | Non-parallel-safe expressions, such as user variables @a:=1, are not supported for parallel execution. |
parallel_query_switch='force=on' to bypass all checks):max_parallel_degree > 0parallel_plan_cost_threshold.max_parallel_degree is 0.plan_cost_less_than_threshold → Decrease parallel_plan_cost_threshold.SET parallel_query_switch='force=on' to force parallel execution.max_parallel_degree.CALL dbms_admin.statement_outline_add_rule('rule_name','SELECT /*+ PARALLEL(4) */ SUM(c), b FROM t1 GROUP BY b');
PARALLEL(PARTITION) to scan by partition.PARALLEL(DYNAMIC_RANGE) to scan by range.Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários