Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:36:25+00:00 2026-05-26T21:36:25+00:00

I have been learning about indexes in Oracle SQL, and I wanted to conduct

  • 0

I have been learning about indexes in Oracle SQL, and I wanted to conduct a small experiment with a test table to see how indexes really worked. As I discovered from an earlier post made here, the best way to do this is with EXPLAIN PLAN. However, I am running into something which confuses me.

My sample table contains attributes (EmpID, Fname, Lname, Occupation, …. etc). I populated it with 500,000 records using a java program I wrote (random names, occupations, etc). Now, here are some sample queries with and without indexes:

NO INDEX:

SELECT Fname FROM EMPLOYEE WHERE Occupation = 'DOCTOR';

EXPLAIN PLAN says:

OPERATION                         OPTIMIZER COST
TABLE ACCESS(FULL) TEST.EMPLOYEE  ANALYZED  1169

Now I create index:

CREATE INDEX occupation_idx
    ON EMPLOYEE (Occupation);

WITH INDEX “occupation_idx”:

SELECT Fname FROM EMPLOYEE WHERE Occupation = 'DOCTOR';

EXPLAIN PLAN says:

OPERATION                         OPTIMIZER COST
TABLE ACCESS(FULL) TEST.EMPLOYEE  ANALYZED  1169

So… the cost is STILL the same, 1169? Now I try this:

WITH INDEX “occupation_idx”:

SELECT Occupation FROM EMPLOYEE WHERE Occupation = 'DOCTOR';

EXPLAIN PLAN says:

OPERATION                              OPTIMIZER COST
INDEX(RANGE SCAN) TEST.OCCUPATION_IDX  ANALYZED  67

So, it appears that the index only is utilized when that column is the only one I’m pulling values from. But I thought that the point of an index was to unlock the entire record using the indexed column as the key? The search above is a pretty pointless one… it searches for values which you already know. The only worthwhile query I can think of which ONLY involves an indexed column’s value (and not the rest of the record) would be an aggregate such as COUNT or something.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:36:25+00:00Added an answer on May 26, 2026 at 9:36 pm

    Even with your index, Oracle decided to do a full scan for the second query.

    Why did it do this? Oracle would have created two plans and come up with a cost for each:-

    1) Full scan

    2) Index access

    Oracle selected the plan with the lower cost. Obviously it came up with the full scan as the lower cost.

    If you want to see the cost of the index plan, you can do an explain plan with a hint like this to force the index usage:

    SELECT /*+ INDEX(EMPLOYEE occupation_idx) */ Fname
    FROM EMPLOYEE WHERE Occupation = 'DOCTOR';
    

    If you do an explain plan on the above, you will see that the cost is greater than the full scan cost. This is why Oracle did not choose to use the index.

    A simple way to consider the cost of the index plan is:-

    • The blevel of the index (how many blocks must be read from top to bottom)
    • The number of table blocks that must be subsequently read for records matching in the index. This relies on Oracle’s estimate of the number of employees that have an occupation of ‘DOCTOR’. In your simple example, this would be:

      number of rows / number of distinct values

    More complicated considerations include the clustering factory and index cost adjustments which both reflect the likelyhood that a block that is read is already in memory and hence does not need to read from disk.

    Perhaps you could update your question with the results from your query with the index hint and also the results of this query:-

    SELECT COUNT(*), COUNT(DISTINCT( Occupation ))
    FROM EMPLOYEE;
    

    This will allow people to comment on the cost of the index plan.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning about the basics of C# but haven't come across a
Recently I have been learning about WMI and WQL. I found out the list
I am currently learning about basic networking in java. I have been playing around
I've been learning wpf for about a week now.. and i have a basic
I have been learning about various functional languages for some time now including Haskell,
I have been learning about TDD (using JUnit) and I have a doubt about
I have recently been learning more about design patterns and thought I'd take a
I'm 14 and have been learning java for about 4/5 months. I'm coding a
As of last night, I decided to start learning about WPF and have been
I've been learning about CSS Sprites. I have been skeptical because cross-browser compatibility is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.