简体   繁体   English

在Oracle过程中交换分区后的Dbms_Stats.Gather_Table_Stats吗?

[英]Dbms_Stats.Gather_Table_Stats after partition exchange in Oracle procedure?

I have an oracle procedure that inserts all the rows from "table1 Partition (P1)" into table2. 我有一个oracle过程,它将“ table1分区(P1)”中的所有行插入到table2中。 I update a field in table2 and then swap the partition back to table1: 我更新了table2中的一个字段,然后将分区交换回table1:

Alter Table table1 Exchange Partition P1 WITH TABLE table2 Including Indexes Without Validation;

This works. 这可行。

Question: Do I need to gather table stats after? 问题:我需要在此之后收集表格统计信息吗? Code: 码:

EXECUTE  Dbms_Stats.Gather_Table_Stats (Ownname => 'MySchema', Tabname => 'Table1', Partname 
=> 'P1, Granularity =>  'ALL', Degree => 32);

Takes a long time to run and there are some other issues involved. 运行需要很长时间,并且还涉及其他一些问题。

thanks a lot, I've googled and can't find a definitive answer 非常感谢,我已经用谷歌搜索了,找不到确切的答案

  • Steve 史蒂夫

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production Oracle Database 11g企业版11.2.0.3.0版-64位生产

When you run exchange partition the statistics of the table will become the statistics of the partition and the statistics of the partition will become the statistics of the table, ie the statistics are exchanged too. 当您运行exchange partition时,表的统计信息将成为exchange partition的统计信息,而分区的统计信息将成为表的统计信息,即统计信息也将被交换。

Here I have a table with three partitions and originally all statistics are there: 在这里,我有一个包含三个分区的表,最初所有的统计信息都在这里:

0:admspm@spmdtz> printStats -p location -- (*)

Table_Name|object_Type   |subobject  |last_Analyzed|num_Rows|sample_Size|
-------------------------------------------------------------------------
LOCATION  |Table         |           |06.04. 15:23 |     817|        817|
LOCATION  |TablePartition|PARTITION_1|06.04. 15:23 |     272|        272|
LOCATION  |TablePartition|PARTITION_2|06.04. 15:23 |     272|        272|
LOCATION  |TablePartition|PARTITION_3|06.04. 15:23 |     273|        273|

Now a swap out a partition and swap it back in: 现在换出一个分区,然后换回来:

0:admspm@spmdtz> create table xxx as select * from location where par_id=3;
Table Xxx created.
0:admspm@spmdtz> alter table location exchange partition partition_3 
                 with table xxx;
Table Location altered.

and the statistics are gone: 并且统计信息消失了:

0:admspm@spmdtz> printStats -p location

Table_Name|object_Type   |subobject  |last_Analyzed|num_Rows|sample_Size|
-------------------------------------------------------------------------
LOCATION  |Table         |           |06.04. 15:23 |     817|        817|
LOCATION  |TablePartition|PARTITION_1|06.04. 15:23 |     272|        272|
LOCATION  |TablePartition|PARTITION_2|06.04. 15:23 |     272|        272|
LOCATION  |TablePartition|PARTITION_3|             |        |           |

However when I analyze the swap table 'XXX' 但是,当我分析交换表“ XXX”时

0:admspm@spmdtz> stats -gT xxx -- (*)

And swap back in, I get correct statistics again 换回去,我再次得到正确的统计数据

0:admspm@spmdtz> alter table location exchange partition partition_3 
                 with table xxx;
Table Location altered.
0:admspm@spmdtz> printStats -p location

Table_Name|object_Type   |subobject  |last_Analyzed|num_Rows|sample_Size|
-------------------------------------------------------------------------
LOCATION  |Table         |           |06.04. 15:23 |     817|        817|
LOCATION  |TablePartition|PARTITION_1|06.04. 15:23 |     272|        272|
LOCATION  |TablePartition|PARTITION_2|06.04. 15:23 |     272|        272|
LOCATION  |TablePartition|PARTITION_3|02.10. 18:24 |     273|        273|

(*) these commands are made available by the senora tool (*)这些命令由senora工具提供

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM