sql - Does an index on a unique field in a table allow a select count(*) to happen instantly? If not why not? -
I know that there is a lot of trouble about SQL tuning. Today I was planning an expansion on a query and I saw that it was not using the index, when I thought it should probably be. Okay, I am explaining the simple and simple (and more indexed in my mind) questions, as long as I select
count (*) from table_name
I'm sure it will return immediately and will show the use of the index, because there are many indexes in this table, in which the row_id column also includes an index, which is unique. Yet the explained plan showed a full table scan, and it took several seconds to complete. (We have 3 million rows in this table).
Why would a full table scan to count rows in this table? I would like to think that since Oracle is already indexing a unique field, and to track every combination and updates in that table, it will caching the line number somewhere. Even if it is not, will not it be faster to scan the whole index than scanning the whole table?
I have two principles that the principle one is that I imagine how indexes work wrongly, the theory is that somewhere in our Oracle setup some settings or parameters to optimize the query of Oracle (We are on Oracle 9i) Can anyone illuminate me?
oracle
does not cache COUNT (*)
.
MySQL
(can handle it), because MyISAM
is no transaction and that's the same < Code> COUNT (*) is visible by anyone.
Oracle
is the transaction, and the line deleted in other transactions is still visible by your transaction. / P>
Oracle
should scan it, see if it has been removed, go to UNDO
, make sure that it is still the approach of your transaction
Actually, any UNIQUE
is different from the UNIQUE
value indexing by being indexed in a logical manner.
In fact, you can create a UNIQUE
on a column with a non-unique index defined, and will be used to force the index.
If a column is used for non- NULL
, a INDEX FAST FULL SCAN
more than COUNT
this column Could.
This is a special access method, used for cases when the index order is not important, it does not exceed B-tree
, but instead only Reads pages sequentially.
Since there is less than one index table, therefore COUNT
a FULL
Comments
Post a Comment