X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9F69852906 for ; Mon, 13 Jun 2005 11:54:51 -0300 (ADT) 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 41812-01 for ; Mon, 13 Jun 2005 14:54:49 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id C8840528E0 for ; Mon, 13 Jun 2005 11:54:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j5DEsqYW019855; Mon, 13 Jun 2005 10:54:52 -0400 (EDT) To: Alex Stapleton Cc: pgsql-performance@postgresql.org Subject: Re: PostgreSQL using the wrong Index In-reply-to: <2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.com> References: <2D1A68BF-B3A4-490E-8053-3CF6626B8DAF@advfn.com> Comments: In-reply-to Alex Stapleton message dated "Mon, 13 Jun 2005 14:02:30 +0100" Date: Mon, 13 Jun 2005 10:54:52 -0400 Message-ID: <19854.1118674492@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/292 X-Sequence-Number: 12929 Alex Stapleton writes: > l1_historical=# \d "N_intra_pkey" > Index "N_intra_pkey" > Column | Type > --------+----------------------------- > symbol | text > time | timestamp without time zone > unique btree (primary key) > and on queries like this > select * from "N_intra" where symbol='SOMETHING WHICH DOESNT EXIST' > order by time desc limit 1; This was just covered in excruciating detail yesterday ... You need to write order by symbol desc, time desc limit 1 to get the planner to recognize the connection to the sort order of this index. Since you're only selecting one value of symbol, the actual output doesn't change. > Oh, we are running 7.4.2 btw. And our random_page_cost = 1 I'll bet lunch that that is a bad selection of random_page_cost, unless your database is so small that it all fits in RAM. regards, tom lane