Skip to Main Content
  • Questions
  • Data index inside compressed index for cardinality calculation?

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Marko.

Asked: April 11, 2018 - 9:47 am UTC

Last updated: April 13, 2018 - 1:10 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

I have been wondering why Oracle 11 does not follow explained plan for subquery execution with cost based optimiser.
It selects other index for execution which causes very slow performance 34M row table. Table got 900 000 rows in seven weeks.

Problem exists ofthen when query allways target newest rows by and should select date as first column (location as second). Later next times pretty soon it ends up select index with location as first column.
In queries there are 8 to 10 fields in where section with 3 to 5 predicates. There is few hundreds locations.

For up to now we have updated statistics to fix index selection.

I believe the problem being in new rows with no histograms and date as primary field.

I do not know how often statistics are updated in normal usage. Scheduled oracles own automation is not turned on.

And my question is:

Would same (date as first column) compressed index remove need update to histograms? Oracle could use data index inside compressed index for cardinality calculation, but will it do so?

To do this database would need to keep count of duplicate entries of data index inside compressed index to get exact cardinality very fast and without histograms.

If cardinality calculation is not currently affected as suggested this question, then this will come as suggestion of improment.

and Chris said...

Seven weeks to fetch 900k rows?! Seriously? I think you've got something more seriously wrong than the optimizer choosing the wrong index...

Anyway, compressing an index doesn't remove the need for histograms.

Histograms are to help the database identify an uneven distribution of values
Compression (may) decrease the size of an index by removing duplicated values

I'm not sure how storing counts of duplicated values in a compressed index would make histograms redundant.

The optimizer chooses a plan before accessing any objects in the query. This is based on stats. Such as histograms.

To use cardinality counts in an index, the database would (potentially) have to go to all the indexes on all the tables in the query. That's a lot of wasted effort. Especially if the net result is a full table scan is the best method!

Rating

  (1 rating)

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

Comments

Hmm

A reader, April 13, 2018 - 7:50 am UTC

I think he means that's the rate of data being added to the table ie it has gained 900k rows in 7 weeks
Chris Saxon
April 13, 2018 - 1:10 pm UTC

Perhaps...

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.