use mysql; --disable_warnings drop table if exists t1, t2; --enable_warnings create table t1 ( b varchar(30) ) ENGINE = MYISAM ; create table t2 ( b varchar(30) ) ENGINE = BDB ; commit ; set @arg00='two' ; ###### statements for comparison purposes ### case 1: outer table(empty), inner table(empty), variable select 1 as my_column FROM t2 where exists ( select 1 from t1 where b = @arg00 ) ; insert into t1 values ('one'); commit; ### case 2: outer table(empty), inner table(non empty), variable select 1 as my_column FROM t2 where exists ( select 1 from t1 where b = @arg00 ) ; ### case 3: outer table(non empty), inner table(empty), no variable select 1 as my_column FROM t1 where exists ( select 1 from t2 where b = 'two' ) ; ### problem : outer table(non empty), inner table(empty), variable select 1 as my_column FROM t1 where exists ( select 1 from t2 where b = @arg00 ) ; # The (incomplete) property matrix # remark outer table inner table use of variable problem # case 1: empty empty YES NO # case 2: empty non empty YES NO # case 3: non empty empty NO NO # problem : non empty empty YES YES # BTW: The effect will not change if # - I replace t1 with t2 (work on the same physical table) # or - the constant 1 is replaced with a column from the outer table. # My assumptions: # - The problem occurs during execution of the statement, when the server # already knows that that the outer table is not empty. # - The behaviour is very strange, because it depends on the use of the # variable. # - The problem depends on the use of the BDB table handler for the table t2. # If I replace BDB with MYISAM, the problem disappears.