Bug #13126 | join among several tables returns empty set | ||
---|---|---|---|
Submitted: | 13 Sep 2005 3:12 | Modified: | 9 Nov 2005 3:07 |
Reporter: | Timothy Smith | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 5.0.12 | OS: | Any (any) |
Assigned to: | Sergey Petrunya | CPU Architecture: | Any |
[13 Sep 2005 3:12]
Timothy Smith
[13 Sep 2005 3:13]
Timothy Smith
complete test case showing the bug
Attachment: bug2.sql (application/octet-stream, text), 13.55 KiB.
[13 Sep 2005 3:40]
Timothy Smith
I forgot to mention a small detail, and maybe it's not important. One time I tested this, with the customer's actual data, I would get 35 results from the query that ands with "join foo" (with no ON clause for final join). But I got 0 results when I added an ON clause (I should have gotten 7 rows back). I can't seem to repeat that exact behavior now, unfortunately. But I thought I should mention it, in case it helps. Timothy
[29 Sep 2005 21:58]
Sergey Petrunya
BUG#13452 seems to be the same problem, so that bug is a duplicate of this one.
[30 Sep 2005 6:28]
Timour Katchaounov
A smaller test query is: select count(*) from ((h left join (j join k on (j.w=0 and j.x=k.x) join i on (k.o=i.o and j.o=k.o)) on h.h = k.h) join e on h.h = e.q) join c where e.q = c.q; To make the query work it is sufficient to change the last join to a straigh_join which forces a different join order.
[7 Oct 2005 13:03]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/internals/30814
[25 Oct 2005 15:24]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/internals/31458
[1 Nov 2005 5:32]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/internals/31716
[7 Nov 2005 4:08]
Sergey Petrunya
The fix has been pushed into 5.0.16 tree. Notes for the changelog: for queries with nested outer joins the optimizer could choose join orders that the executioner could not handle. The fix is that now optimizer doesn't choose such join orders.
[9 Nov 2005 3:07]
Paul DuBois
Noted in 5.0.16 changelog.
[9 Feb 2006 9:03]
Aaron Fischer
Hello. I've upgraded to 5.0.18, which includes the fix to this bug. However, the bug remains. Most NATURAL JOINs still return the empty set; (explicitly writing the NATURAL JOIN as a JOIN works just fine). Is there a way to verify my branch has the correct version of this fix? Or to verify that the original fix indeed works in all cases? Please advise. Thanks!
[9 Feb 2006 14:35]
Sergey Petrunya
Aaron, The code released as 5.0.18 includes the fix for *this* bug. However this bug happened irrespectively of whether one used NATURAL JOIN syntax or specified field equalities explicitly. If you're getting wrong results only with NATURAL JOIN syntax, it seems like you're hitting some other issue. Could you please report a new bug and provide there a test case (table creation/fill statements and a query that produces wrong results)? Thanks in advance.
[16 Apr 2006 8:56]
Aaron Fischer
Sergey, thanks for replying. Turns out this was my (extremely foolish) error. I had a common TIMESTAMP attribute named '_last_modified_date' in all my tables. A natural join would (naturally) try to match on this commonly named attribute across two tables -- and being a timestamp, no wonder I kept getting the empty set. The explicit inner joins I was trying omited this attribute (didn't even cross my mind).