Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id B2A7B2E0032 for ; Fri, 18 Apr 2008 16:23:38 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 13129-03 for ; Fri, 18 Apr 2008 16:23:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from shrek.krogh.cc (2605ds1-ynoe.1.fullrate.dk [90.184.12.24]) by developer.postgresql.org (Postfix) with ESMTP id 91D372E0042 for ; Fri, 18 Apr 2008 16:23:29 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by shrek.krogh.cc (Postfix) with ESMTP id 6DE773BF458; Fri, 18 Apr 2008 21:23:25 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at shrek.krogh.cc Received: from shrek.krogh.cc ([127.0.0.1]) by localhost (shrek.krogh.cc [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0A2CZQhd6Jga; Fri, 18 Apr 2008 21:23:16 +0200 (CEST) Received: from [192.168.1.5] (unknown [90.184.13.46]) by shrek.krogh.cc (Postfix) with ESMTP id 1C9073BEE06; Fri, 18 Apr 2008 21:23:13 +0200 (CEST) Message-ID: <4808F51D.40102@krogh.cc> Date: Fri, 18 Apr 2008 21:23:09 +0200 From: Jesper Krogh User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: Craig Ringer CC: pgsql-performance@postgresql.org Subject: Re: Message queue table.. References: <4808DF33.8000008@krogh.cc> <4808E600.3060108@postnewspapers.com.au> In-Reply-To: <4808E600.3060108@postnewspapers.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/279 X-Sequence-Number: 29772 Craig Ringer wrote: > Jesper Krogh wrote: >> >> Hi. >> >> I have this "message queue" table.. currently with 8m+ records. >> Picking the top priority messages seem to take quite long.. it is just >> a matter of searching the index.. (just as explain analyze tells me it >> does). >> >> Can anyone digest further optimizations out of this output? (All >> records have funcid=4) > > You mean all records of interest, right, not all records in the table? Actually all the records.. since all the other virtual queues currently are empty. > What indexes do you have in place? What's the schema? Can you post a "\d > tablename" from psql? > >> # explain analyze SELECT job.jobid, job.funcid, job.arg, job.uniqkey, >> job.insert_time, job.run_after, job.grabbed_until, job.priority, >> job.coalesce FROM workqueue.job WHERE (job.funcid = 4) AND >> (job.run_after <= 1208442668) AND (job.grabbed_until <= 1208442668) >> AND (job.coalesce = 'Efam') ORDER BY funcid, priority ASC LIMIT 1 I found that removing the funcid from the order by made it use a better index. (priority, run_after, grabbed_until) that probably makes sense since the funcid doesnt give any value in the index at all. thanks for leading me back on track. Jesper -- Jesper