Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 _________________________ 2 __________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
3 _________________________ 4 __________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Optimization of Statements Optimization of Statements
Example:
Optimized Statement:
SELECT NAME, INITIALS
FROM PLAYERS
SELECT NAME, INITIALS
WHERE PLAYERNO = 6
FROM PLAYERS
OR PLAYERNO = 83
WHERE PLAYERNO IN (6, 83, 44)
OR PLAYERNO = 44
5 _________________________ 6 __________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
7 _________________________ 8 __________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Optimization of Statements Optimization of Statements
9 _________________________ 10 _________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Example:
SELECT PLAYERNO, NAME Avoid DISTINCT
FROM PLAYERS
WHERE EXISTS SpecifyingDISTINCT in the SELECT
(SELECT '101' clause removes the duplicate rows
from the result.
FROM PENALTIES
WHERE
PENALTIES.PLAYERNO =
PLAYERS.PLAYERNO)
*Property of STI K0019 *Property of STI K0019
11 ________________________ 12 _________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Optimization of Statements Optimization of Statements
Example:
Avoid Unnecessary Use of the UNION
SELECT DISTINCT MATCHNO, Operator
NAME
FROM MATCHES, PLAYERS
The
UNION operator must only be
WHERE MATCHES.PLAYERNO = used if required and relevant.
PLAYERS.PLAYERNO
13 ________________________ 14 _________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Example:
SELECT MATCHNO, WON - LOST Isolate Columns in Conditions
FROM MATCHES
When an index is defined on a
WHERE WON >= LOST
column that occurs in a calculation
UNION or scalar function, that index will not
SELECT MATCHNO, LOST - WON be used.
FROM MATCHES
WHERE WON < LOST
15 ________________________ 16 _________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Optimization of Statements Optimization of Statements
17 ________________________ 18 _________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
Example:
Largest Table Last SELECT * FROM
PLAYERS, TEAMS
In
formulating joins, it is possible that
the sequence of the tables in the Optimized Statement:
FROM clause can affect the SELECT * FROM
processing speed.
TEAMS, PLAYERS
19 ________________________ 20 _________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________
___________________________ ___________________________