Joinutility seperatorLogin utility separator Infobright.com
   
 
Strange behaviour of query with left join on subquery
Posted: 08 July 2009 11:08 AM   Ignore ]  
Newbie
Rank
Total Posts:  2
Joined  2009-05-05

Hi,
I’ve some problems with queries having left join with subselect.
Let me explain with a simple example.
Let dummy(a int) and dummy2(a int) two tables.
Let’s insert the value 0 into the table dummy.

mysqlselect from dummy;
+------+
a    |
+------+
|    
|
+------+ 

The following query returns correctly the value

mysqlselect from dummy a left join dummy2 as b on a.a=b.a;
+------+------+
a    a    |
+------+------+
|    
NULL |
+------+------+ 

while this one

mysqlselect from dummy a left join (select a from dummy2) as b on a.a=b.a;
Empty 
set (0.03 sec

gives empty set, that’s should be wrong.
I think that this could be a bug.

I did implement the following workaround

mysqlselect from dummy a left join (select -as a from dummy union all select a from dummy2) as b on a.a=b.a;
+------+------+
a    a    |
+------+------+
|    
NULL |
+------+------+ 

I’ve tried the same queries with another dbms and it works.
Best greetings,
Salvo Nicotra

Profile
 
Posted: 09 July 2009 10:31 AM   Ignore ]   [ # 1 ]  
Sr. Member
Avatar
RankRankRankRank
Total Posts:  453
Joined  2008-08-18

Hello Salvo,

This is a bug. We identified it some time ago.

Actually, it’s related specifically to:

select a from dummy2

where dummy2 is an empty table.

Apologies! It is fixed in the next release, which is going to be available soon.

Best greetings,

Dominik

Signature 
Profile
 
Posted: 09 July 2009 10:58 AM   Ignore ]   [ # 2 ]  
Newbie
Rank
Total Posts:  2
Joined  2009-05-05

Hello Dominik,
thank you very much for quick reply.

Dominik Slezak - 09 July 2009 10:31 AM

Hello Salvo,
This is a bug. We identified it some time ago.
Actually, it’s related specifically to:

select a from dummy2

where dummy2 is an empty table.

May be it can be useful to notice that it seems that the problem also appears if the subquery gives empty set,
not only if the table is empty.
For example select from dummy that contains only “0” values

mysqlselect from dummy a left join (select a from dummy where a=3) as b on a.a=b.a;
Empty 
set (0.03 sec

Apologies! It is fixed in the next release, which is going to be available soon.
Best greetings,
Dominik

Great.
Bye
Salvo

Profile
 
Posted: 09 July 2009 03:08 PM   Ignore ]   [ # 3 ]  
Sr. Member
Avatar
RankRankRankRank
Total Posts:  453
Joined  2008-08-18

Hello Salvo,

salvo.nicotra - 09 July 2009 10:58 AM

May be it can be useful to notice that it seems that the problem also appears if the subquery gives empty set, not only if the table is empty.

Yes, this is precisely the description of the bug.

Salvo, I hope that you’ll be able to apply a workaround for a while and then you’ll be able to switch smoothly to the next release.

Best greetings,

Dominik

Signature 
Profile
 
Posted: 18 August 2009 08:51 AM   Ignore ]   [ # 4 ]  
Newbie
Rank
Total Posts:  5
Joined  2009-08-18

Apologies! It is fixed in the next release, which is going to be available soon.

Can you please confirm which release this fix was available from? I notice v3.2 (RC1) is now available, but I’ve been unable to find detailed enough release notes to determine if this fix is included.

Many Thanks

Mark.

Profile
 
Posted: 18 August 2009 08:59 AM   Ignore ]   [ # 5 ]  
Sr. Member
Avatar
RankRankRankRank
Total Posts:  453
Joined  2008-08-18

Hello Mark,

It should work in 3.2 RC1.

Best greetings,

Dominik

Signature 
Profile
 
Posted: 20 August 2009 12:33 PM   Ignore ]   [ # 6 ]  
Jr. Member
RankRank
Total Posts:  94
Joined  2008-08-18

Hi,

I tried it on 3.2RC1, and it works.

Thanks

[ Edited: 20 August 2009 01:31 PM by Wayne Xie]
Profile