Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 282592E0062 for ; Fri, 18 Apr 2008 15:19:10 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 31589-03 for ; Fri, 18 Apr 2008 15:19:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by developer.postgresql.org (Postfix) with ESMTP id 278162E0042 for ; Fri, 18 Apr 2008 15:19:06 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id C278DC2BF; Sat, 19 Apr 2008 02:19:00 +0800 (WST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 199681E0435; Sat, 19 Apr 2008 02:19:04 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8MQEAgOsQ6ed; Sat, 19 Apr 2008 02:19:03 +0800 (WST) Received: from [203.161.97.213] (203.161.97.213.static.amnet.net.au [203.161.97.213]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTP id 2A22D1E0434; Sat, 19 Apr 2008 02:19:03 +0800 (WST) Message-ID: <4808E600.3060108@postnewspapers.com.au> Date: Sat, 19 Apr 2008 02:18:40 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Jesper Krogh Cc: pgsql-performance@postgresql.org Subject: Re: Message queue table.. References: <4808DF33.8000008@krogh.cc> In-Reply-To: <4808DF33.8000008@krogh.cc> X-Enigmail-Version: 0.95.6 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/276 X-Sequence-Number: 29769 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? 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 > ; > > 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) Without seeing the schema and index definitions ... maybe you'd benefit from a multiple column index. I'd experiment with an index on (funcid,priority) first. -- Craig Ringer