Q: Estimated Cost from SET EXPLAIN?
Posted in 1995
Topics: Performance & Tuning, SQL Development & Query Writing
Attached is the actual output from our problem site and a brief explanation
of what is happening. If you could post this (and show me where and how
you post such questions), I would appreciate it. Let me know. The
'sqexplain.out' output follows. Thanks.
PROBLEM:
The following 'sqexplain.out' output relates to slightly different select
statements.
QUERY_1 represents output from a select statement employing
a "from occupant, directory" approach, yielding an "Estimated Cost" which
appears to be "appropriate" but produces a "SEQUENTIAL SCAN".
QUERY_2 represents output from a select statement employing a "from
directory, occupant" approach, yielding an "Estimated Cost" which is
negative but appropriately utilizes the index which exists for the
directory table (which does not appear to help).
QUERY_1 and QUERY_2 selects are about the same speed at one particular
site, but at all other sites, QUERY_2 is a much faster select
(less than 1-second vs. 7-10 seconds), AND, always produces a positive
"appropriate" "Estimated Cost" value.
QUESTION:
Does a negative "Estimated Cost" value indicate that there can be a problem
with the database and/or select methodology? and if so, what kind of
problems and how can they be rectified?
QUERY_1:
--------
select entryid, entrytype, aux, lastname, firstname, midname, linenum, dirline,
length(room) rmlen, room from occupant, directory
where occupant.room="2701P"
and directory.entryid=occupant.occid
Estimated Cost: 893
Estimated # of Rows Returned: 2
1) acs.directory: SEQUENTIAL SCAN
2) acs.occupant: INDEX PATH
Filters: acs.occupant.room = '2701P'
(1) Index Keys: occid
Lower Index Filter: acs.occupant.occid = acs.directory.entryid
QUERY_2:
--------
select entryid, entrytype, aux, lastname, firstname, midname, linenum, dirline,
length(room) rmlen, room from directory, occupant
where occupant.room="2701P"
and directory.entryid=occupant.occid
order by rmlen, room, lastname, firstname, midname, entryid, linenum
Estimated Cost: -11230
Estimated # of Rows Returned: 2
Temporary Files Required For: Order By
1) acs.occupant: INDEX PATH
(1) Index Keys: room
Lower Index Filter: acs.occupant.room = '2701P'
2) acs.directory: INDEX PATH
(1) Index Keys: entryid
Lower Index Filter: acs.directory.entryid = acs.occupant.occid
GRFollis (follis@esd.dl.nec.com)
--
--------------------------------------------------------------------------
The most widely used computer language ....
$*#%"&@+!
--------------------------------------------------------------------------