Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 96ED72E0032 for ; Fri, 18 Apr 2008 16:27:09 -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 48390-05 for ; Fri, 18 Apr 2008 16:27:06 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 6BC322E002D for ; Fri, 18 Apr 2008 16:27:06 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m3IJR2HW007591; Fri, 18 Apr 2008 15:27:02 -0400 (EDT) To: Jesper Krogh cc: pgsql-performance@postgresql.org Subject: Re: Message queue table.. In-reply-to: <4808DF33.8000008@krogh.cc> References: <4808DF33.8000008@krogh.cc> Comments: In-reply-to Jesper Krogh message dated "Fri, 18 Apr 2008 19:49:39 +0200" Date: Fri, 18 Apr 2008 15:27:02 -0400 Message-ID: <7590.1208546822@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/280 X-Sequence-Number: 29773 Jesper Krogh writes: > 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). > 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 Well, what that's doing in English is: scan all the rows with funcid = 4, in priority order, until we hit the first one satisfying the filter conditions. Apparently there are a lot of low-priority rows that have funcid = 4 but not the other conditions. If it's the "coalesce" condition that's the problem, an index on (funcid, coalesce, priority) --- or (coalesce, funcid, priority) --- would probably help. I'm not sure there's a simple fix if it's the other conditions that are really selective. regards, tom lane