Re: Regression in query optimizer when upgrading from 9.4.5 to 9.5.2?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "Erdmann, Markus (at) Bellevue" <Markus(dot)Erdmann(at)cbre(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Regression in query optimizer when upgrading from 9.4.5 to 9.5.2?
Date: 2016-06-20 20:36:26
Message-ID: CAKFQuwZiwhVVUzAF3o4A71R50ymhsOrfysH2ZrEdMCyLoWLpcg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jun 17, 2016 at 5:05 PM, Erdmann, Markus @ Bellevue <
Markus(dot)Erdmann(at)cbre(dot)com> wrote:

> Thank you Tom and David for your very helpful replies. We dumped and
> restored the RDS staging database on a local installation of pg and were
> not able to reproduce the issue in 9.5.2, which led us to try running a
> VACUUM ANALYZE and recreating indexes. After this we no longer saw a
> discrepancy between the query plan in the separate environments. Is this
> what you meant, Tom, by making sure to ANALYZE? Or did you mean including
> ANALYZE in EXPLAIN ANALYZE?
>
>
​Please don't top-post.

Yes, using "[VACUUM] ANALYZE" is what was meant (the VACUUM doesn't hurt -
and possibly helps - but wasn't required). ANALYZE recomputes the
statistics for your database. The apparent problem was that those
statistics were wrong which causes the planner to choose the wrong plan.

EXPLAIN ANALYZE doesn't help in that scenario - the explain and planner
both end up using the bad statistics. The addition of ANALYZE to EXPLAIN
simply tells the system to not only explain your query but to execute it as
well (but discard the results). Aside from sharing the same 7 characters
the two words have nothing in common.

I'm not sure how one would "...includ[e] ANALYZE in EXPLAIN ANALYZE" - you
only get to explain one statement at a time.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Erdmann, Markus @ Bellevue 2016-06-20 22:06:56 Re: Regression in query optimizer when upgrading from 9.4.5 to 9.5.2?
Previous Message David G. Johnston 2016-06-20 20:19:18 Re: Help with namespaces in xpath (PostgreSQL 9.5.3)