Subject RE: [firebird-support] Re: Slow select min()
Author Slavomir Skopalik
Hi, this is really bad idea how to solve this problem.
I'm using for over 5 years this:

SELECT FIRST 1 id FROM DevStateLog WHERE idDevice=:idDevice
PLAN (DEVSTATELOG ORDER DEVSTATELOGDEVICETDATEDESC)
ORDER BY idDevice DESC, tDate DESC

most important part is ORDER BY idDevice DESC, tDate DESC.

Index is defined over idDevice,tDate DESC.

Only version 1.5.x was used correct PLAN automaticaly with PLAN clausule,
newer version alway used bad plan.

Slavek
Ing. Slavomir Skopalik
Jednatel spolecnosti
Elekt Labs s.r.o.
Chaloupky 158
783 72 Velky Tynec
Czech Republic
--------------------------------------------
Mobil: +420 724 207 851
icq:199 118 333
e-mail:skopalik@...
http://www.elektlabs.cz <http://www.elektlabs.cz/>





-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of danny_vdw
Sent: Wednesday, July 29, 2009 8:54 AM
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Re: Slow select min()




>

Like Dimitry said in a previous reply, the query used 2 indices PK_STAT and
STAT_USER_ID. If the index STAT_USER_ID is selective you can better
eliminate the second index.
select min(id+0) as id from stat where user_id = 100

I use this for order by/group by, mostly don't using an index in these
situation are faster then using one.

Danny



__._,_._
.

<http://geo.yahoo.com/serv?s=97359714/grpId=2442406/grpspId=1705115386/msgId
=103582/stime=1248854084/nc1=1/nc2=2/nc3=3>





[Non-text portions of this message have been removed]