Re: When does Postgres cache query plans?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mike Christensen <mike(at)kitchenpc(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: When does Postgres cache query plans?
Date: 2012-09-05 22:51:10
Message-ID: 15600.1346885470@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Mike Christensen <mike(at)kitchenpc(dot)com> writes:
> I'm curious under what circumstances Postgres will cache an execution
> plan for a query.

If you're writing raw SQL, never. The assumption is that the
application knows its usage pattern a lot better than the server does,
and if the application is going to re-execute the same/similar statement
a lot of times, the app ought to make use of a prepared statement for
that.

Some client-side code (such as the JDBC driver) will make use of
prepared statements under the hood, so a lot depends on context.
But sending plain SQL with PQexec() does not result in any cached plan.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sergio Basurto 2012-09-05 23:02:49 Re: regexp_matches question
Previous Message Edson Richter 2012-09-05 22:47:23 Re: Moving several databases into one database with several schemas