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 281751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:13:48+00:00 2026-05-12T05:13:48+00:00

I know just enough about SQL tuning to get myself in trouble. Today I

  • 0

I know just enough about SQL tuning to get myself in trouble. Today I was doing EXPLAIN plan on a query and I noticed it was not using indexes when I thought it probably should. Well, I kept doing EXPLAIN on simpler and simpler (and more indexable in my mind) queries, until I did EXPLAIN on

select count(*) from table_name

I thought for sure this would return instantly and that the explain would show use of an index, as we have many indexes on this table, including an index on the row_id column, which is unique. Yet the explain plan showed a FULL table scan, and it took several seconds to complete. (We have 3 million rows in this table).

Why would oracle be doing a full table scan to count the rows in this table? I would like to think that since oracle is indexing unique fields already, and having to track every insert and update on that table, that it would be caching the row count somewhere. Even if it’s not, wouldn’t it be faster to scan the entire index than to scan the entire table?

I have two theories. Theory one is that I am imagining how indexes work incorrectly. Theory two is that some setting or parameter somewhere in our oracle setup is messing with Oracle’s ability to optimize queries (we are on oracle 9i). Can anyone enlighten me?

  • 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-12T05:13:48+00:00Added an answer on May 12, 2026 at 5:13 am

    Oracle does not cache COUNT(*).

    MySQL with MyISAM does (can afford this), because MyISAM is transactionless and same COUNT(*) is visible by anyone.

    Oracle is transactional, and a row deleted in other transaction is still visible by your transaction.

    Oracle should scan it, see that it’s deleted, visit the UNDO, make sure it’s still in place from your transaction’s point of view, and add it to the count.

    Indexing a UNIQUE value differs from indexing a non-UNIQUE one only logically.

    In fact, you can create a UNIQUE constraint over a column with a non-unique index defined, and the index will be used to enforce the constraint.

    If a column is marked as non-NULL, the an INDEX FAST FULL SCAN over this column can be used for COUNT.

    It’s a special access method, used for cases when the index order is not important. It does not traverse the B-Tree, but instead just reads the pages sequentially.

    Since an index has less pages than the table itself, the COUNT can be faster with an INDEX_FFS than with a FULL

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

Sidebar

Related Questions

Hopefully this should be a fairly straightforward question, I just don't know enough about
Maybe I just don't know .NET well enough yet, but I have yet to
This just won't work. The problem is that I do not know enough to
I know that just using rand() is predictable, if you know what you're doing,
Me stupid. How can I know which assembly to reference if I just know
Google's not coming to my rescue, here, and I just know this is the
I just wanted to know your experience with using resharper. We have a very
I just wanted to know what's the difference between clear() and str(); For example:
Just wanted to know if it is possible to disallow the whole site for
Just want to know if there other optional wrapper framework available that generate client

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.