DBAtlas · 数据库运维图谱

验证分区键和 partition-wise join 的使用

Oracle分区

命令

-- 1) Do both tables have the same partitioning type, key and count?
SELECT p.owner, p.table_name, p.partitioning_type, k.column_name,
       p.partition_count, p.subpartitioning_type
FROM   dba_part_tables p
  JOIN dba_part_key_columns k
    ON k.owner = p.owner AND k.name = p.table_name AND k.object_type = 'TABLE'
WHERE  p.owner = 'CUSTOMER_APP'
  AND  p.table_name IN ('CUSTOMER_H', 'ORDERS_H');

-- 2) Explain the join and inspect the plan shape:
EXPLAIN PLAN FOR
SELECT /*+ PARALLEL(4) */ m.city, SUM(s.amount)
FROM   customer_app.customer_h m
  JOIN customer_app.orders_h s ON s.customer_id = m.id
GROUP  BY m.city;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY(format => 'BASIC +PARALLEL +PARTITION'));
-- Full PWJ: HASH JOIN sits BELOW the PARTITION HASH ALL line (PX PARTITION HASH ALL in parallel)
-- Partial PWJ: PX SEND PARTITION (KEY) on one side only
-- No PWJ: PX SEND HASH / BROADCAST on both sides

作用

两个按连接键等分区的表可以逐对分区进行连接(full partition-wise join),从而大幅减少并行查询中的重分发流量和内存。计划形态会显示是否使用了 PWJ。

适用场景

在 DWH 中设计大型事实表与事实表或事实表与维度表的连接、并行查询出现大量 PX 重分发(PX Deq Credit: send blkd),以及验证分区策略时。

注意

许可:Partitioning 选件(EE 额外付费);并行查询需要 Enterprise Edition。EXPLAIN PLAN 只是估算;请用 DISPLAY_CURSOR/SQL Monitor 查看实际计划。Full PWJ 需要相同的分区数(hash 分区建议为 2 的幂)以及一致的键数据类型。PWJ 也可能出现在串行计划中,但真正的收益在并行执行中。

在 DBAtlas 中打开 →

相关内容