Regular sql query optimization

1. It is best not to use "*" in the query statement instead of the column name, but to use the column name that will actually be used.

Because asterisk will query all the columns of a table, it will consume the query time of the system

2. Minimize the number of table queries

3. Use [not] exists instead of [not] in

Fourth, create an index (it is best to create an index for the relevant columns of each query condition)

(1) Statement to create an index:

 

create index index_name on table_name(column_name);

(2) Monitor indexes (through monitoring, you can know which indexes are not used, and these indexes can be deleted)

 

Statement:

alter index index_name monitoring usage;

 (3) Check index usage

Statement:

select * from v$object_usage;

 (4) delete the index statement

drop index index_name;

 5. Select the driver table (the table immediately after from is usually accessed by a full table scan)

Create an index on the driver table

Six, try to avoid full table scan large table

In the following cases, Oracle will perform a full table scan

(1) The table being queried does not have an index set

(2) All rows need to be returned, with an asterisk "*"

(3) with like and use a statement such as "%"

(4) Conditional restrictions on the index main column, but the function is used

(5) with is null, is not null or! = clauses also cause a full table scan

Seven, pay attention to the connection order of the where clause

Since oracle parses where clauses in a bottom-up order, according to this principle, connections between tables must be written before other where conditions. Those conditions that can filter out the largest data records must be written at the end of the where clause, that is, before performing the table join operation, the more records that are filtered out, the better.

8. View the execution plan and modify it according to the cost of the execution plan

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326361693&siteId=291194637