~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/having.test

  • Committer: Stewart Smith
  • Date: 2010-08-12 16:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: stewart@flamingspork.com-20100812164846-s9bhy47g60bvqs41
bug lp:611379 Equivalent queries with Impossible where return different results

The following two equivalent queries return different results in maria 5.2 and 5.3 (and identical results in mysql 5.5.5) :

SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` ;

SELECT * FROM ( SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` );

MariaDB returns 0 on the second query and NULL on the first, whereas MySQL returns NULL on both. In MariaDB, both EXPLAIN plans agree that "Impossible WHERE noticed after reading const tables"



We have some slightly different output in drizzle:

main.bug_lp611379 [ fail ]
drizzletest: At line 9: query 'explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
as t' failed: 1048: Column 'sum(distinct t1.a)' cannot be null

but the fix gets us the correct query results, although with slightly different execution plans.



This fix is directly ported from MariaDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
select count(*) as count_col1 from t1 group by col1 having col1 = 10;
208
208
select count(*) as count_col1 from t1 as tmp1 group by col1 having col1 = 10;
209
209
select count(*) from t1 group by col2 having col2 = 'hello';
210
 
--error ER_BAD_FIELD_ERROR
 
210
--error 1054
211
211
select count(*) from t1 group by col2 having col1 = 10;
212
212
select col1 as count_col1 from t1 as tmp1 group by col1 having col1 = 10;
213
213
select col1 as count_col1 from t1 as tmp1 group by col1 having count_col1 = 10;
221
221
select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having count_col1 = 10;
222
222
select col1 as count_col1,col2 from t1 as tmp1 group by col1,col2 having col2 = 'hello';
223
223
select col1 as count_col1,col2 as group_col2 from t1 as tmp1 group by col1,col2 having group_col2 = 'hello';
224
 
--error ER_PARSE_ERROR
 
224
--error 1064
225
225
select sum(col1) as co12 from t1 group by col2 having col2 10; 
226
226
select sum(col1) as co2, count(col2) as cc from t1 group by col1 having col1 =10; 
227
 
--error ER_BAD_FIELD_ERROR
 
227
--error 1054
228
228
select t2.col2 from t2 group by t2.col1, t2.col2 having t1.col1 <= 10;
229
229
 
230
230
 
273
273
 
274
274
# nested queries with HAVING, inner having column resolved in outer FROM clause
275
275
# the outer having column is not referenced in GROUP BY which results in an error
276
 
--error ER_BAD_FIELD_ERROR
 
276
--error 1054
277
277
select t1.col1 from t1
278
278
where t1.col2 in 
279
279
      (select t2.col2 from t2 
302
302
# correlated subqueries - inner having column 't1.col2' resolves to
303
303
# the outer FROM clause, which cannot be used because the outer query
304
304
# is grouped
305
 
--error ER_BAD_FIELD_ERROR
 
305
--error 1054
306
306
select sum(col1) from t1
307
307
group by col_t1
308
308
having col_t1 in (select sum(t2.col1) from t2
318
318
#
319
319
# queries with joins and ambiguous column names
320
320
#
321
 
--error ER_NON_UNIQ_ERROR
 
321
--error 1052
322
322
select t1.col1, t2.col1 from t1, t2 where t1.col1 = t2.col1
323
323
group by t1.col1, t2.col1 having col1 = 2;
324
324
 
325
 
--error ER_NON_UNIQ_ERROR
 
325
--error 1052
326
326
select t1.col1*10+t2.col1 from t1,t2 where t1.col1=t2.col1
327
327
group by t1.col1, t2.col1 having col1 = 2;
328
328
 
352
352
 
353
353
select count(s1) from t1 group by s1 having s1*0=0;
354
354
 
355
 
--error ER_NON_UNIQ_ERROR
 
355
-- error 1052
356
356
select * from t1 a, t1 b group by a.s1 having s1 is null;
357
357
# ANSI requires: 0 rows
358
358
# MySQL returns: