Re:

From: greg(at)turnstep(dot)com
To: pgsql-novice(at)postgresql(dot)org
Subject: Re:
Date: 2003-02-07 15:48:59
Message-ID: e91b9b910af6b8a02eab889ac4f78075@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Greg Sabino Mullane (in the other thread) suggested the following alternate,
> but it ran slightly slower on my machine than the original.
>
> SELECT id, date, value FROM sample a WHERE date <='2003-01-01' AND oid =
> (SELECT oid FROM sample WHERE id = a.id AND DATE <='2003-01-01' ORDER BY
> date DESC LIMIT 1)
> ORDER BY id;

You should check this again. There is no way that my query is slower, as
long as you have an index on the "date" column and have run an ANALYZE on
the "sample" table. Try running these:

ANALYZE sample;
CREATE INDEX sample_date on sample(date);
EXPLAIN <the query above>;

...and make sure that it is hitting the sample_date index. I also just
realized that if you have pre-existing indexes, they may be slowing my
query down (e.g. one on "date" *and* "id"). Make sure that the explain
above only uses the sample_date index.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200302071047

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE+Q9VdvJuQZxSWSsgRAjHVAJwP6Qw4L+gOpfCC6yYkgIgJjzkcZQCggZ1y
2ckvZhgeUpQYOByPxHNKOmk=
=ix4n
-----END PGP SIGNATURE-----

In response to

  • Re: at 2003-02-06 21:45:51 from Scott Morrison

Responses

  • Re: at 2003-02-08 08:35:39 from Andrew McMillan

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel Schuchardt 2003-02-07 16:52:34 Re: "function has no parameter $1" - help.
Previous Message Tom Lane 2003-02-07 14:51:08 Re: Database access problem : SOS