Oracle index basics

#######################Query all indexes on one table################################################################################################################################################################################################################################################ ######################## #################

select
      a.table_name, a.index_name, b.column_name, a.uniqueness, a.visibility 
from  
       user_indexes a, user_ind_columns b
where
    a.index_name = b.index_name and  a.table_name -'DEPT';

#######################Query whether the database is CDB or non-CDB#################### #################

select  name,created,cdb,con_id  from v$database;

#######################Query PDB####################### #############

select  name,open_mode,open_time  from v$pdbs;

#######################Index Technology###########################################################################################################################################################################Index############################################## Index Technology####################### #############

The degree to which the index improves performance depends on the selectivity of the data and the way the data is distributed in the data blocks of the table.

When performing a full table scan, Oracle uses multi-block reads to quickly scan the table, and index-based reads are single block reads.

Generally speaking, adding an index on the table will make the execution time of the insert operation on the table three times the original; adding another index will double the slowness; however, a composite index (two or more columns) ) Is not much worse than an index with only one column.

Query logic through the index:

Execute the SQL statement, the optimizer will use the appropriate index to find the value, and find the corresponding ROWID, and then use the ROWID to find the data row on the disk block corresponding to the table.

#######################Query the index on the table######################################################################################################################################################################################################################## ######################### ################

select  table_name,index_name 
from  user_indexes
where  table_name='EMP'

#######################Query the column names corresponding to the index on the table############################################################################################################################################################################################################################ ######################## ##################

select table_name, index_name, column_name, column_position
from user_ind_columns 
order by table_name, index_name, column_position;

#######################Query whether the index is set to invisible################################################################################################################################################################################################################################# ###################### #################

select
           a.table_name, a.index_name,b.column_name, a.uniqueness, a.visibility 
from
           user_indexes a, user_ind_columns b
where
           a.index_name = b.index_name and a.table_name ='DEPT';
By using invisible indexes, you can Create multiple indexes on the same column or on the same multiple columns.
For example, you can use B-tree indexes during the day; use reverse key indexes at night.

####################### Compound Index####################### #############

When an index contains multiple columns, it is called a "composite index". Oracle introduces index skip scan to increase the optimizer's choice when using composite indexes, so the order of the columns in the composite index is very critical.
Generally speaking, the first column of the index should be the column most likely to be used in where, and it should be the most selective column in the index.
Before the introduction of skip scan function, only when the leading list of the index is listed in the where clause, the query can use the index. In other words, if the leading column of the index does not appear in where, the execution plan may not use the index.
After introducing the skip scan function, even if the leading column of the index does not appear in where, the optimizer will still use the index, and the optimizer may choose index fast full scan or full table scan or index skip scan .

Two common index scan methods: unique scan and range scan.
In a unique scan, the database knows that every value contained is unique.
In a range scan, the database will return multiple eligible values ​​from the index based on query conditions.

#######################Not equal to operation and NULL###################### ################

Indexes can only be used to look up data that already exists in the table. When the inequality operator is used in the where clause, the indexes on the columns used therein cannot be used.

If you use is null or is not null in where, Oracle will not index NULL values ​​in the B+ tree. In the case of NULL, unless the bitmap index is used. This is also why when creating a table, specifying the not null constraint on a column will disable NULL values, which also avoids index-related performance problems caused by NULL values.

####################### like  '%XXX%' 和 like  ‘X%’######################################

Like'X%' can use indexes, but like'%XX%' still cannot use indexes in Oracle 12c.

####################### USING FUNCTION####################### #############

If a function appears on the left side of the equal sign in the where condition, the index on the column processed by the function will not be available.

Unless you use a function-based index, you can change this status quo.

#######################Comparison does not match the data type############################################################################################################################################################################################################################################### ############ ################

Oracle not only will not report errors for mismatched data types, but will perform implicit data type conversion. This brings huge performance problems.

#######################Cluster factor########################################################################################################################################################################################################################################################################### ##############

A measure of the orderliness of an index compared to the table in which it is located, used to check the cost of a table lookup performed after the index is accessed. The clustering factor records the number of data blocks that need to be read when scanning the index.

If the index used has a larger clustering factor, more table data blocks must be accessed to obtain the corresponding data rows in each index block.

If the clustering factor is close to the number of data blocks in the table, it means that the sorting of the data rows corresponding to the index is in good condition;

If the clustering factor is close to the number of data rows in the table, it means that the data blocks corresponding to the index are not well sorted.

#######################二元高####################### ##############

The so-called dual height is actually the level of the index tree.

#######################直方图####################### #############

Oracle's histogram is highly balanced rather than width balanced. All buckets in a highly balanced histogram have the same number of rows. The start and end of the bucket depend on the number of rows containing these values.

The width histogram specifies the value range of each bucket, and then counts the number of rows in this range, which may result in a large difference in the number of rows in the bucket, which is obviously not ideal.

#######################Quick Full Scan###################### #################################################################################################################################################################################################################################################### ##############

During the fast full scan of the index, oracle reads all leaf blocks on the B-tree index. This index can be read sequentially, so how many blocks can be read at a time.

The DB_FILE_MULTIBLOCK_READ_COUNT parameter in the initialization file can control the number of blocks read by colleagues.

INDEX(FAST_FULL_SCAN)

Compared to a full table scan, a fast full scan requires less physical IO, and queries can be completed faster.

My understanding is that in the case of Samsung index (the query column and where column are all in the index), a fast full scan will occur.

#######################Jumping Scan####################### ##############

The feature of index skip scan allows the optimizer to use a composite index, even if the leading column of the index is not in where. Index skip scan is much faster than index full scan because only a small number of read operations need to be performed.

INDEX(SKIP_SCAN)

 

Guess you like

Origin blog.csdn.net/David_ifx/article/details/115193349