1. * Number of execution efficiency caused by
Minimize the use of SELECT * to query, when you query using *,
The database is parsed and the * is converted to all columns.
Select COUNT (si.student_id)
From Student_info si (student_id as index)
And
Select COUNT (*) from Student_info si
Execution. The above statement is significantly faster than the following statement without index statistics
2. Avoid using calculations on indexed columns.
Where clause, if the index column is part of a function. The optimizer will use a full table scan without using an index.
Example:
Low efficiency:
SELECT ... From DEPT WHERE SAL * > 25000;
Efficient:
SELECT ... From DEPT WHERE SAL > 25000/12;
3, replace > with >=
Efficient:
SELECT * from EMP WHERE DEPTNO >=4
Low efficiency:
SELECT * from EMP WHERE DEPTNO >3
The difference between the two is that the former DBMS will jump directly to the first record that DEPT equals 4 and the latter will first navigate to the Deptno=3 record and scan forward to the first record with a DEPT greater than 3.
4. Replace or with UNION (for indexed columns)
In general, replacing OR in a WHERE clause with UNION will have a good effect. Using OR on an indexed column causes a full table scan. Note that the above rules are valid only for multiple indexed columns. If a column is not indexed, the query efficiency may be reduced because you did not select OR. In the following example, indexes are built on both loc_id and region.
Efficient:
SELECT loc_id, Loc_desc, Region
From location
WHERE loc_id = 10
UNION
SELECT loc_id, Loc_desc, Region
From location
WHERE region = "MELBOURNE"
Low efficiency:
SELECT loc_id, Loc_desc, Region
From location
WHERE loc_id = ten OR region = "MELBOURNE"
If you persist in using OR, you need to return the least logged index column to the front.
5. Replace or with in
This is a simple and easy-to-remember rule, but the actual execution effect has to be tested, and under Oracle8i, the execution path seems to be the same.
Low efficiency:
SELECT .... From location WHERE loc_id = ten or loc_id = or loc_id = 30
Efficient
SELECT ... From location WHERE loc_in in (10,20,30);
6. Avoid using is null and is not NULL on index columns
7. Where execution order
Where execution is performed from top to bottom
SELECT *
From Student_info si--Student Information Form
Where si.school_id=10--academy ID
and si.system_id=100--System ID
When placing a WHERE clause, place the condition that can filter large amounts of data at the bottom
8. Optimizations in the From field:
Oracle Yasuteru Loading table data from right to left, you should put the table that can exclude the most data to the back (base table) .
For example, in the context of the query, put the curriculum back, the score table in front, because the curriculum data is generally relatively small, associated with the time can quickly filter out some of the performance data.
9. Invalid index
1. Index invalidation due to operation
2. Index invalidation due to type conversion
3. Problems caused by the calculation on the index column
4. Is the problem caused by not NULL (student_id as index)
5, order by causes index invalidation (student_id is index)
6. Auto-Select Index
7.! = Causes index invalidation
8. Index invalidation due to%
Oracle Common SQL statement optimizations