From: Alex <cdalxndr@yahoo.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@lists.postgresql.org, Pavel Stehule <pavel.stehule@gmail.com>
Subject: Re: BUG #15618: Duplicating a join clause breaks index use
Date: Sat, 2 Feb 2019 15:53:30 +0000 (UTC)
Message-ID: <602024371.2009661.1549122810083@mail.yahoo.com> (raw)
In-Reply-To: <23837.1549120085@sss.pgh.pa.us>
References: <15618-5357e448d7cbeb27@postgresql.org>
<CAFj8pRAFqKsQcyLfrzm2NAfuEvDMk8mV+6TsxF5UrhGKgv2opg@mail.gmail.com>
<378349148.1969803.1549109284822@mail.yahoo.com>
<23837.1549120085@sss.pgh.pa.us>
Indeed, increasing those two parameter values results in a fast query.
With default values, the planning time is ~2ms but execution time is ~4600ms.With increased values, the planning time increases by 0.5ms (2.5ms) but execution time drops to 0.7ms (aprox x6000 faster).
As the impact on the execution time is very high, shouldn't another mechanism be used instead of parameters join_collapse_limit or from_collapse_limit, such as some maximum planning time?
With a maximum planning time, faster machines will benefit from better query planning.
Another suggestion is to run a benchmark on the machine to automatically determine some good values, and attach hardware info to the results, to recompute in case hardware changes (although hdd performance may degrade with fragmentation and ssd with space occupied).
On Saturday, February 2, 2019, 5:08:15 PM GMT+2, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Alex <cdalxndr@yahoo.com> writes:
> select
> ...
> from
> product p
> left outer join product_property pp on p.id=pp.product_id
> left outer join product_property_value ppv on pp.value_id=ppv.id
> left outer join description_element de on pp.description_source=de.id
> left outer join description_value dev on de.description_value_id=dev.id
> left outer join description_element dep on de.parent=dep.id
> left outer join description_value depv on dep.description_value_id=depv.id
> left outer join shop_category sc_dup on p.shop_category=sc_dup.id --duplicate join
> left outer join shop_category sc on p.shop_category=sc.id
> left outer join category c on sc.category=c.id
> where
> c.id=8511
I suspect the real issue here has little to do with the "duplicate" nature
of the extra join, and a lot to do with the fact that your query exceeds
join_collapse_limit. That causes the planner to break it up in a
semi-arbitrary way to limit planning time. Adding one more join moves
where the break happens, and evidently is preventing the planner from
discovering a good join order.
You want join_collapse_limit to be at least 10 to handle this query well,
since 10 tables are mentioned. The default value, 8, is kinda tuned for
older and slower machines than most of us use today. I wouldn't make it
enormous, because it does prevent exponential planning time growth for
many tables, but you could likely get away with 15 or so. You should
likely keep from_collapse_limit in sync with that too.
regards, tom lane
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: cdalxndr@yahoo.com, tgl@sss.pgh.pa.us, pavel.stehule@gmail.com
Subject: Re: BUG #15618: Duplicating a join clause breaks index use
In-Reply-To: <602024371.2009661.1549122810083@mail.yahoo.com>
References: <15618-5357e448d7cbeb27@postgresql.org> <CAFj8pRAFqKsQcyLfrzm2NAfuEvDMk8mV+6TsxF5UrhGKgv2opg@mail.gmail.com> <378349148.1969803.1549109284822@mail.yahoo.com> <23837.1549120085@sss.pgh.pa.us> <602024371.2009661.1549122810083@mail.yahoo.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