X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0000D9DCDC2 for ; Thu, 16 Mar 2006 16:36:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10661-08 for ; Thu, 16 Mar 2006 16:36:02 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id E90B19DCDB1 for ; Thu, 16 Mar 2006 16:35:59 -0400 (AST) Received: from mx1.vodamail.co.za (mx1.vodamail.co.za [196.11.146.148]) by svr4.postgresql.org (Postfix) with ESMTP id 577735AF95D for ; Thu, 16 Mar 2006 20:36:00 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by mx1.vodamail.co.za (Postfix) with ESMTP id CBCE149E49; Thu, 16 Mar 2006 22:35:54 +0200 (SAST) Received: from mx1.vodamail.co.za ([127.0.0.1]) by localhost (mx1.vodamail.co.za [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13872-01; Thu, 16 Mar 2006 22:35:53 +0200 (SAST) Received: from josh.flame2.flame.co.za (unknown [10.48.30.20]) by mx1.vodamail.co.za (Postfix) with ESMTP id CB63B49D29; Thu, 16 Mar 2006 22:35:43 +0200 (SAST) Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by josh.flame2.flame.co.za (8.12.11/8.12.11) with ESMTP id k2GKYp6O003314; Thu, 16 Mar 2006 22:35:31 +0200 Subject: Indexes with descending date columns From: Theo Kramer Reply-To: theo@flame.co.za To: pgsql-performance@postgresql.org Content-Type: text/plain Organization: Flame Computing Enterprises cc Message-Id: <1142541290.2812.45.camel@josh> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 16 Mar 2006 22:34:51 +0200 Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at vodamail.co.za X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200603/255 X-Sequence-Number: 17692 Hi I have a performance problem when traversing a table in index order with multiple columns including a date column in date reverse order. Below follows a simplified description of the table, the index and the associated query \d prcdedit prcdedit_prcd | character(20) | prcdedit_date | timestamp without time zone | Indexes: "prcdedit_idx" btree (prcdedit_prcd, prcdedit_date) When invoking a query such as select oid, prcdedit_prcd, prcdedit_date, 'dd/mm/yyyy hh24:mi:ss') as mydate where prcdedit_prcd > 'somevalue' order by prcdedit_prcd, prcdedit_date desc; the peformance is dismal. However removing the 'desc' qualifier as follows the query flys select oid, prcdedit_prcd, prcdedit_date, 'dd/mm/yyyy hh24:mi:ss') as mydate where prcdedit_prcd > 'somevalue' order by prcdedit_prcd, prcdedit_date; PostgreSQL Version = 8.1.2 Row count on the table is > 300000 Explain is as follows for desc Limit (cost=81486.35..81486.41 rows=25 width=230) (actual time=116619.652..116619.861 rows=25 loops=1) -> Sort (cost=81486.35..82411.34 rows=369997 width=230) (actual time=116619.646..116619.729 rows=25 loops=1) Sort Key: prcdedit_prcd, prcdedit_date, oid -> Bitmap Heap Scan on prcdedit (cost=4645.99..23454.94 rows=369997 width=230) (actual time=376.952..11798.834 rows=369630 loops=1) Recheck Cond: (prcdedit_prcd > '063266 '::bpchar) -> Bitmap Index Scan on prcdedit_idx (cost=0.00..4645.99 rows=369997 width=0) (actual time=366.048..366.048 rows=369630 loops=1) Index Cond: (prcdedit_prcd > '063266 '::bpchar) Total runtime: 116950.175 ms and as follows when I remove the 'desc' Limit (cost=0.00..2.34 rows=25 width=230) (actual time=0.082..0.535 rows=25 loops=1) -> Index Scan using prcdedit_idx on prcdedit (cost=0.00..34664.63 rows=369997 width=230) (actual time=0.075..0.405 rows=25 loops=1) Index Cond: (prcdedit_prcd > '063266 '::bpchar) Total runtime: 0.664 ms Any assistance/advice much appreciated. -- Regards Theo