Select from several partitions at once

夙愿已清 提交于 2019-12-01 00:28:48

You almost never want to use the PARTITION clause when querying a partitioned table. You almost always want to specify a predicate that allows Oracle to do partition pruning on its own.

SELECT t.column1, t.column2
  FROM first_table t
 WHERE t.partitioned_date_column >= <<date that delimits fast partitions>>
   AND t.column3 = 'someVal'

When you specify a predicate on the date column that the table is partitioned on, Oracle can automatically determine which partition(s) need to be accessed.

you can get deadlock if you are trying to execute three queries in parallel on your own, for example running at the same time:

insert into t2 select from t1 partition ("P1");

and then in another shell/window/job:

insert into t2 select from t1 partition ("P2")

If you query

select *
from t1
where date_column_used_for_partition >= 3_dates_ago

Oracle will select only the three partitions that you need and you won't need to use UNION.

In this way you can put your INSERT INTO... SELECT statement in a single query and you don't need to worry about deadlock, the Oracle engine will know in which partition of the second table it has to insert the data and he will manage the inserts for you.

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