Re: BUG #3865: ERROR: failed to build any 8-way joins

Lists: pgsql-bugs
From: "Oleg Kharin" <ok(at)uvadrev(dot)udmnet(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3865: ERROR: failed to build any 8-way joins
Date: 2008-01-09 18:07:55
Message-ID: 200801091807.m09I7tMY098525@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3865
Logged by: Oleg Kharin
Email address: ok(at)uvadrev(dot)udmnet(dot)ru
PostgreSQL version: 8.2.6
Operating system: CentOS 5.1 x86 64-bit
Description: ERROR: failed to build any 8-way joins
Details:

After PostgreSQL 8.2.5 to 8.2.6 upgrade there is a query that generates:
ERROR: failed to build any 8-way joins.

The text of the query is rather big. It will be better to attach its text as
a file as well as the SQL script that creates a test case. But I don't know
how to post a file in the bug report form.

Oleg


From: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
To: Oleg Kharin <ok(at)uvadrev(dot)udmnet(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3865: ERROR: failed to build any 8-way joins
Date: 2008-01-09 19:30:33
Message-ID: 478520D9.8020607@kaltenbrunner.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Oleg Kharin wrote:
> The following bug has been logged online:
>
> Bug reference: 3865
> Logged by: Oleg Kharin
> Email address: ok(at)uvadrev(dot)udmnet(dot)ru
> PostgreSQL version: 8.2.6
> Operating system: CentOS 5.1 x86 64-bit
> Description: ERROR: failed to build any 8-way joins
> Details:
>
> After PostgreSQL 8.2.5 to 8.2.6 upgrade there is a query that generates:
> ERROR: failed to build any 8-way joins.
>
> The text of the query is rather big. It will be better to attach its text as
> a file as well as the SQL script that creates a test case. But I don't know
> how to post a file in the bug report form.

you can simply reply to this mail and attach a testcase or post it on a
website for download - but we will definitly need a testcase for that ...

Stefan


From: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
To: Oleg Kharin <ok(at)uvadrev(dot)udmnet(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3865: ERROR: failed to build any 8-way joins
Date: 2008-01-10 07:48:37
Message-ID: 4785CDD5.5070702@kaltenbrunner.cc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

[RESENDING because the attachments seems to have caused the mail to
disappear]

Oleg Kharin wrote:
> Hi, Stefan

Hi Oleg!

I have readded the list and the testcases to the CC so that others can
participate in the discussion too ...

>
> init826.sql builds necessary tables and indexes. The test query is in
> the file query826.sql.

I can confirm that this works on 8.2.5 but fails:

* on -HEAD
* on 8.2.6 (so we have a rather bad regression)

with a join_collaps_limit > 3 and < 10 - you could increase that on your
box but it is likely that other queries are affected in a different way
so it might not help at all.

the testcase from oleg is available on:

http://www.kaltenbrunner.cc/files/init826.sql (DDL)
http://www.kaltenbrunner.cc/files/query826.sql (Query)

Stefan


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>
Cc: Oleg Kharin <ok(at)uvadrev(dot)udmnet(dot)ru>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3865: ERROR: failed to build any 8-way joins
Date: 2008-01-10 22:00:02
Message-ID: 10957.1200002402@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc> writes:
> I can confirm that this works on 8.2.5 but fails:
> * on -HEAD
> * on 8.2.6 (so we have a rather bad regression)

> with a join_collaps_limit > 3 and < 10 - you could increase that on your
> box but it is likely that other queries are affected in a different way
> so it might not help at all.

> the testcase from oleg is available on:
> http://www.kaltenbrunner.cc/files/init826.sql (DDL)
> http://www.kaltenbrunner.cc/files/query826.sql (Query)

I looked into this and found that it's caused by this patch:
http://archives.postgresql.org/pgsql-committers/2007-10/msg00409.php

The problem is that have_join_order_restriction() concludes that we
don't need to force clauseless joins for certain combinations of
relations because it sees that there are available join clauses for one
or both relations. However, in this example (with join_collapse_limit
less than 10) this is happening inside a subset of the total collection
of relations, and the join clauses it's seeing link to relations that
are outside the current subset. The only way to form a plan for the
subset is to do at least one clauseless join, but the code doesn't
explore that path and so fails to form a valid plan.

The most expedient way to fix it seems to be to make
has_legal_joinclause consider, not the set of all relations anywhere
in the query, but just members of the current initial_rels list.
There's a notational problem, which is that that's currently a local
in make_rel_from_joinlist() and not accessible from anywhere near
has_legal_joinclause. We could add a field to PlannerInfo to
pass it down; but I find that a tad ugly :-(

Now in a situation where this is happening, we *know* we are generating
a pretty crummy plan by forcing the clauseless join --- if we'd been
operating with a higher collapse_limit we would have found another plan
not requiring a clauseless join. So a nicer fix would be to somehow
modify the "joinlist" subdivision of the planning problem so that we
don't get backed into this type of corner. I don't currently see any
way to do that though --- at the point where we're setting up the
joinlists, the information is theoretically available but discovering
there's going to be a problem seems to require duplicating a lot of the
subsequent planning work.

In the meantime, the suggestion to raise join_collapse_limit is probably
a reasonable workaround for the OP.

regards, tom lane


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stefan Kaltenbrunner <stefan(at)kaltenbrunner(dot)cc>, Oleg Kharin <ok(at)uvadrev(dot)udmnet(dot)ru>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3865: ERROR: failed to build any 8-way joins
Date: 2008-01-11 05:08:14
Message-ID: 7922.1200028094@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

I wrote:
> The most expedient way to fix it seems to be to make
> has_legal_joinclause consider, not the set of all relations anywhere
> in the query, but just members of the current initial_rels list.

8.2 patch is here, if you need it now:
http://archives.postgresql.org/pgsql-committers/2008-01/msg00164.php

regards, tom lane


From: "Oleg Kharin" <ok(at)uvadrev(dot)udmnet(dot)ru>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #3865: ERROR: failed to build any 8-way joins
Date: 2008-01-14 13:38:02
Message-ID: 001f01c856b2$af7e3330$0e7a9990$@udmnet.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

> 8.2 patch is here, if you need it now:
> http://archives.postgresql.org/pgsql-committers/2008-01/msg00164.php

Thanks. I have applied this patch and everything works fine.

Regards,
Oleg