News for hackers. Stuff that matters.
Re:How to assert that your SQL does not do full table scans by ergo98 on Friday March 26, 2010 @10:42AM (#1221114)
>With only an index on one of the columns, Oracle at least will still use that index.

Not necessarily. Oracle, and every other decent database, will look at stats to guess how many hits will return, comparing that with the total row count of the target table, and will often choose not to use indexes.

Say you only have an index on QuestionId, and you have 10 questions with 100 answers each. If you did a select for QuestionId = 5 and ParticipantId = 100, and included in the results or the where clause a column not in the index (the index isn't covering, and participantid and text aren't in the index), the query engine will estimate that the index will return 100 rows give or take (often stats yield wrong results), and to perform and then dereference from 100 index lookups loses way more than it gains, so it will simply do a table scan.

Re:How to assert that your SQL does not do full table scans by Femur on Friday March 26, 2010 @11:15AM (#1221202)
Excellent demonstration of Oracle's inner workings!

The modern Oracle uses a Cost-Based approach wherein the query optimizer will attempt to perform the lowest-cost opration to satisfy the query. If that means performing a full-table scan as opposed to utilizing an index, then this is what will be done. Statistics, data histograms, parameters (such as OPTIMIZER_ INDEX_COST_ADJ) all come into play.