The myth of indexing using indexes: The magical use of null values
It is not because a completely empty entry is not logged to the index, it is determined not to use null values, on the contrary, sometimes a reasonable use of Oracle's NULL value will bring our query several times or even dozens of times times more efficient.
For example, add a table with a field that is "processing time", if a transaction is not processed, the column is empty, and in most cases the transaction is always 10% or less of the total number of records, while the record waiting to be processed (the "Processing Time" column is empty) is always the majority of records, then the Wait time "This column is indexed, and there is always a small number of records in the index, and the way we want to access it is when we access all of the records in the table (that is, 10% or more), we want to retrieve it through a full table scan; When we want to access the transactions that have been processed (that is, 5% or less), we want to access them through the index, because the number of records in the index is very small, see the following example:
Sql> CREATE TABLE TT as SELECT * from Sys.dba_objects;
Table created
Executed in 0.601 seconds
Sql> ALTER TABLE TT Add (t int);
Table Altered
Executed in 0.061 seconds
Sql> Select COUNT (*) from TT;
COUNT (*)
----------
6131c
Executed in 0.01 seconds
Sql> UPDATE TT set t=1 where owner= ' DEMO ';
Ten rows updated
Executed in 0.03 seconds
Sql> COMMIT;
Commit Complete
Executed in 0 seconds
Sql> Select COUNT (*) from TT where owner= ' DEMO ';
COUNT (*)
----------
Number of 10―――――――――――――― already processed
Executed in 0.08 seconds
S
Sql> Select COUNT (*) from TT;
COUNT (*)
----------
Total number of 6131―――――――――――――― records
Executed in 0.01 seconds
The following query, because it accesses most of the records in the table (the number of records that are processed, that is, more than 10%), can be seen, using a full table scan as we would like to:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.