X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.193]) by svr1.postgresql.org (Postfix) with ESMTP id 6F2DE30ECA1 for ; Sun, 15 Jun 2003 22:38:16 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr1.postgresql.org [64.117.224.193]) (amavisd-new, port 10024) with ESMTP id 86672-07 for ; Sun, 15 Jun 2003 19:38:06 -0300 (ADT) Received: from game.over.net (unknown [193.189.169.9]) by svr1.postgresql.org (Postfix) with ESMTP id 40C5A30D174 for ; Sun, 15 Jun 2003 19:38:05 -0300 (ADT) Received: from localhost.over.net ([127.0.0.1]:48907 "EHLO zvezek.over.net") by mail.over.net with ESMTP id ; Mon, 16 Jun 2003 00:38:05 +0200 Message-Id: <5.2.1.1.0.20030616002729.01bba2e0@127.0.0.1> X-Sender: tmail@127.0.0.1 X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Mon, 16 Jun 2003 00:37:30 +0200 To: pgsql-performance@postgresql.org From: Tomaz Borstnar Subject: Re: any way to use indexscan to get last X values In-Reply-To: <23329.1055695990@sss.pgh.pa.us> References: <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> <5.2.1.1.0.20030615161722.025c7630@127.0.0.1> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200306/71 X-Sequence-Number: 2155 At 18:53 15.6.2003, you wrote: >I've applied the attached patch to CVS tip to cure the latter problem. >With this, a two-column index, and compatible column ordering in ORDER >BY and GROUP BY, I get a reasonable-looking fast-start plan. The patch >will not apply exactly against 7.3 because there's a renamed function >call in there, but you could make it work with a little effort. You mean this: /* * ordering_oper_opid - convenience routine for oprid(ordering_oper()) * * This was formerly called any_ordering_op() */ A little later... WOW! 100 to 130 times faster on same dataset and additional index on (modifystamp,thread) which was not really useful before this patch! krtjavendan34=> EXPLAIN ANALYZE SELECT thread, modifystamp, count(id) AS tcount,abstime(modifystamp) AS latest, max(id) as maxid FROM tjavendan WHERE approved='Y' GROUP BY modifystamp, thread ORDER BY modifystamp desc, thread desc limit 40; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.00..97.13 rows=40 width=12) (actual time=1.07..48.71 rows=40 loops=1) -> Aggregate (cost=0.00..20947.38 rows=8626 width=12) (actual time=1.05..48.23 rows=41 loops=1) -> Group (cost=0.00..20516.06 rows=86265 width=12) (actual time=0.35..42.25 rows=843 loops=1) -> Index Scan Backward using tjavendan_modstamp_thrd on tjavendan (cost=0.00..20084.73 rows=86265 width=12) (actual time=0.34..31.29 rows=844 loops=1) Filter: (approved = 'Y'::bpchar) Total runtime: 50.20 msec (6 rows) Used to be between 5800 and 6741 msec before this patch! Thanks!