Which of the two queries is more efficient?
-
SELECT *FROM Emp
WHERE DeptNo<>20 -
SELECT *FROM Emp
WHERE NOT Deptno=20
My trainer told me the 1st one is more efficient and I understand the reason but how can I check this using Oracle 10g? He used some commands to show the CPU cycles consumed but I can’t find them after a Google Search.
Outputs using AUTOTRACE are the same.
SQL> SELECT *FROM Emp
WHERE DeptNo<>20
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=9 Bytes=333
)
1 0 TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=9 Bytes=
333)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
1125 bytes sent via SQL*Net to client
508 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
SQL> SELECT *FROM Emp
WHERE NOT Deptno=20
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=3 Card=9 Bytes=333
)
1 0 TABLE ACCESS (FULL) OF 'EMP' (TABLE) (Cost=3 Card=9 Bytes=
333)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
8 consistent gets
0 physical reads
0 redo size
1125 bytes sent via SQL*Net to client
508 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
9 rows processed
In oracle both of these will be processed in the same way. Any difference will occur in parsing (=subdividing) the query, and even that will be make know difference if the queries run several times, because the parsing results are cached.
Focus efficiency efforts on more inefficient processes, e.g. joins and subqueries.