How does one do a SQL select over multiple partitions?

痴心易碎 提交于 2019-12-13 11:40:27

问题


Is there a more efficient way than:

select * from transactions partition( partition1 ) 
union all 
select * from transactions partition( partition2 ) 
union all 
select * from transactions partition( partition3 ); 

回答1:


It should be exceptionally rare that you use the PARTITION( partitionN ) syntax in a query.

You would normally just want to specify values for the partition key and allow Oracle to perform partition elimination. If your table is partitioned daily based on TRANSACTION_DATE, for example

SELECT *
  FROM transactions
 WHERE transaction_date IN (date '2010-11-22', 
                            date '2010-11-23', 
                            date '2010-11-24')

would select all the data from today's partition, yesterday's partition, and the day before's partition.




回答2:


Can you provide additional context? What are your predicates? What makes you think that you need to explicitly tell the optimizer to go against multiple partitions. You may have the wrong partition key in use, for example.



来源:https://stackoverflow.com/questions/4268139/how-does-one-do-a-sql-select-over-multiple-partitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!