Knowledge increases exponentially. Today, you probably own more books than great universities of times past—Cambridge University owned less than two hundred books in the fifteenth century. First came the invention of writing, then alphabets, then paper, then the printing press, then mechanization. Each step caused an exponential increase in the collective human knowledge. In our generation, Al Gore invented the internet and the last barriers to the spread of knowledge have been broken. Today, everybody has the ability to contribute, communicate, and collaborate. We are all caught up in a tsunami, an avalanche, a conflagration, a veritable explosion of knowledge for the betterment of humankind. This is the blog of the good folks at Database Specialists, a brave band of Oracle database administrators from the great state of California. We bid you greeting, traveler. We hope you find something of value on these pages and we wish you good fortune in your journey.

Always the low cost…

  may be the tagline for a major retailer, but it’s not always a reliable term in Oracle. A question at a panel session here at the Hotsos Symposium made me think of a situation with a client just last week.

 

Can you tell which of these execution plans is better?

 

SELECT STATEMENT Optimizer=ALL_ROWS (Cost=36111)

  HASH (GROUP BY) (Cost=36111 Card=679428 Bytes=48918816)

    HASH JOIN (OUTER) (Cost=24847 Card=679428 Bytes=48918816)

      INDEX (RANGE SCAN) OF “INDEX_1″ (Cost=5139 Card=559570 Bytes=31335920)

      INDEX (RANGE SCAN) OF “INDEX_2″ (Cost=10913 Card=1206767 Bytes=19308272)

 

SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6)

  HASH (GROUP BY) (Cost=6 Card=1 Bytes=72)

    NESTED LOOPS (OUTER) (Cost=5 Card=1 Bytes=72)

      INDEX (RANGE SCAN) OF “INDEX_1″ (Cost=3 Card=1 Bytes=56)

      INDEX (RANGE SCAN) OF “INDEX_2″ (Cost=2 Card=1 Bytes=16)

At first glance, most people would say “the second one, with a cost of 6″.  However, in actuality the second execution plan averaged an elapsed time of 5076 seconds, while the first, with the much higher “cost”, averaged 80 seconds.

The plan which performed poorly was derived based on statistics that the optimizer had, which apparently didn’t properly represent the data sought by the query.  So its “cost” is going to be inaccurate, just as the execution plan is not optimal.

 

 

 

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>