SQL optimization, index

  1. IN operator as little as possible, substantially all of the IN operator may be replaced with EXISTS, IN or EXIST when selecting operations, according to specifically consider the capacity size table
  2. Try to use the external connection or alternatively NOT EXISTS NOT IN operator. NOT IN can not be applied because the index table.
  3. Do not try to <> or! = Operator. Is not equal operator is never used in the index, so it will only process a full table scan
  4. When setting table, the column index is set to NOT NULL. Determines whether the character is empty index is generally not applied, because the index B-tree index is not null.
  5. Try to do the wildcard% or _ as the first character of the query string. Because these two in one as the first character of the query string, the index will not be used
  6. Where clause avoid the use of columns in the index calculation. If the index is not based on the function, then when the index in the where clause column using the function, the index will not work, thus avoiding the use of the where clause of the column in the index calculation.
  7. With> = replaced>.
  8. Conditions sequence where the following claims. where the latter condition, the statement written at the top table joins, maximum number of records can be filtered off living conditions.
  9. Alias ​​table, and each column of the prefix. When connecting a plurality of tables in the SQL statement, the table alias prefix and it as each column, thus reducing the analysis time.
  10. Be explicit or implicit computation of the field can not be indexed.
  11. Replaced by UNION ALL UNION. UNION is the most common set of operations, a plurality of records into a single set of cascade, is returned to the data row has unique requirements, it is required to Oracle SORT UNIQUE operation, and if the result set is relatively large, the operation will be relatively slow; UNION ALL operation does not exclude duplicate rows, so much faster, if the data itself there is less possibility of duplicate rows, with many UNION ALL UNION efficiency will be higher than with the

index

select * from user_indexes existing index query
select * from user_ind_columns query the index built on those fields.

Index is: for lifting objects database query efficiency, by the method of rapid positioning data, reduce disk I / O operations, the index information table is stored independently, Oracle Database automatic maintenance and maintenance index.
Index is divided into unique index non-unique index.

Create an index principle:
operating in select accounts creating an index on most tables.
Create indexes appear in the where clause of the most frequent columns.
Create an index on columns with high selectivity,

Create index create index index name on table name (field name)

Delete the index drop index index name

He published 195 original articles · won praise 55 · views 50000 +

Guess you like

Origin blog.csdn.net/weixin_42470710/article/details/104097535