Analysis & Answer
From the perspective of functional logic, it can be divided into:
- Ordinary index INDEX (ordinary index) ALTER TABLE
table_name
ADD INDEX index_name (column
) - Unique index UNIQUE (unique index) ALTER TABLE
table_name
ADD UNIQUE (column
) - Primary key index PRIMARY KEY (primary key index) ALTER TABLE
table_name
ADD PRIMARY KEY (column
) - Composite Index Composite Index ALTER TABLE
table_name
ADD INDEX index_name (column1
,column2
,column3
) - Full text index FULLTEXT (full text index) ALTER TABLE
table_name
ADD FULLTEXT (column
)
From the perspective of data structure, it can be divided into:
- B+ tree index
- hash index
- full text index
- Spatial data index (R-Tree index) ( not required )
From the perspective of physical storage, it can be divided into:
- clustered index
- nonclustered index
Reflect & Expand
Tell me about the database index type? (Oracle)
logically:
- Single column single row index
- Concatenated multi-row index
- Unique unique index
- NonUnique non-unique index
- Function-based function index
- Domain domain index
Physically:
- Partitioned partition index
- NonPartitioned non-partitioned index
- B-tree:
- Normal normal type B tree
- Rever Key reverse B-tree
- Bitmap bitmap index
Index structure:
B-tree:
- Suitable for a large number of additions, deletions, and changes (OLTP);
- Cannot use queries containing the OR operator;
- Suitable for columns with high cardinality (many unique values)
- Typical tree structure;
- Each node is a data block;
- Most of them are physically one layer, two layers or three layers, and logically three layers;
- Leaf block data is sorted, increasing from left to right;
- In the branch block and the root block are the ranges of the index;
Bitmap:
- fit and decision support system;
- The cost of doing UPDATE is very high;
- Very suitable for OR operator queries;
- Bitmap indexes can only be built when the cardinality is relatively small;
The B*tree index is usually more suitable when accessing a small amount of data. For example, you access no more than 5% of the data in the table. Of course, this is only a relative ratio and applies to general situations. Bitmap is often used in data warehouses for low-cardinality columns, such as gender and other fields with many repeated values. The smaller the cardinality, the better.
Meow Interview Assistant: One-stop solution to interview questions, you can search the WeChat applet [Meow Interview Assistant] or follow [Meow Brush Questions] -> Interview Assistant free questions. If you have good interview knowledge or skills, look forward to your sharing!