Re: PostgreSQL using the wrong Index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alex Stapleton <alexs(at)advfn(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: PostgreSQL using the wrong Index
Date: 2005-06-13 14:54:52
Message-ID: 19854.1118674492@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Alex Stapleton <alexs(at)advfn(dot)com> 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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Alex Stapleton 2005-06-13 15:20:19 Re: PostgreSQL using the wrong Index
Previous Message John A Meinel 2005-06-13 14:51:57 Re: Index ot being used