On Sun, 2002-05-19 at 06:32, Keary Suska wrote:
>
> The drawback to using LIMIT is that you are executing the query on every
> call, and Postgres cannot optimize on a LIMIT as was mentioned, because the
> entire query has to be collected before the LIMIT can be applied. However,
> IIRC, Postgres does query result caching, so subsequent calls on the same
> query will tend to be faster, providing there is enough memory allocated to
> support it.
PostgreSQL will certainly take LIMIT into account when planning queries.
EXPLAIN SELECT * FROM mybigtable WHERE x = y;
and
EXPLAIN SELECT * FROM mybigtable WHERE x = y LIMIT n;
Will regularly show different query plans.
For more complex queries, however, the plans are less likely to differ
by much.
OTOH PostgreSQL does _not_ do result caching, unless you have applied
some patches that were floating around last year some time.
Regards,
Andrew.
--
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
Are you enrolled at http://schoolreunions.co.nz/ yet?