Re: slow SELECT ... LIMIT query - Mailing list pgsql-general

From Tom Lane
Subject Re: slow SELECT ... LIMIT query
Date
Msg-id 23919.995560595@sss.pgh.pa.us
Whole thread Raw
In response to RE: slow SELECT ... LIMIT query  ("Simon Stanlake" <stanlake@hi.ca>)
List pgsql-general
"Simon Stanlake" <stanlake@hi.ca> writes:
> can anyone tell me what slowed down the first query?

Well, the first one is going to scan (backwards) in datetimestamp order
until it finds a row with unitid = 2.  The second one is going to use
the unitid index to pick out just the rows with unitid = 2, and then
sort them by timestamp.  Depending on how many rows have unitid = 2
and how new the latest one is, I could see either of these being way
faster than the other.

            regards, tom lane

pgsql-general by date:

Previous
From: "Simon Stanlake"
Date:
Subject: RE: slow SELECT ... LIMIT query
Next
From: Kenneth Been
Date:
Subject: many tables in db