gpt4 book ai didi

sql - 如何从oracle表中的多个分区中选择数据

转载 作者:行者123 更新时间:2023-12-05 09:15:26 26 4
gpt4 key购买 nike

我正在尝试从分区表中的多个分区中选择数据。它适用于单个分区(select * from table partitions(ParititonName),但不能选择多个分区(select * from table partitions(Part1,part2) .您能否告诉我如何在单个查询中选择多个分区。

最佳答案

如果您需要在查询中明确地处理分区名称 - 这不是典型的用例(因为您经常使用 WHERE 谓词进行分区修剪) - 但可能是 哈希分区,你可以使用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 |
----------------------------------------------------------------------------------------------------

关于sql - 如何从oracle表中的多个分区中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52474515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com