Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id D4E9D2E0078 for ; Fri, 18 Apr 2008 14:50:20 -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 96339-08 for ; Fri, 18 Apr 2008 14:50:13 -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 4D6072E0050 for ; Fri, 18 Apr 2008 14:50:15 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by shrek.krogh.cc (Postfix) with ESMTP id ADF153BF458 for ; Fri, 18 Apr 2008 19:50:13 +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 v3FJtUgUanGq for ; Fri, 18 Apr 2008 19:49:30 +0200 (CEST) Received: from [192.168.1.5] (unknown [90.184.13.46]) by shrek.krogh.cc (Postfix) with ESMTP id 885BF3BEE06 for ; Fri, 18 Apr 2008 19:49:30 +0200 (CEST) Message-ID: <4808DF33.8000008@krogh.cc> Date: Fri, 18 Apr 2008 19:49:39 +0200 From: Jesper Krogh User-Agent: Thunderbird 2.0.0.12 (X11/20080227) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Message queue table.. 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/274 X-Sequence-Number: 29767 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) # 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 ; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.09 rows=1 width=106) (actual time=245.273..245.274 rows=1 loops=1) -> Index Scan using workqueue_job_funcid_priority_idx on job (cost=0.00..695291.80 rows=8049405 width=106) (actual time=245.268..245.268 rows=1 loops=1) Index Cond: (funcid = 4) Filter: ((run_after <= 1208442668) AND (grabbed_until <= 1208442668) AND ("coalesce" = 'Efam'::text)) Total runtime: 245.330 ms (5 rows) -- Jesper