pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <david.rowley@2ndquadrant.com>
To: Mitar <mmitar@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Optimizing the same PREPAREd static query (without parameters)
Date: Mon, 7 Jan 2019 21:44:14 +1300
Message-ID: <CAKJS1f8E_LU7RtsCuN+ezFBLXTZLf3726aNDf6McaUw3twGd3g@mail.gmail.com> (raw)
In-Reply-To: <CAKLmikMPAZHJRON5CUviVysDvaiSQeOduWjCbUC2G89Shs=r+A@mail.gmail.com>
References: <CAKLmikOWUkVGB6sG5BC6DeiWDjMn1A4DLDX32h+3Mppj=YonWQ@mail.gmail.com>
	<CAKJS1f-oH6BOMgfDMveMd69TDuaxVn8eK0+eWmBv1s9bDmPV-g@mail.gmail.com>
	<CAKLmikMPAZHJRON5CUviVysDvaiSQeOduWjCbUC2G89Shs=r+A@mail.gmail.com>

On Mon, 7 Jan 2019 at 21:40, Mitar <mmitar@gmail.com> wrote:
>
> On Mon, Jan 7, 2019 at 12:09 AM David Rowley
> <david.rowley@2ndquadrant.com> wrote:
> > On Mon, 7 Jan 2019 at 18:54, Mitar <mmitar@gmail.com> wrote:
> > > If I have a PREPAREd query without parameters (static) and I EXECUTE
> > > it repeatedly in the same session, does PostgreSQL learn/optimize
> > > anything across those runs?
> >
> > Yes, it will generate the query plan on the first invocation of
> > EXECUTE and use that plan for all subsequent EXECUTEs for the session
> > until you DEALLOCATE the prepared query or DISCARD PLANS/ALL;
>
> So this sounds more like no? So the same plan is used, so PostgreSQL
> is not further optimizing the plan based on any statistics or
> anything?

You asked if it learned anything. I mentioned that it learns the query
plan, so I'd have said "Yes".

If you're asking if it caches the result and foregoes scanning the
underlying tables, then that's a  "No". Else what further optimising
did you have in mind?

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services




view thread (6+ messages)  latest in thread

Message-ID: <CAKJS1f8E_LU7RtsCuN+ezFBLXTZLf3726aNDf6McaUw3twGd3g@mail.gmail.com>
Permalink:  ../CAKJS1f8E_LU7RtsCuN+ezFBLXTZLf3726aNDf6McaUw3twGd3g@mail.gmail.com/
Also on:    postgresql.org/message-id/CAKJS1f8E_LU7RtsCuN+ezFBLXTZLf3726aNDf6McaUw3twGd3g@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: david.rowley@2ndquadrant.com, mmitar@gmail.com
  Subject: Re: Optimizing the same PREPAREd static query (without parameters)
  In-Reply-To: <CAKJS1f8E_LU7RtsCuN+ezFBLXTZLf3726aNDf6McaUw3twGd3g@mail.gmail.com>
  References: <CAKLmikOWUkVGB6sG5BC6DeiWDjMn1A4DLDX32h+3Mppj=YonWQ@mail.gmail.com> <CAKJS1f-oH6BOMgfDMveMd69TDuaxVn8eK0+eWmBv1s9bDmPV-g@mail.gmail.com> <CAKLmikMPAZHJRON5CUviVysDvaiSQeOduWjCbUC2G89Shs=r+A@mail.gmail.com> <CAKJS1f8E_LU7RtsCuN+ezFBLXTZLf3726aNDf6McaUw3twGd3g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox