views:

2575

answers:

2

I have a few questions about optimizing this type of load.

One builds a new table of data to be loaded into a partitioned table and then builds the indexes on this new table.

  1. Should you build the index with the COMPUTE STATISTICS option or use the Cascade option of the DBMS_Stats?

  2. Should you gather stats on the table before the swap or on the partition after the swap?

  3. If you do it after the swap and you specify the partition name in the parameter list, what interplay does the granularity parameter have? For instance, if I specify a partition name and then set granularity to 'GLOBAL AND PARTITION' does that do Global at all? Does it do just that one partition?

A: 
  1. DBMS_STATS is considered the proper way to calculate statistics for this version. Building the index with the COMPUTE STATISTICS is doable, but usually you want to calculate all your stats at one time and take snapshots.

  2. You want to gather stats after the swap. This way the optimizer will make the best guess for executing queries using that partitions' data.

  3. Why would you put both?

Adam Hawkes
Why would you put both?Both Table and Partition stats? because they are used independently and both are necessary.
+1  A: 

Should you build the index with the COMPUTE STATISTICS option or use the Cascade option of the DBMS_Stats?

If this is a data warehouse then first consider not gathering statistics at all, and using dynamic sampling. Second, if you do gather statistics then by all means use compute statistics on the index.

Should you gather stats on the table before the swap or on the partition after the swap?

Gather statistics on the new-data table before the swap to get partition statistics on the new data -- gather statistics on the partitioned table afterwards to gather table statistics

If you do it after the swap and you specify the partition name in the parameter list, what interplay does the granularity parameter have? For instance, if I specify a partition name and then set granularity to 'GLOBAL AND PARTITION' does that do Global at all? Does it do just that one partition?

See above.

Seriously, give no statistics and dynamic sampling a chance.

David Aldridge
it's a reporting table. A complex query that's materialized once a day. Is that a DW? Probably not, maybe a little. That's a really good tip about dynamic sampling, I'll have to try it out. And the part about table and partition is kinda where is was leaning. Makes sense.