Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Navinth.

Asked: August 17, 2017 - 4:33 pm UTC

Last updated: August 18, 2017 - 1:01 am UTC

Version: Oracle 12.2.0.1

Viewed 1000+ times

You Asked

Hello,

I have couple of things to be clarified related to extended statistics type Column Group Statistics.

When we alter some table column, I think it's always a good idea to drop the extended statistics before we proceed with the change.
We can find if we have such using USER_STAT_EXTENSIONS vew.

When it comes to deletion of this stats, we found some extended statistics which are not possible to be removed from DBMS_Stats.Drop_Extended_Stats method.
The ones which have the value Droppable=NO in user_stat_extensions view.

May I know what does it mean by Droppable=NO in this extended statistics view?

I also noticed that in most of this 'Droppable=NO' columns, extension name is prefixed with SYS_NC (while most of Droppable=YES are SYS_STS).
What do SYS_NC & SYS_STS actually mean?

Is it recommended to drop these 'Droppable=NO' column statistics somehow? or should we refrain from that?
In other words should we only drop extended statistics which are listed as Droppable=YES when it comes to scenarios like altering columns?

Thanks & Best Regards,
Navinth

and Connor said...

If the extension is needed to support some other function, then we can't drop it. Here's an example

SQL>
SQL> create table t ( x int, y int);

Table created.

SQL>
SQL> insert into t (x,y) select rownum, rownum from dual connect by level <=100;

100 rows created.

SQL>
SQL> exec dbms_stats.gather_table_stats('','T');

PL/SQL procedure successfully completed.

SQL>
SQL> select * from user_stat_extensions
  2  where table_name = 'T';

no rows selected


So we start with no extensions. Now we add one to handle the relationship between X and Y

SQL>
SQL>
SQL> select dbms_stats.create_extended_stats('','T','(x,y)') from dual;

DBMS_STATS.CREATE_EXTENDED_STATS('','T','(X,Y)')
----------------------------------------------------------------------------------------------------------------------------------
SYS_STUYPW88OE302TFVBNC6$MMQXE

1 row selected.

SQL>
SQL> exec dbms_stats.gather_table_stats('','T');

PL/SQL procedure successfully completed.

SQL>
SQL> select * from user_stat_extensions
  2  where table_name = 'T'
  3  @pr
==============================
TABLE_NAME                    : T
EXTENSION_NAME                : SYS_STUYPW88OE302TFVBNC6$MMQXE
EXTENSION                     : ("X","Y")
CREATOR                       : USER
DROPPABLE                     : YES

PL/SQL procedure successfully completed.


Now that extension is droppable, because (for lack of a better term) it is "standalone" in that it does not underpin any other function, and as well saw a few lines up, the table works just fine without it.

But now lets do this...

SQL>
SQL> alter table t add  z int generated always as (y+x);

Table altered.

SQL>
SQL> exec dbms_stats.gather_table_stats('','T');

PL/SQL procedure successfully completed.

SQL>
SQL> select * from user_stat_extensions
  2  where table_name = 'T'
  3  @pr
==============================
TABLE_NAME                    : T
EXTENSION_NAME                : SYS_STUYPW88OE302TFVBNC6$MMQXE
EXTENSION                     : ("X","Y")
CREATOR                       : USER
DROPPABLE                     : YES
==============================
TABLE_NAME                    : T
EXTENSION_NAME                : Z
EXTENSION                     : ("Y"+"X")
CREATOR                       : SYSTEM
DROPPABLE                     : NO

PL/SQL procedure successfully completed.


SQL>
SQL>


We added an extension to explicitly support statistics on the new virtual column we just added. We need that for virtual column functionality to work, and hence you're not allowed to drop it.

There's nothing new in this approach - it's like you can't drop an index used for a primary key. They are bound together.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Navinth Bakmeedeniya, September 02, 2017 - 8:48 am UTC

Thanks for the detailed explanation Connor..


More to Explore

Performance

Get all the information about database performance in the Database Performance guide.