X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 57E9132A4E5 for ; Sun, 3 Oct 2004 04:37:28 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55283-02 for ; Sun, 3 Oct 2004 03:37:24 +0000 (GMT) Received: from mpls-qmqp-02.inet.qwest.net (mpls-qmqp-02.inet.qwest.net [63.231.195.113]) by svr1.postgresql.org (Postfix) with SMTP id A550732A515 for ; Sun, 3 Oct 2004 04:37:22 +0100 (BST) Received: (qmail 76499 invoked by uid 0); 3 Oct 2004 02:18:24 -0000 Received: from mpls-pop-10.inet.qwest.net (63.231.195.10) by mpls-qmqp-02.inet.qwest.net with QMQP; 3 Oct 2004 02:18:24 -0000 Received: from 63-227-127-37.dnvr.qwest.net (HELO ?10.0.0.2?) (63.227.127.37) by mpls-pop-10.inet.qwest.net with SMTP; 3 Oct 2004 03:37:21 -0000 Date: Sat, 02 Oct 2004 21:39:21 -0600 Message-Id: <1096774761.32732.11.camel@localhost.localdomain> From: "Scott Marlowe" To: "Stephan Szabo" Cc: "Shane|SkinnyCorp" , "PgSQL ADMIN" Subject: Re: PLEASE GOD HELP US! In-Reply-To: <20041002143450.V11227@megazone.bigpanda.com> References: <00ab01c4a7f4$f04fffd0$3402a8c0@shanepc> <1096691616.2611.22.camel@localhost.localdomain> <20041002080923.C99145@megazone.bigpanda.com> <1096751454.2611.33.camel@localhost.localdomain> <20041002143450.V11227@megazone.bigpanda.com> Content-Type: text/plain Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/56 X-Sequence-Number: 15049 On Sat, 2004-10-02 at 15:42, Stephan Szabo wrote: > On Sat, 2 Oct 2004, Scott Marlowe wrote: > > So would a union give good performance? Just union the first 25 or less > > with status=5 with the rest, using a 1 and 0 in each union to order by > > first? Hopefully the indexes would then be used. > > You'd want to use union all I think and you may have to put limits on the > unioned arms to get good behavior. I think the expression index would > probably work without changing the query (at least for relatively low > offsets) at the cost of having an extra index to maintain. > I wonder if this would offer any improvement: select * from ( (SELECT 2 as a,* FROM thread_listing AS t where t.status=5 ORDER BY t.lastreply desc limit 25) union (SELECT 1 as a,* FROM thread_listing AS t where t.status<>5 order by t.lastreply desc limit 25) ) as p order by p.a desc, p.lastreply desc limit 25; Or is there a moving offset we have to deal with here?