Re: Strange influence of default_statistics_target

From: Вадим Акбашев <ufaowl(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Strange influence of default_statistics_target
Date: 2017-01-19 09:11:59
Message-ID: CALoKji93h-tt6u2c9co1pZ0OaiaU--cRL4keAO8M9pP_M-EHXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Sorry, i've forgot to attach files themselves

2017-01-18 19:18 GMT+05:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> =?UTF-8?B?0JLQsNC00LjQvCDQkNC60LHQsNGI0LXQsg==?= <ufaowl(at)gmail(dot)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
>

Attachment Content-Type Size
plan_500 application/octet-stream 12.3 KB
plan_700 application/octet-stream 21.3 KB
query application/octet-stream 7.2 KB
stat_500 application/octet-stream 10.3 KB
stat_700 application/octet-stream 10.6 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2017-01-19 09:37:31 Re: Bug in Physical Replication Slots (at least 9.5)?
Previous Message Michael Paquier 2017-01-19 07:47:47 Re: pg_dump 9.6 doesn't honour pg_extension_config_dump for sequences