From: | Neil Conway <neilc(at)samurai(dot)com> |
---|---|
To: | Harald Krake <harald(at)krake(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: prepared statements and analyze in 7.3 |
Date: | 2002-12-17 16:34:29 |
Message-ID: | 1040142869.456.72.camel@tokyo |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, 2002-12-16 at 11:32, Harald Krake wrote:
> does an ANALYZE invalidate the cached query plans of prepared statements?
No.
> I wonder whether I have to re-prepare after an ANALYZE for long running
> prepared statements to benefit from possibly optimized query plans.
Yes, you'll have to.
Note also that the query plan produced by 'EXPLAIN <statement>' is not
necessarily the same one that will be used when the statement is
prepared (due to the absence of literals in the prepared query). As the
PREPARE reference page notes:
In some situations, the query plan produced by PostgreSQL for a prepared
query may be inferior to the plan produced if the query were submitted
and executed normally. This is because when the query is planned (and
the optimizer attempts to determine the optimal query plan), the actual
values of any parameters specified in the query are unavailable.
PostgreSQL collects statistics on the distribution of data in the table,
and can use constant values in a query to make guesses about the likely
result of executing the query. Since this data is unavailable when
planning prepared queries with parameters, the chosen plan may be
sub-optimal.
Cheers,
Neil
--
Neil Conway <neilc(at)samurai(dot)com> || PGP Key ID: DB3C29FC
From | Date | Subject | |
---|---|---|---|
Next Message | Zengfa Gao | 2002-12-17 17:10:14 | JDBC, PgSQL 7.2: transactions not supported!! |
Previous Message | Neil Conway | 2002-12-17 16:31:52 | Re: 7.3 Prepared statements |