Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
Closely related to this bug, older versions of MySQL don't handle right joins correctly.
drop table if exists t1,t2,t3;
create table t1 (i int);
create table t2 (i int);
create table t3 (i int);
insert into t1 values(1),(2);
insert into t2 values(2),(3);
insert into t3 values(2),(4);
That sets things up. Now let's try the query:
select t1.i, t2.i, t3.i
from t1
inner join t2 on t2.i = t1.i
right join t3 on t3.i = t2.i;
On 4.0.18 this returns:
+------+------+------+
| i | i | i |
+------+------+------+
| 1 | NULL | 2 |
| 2 | 2 | 2 |
| 1 | NULL | 4 |
| 2 | NULL | 4 |
+------+------+------+
On 5.0.38 this correctly returns:
+------+------+------+
| i | i | i |
+------+------+------+
| 2 | 2 | 2 |
| NULL | NULL | 4 |
+------+------+------+
That's why this SQL, after being fixed, still failed on our production server. I've blown much of today trying to find this bug. Now that I've found it, I don't know how to fix it using only SQL.
It turns out that it's this bug on all versions of MySQL less than version 5. RIGHT JOINs return incorrect results after INNER JOINs.
First thing I'd try (Score:1)
No idea if this actually fixes the problem. Depends on what the query planner turns it into, I guess.
Re: (Score:2)
4.0.18 doesn't allow subqueries.
Re: (Score:1)
Are you sure? ISTR using them in some 4.x version; maybe it was 4.1? Sigh.
Re: (Score:2)
From the MySQL docs [mysql.com]:
Re: (Score:2)
what about LEFT? (Score:1)
Failing that, isn't a RIGHT JOIN just a LEFT JOIN with the table order reversed? If you list the tables in reverse order and use a LEFT JOIN will it work?
Re: (Score:2)
No, because reversing the order gives you this:
That final INNER JOIN excludes the NULL row we need.
Re: (Score:1)
Re: (Score:1)
How… relational.
Re: (Score:1)
Re: (Score:2)
Agreed. It's like taking potshots at Perl 5.005.
Re: (Score:1)
Huh, that was a criticism of MySQL?
Re: (Score:1)
Re: (Score:1)
It just struck me as funny after reading the posts Ovid recently wrote about real relational databases, noting among other things that a select query there returns a bonafide table.
Re: (Score:1)
I understand the frustration since it's sometimes hard to upgrade critical pieces like MySQL or Perl, but how many bugs do you publicly complain about in Perl 5.8.1. Probably not many. You instead use a more recent version without those bugs or you work around them.
At least you don't have a vendor company forcing you to upgrade. Which means you do it at your own pace and consequences. Only you (meaning whatever company you'