From: Tom Lane <tgl@sss.pgh.pa.us>
To: Вадим Акбашев <ufaowl@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Strange influence of default_statistics_target
Date: Wed, 18 Jan 2017 09:18:29 -0500
Message-ID: <13996.1484749109@sss.pgh.pa.us> (raw)
In-Reply-To: <CALoKji-qHPvXAL7omEoB0n2g5WudFDmqXf3tsMBUwYdtiiQRVA@mail.gmail.com>
References: <CALoKji-qHPvXAL7omEoB0n2g5WudFDmqXf3tsMBUwYdtiiQRVA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
=?UTF-8?B?0JLQsNC00LjQvCDQkNC60LHQsNGI0LXQsg==?= <ufaowl@gmail.com> writes:
> I have encountered a problem with querry plan building:
> I'd set default_statistics_target=700, run analyze. Postgres optimize had
> chosen plan with hash_join and it took ~1 min for qerry to complete.
> Then i set default_statistics_target=500 and the plan was significantly
> changed and was using merge_join instead, complition time reduced in
> hundreds times, cost reduced drastically.
> Now i can't understand why more precise statistics leads to less optimized
> plan and what is the right way to use default_statistics_target parameter?
> I attach both good and bad querry plans and the querry itself
Are those really the same query? Plan 2 is enforcing a "number_value IS
NOT NULL" condition on "attribute_value av1" that I don't see in plan 1.
And neither plan seems to have much to do with the query, since the
query has UNIONs that aren't in the plans.
But the short answer seems to be that in both cases, the only reason that
the plan doesn't take forever to run is that one sub-join chances to yield
precisely zero rows, and the PG executor happens to be more efficient
about that corner case in the one plan shape than the other. The planner
doesn't take the possibility of that short-circuit happening into account,
since it generally cannot be sure that a sub-join wouldn't yield any rows.
So it's just luck that one plan is noticeably faster in this case.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, ufaowl@gmail.com
Subject: Re: Strange influence of default_statistics_target
In-Reply-To: <13996.1484749109@sss.pgh.pa.us>
References: <CALoKji-qHPvXAL7omEoB0n2g5WudFDmqXf3tsMBUwYdtiiQRVA@mail.gmail.com> <13996.1484749109@sss.pgh.pa.us>
* 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