Oracle index, this is enough

What is an index

An index is an optional structure associated with a table. It is a way to quickly access data and improve database performance. The database can explicitly create an index to speed up the execution of SQL statements on the table. When the index key is used as a query condition, the index will directly point to the position of the row containing these values. Even if the index is deleted, there is no need to modify any SQL statement. definition

Index classification

Physical classification Logical classification
Partitioned or non-partitioned index Single column or combined index
B-tree index Unique or non-unique index
Normal or reverse key index Based on functional index
Bitmap index

B-tree index

The B-tree index is usually also called a standard index. The top of the index is , which contains items that point to the next level in the index. The next level is the sub-block, and the sub-block points to the next-level block of the index. The lowest level is 叶节点the index entry that points to the table row. The leaf block is 双向链表helpful to scan the index in ascending and descending order of keywords

SQL>create [unique] index_name on table_name(column_list) 
[tablespace tablespace_name]

- unique: Used to specify a unique index, by default it is a non-unique index
- index_name: Index name
- table_name: Table name
- column_list: Column name, can be multiple columns, separated by commas
- tablespace_name: Specify a table space for the index

Unique index and non-unique index

  • Unique index:

There are no duplicate values ​​in any two rows in the column that defines the index. The index key in the unique index can only point to one row in the table. Create a corresponding unique index when creating a primary key constraint and creating a unique constraint

  • Non-unique index:

A single keyword can have multiple rows associated with it

Reverse key index

与常规B树索引相反,反向键索引在保持列顺序的同时反转列的字节。反向索引通过反转索引
键的数据值来实现,其优点是对于连续增长的索引列,反转索引列可以将索引数据分散在多
个索引块间,减少I/O瓶颈的发生。
SQL>create unique index_reverse_name on table_name(column_list) REVERSE;

REVERSE

Bitmap index

The advantage of the bitmap index is that it is most suitable 低基数列(the value of this column is finite and theoretically will not be infinite). For example, the type of job (job column) in the employee table, even if there are millions of employee records, the type of job is also calculable, and the type of job column can be used as the 位图索引category column of the book table.

Bitmap index has the following advantages

  • For a large number of instant queries, the response time can be reduced
  • Compared with other indexing technologies, the space occupied is significantly reduced
  • Even in terminal hardware with very low configuration, significant performance can be obtained
    . Bitmap index does not directly store rowId, but stores the mapping of byte bits to rowId, reducing response time and saving space.
    位图索引Should not be applied to the frequent occurrence of insert, update, deleteon the operating table, the DML operations are costly in terms of performance, bitmap index is best suited for data warehousing and decision support systems
SQL>create bitmap index index_bit_name on table_name(column_name)

Other indexes

  • Composite index: create an index on multiple columns in the table, the columns in the index do not have to be in the same order as the columns in the table, nor do they have to be adjacent to each other
    • Use scenario :When certain fields are often combined with the and operator in the where clause of the SQL statement to be used as the filter key predicate
    • Compound index field sorting principle
      • The most 频繁used field comes first
      • Use the same frequency, put the most 选择性field first
  • Function-based index: If the function or expression used involves one or more columns in the table being built, a function-based index is created. The index given to the function can be created as a B-tree or bitmap index.
    • No aggregate function can appear in the expression,
    • Cannot be created on a LOB type column,
    • Must have QUERT REWRITE permission when creating

Index usage principle

  • Create an index after importing data in the table. Otherwise, the index must be updated every time data is inserted into the table
  • Create indexes on appropriate tables and fields. If frequently retrieved data is less than 15% of the table, you need to create indexes
  • Limit the number of indexes in the table. The more indexes, the greater the workload of index modification when modifying the table

to sum up

  • B-tree index is a general index, it is the default index type when creating an index
  • The reverse key index is built on a column whose value is continuously increasing
  • Bitmap index is suitable for creating on low cardinality columns
  • Based on functional index
  • Index usage principle

Guess you like

Origin blog.csdn.net/qq_44621891/article/details/109045303