【发布时间】:2019-02-27 16:20:34
【问题描述】:
我正在尝试从分区表的多个分区中选择数据。它适用于单个分区(select * from table partition(ParititonName),但不能选择多个分区(select * from table partitions(Part1,part2).
请告诉我如何在单个查询中选择多个分区。
【问题讨论】:
-
您能提供一些示例数据并期待结果吗?
我正在尝试从分区表的多个分区中选择数据。它适用于单个分区(select * from table partition(ParititonName),但不能选择多个分区(select * from table partitions(Part1,part2).
请告诉我如何在单个查询中选择多个分区。
【问题讨论】:
您不必关心这些。 “分区”与“存储”有关,Oracle 关心它。您只需要运行您想要的任何查询,例如如果 EMP 表在 DEPTNO 列上分区(每个部门都转到自己的分区),你仍然会运行
select deptno, empno, ename, sal
from emp
where deptno in (10, 20);
您没有指定分区。
【讨论】:
如果您需要在查询中明确地处理分区名称 - 这不是典型的用例(因为您经常使用 WHERE 谓词进行 partition pruning) - 但可能是 @ 987654322@,您可以使用UNION ALL访问更多分区。
select * from TAB partition (Part1)
union all
select * from TAB partition (Part2);
execution plan 显示(请参阅 Pstart 和 Pstop 列)仅访问分区 1 和 2。
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 86 | 4 (0)| 00:00:01 | | |
| 1 | UNION-ALL | | | | | | | |
| 2 | PARTITION HASH SINGLE | | 1 | 43 | 2 (0)| 00:00:01 | 1 | 1 |
| 3 | TABLE ACCESS STORAGE FULL| TAB | 1 | 43 | 2 (0)| 00:00:01 | 1 | 1 |
| 4 | PARTITION HASH SINGLE | | 1 | 43 | 2 (0)| 00:00:01 | 2 | 2 |
| 5 | TABLE ACCESS STORAGE FULL| TAB | 1 | 43 | 2 (0)| 00:00:01 | 2 | 2 |
----------------------------------------------------------------------------------------------------
【讨论】: