~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/func.cc

  • 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:
23
23
#include <drizzled/sql_list.h>
24
24
 
25
25
#include <drizzled/function/math/int.h>
26
 
#include <drizzled/field/int32.h>
27
 
#include <drizzled/field/int64.h>
 
26
#include <drizzled/field/int64_t.h>
 
27
#include <drizzled/field/long.h>
28
28
#include <drizzled/field/double.h>
29
29
#include <drizzled/field/decimal.h>
30
30
#include <drizzled/session.h>
63
63
  _session(*current_session),
64
64
  allowed_arg_cols(1)
65
65
{
66
 
  collation.set(DERIVATION_SYSCONST);
67
66
  set_arguments(list);
68
67
}
69
68
 
87
86
    }
88
87
    memcpy(args, item->args, sizeof(Item*)*arg_count);
89
88
  }
90
 
  collation.set(DERIVATION_SYSCONST);
91
89
}
92
90
 
93
91
 
454
452
 
455
453
Field *Item_func::tmp_table_field(Table *table)
456
454
{
457
 
  Field *field= NULL;
 
455
  Field *field;
458
456
 
459
457
  switch (result_type()) {
460
458
  case INT_RESULT:
461
459
    if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
462
 
      field= new field::Int64(max_length, maybe_null, name, unsigned_flag);
 
460
      field= new Field_int64_t(max_length, maybe_null, name, unsigned_flag);
463
461
    else
464
 
      field= new field::Int32(max_length, maybe_null, name, unsigned_flag);
 
462
      field= new Field_long(max_length, maybe_null, name, unsigned_flag);
465
463
    break;
466
 
 
467
464
  case REAL_RESULT:
468
465
    field= new Field_double(max_length, maybe_null, name, decimals);
469
466
    break;
470
 
 
471
467
  case STRING_RESULT:
472
468
    return make_string_field(table);
473
 
 
474
469
  case DECIMAL_RESULT:
475
470
    field= new Field_decimal(my_decimal_precision_to_length(decimal_precision(),
476
471
                                                            decimals,
481
476
                             unsigned_flag);
482
477
    break;
483
478
  case ROW_RESULT:
 
479
  default:
484
480
    // This case should never be chosen
485
481
    assert(0);
 
482
    field= 0;
486
483
    break;
487
484
  }
488
 
 
489
485
  if (field)
490
486
    field->init(table);
491
 
 
492
487
  return field;
493
488
}
494
489
 
625
620
 
626
621
void Item_func::signal_divide_by_null()
627
622
{
628
 
  my_error(ER_DIVISION_BY_ZERO, MYF(0));
629
 
  null_value= 0;
 
623
  push_warning(getSessionPtr(), DRIZZLE_ERROR::WARN_LEVEL_ERROR, ER_DIVISION_BY_ZERO, ER(ER_DIVISION_BY_ZERO));
 
624
  null_value= 1;
630
625
}
631
626
 
632
627