[BUGS] Strange influence of default_statistics_target - Mailing list pgsql-bugs

From Вадим Акбашев
Subject [BUGS] Strange influence of default_statistics_target
Date
Msg-id CALoKji-qHPvXAL7omEoB0n2g5WudFDmqXf3tsMBUwYdtiiQRVA@mail.gmail.com
Whole thread Raw
Responses Re: [BUGS] Strange influence of default_statistics_target  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Hello!
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

Attachment

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [BUGS] Bug in Physical Replication Slots (at least 9.5)?
Next
From: Joel Sanger
Date:
Subject: [BUGS] BUG #14263: Query planner is slow to plan UPDATE on a table with many partitions