X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 505DAD1BB36 for ; Wed, 28 Jan 2004 11:24:21 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 38398-08 for ; Wed, 28 Jan 2004 07:23:52 -0400 (AST) Received: from postal.trymedia.com (204-247-59-99.trymedia.com [204.247.59.99]) by svr1.postgresql.org (Postfix) with ESMTP id 6503CD1D287 for ; Wed, 28 Jan 2004 07:23:49 -0400 (AST) Received: by postal.trymedia.com (Postfix, from userid 100) id 74B05236F52; Wed, 28 Jan 2004 03:23:50 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by postal.trymedia.com (Postfix) with SMTP id E50D8236F5B for ; Wed, 28 Jan 2004 03:23:39 -0800 (PST) Received: from alexandra (233.Red-213-0-1.pooles.rima-tde.net [213.0.1.233]) by postal.trymedia.com (Postfix) with ESMTP id DC423236F5A for ; Wed, 28 Jan 2004 03:23:38 -0800 (PST) Reply-To: From: "Alexandra Birch" To: Subject: limit 1 and functional indexes Date: Wed, 28 Jan 2004 12:23:38 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.0 tagged_above=0.0 required=5.0 tests=MSGID_GOOD_EXCHANGE, RCVD_IN_RFCI X-Spam-Level: * X-Archive-Number: 200401/232 X-Sequence-Number: 16625 Hi, Postgres choses the wrong index when I add limit 1 to the query. This should not affect the index chosen. I read that functional indexes are sometimes not chosen correctly by optimizer. Is there anything I can do to always use the functional index in the following queries? Query with limit 1 choses wrong index: --------------------------------------------------------------------------------------- explain select code from transactions where UPPER(pop) = UPPER('79bcdc8a4a4f99e7c111111111111111') order by order_date DESC LIMIT 1 Index Scan Backward using transactions_date_aff on transactions (cost=0.00..930780.96 rows=2879 width=33) --------------------------------------------------------------------------------------- Without limit 1 choses correct index: --------------------------------------------------------------------------------------- explain select code from transactions where UPPER(pop) = UPPER('79bcdc8a4a4f99e7c111111111111111') order by order_date DESC Index Scan using transactions_pop_i on transactions (cost=0.00..11351.72 rows=2879 width=33) --------------------------------------------------------------------------------------- We have postgresql-7.3.2-3. Thank you, Alexandra