Create and use indexes

Create a standard index:
CREATE INDEX index name ON table name (column name) TABLESPACE table space name;
create a unique index:
CREATE unique INDEX index name ON table name (column name) TABLESPACE table space name;
create a composite index:
CREATE INDEX index name ON Table name (column name 1, column name 2) TABLESPACE table space name;
create a reverse key index:
CREATE INDEX index name ON table name (column name) reverse TABLESPACE table space name;

index usage principle :
it is recommended to establish NOT NULL constraints for index fields
Tables that are often connected to other tables should be indexed on the join field; fields that
often appear in the Where clause and are highly filterable, especially those of large tables, should be indexed;
the key to high selectivity Indexes should be built;
keywords with low selectivity can be used, but when the value distribution of the data is very different, the index can still be used to improve the efficiency when the selective data is relatively small. The establishment of a
compound index requires careful analysis; try to consider using a single-field index Substitute:
A. Correctly select the first field in the composite index, which is generally more selective and commonly used in the where clause;
B. Several fields of the composite index often appear in the Where clause in an AND mode at the same time. A composite index can be established in the sentence; otherwise, a single-field index;
C. If the fields contained in the composite index often appear in the Where clause alone, it will be decomposed into multiple single-field indexes;
D. If the composite index contains more than 3 fields, then carefully consider its necessity and consider reducing the composite fields;
E. If there is both a single-field index and a composite index on these fields, the composite index can generally be deleted. Indexes;
tables with frequent DML, do not build too many indexes;
do not use those frequently modified columns as index columns;
the advantages and disadvantages of indexes:
a bit:
1. Create a unique index to ensure the uniqueness of each row of data in the database table
2 . Greatly speed up the retrieval of data, which is the main reason for creating indexes.
3. It is especially meaningful to speed up the connection between tables and tables, especially in terms of realizing the referential integrity of data.
4. When using grouping and sorting clauses for data retrieval, the time for grouping and sorting in the query can also be significantly reduced.
Disadvantages:
1. The index is created on the table, not on the view
2. It takes time to create and maintain the index, and this time increases as the amount of data increases
3. The index needs to occupy physical space, except that the data table occupies data In addition to the space, each index also occupies a certain amount of physical space. If a clustered index is to be established, the required space will be larger
. 4. When adding, deleting and modifying data in the table, the index also needs to be Dynamic maintenance reduces data maintenance speed

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326721917&siteId=291194637