我们可以有一个 where 子句来从中删除吗?分区<部分>?部分>
我有一个基于时间戳分区的表(例如partition1
将有9个月前的数据,partition2
有6个月前的数据,partition3
有3个月的数据几个月前的数据等等)
我需要根据特定分区上的条件删除数据。
delete from table1 partition partition3
where group id in ( select * from table1 where group_code='pilot');
此操作是否仅从partiton3
中删除?
I have a table partitioned based on time stamp (like partition1
will have 9 months old data, partition2
have 6 months old data, partition3
have 3 months old data and so on)
I need to delete data based on a condition on a specific partition.
delete from table1 partition partition3
where group id in ( select * from table1 where group_code='pilot');
Is this operation will delete only from partiton3
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,语法是:
其次,您不应该引用分区名称。它创建了对表的物理布局的依赖。今天可能每月进行一次分区,但将来可能会在几周或几天内重新分区。当这种情况发生时,你的代码就会崩溃。 Oracle 可以根据分区列上的谓词很好地推断出分区。尝试忘记正在分区的表。
第三,由于
select *
与 ID 进行比较,您的子选择将失败。您正在寻找的声明可能如下所示:
First of all, the syntax is:
Secondly, you shouldn't refer to partition names. It creates a dependency on the physical layout of the table. It may be partitioned monthly today, but it may be repartitioned on weeks or days sometime in the future. When this happens, your code will break. Oracle can infer the partition just fine from a predicate on the partitioning column. Try to forget about the table being partitioned.
Third, your subselect will fail because of
select *
being compared to ID.The statement you are looking for likely looks something like this:
分区工作透明,这意味着您可以简单地执行常规操作。
优化器将知道第二个谓词意味着只有来自分区3的数据需要删除。
问候,
抢。
Partitioning works transparently, meaning that you can simply do a regular
The optimizer will know that the second predicate means that only data from partition3 needs deleting.
Regards,
Rob.