~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_cmpfunc.cc

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  This file defines all compare functions
22
22
*/
23
23
 
24
 
#include <drizzled/server_includes.h>
25
 
#include <drizzled/sql_select.h>
 
24
#ifdef USE_PRAGMA_IMPLEMENTATION
 
25
#pragma implementation                          // gcc: Class implementation
 
26
#endif
 
27
 
 
28
#include "mysql_priv.h"
 
29
#include <m_ctype.h>
 
30
#include "sql_select.h"
26
31
 
27
32
static bool convert_constant_item(THD *, Item_field *, Item **);
28
33
 
29
34
static Item_result item_store_type(Item_result a, Item *item,
30
 
                                   bool unsigned_flag)
 
35
                                   my_bool unsigned_flag)
31
36
{
32
37
  Item_result b= item->result_type();
33
38
 
42
47
    return INT_RESULT;
43
48
}
44
49
 
45
 
static void agg_result_type(Item_result *type, Item **items, uint32_t nitems)
 
50
static void agg_result_type(Item_result *type, Item **items, uint nitems)
46
51
{
47
52
  Item **item, **item_end;
48
 
  bool unsigned_flag= 0;
 
53
  my_bool unsigned_flag= 0;
49
54
 
50
55
  *type= STRING_RESULT;
51
56
  /* Skip beginning NULL items */
90
95
 
91
96
static int cmp_row_type(Item* item1, Item* item2)
92
97
{
93
 
  uint32_t n= item1->cols();
 
98
  uint n= item1->cols();
94
99
  if (item2->check_cols(n))
95
100
    return 1;
96
 
  for (uint32_t i=0; i<n; i++)
 
101
  for (uint i=0; i<n; i++)
97
102
  {
98
103
    if (item2->element_index(i)->check_cols(item1->element_index(i)->cols()) ||
99
104
        (item1->element_index(i)->result_type() == ROW_RESULT &&
127
132
    0  otherwise
128
133
*/
129
134
 
130
 
static int agg_cmp_type(Item_result *type, Item **items, uint32_t nitems)
 
135
static int agg_cmp_type(Item_result *type, Item **items, uint nitems)
131
136
{
132
 
  uint32_t i;
 
137
  uint i;
133
138
  type[0]= items[0]->result_type();
134
139
  for (i= 1 ; i < nitems ; i++)
135
140
  {
166
171
  @return aggregated field type.
167
172
*/
168
173
 
169
 
enum_field_types agg_field_type(Item **items, uint32_t nitems)
 
174
enum_field_types agg_field_type(Item **items, uint nitems)
170
175
{
171
 
  uint32_t i;
 
176
  uint i;
172
177
  if (!nitems || items[0]->result_type() == ROW_RESULT )
173
178
    return (enum_field_types)-1;
174
179
  enum_field_types res= items[0]->field_type();
194
199
    Bitmap of collected types - otherwise
195
200
*/
196
201
 
197
 
static uint32_t collect_cmp_types(Item **items, uint32_t nitems)
 
202
static uint collect_cmp_types(Item **items, uint nitems)
198
203
{
199
 
  uint32_t i;
200
 
  uint32_t found_types;
 
204
  uint i;
 
205
  uint found_types;
201
206
  Item_result left_result= items[0]->result_type();
202
 
  assert(nitems > 1);
 
207
  DBUG_ASSERT(nitems > 1);
203
208
  found_types= 0;
204
209
  for (i= 1; i < nitems ; i++)
205
210
  {
264
269
  NULL if some arg is NULL.
265
270
*/
266
271
 
267
 
int64_t Item_func_not::val_int()
 
272
longlong Item_func_not::val_int()
268
273
{
269
 
  assert(fixed == 1);
 
274
  DBUG_ASSERT(fixed == 1);
270
275
  bool value= args[0]->val_bool();
271
276
  null_value=args[0]->null_value;
272
277
  return ((!null_value && value == 0) ? 1 : 0);
293
298
*/
294
299
 
295
300
 
296
 
int64_t Item_func_not_all::val_int()
 
301
longlong Item_func_not_all::val_int()
297
302
{
298
 
  assert(fixed == 1);
 
303
  DBUG_ASSERT(fixed == 1);
299
304
  bool value= args[0]->val_bool();
300
305
 
301
306
  /*
302
 
    return true if there was records in underlying select in max/min
 
307
    return TRUE if there was records in underlying select in max/min
303
308
    optimization (ALL subquery)
304
309
  */
305
310
  if (empty_underlying_subquery())
330
335
  Item_func_not_all.
331
336
 
332
337
  @return
333
 
    (return true if underlying subquery do not return rows) but if subquery
334
 
    returns some rows it return same value as argument (true/false).
 
338
    (return TRUE if underlying subquery do not return rows) but if subquery
 
339
    returns some rows it return same value as argument (TRUE/FALSE).
335
340
*/
336
341
 
337
 
int64_t Item_func_nop_all::val_int()
 
342
longlong Item_func_nop_all::val_int()
338
343
{
339
 
  assert(fixed == 1);
340
 
  int64_t value= args[0]->val_int();
 
344
  DBUG_ASSERT(fixed == 1);
 
345
  longlong value= args[0]->val_int();
341
346
 
342
347
  /*
343
 
    return false if there was records in underlying select in max/min
 
348
    return FALSE if there was records in underlying select in max/min
344
349
    optimization (SAME/ANY subquery)
345
350
  */
346
351
  if (empty_underlying_subquery())
386
391
 
387
392
  if (!(*item)->with_subselect && (*item)->const_item())
388
393
  {
 
394
    TABLE *table= field->table;
389
395
    ulong orig_sql_mode= thd->variables.sql_mode;
390
396
    enum_check_fields orig_count_cuted_fields= thd->count_cuted_fields;
391
 
    uint64_t orig_field_val= 0; /* original field value if valid */
 
397
    my_bitmap_map *old_write_map;
 
398
    my_bitmap_map *old_read_map;
 
399
    ulonglong orig_field_val= 0; /* original field value if valid */
392
400
 
 
401
    if (table)
 
402
    {
 
403
      old_write_map= dbug_tmp_use_all_columns(table, table->write_set);
 
404
      old_read_map= dbug_tmp_use_all_columns(table, table->read_set);
 
405
    }
393
406
    /* For comparison purposes allow invalid dates like 2000-01-32 */
394
407
    thd->variables.sql_mode= (orig_sql_mode & ~MODE_NO_ZERO_DATE) | 
395
408
                             MODE_INVALID_DATES;
412
425
    /* Restore the original field value. */
413
426
    if (field_item->depended_from)
414
427
    {
415
 
      result= field->store(orig_field_val, true);
 
428
      result= field->store(orig_field_val, TRUE);
416
429
      /* orig_field_val must be a valid value that can be restored back. */
417
 
      assert(!result);
 
430
      DBUG_ASSERT(!result);
418
431
    }
419
432
    thd->variables.sql_mode= orig_sql_mode;
420
433
    thd->count_cuted_fields= orig_count_cuted_fields;
 
434
    if (table)
 
435
    {
 
436
      dbug_tmp_restore_column_map(table->write_set, old_write_map);
 
437
      dbug_tmp_restore_column_map(table->read_set, old_read_map);
 
438
    }
421
439
  }
422
440
  return result;
423
441
}
465
483
  }
466
484
 
467
485
  thd= current_thd;
468
 
 
469
 
  if (args[0]->real_item()->type() == FIELD_ITEM)
 
486
  if (!thd->is_context_analysis_only())
470
487
  {
471
 
    Item_field *field_item= (Item_field*) (args[0]->real_item());
472
 
    if (field_item->field->can_be_compared_as_int64_t() &&
473
 
        !(field_item->is_datetime() && args[1]->result_type() == STRING_RESULT))
 
488
    if (args[0]->real_item()->type() == FIELD_ITEM)
474
489
    {
475
 
      if (convert_constant_item(thd, field_item, &args[1]))
 
490
      Item_field *field_item= (Item_field*) (args[0]->real_item());
 
491
      if (field_item->field->can_be_compared_as_longlong() &&
 
492
          !(field_item->is_datetime() &&
 
493
            args[1]->result_type() == STRING_RESULT))
476
494
      {
477
 
        cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
478
 
                         INT_RESULT);           // Works for all types.
479
 
        args[0]->cmp_context= args[1]->cmp_context= INT_RESULT;
480
 
        return;
 
495
        if (convert_constant_item(thd, field_item, &args[1]))
 
496
        {
 
497
          cmp.set_cmp_func(this, tmp_arg, tmp_arg+1,
 
498
                           INT_RESULT);         // Works for all types.
 
499
          args[0]->cmp_context= args[1]->cmp_context= INT_RESULT;
 
500
          return;
 
501
        }
481
502
      }
482
503
    }
483
 
 
484
504
    if (args[1]->real_item()->type() == FIELD_ITEM)
485
505
    {
486
506
      Item_field *field_item= (Item_field*) (args[1]->real_item());
487
 
      if (field_item->field->can_be_compared_as_int64_t() &&
 
507
      if (field_item->field->can_be_compared_as_longlong() &&
488
508
          !(field_item->is_datetime() &&
489
509
            args[0]->result_type() == STRING_RESULT))
490
510
      {
510
530
  switch (type) {
511
531
  case ROW_RESULT:
512
532
  {
513
 
    uint32_t n= (*a)->cols();
 
533
    uint n= (*a)->cols();
514
534
    if (n != (*b)->cols())
515
535
    {
516
536
      my_error(ER_OPERAND_COLUMNS, MYF(0), n);
519
539
    }
520
540
    if (!(comparators= new Arg_comparator[n]))
521
541
      return 1;
522
 
    for (uint32_t i=0; i < n; i++)
 
542
    for (uint i=0; i < n; i++)
523
543
    {
524
544
      if ((*a)->element_index(i)->cols() != (*b)->element_index(i)->cols())
525
545
      {
561
581
        which would be transformed to:
562
582
        WHERE col= 'j'
563
583
      */
564
 
      (*a)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
565
 
      (*b)->walk(&Item::set_no_const_sub, false, (unsigned char*) 0);
 
584
      (*a)->walk(&Item::set_no_const_sub, FALSE, (uchar*) 0);
 
585
      (*b)->walk(&Item::set_no_const_sub, FALSE, (uchar*) 0);
566
586
    }
567
587
    break;
568
588
  }
590
610
  {
591
611
    if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
592
612
    {
593
 
      precision= 5 / log_10[cmax((*a)->decimals, (*b)->decimals) + 1];
 
613
      precision= 5 / log_10[max((*a)->decimals, (*b)->decimals) + 1];
594
614
      if (func == &Arg_comparator::compare_real)
595
615
        func= &Arg_comparator::compare_real_fixed;
596
616
      else if (func == &Arg_comparator::compare_e_real)
599
619
    break;
600
620
  }
601
621
  default:
602
 
    assert(0);
 
622
    DBUG_ASSERT(0);
603
623
  }
604
624
  return 0;
605
625
}
627
647
    converted value. 0 on error and on zero-dates -- check 'failure'
628
648
*/
629
649
 
630
 
static uint64_t
631
 
get_date_from_str(THD *thd, String *str, enum enum_drizzle_timestamp_type warn_type,
 
650
static ulonglong
 
651
get_date_from_str(THD *thd, String *str, timestamp_type warn_type,
632
652
                  char *warn_name, bool *error_arg)
633
653
{
634
 
  uint64_t value= 0;
 
654
  ulonglong value= 0;
635
655
  int error;
636
 
  DRIZZLE_TIME l_time;
637
 
  enum enum_drizzle_timestamp_type ret;
 
656
  MYSQL_TIME l_time;
 
657
  enum_mysql_timestamp_type ret;
638
658
 
639
659
  ret= str_to_datetime(str->ptr(), str->length(), &l_time,
640
660
                       (TIME_FUZZY_DATE | MODE_INVALID_DATES |
641
 
                        (thd->variables.sql_mode & MODE_NO_ZERO_DATE)),
 
661
                        (thd->variables.sql_mode &
 
662
                         (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE))),
642
663
                       &error);
643
664
 
644
 
  if (ret == DRIZZLE_TIMESTAMP_DATETIME || ret == DRIZZLE_TIMESTAMP_DATE)
 
665
  if (ret == MYSQL_TIMESTAMP_DATETIME || ret == MYSQL_TIMESTAMP_DATE)
645
666
  {
646
667
    /*
647
668
      Do not return yet, we may still want to throw a "trailing garbage"
648
669
      warning.
649
670
    */
650
 
    *error_arg= false;
651
 
    value= TIME_to_uint64_t_datetime(&l_time);
 
671
    *error_arg= FALSE;
 
672
    value= TIME_to_ulonglong_datetime(&l_time);
652
673
  }
653
674
  else
654
675
  {
655
 
    *error_arg= true;
 
676
    *error_arg= TRUE;
656
677
    error= 1;                                   /* force warning */
657
678
  }
658
679
 
659
680
  if (error > 0)
660
 
    make_truncated_value_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
681
    make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
661
682
                                 str->ptr(), str->length(),
662
683
                                 warn_type, warn_name);
663
684
 
698
719
*/
699
720
 
700
721
enum Arg_comparator::enum_date_cmp_type
701
 
Arg_comparator::can_compare_as_dates(Item *a, Item *b, uint64_t *const_value)
 
722
Arg_comparator::can_compare_as_dates(Item *a, Item *b, ulonglong *const_value)
702
723
{
703
724
  enum enum_date_cmp_type cmp_type= CMP_DATE_DFLT;
704
725
  Item *str_arg= 0, *date_arg= 0;
727
748
  if (cmp_type != CMP_DATE_DFLT)
728
749
  {
729
750
    /*
730
 
      Do not cache GET_USER_VAR() function as its const_item() may return true
 
751
      Do not cache GET_USER_VAR() function as its const_item() may return TRUE
731
752
      for the current thread but it still may change during the execution.
732
753
    */
733
754
    if (cmp_type != CMP_DATE_WITH_DATE && str_arg->const_item() &&
735
756
        ((Item_func*)str_arg)->functype() != Item_func::GUSERVAR_FUNC))
736
757
    {
737
758
      THD *thd= current_thd;
738
 
      uint64_t value;
 
759
      ulonglong value;
739
760
      bool error;
740
761
      String tmp, *str_val= 0;
741
 
      enum enum_drizzle_timestamp_type t_type= (date_arg->field_type() == DRIZZLE_TYPE_NEWDATE ?
742
 
                              DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME);
 
762
      timestamp_type t_type= (date_arg->field_type() == MYSQL_TYPE_DATE ?
 
763
                              MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME);
743
764
 
744
765
      str_val= str_arg->val_str(&tmp);
745
766
      if (str_arg->null_value)
764
785
    item_arg   [in/out] item to retrieve TIME value from
765
786
    cache_arg  [in/out] pointer to place to store the cache item to
766
787
    warn_item  [in]     unused
767
 
    is_null    [out]    true <=> the item_arg is null
 
788
    is_null    [out]    TRUE <=> the item_arg is null
768
789
 
769
790
  DESCRIPTION
770
791
    Retrieves the correct TIME value from given item for comparison by the
771
792
    compare_datetime() function.
772
 
    If item's result can be compared as int64_t then its int value is used
 
793
    If item's result can be compared as longlong then its int value is used
773
794
    and a value returned by get_time function is used otherwise.
774
795
    If an item is a constant one then its value is cached and it isn't
775
796
    get parsed again. An Item_cache_int object is used for for cached values.
780
801
    obtained value
781
802
*/
782
803
 
783
 
uint64_t
784
 
get_time_value(THD *thd __attribute__((unused)),
785
 
               Item ***item_arg, Item **cache_arg,
786
 
               Item *warn_item __attribute__((unused)),
787
 
               bool *is_null)
 
804
ulonglong
 
805
get_time_value(THD *thd, Item ***item_arg, Item **cache_arg,
 
806
               Item *warn_item, bool *is_null)
788
807
{
789
 
  uint64_t value;
 
808
  ulonglong value;
790
809
  Item *item= **item_arg;
791
 
  DRIZZLE_TIME ltime;
 
810
  MYSQL_TIME ltime;
792
811
 
793
 
  if (item->result_as_int64_t())
 
812
  if (item->result_as_longlong())
794
813
  {
795
814
    value= item->val_int();
796
815
    *is_null= item->null_value;
798
817
  else
799
818
  {
800
819
    *is_null= item->get_time(&ltime);
801
 
    value= !*is_null ? TIME_to_uint64_t_datetime(&ltime) : 0;
 
820
    value= !*is_null ? TIME_to_ulonglong_datetime(&ltime) : 0;
802
821
  }
803
822
  /*
804
 
    Do not cache GET_USER_VAR() function as its const_item() may return true
 
823
    Do not cache GET_USER_VAR() function as its const_item() may return TRUE
805
824
    for the current thread but it still may change during the execution.
806
825
  */
807
826
  if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
823
842
                                        Item_result type)
824
843
{
825
844
  enum enum_date_cmp_type cmp_type;
826
 
  uint64_t const_value= (uint64_t)-1;
 
845
  ulonglong const_value= (ulonglong)-1;
827
846
  a= a1;
828
847
  b= a2;
829
848
 
836
855
    a_cache= 0;
837
856
    b_cache= 0;
838
857
 
839
 
    if (const_value != (uint64_t)-1)
 
858
    if (const_value != (ulonglong)-1)
840
859
    {
841
860
      Item_cache_int *cache= new Item_cache_int();
842
861
      /* Mark the cache as non-const to prevent re-caching. */
859
878
    get_value_func= &get_datetime_value;
860
879
    return 0;
861
880
  }
862
 
  else if (type == STRING_RESULT && (*a)->field_type() == DRIZZLE_TYPE_TIME &&
863
 
           (*b)->field_type() == DRIZZLE_TYPE_TIME)
 
881
  else if (type == STRING_RESULT && (*a)->field_type() == MYSQL_TYPE_TIME &&
 
882
           (*b)->field_type() == MYSQL_TYPE_TIME)
864
883
  {
865
884
    /* Compare TIME values as integers. */
866
885
    thd= current_thd;
888
907
  b_type= (*b)->field_type();
889
908
  a_cache= 0;
890
909
  b_cache= 0;
891
 
  is_nulls_eq= false;
 
910
  is_nulls_eq= FALSE;
892
911
  func= &Arg_comparator::compare_datetime;
893
912
  get_value_func= &get_datetime_value;
894
913
}
903
922
    item_arg   [in/out] item to retrieve DATETIME value from
904
923
    cache_arg  [in/out] pointer to place to store the caching item to
905
924
    warn_item  [in]     item for issuing the conversion warning
906
 
    is_null    [out]    true <=> the item_arg is null
 
925
    is_null    [out]    TRUE <=> the item_arg is null
907
926
 
908
927
  DESCRIPTION
909
928
    Retrieves the correct DATETIME value from given item for comparison by the
910
929
    compare_datetime() function.
911
 
    If item's result can be compared as int64_t then its int value is used
 
930
    If item's result can be compared as longlong then its int value is used
912
931
    and its string value is used otherwise. Strings are always parsed and
913
932
    converted to int values by the get_date_from_str() function.
914
933
    This allows us to compare correctly string dates with missed insignificant
923
942
    obtained value
924
943
*/
925
944
 
926
 
uint64_t
 
945
ulonglong
927
946
get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
928
947
                   Item *warn_item, bool *is_null)
929
948
{
930
 
  uint64_t value= 0;
 
949
  ulonglong value= 0;
931
950
  String buf, *str= 0;
932
951
  Item *item= **item_arg;
933
952
 
934
 
  if (item->result_as_int64_t())
 
953
  if (item->result_as_longlong())
935
954
  {
936
955
    value= item->val_int();
937
956
    *is_null= item->null_value;
938
957
    enum_field_types f_type= item->field_type();
939
958
    /*
940
 
      Item_date_add_interval may return DRIZZLE_TYPE_STRING as the result
 
959
      Item_date_add_interval may return MYSQL_TYPE_STRING as the result
941
960
      field type. To detect that the DATE value has been returned we
942
961
      compare it with 100000000L - any DATE value should be less than it.
943
962
      Don't shift cached DATETIME values up for the second time.
944
963
    */
945
 
    if (f_type == DRIZZLE_TYPE_NEWDATE ||
946
 
        (f_type != DRIZZLE_TYPE_DATETIME && value < 100000000L))
 
964
    if (f_type == MYSQL_TYPE_DATE ||
 
965
        (f_type != MYSQL_TYPE_DATETIME && value < 100000000L))
947
966
      value*= 1000000L;
948
967
  }
949
968
  else
952
971
    *is_null= item->null_value;
953
972
  }
954
973
  if (*is_null)
955
 
    return ~(uint64_t) 0;
 
974
    return ~(ulonglong) 0;
956
975
  /*
957
976
    Convert strings to the integer DATE/DATETIME representation.
958
977
    Even if both dates provided in strings we can't compare them directly as
963
982
  {
964
983
    bool error;
965
984
    enum_field_types f_type= warn_item->field_type();
966
 
    enum enum_drizzle_timestamp_type t_type= f_type ==
967
 
      DRIZZLE_TYPE_NEWDATE ? DRIZZLE_TIMESTAMP_DATE : DRIZZLE_TIMESTAMP_DATETIME;
 
985
    timestamp_type t_type= f_type ==
 
986
      MYSQL_TYPE_DATE ? MYSQL_TIMESTAMP_DATE : MYSQL_TIMESTAMP_DATETIME;
968
987
    value= get_date_from_str(thd, str, t_type, warn_item->name, &error);
969
988
    /*
970
989
      If str did not contain a valid date according to the current
974
993
    */
975
994
  }
976
995
  /*
977
 
    Do not cache GET_USER_VAR() function as its const_item() may return true
 
996
    Do not cache GET_USER_VAR() function as its const_item() may return TRUE
978
997
    for the current thread but it still may change during the execution.
979
998
  */
980
999
  if (item->const_item() && cache_arg && (item->type() != Item::FUNC_ITEM ||
981
1000
      ((Item_func*)item)->functype() != Item_func::GUSERVAR_FUNC))
982
1001
  {
983
 
    Item_cache_int *cache= new Item_cache_int(DRIZZLE_TYPE_DATETIME);
 
1002
    Item_cache_int *cache= new Item_cache_int(MYSQL_TYPE_DATETIME);
984
1003
    /* Mark the cache as non-const to prevent re-caching. */
985
1004
    cache->set_used_tables(1);
986
1005
    cache->store(item, value);
1002
1021
    with help of the get_datetime_value() function.
1003
1022
 
1004
1023
  RETURN
1005
 
    If is_nulls_eq is true:
 
1024
    If is_nulls_eq is TRUE:
1006
1025
       1    if items are equal or both are null
1007
1026
       0    otherwise
1008
 
    If is_nulls_eq is false:
 
1027
    If is_nulls_eq is FALSE:
1009
1028
      -1   a < b or one of items is null
1010
1029
       0   a == b
1011
1030
       1   a > b
1013
1032
 
1014
1033
int Arg_comparator::compare_datetime()
1015
1034
{
1016
 
  bool is_null= false;
1017
 
  uint64_t a_value, b_value;
 
1035
  bool is_null= FALSE;
 
1036
  ulonglong a_value, b_value;
1018
1037
 
1019
1038
  /* Get DATE/DATETIME/TIME value of the 'a' item. */
1020
1039
  a_value= (*get_value_func)(thd, &a, &a_cache, *b, &is_null);
1079
1098
    if ((res2= (*b)->val_str(&owner->tmp_value2)))
1080
1099
    {
1081
1100
      owner->null_value= 0;
1082
 
      uint32_t res1_length= res1->length();
1083
 
      uint32_t res2_length= res2->length();
1084
 
      int cmp= memcmp(res1->ptr(), res2->ptr(), cmin(res1_length,res2_length));
 
1101
      uint res1_length= res1->length();
 
1102
      uint res2_length= res2->length();
 
1103
      int cmp= memcmp(res1->ptr(), res2->ptr(), min(res1_length,res2_length));
1085
1104
      return cmp ? cmp : (int) (res1_length - res2_length);
1086
1105
    }
1087
1106
  }
1218
1237
 
1219
1238
int Arg_comparator::compare_int_signed()
1220
1239
{
1221
 
  int64_t val1= (*a)->val_int();
 
1240
  longlong val1= (*a)->val_int();
1222
1241
  if (!(*a)->null_value)
1223
1242
  {
1224
 
    int64_t val2= (*b)->val_int();
 
1243
    longlong val2= (*b)->val_int();
1225
1244
    if (!(*b)->null_value)
1226
1245
    {
1227
1246
      owner->null_value= 0;
1241
1260
 
1242
1261
int Arg_comparator::compare_int_unsigned()
1243
1262
{
1244
 
  uint64_t val1= (*a)->val_int();
 
1263
  ulonglong val1= (*a)->val_int();
1245
1264
  if (!(*a)->null_value)
1246
1265
  {
1247
 
    uint64_t val2= (*b)->val_int();
 
1266
    ulonglong val2= (*b)->val_int();
1248
1267
    if (!(*b)->null_value)
1249
1268
    {
1250
1269
      owner->null_value= 0;
1264
1283
 
1265
1284
int Arg_comparator::compare_int_signed_unsigned()
1266
1285
{
1267
 
  int64_t sval1= (*a)->val_int();
 
1286
  longlong sval1= (*a)->val_int();
1268
1287
  if (!(*a)->null_value)
1269
1288
  {
1270
 
    uint64_t uval2= (uint64_t)(*b)->val_int();
 
1289
    ulonglong uval2= (ulonglong)(*b)->val_int();
1271
1290
    if (!(*b)->null_value)
1272
1291
    {
1273
1292
      owner->null_value= 0;
1274
 
      if (sval1 < 0 || (uint64_t)sval1 < uval2)
 
1293
      if (sval1 < 0 || (ulonglong)sval1 < uval2)
1275
1294
        return -1;
1276
 
      if ((uint64_t)sval1 == uval2)
 
1295
      if ((ulonglong)sval1 == uval2)
1277
1296
        return 0;
1278
1297
      return 1;
1279
1298
    }
1289
1308
 
1290
1309
int Arg_comparator::compare_int_unsigned_signed()
1291
1310
{
1292
 
  uint64_t uval1= (uint64_t)(*a)->val_int();
 
1311
  ulonglong uval1= (ulonglong)(*a)->val_int();
1293
1312
  if (!(*a)->null_value)
1294
1313
  {
1295
 
    int64_t sval2= (*b)->val_int();
 
1314
    longlong sval2= (*b)->val_int();
1296
1315
    if (!(*b)->null_value)
1297
1316
    {
1298
1317
      owner->null_value= 0;
1299
1318
      if (sval2 < 0)
1300
1319
        return 1;
1301
 
      if (uval1 < (uint64_t)sval2)
 
1320
      if (uval1 < (ulonglong)sval2)
1302
1321
        return -1;
1303
 
      if (uval1 == (uint64_t)sval2)
 
1322
      if (uval1 == (ulonglong)sval2)
1304
1323
        return 0;
1305
1324
      return 1;
1306
1325
    }
1312
1331
 
1313
1332
int Arg_comparator::compare_e_int()
1314
1333
{
1315
 
  int64_t val1= (*a)->val_int();
1316
 
  int64_t val2= (*b)->val_int();
 
1334
  longlong val1= (*a)->val_int();
 
1335
  longlong val2= (*b)->val_int();
1317
1336
  if ((*a)->null_value || (*b)->null_value)
1318
1337
    return test((*a)->null_value && (*b)->null_value);
1319
1338
  return test(val1 == val2);
1324
1343
*/
1325
1344
int Arg_comparator::compare_e_int_diff_signedness()
1326
1345
{
1327
 
  int64_t val1= (*a)->val_int();
1328
 
  int64_t val2= (*b)->val_int();
 
1346
  longlong val1= (*a)->val_int();
 
1347
  longlong val2= (*b)->val_int();
1329
1348
  if ((*a)->null_value || (*b)->null_value)
1330
1349
    return test((*a)->null_value && (*b)->null_value);
1331
1350
  return (val1 >= 0) && test(val1 == val2);
1337
1356
  bool was_null= 0;
1338
1357
  (*a)->bring_value();
1339
1358
  (*b)->bring_value();
1340
 
  uint32_t n= (*a)->cols();
1341
 
  for (uint32_t i= 0; i<n; i++)
 
1359
  uint n= (*a)->cols();
 
1360
  for (uint i= 0; i<n; i++)
1342
1361
  {
1343
1362
    res= comparators[i].compare();
1344
1363
    if (owner->null_value)
1380
1399
{
1381
1400
  (*a)->bring_value();
1382
1401
  (*b)->bring_value();
1383
 
  uint32_t n= (*a)->cols();
1384
 
  for (uint32_t i= 0; i<n; i++)
 
1402
  uint n= (*a)->cols();
 
1403
  for (uint i= 0; i<n; i++)
1385
1404
  {
1386
1405
    if (!comparators[i].compare())
1387
1406
      return 0;
1420
1439
  if (args[0]->null_value)
1421
1440
  {
1422
1441
    /*
1423
 
      NULL val IS {true, false} --> false
1424
 
      NULL val IS NOT {true, false} --> true
 
1442
      NULL val IS {TRUE, FALSE} --> FALSE
 
1443
      NULL val IS NOT {TRUE, FALSE} --> TRUE
1425
1444
    */
1426
1445
    return (! affirmative);
1427
1446
  }
1428
1447
 
1429
1448
  if (affirmative)
1430
1449
  {
1431
 
    /* {true, false} val IS {true, false} value */
 
1450
    /* {TRUE, FALSE} val IS {TRUE, FALSE} value */
1432
1451
    return (val == value);
1433
1452
  }
1434
1453
 
1435
 
  /* {true, false} val IS NOT {true, false} value */
 
1454
  /* {TRUE, FALSE} val IS NOT {TRUE, FALSE} value */
1436
1455
  return (val != value);
1437
1456
}
1438
1457
 
1439
1458
 
1440
 
int64_t Item_func_truth::val_int()
 
1459
longlong Item_func_truth::val_int()
1441
1460
{
1442
1461
  return (val_bool() ? 1 : 0);
1443
1462
}
1444
1463
 
1445
1464
 
1446
 
bool Item_in_optimizer::fix_left(THD *thd, Item **ref __attribute__((unused)))
 
1465
bool Item_in_optimizer::fix_left(THD *thd, Item **ref)
1447
1466
{
1448
1467
  if ((!args[0]->fixed && args[0]->fix_fields(thd, args)) ||
1449
1468
      (!cache && !(cache= Item_cache::get_cache(args[0]))))
1459
1478
  }
1460
1479
  else
1461
1480
  {
1462
 
    uint32_t n= cache->cols();
1463
 
    for (uint32_t i= 0; i < n; i++)
 
1481
    uint n= cache->cols();
 
1482
    for (uint i= 0; i < n; i++)
1464
1483
    {
1465
1484
      if (args[0]->element_index(i)->used_tables())
1466
1485
        ((Item_cache *)cache->element_index(i))->set_used_tables(OUTER_REF_TABLE_BIT);
1479
1498
 
1480
1499
bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
1481
1500
{
1482
 
  assert(fixed == 0);
 
1501
  DBUG_ASSERT(fixed == 0);
1483
1502
  if (fix_left(thd, ref))
1484
 
    return true;
 
1503
    return TRUE;
1485
1504
  if (args[0]->maybe_null)
1486
1505
    maybe_null=1;
1487
1506
 
1488
1507
  if (!args[1]->fixed && args[1]->fix_fields(thd, args+1))
1489
 
    return true;
 
1508
    return TRUE;
1490
1509
  Item_in_subselect * sub= (Item_in_subselect *)args[1];
1491
1510
  if (args[0]->cols() != sub->engine->cols())
1492
1511
  {
1493
1512
    my_error(ER_OPERAND_COLUMNS, MYF(0), args[0]->cols());
1494
 
    return true;
 
1513
    return TRUE;
1495
1514
  }
1496
1515
  if (args[1]->maybe_null)
1497
1516
    maybe_null=1;
1500
1519
  not_null_tables_cache|= args[1]->not_null_tables();
1501
1520
  const_item_cache&= args[1]->const_item();
1502
1521
  fixed= 1;
1503
 
  return false;
 
1522
  return FALSE;
1504
1523
}
1505
1524
 
1506
1525
 
1507
 
int64_t Item_in_optimizer::val_int()
 
1526
longlong Item_in_optimizer::val_int()
1508
1527
{
1509
1528
  bool tmp;
1510
 
  assert(fixed == 1);
 
1529
  DBUG_ASSERT(fixed == 1);
1511
1530
  cache->store(args[0]);
1512
1531
  
1513
1532
  if (cache->null_value)
1516
1535
    {
1517
1536
      /*
1518
1537
        We're evaluating "NULL IN (SELECT ...)". The result can be NULL or
1519
 
        false, and we can return one instead of another. Just return NULL.
 
1538
        FALSE, and we can return one instead of another. Just return NULL.
1520
1539
      */
1521
1540
      null_value= 1;
1522
1541
    }
1532
1551
      {
1533
1552
        /*
1534
1553
          We're evaluating "NULL IN (SELECT ...)". The result is:
1535
 
             false if SELECT produces an empty set, or
 
1554
             FALSE if SELECT produces an empty set, or
1536
1555
             NULL  otherwise.
1537
1556
          We disable the predicates we've pushed down into subselect, run the
1538
1557
          subselect and see if it has produced any rows.
1540
1559
        Item_in_subselect *item_subs=(Item_in_subselect*)args[1]; 
1541
1560
        if (cache->cols() == 1)
1542
1561
        {
1543
 
          item_subs->set_cond_guard_var(0, false);
 
1562
          item_subs->set_cond_guard_var(0, FALSE);
1544
1563
          (void) args[1]->val_bool_result();
1545
1564
          result_for_null_param= null_value= !item_subs->engine->no_rows();
1546
 
          item_subs->set_cond_guard_var(0, true);
 
1565
          item_subs->set_cond_guard_var(0, TRUE);
1547
1566
        }
1548
1567
        else
1549
1568
        {
1550
 
          uint32_t i;
1551
 
          uint32_t ncols= cache->cols();
 
1569
          uint i;
 
1570
          uint ncols= cache->cols();
1552
1571
          /*
1553
1572
            Turn off the predicates that are based on column compares for
1554
1573
            which the left part is currently NULL
1556
1575
          for (i= 0; i < ncols; i++)
1557
1576
          {
1558
1577
            if (cache->element_index(i)->null_value)
1559
 
              item_subs->set_cond_guard_var(i, false);
 
1578
              item_subs->set_cond_guard_var(i, FALSE);
1560
1579
          }
1561
1580
          
1562
1581
          (void) args[1]->val_bool_result();
1564
1583
          
1565
1584
          /* Turn all predicates back on */
1566
1585
          for (i= 0; i < ncols; i++)
1567
 
            item_subs->set_cond_guard_var(i, true);
 
1586
            item_subs->set_cond_guard_var(i, TRUE);
1568
1587
        }
1569
1588
      }
1570
1589
    }
1585
1604
 
1586
1605
void Item_in_optimizer::cleanup()
1587
1606
{
 
1607
  DBUG_ENTER("Item_in_optimizer::cleanup");
1588
1608
  Item_bool_func::cleanup();
1589
1609
  if (!save_cache)
1590
1610
    cache= 0;
1591
 
  return;
 
1611
  DBUG_VOID_RETURN;
1592
1612
}
1593
1613
 
1594
1614
 
1621
1641
    @retval NULL if an error occurred
1622
1642
*/
1623
1643
 
1624
 
Item *Item_in_optimizer::transform(Item_transformer transformer, unsigned char *argument)
 
1644
Item *Item_in_optimizer::transform(Item_transformer transformer, uchar *argument)
1625
1645
{
1626
1646
  Item *new_item;
1627
1647
 
1628
 
  assert(arg_count == 2);
 
1648
  DBUG_ASSERT(arg_count == 2);
1629
1649
 
1630
1650
  /* Transform the left IN operand. */
1631
1651
  new_item= (*args)->transform(transformer, argument);
1647
1667
    transformation, we only make both operands the same.
1648
1668
    TODO: is it the way it should be?
1649
1669
  */
1650
 
  assert((args[1])->type() == Item::SUBSELECT_ITEM &&
 
1670
  DBUG_ASSERT((args[1])->type() == Item::SUBSELECT_ITEM &&
1651
1671
              (((Item_subselect*)(args[1]))->substype() ==
1652
1672
               Item_subselect::IN_SUBS ||
1653
1673
               ((Item_subselect*)(args[1]))->substype() ==
1663
1683
 
1664
1684
 
1665
1685
 
1666
 
int64_t Item_func_eq::val_int()
 
1686
longlong Item_func_eq::val_int()
1667
1687
{
1668
 
  assert(fixed == 1);
 
1688
  DBUG_ASSERT(fixed == 1);
1669
1689
  int value= cmp.compare();
1670
1690
  return value == 0 ? 1 : 0;
1671
1691
}
1679
1699
  maybe_null=null_value=0;
1680
1700
}
1681
1701
 
1682
 
int64_t Item_func_equal::val_int()
 
1702
longlong Item_func_equal::val_int()
1683
1703
{
1684
 
  assert(fixed == 1);
 
1704
  DBUG_ASSERT(fixed == 1);
1685
1705
  return cmp.compare();
1686
1706
}
1687
1707
 
1688
 
int64_t Item_func_ne::val_int()
 
1708
longlong Item_func_ne::val_int()
1689
1709
{
1690
 
  assert(fixed == 1);
 
1710
  DBUG_ASSERT(fixed == 1);
1691
1711
  int value= cmp.compare();
1692
1712
  return value != 0 && !null_value ? 1 : 0;
1693
1713
}
1694
1714
 
1695
1715
 
1696
 
int64_t Item_func_ge::val_int()
 
1716
longlong Item_func_ge::val_int()
1697
1717
{
1698
 
  assert(fixed == 1);
 
1718
  DBUG_ASSERT(fixed == 1);
1699
1719
  int value= cmp.compare();
1700
1720
  return value >= 0 ? 1 : 0;
1701
1721
}
1702
1722
 
1703
1723
 
1704
 
int64_t Item_func_gt::val_int()
 
1724
longlong Item_func_gt::val_int()
1705
1725
{
1706
 
  assert(fixed == 1);
 
1726
  DBUG_ASSERT(fixed == 1);
1707
1727
  int value= cmp.compare();
1708
1728
  return value > 0 ? 1 : 0;
1709
1729
}
1710
1730
 
1711
 
int64_t Item_func_le::val_int()
 
1731
longlong Item_func_le::val_int()
1712
1732
{
1713
 
  assert(fixed == 1);
 
1733
  DBUG_ASSERT(fixed == 1);
1714
1734
  int value= cmp.compare();
1715
1735
  return value <= 0 && !null_value ? 1 : 0;
1716
1736
}
1717
1737
 
1718
1738
 
1719
 
int64_t Item_func_lt::val_int()
 
1739
longlong Item_func_lt::val_int()
1720
1740
{
1721
 
  assert(fixed == 1);
 
1741
  DBUG_ASSERT(fixed == 1);
1722
1742
  int value= cmp.compare();
1723
1743
  return value < 0 && !null_value ? 1 : 0;
1724
1744
}
1725
1745
 
1726
1746
 
1727
 
int64_t Item_func_strcmp::val_int()
 
1747
longlong Item_func_strcmp::val_int()
1728
1748
{
1729
 
  assert(fixed == 1);
 
1749
  DBUG_ASSERT(fixed == 1);
1730
1750
  String *a=args[0]->val_str(&tmp_value1);
1731
1751
  String *b=args[1]->val_str(&tmp_value2);
1732
1752
  if (!a || !b)
1736
1756
  }
1737
1757
  int value= sortcmp(a,b,cmp.cmp_collation.collation);
1738
1758
  null_value=0;
1739
 
  return !value ? 0 : (value < 0 ? (int64_t) -1 : (int64_t) 1);
 
1759
  return !value ? 0 : (value < 0 ? (longlong) -1 : (longlong) 1);
1740
1760
}
1741
1761
 
1742
1762
 
1753
1773
    return 0;
1754
1774
  if (negated != ((Item_func_opt_neg *) item_func)->negated)
1755
1775
    return 0;
1756
 
  for (uint32_t i=0; i < arg_count ; i++)
 
1776
  for (uint i=0; i < arg_count ; i++)
1757
1777
    if (!args[i]->eq(item_func->arguments()[i], binary_cmp))
1758
1778
      return 0;
1759
1779
  return 1;
1762
1782
 
1763
1783
void Item_func_interval::fix_length_and_dec()
1764
1784
{
1765
 
  uint32_t rows= row->cols();
 
1785
  uint rows= row->cols();
1766
1786
  
1767
1787
  use_decimal_comparison= ((row->element_index(0)->result_type() ==
1768
1788
                            DECIMAL_RESULT) ||
1770
1790
                            INT_RESULT));
1771
1791
  if (rows > 8)
1772
1792
  {
1773
 
    bool not_null_consts= true;
 
1793
    bool not_null_consts= TRUE;
1774
1794
 
1775
 
    for (uint32_t i= 1; not_null_consts && i < rows; i++)
 
1795
    for (uint i= 1; not_null_consts && i < rows; i++)
1776
1796
    {
1777
1797
      Item *el= row->element_index(i);
1778
1798
      not_null_consts&= el->const_item() & !el->is_null();
1784
1804
    {
1785
1805
      if (use_decimal_comparison)
1786
1806
      {
1787
 
        for (uint32_t i= 1; i < rows; i++)
 
1807
        for (uint i= 1; i < rows; i++)
1788
1808
        {
1789
1809
          Item *el= row->element_index(i);
1790
1810
          interval_range *range= intervals + (i-1);
1809
1829
      }
1810
1830
      else
1811
1831
      {
1812
 
        for (uint32_t i= 1; i < rows; i++)
 
1832
        for (uint i= 1; i < rows; i++)
1813
1833
        {
1814
1834
          intervals[i-1].dbl= row->element_index(i)->val_real();
1815
1835
        }
1839
1859
    - arg_count if higher than biggest argument
1840
1860
*/
1841
1861
 
1842
 
int64_t Item_func_interval::val_int()
 
1862
longlong Item_func_interval::val_int()
1843
1863
{
1844
 
  assert(fixed == 1);
 
1864
  DBUG_ASSERT(fixed == 1);
1845
1865
  double value;
1846
1866
  my_decimal dec_buf, *dec= NULL;
1847
 
  uint32_t i;
 
1867
  uint i;
1848
1868
 
1849
1869
  if (use_decimal_comparison)
1850
1870
  {
1862
1882
 
1863
1883
  if (intervals)
1864
1884
  {                                     // Use binary search to find interval
1865
 
    uint32_t start,end;
 
1885
    uint start,end;
1866
1886
    start= 0;
1867
1887
    end=   row->cols()-2;
1868
1888
    while (start != end)
1869
1889
    {
1870
 
      uint32_t mid= (start + end + 1) / 2;
 
1890
      uint mid= (start + end + 1) / 2;
1871
1891
      interval_range *range= intervals + mid;
1872
 
      bool cmp_result;
 
1892
      my_bool cmp_result;
1873
1893
      /*
1874
1894
        The values in the range intervall may have different types,
1875
1895
        Only do a decimal comparision of the first argument is a decimal
1970
1990
{
1971
1991
  max_length= 1;
1972
1992
  int i;
1973
 
  bool datetime_found= false;
 
1993
  bool datetime_found= FALSE;
1974
1994
  int time_items_found= 0;
1975
 
  compare_as_dates= true;
 
1995
  compare_as_dates= TRUE;
1976
1996
  THD *thd= current_thd;
1977
1997
 
1978
1998
  /*
1998
2018
    {
1999
2019
      if (args[i]->is_datetime())
2000
2020
      {
2001
 
        datetime_found= true;
 
2021
        datetime_found= TRUE;
2002
2022
        continue;
2003
2023
      }
2004
 
      if (args[i]->field_type() == DRIZZLE_TYPE_TIME &&
2005
 
          args[i]->result_as_int64_t())
 
2024
      if (args[i]->field_type() == MYSQL_TYPE_TIME &&
 
2025
          args[i]->result_as_longlong())
2006
2026
        time_items_found++;
2007
2027
    }
2008
2028
  }
2009
2029
  if (!datetime_found)
2010
 
    compare_as_dates= false;
 
2030
    compare_as_dates= FALSE;
2011
2031
 
2012
2032
  if (compare_as_dates)
2013
2033
  {
2023
2043
           thd->lex->sql_command != SQLCOM_SHOW_CREATE)
2024
2044
  {
2025
2045
    Item_field *field_item= (Item_field*) (args[0]->real_item());
2026
 
    if (field_item->field->can_be_compared_as_int64_t())
 
2046
    if (field_item->field->can_be_compared_as_longlong())
2027
2047
    {
2028
2048
      /*
2029
2049
        The following can't be recoded with || as convert_constant_item
2038
2058
}
2039
2059
 
2040
2060
 
2041
 
int64_t Item_func_between::val_int()
 
2061
longlong Item_func_between::val_int()
2042
2062
{                                               // ANSI BETWEEN
2043
 
  assert(fixed == 1);
 
2063
  DBUG_ASSERT(fixed == 1);
2044
2064
  if (compare_as_dates)
2045
2065
  {
2046
2066
    int ge_res, le_res;
2051
2071
    le_res= le_cmp.compare();
2052
2072
 
2053
2073
    if (!args[1]->null_value && !args[2]->null_value)
2054
 
      return (int64_t) ((ge_res >= 0 && le_res <=0) != negated);
 
2074
      return (longlong) ((ge_res >= 0 && le_res <=0) != negated);
2055
2075
    else if (args[1]->null_value)
2056
2076
    {
2057
2077
      null_value= le_res > 0;                   // not null if false range.
2070
2090
    a=args[1]->val_str(&value1);
2071
2091
    b=args[2]->val_str(&value2);
2072
2092
    if (!args[1]->null_value && !args[2]->null_value)
2073
 
      return (int64_t) ((sortcmp(value,a,cmp_collation.collation) >= 0 &&
 
2093
      return (longlong) ((sortcmp(value,a,cmp_collation.collation) >= 0 &&
2074
2094
                          sortcmp(value,b,cmp_collation.collation) <= 0) !=
2075
2095
                         negated);
2076
2096
    if (args[1]->null_value && args[2]->null_value)
2088
2108
  }
2089
2109
  else if (cmp_type == INT_RESULT)
2090
2110
  {
2091
 
    int64_t value=args[0]->val_int(), a, b;
 
2111
    longlong value=args[0]->val_int(), a, b;
2092
2112
    if ((null_value=args[0]->null_value))
2093
2113
      return 0;                                 /* purecov: inspected */
2094
2114
    a=args[1]->val_int();
2095
2115
    b=args[2]->val_int();
2096
2116
    if (!args[1]->null_value && !args[2]->null_value)
2097
 
      return (int64_t) ((value >= a && value <= b) != negated);
 
2117
      return (longlong) ((value >= a && value <= b) != negated);
2098
2118
    if (args[1]->null_value && args[2]->null_value)
2099
2119
      null_value=1;
2100
2120
    else if (args[1]->null_value)
2115
2135
    a_dec= args[1]->val_decimal(&a_buf);
2116
2136
    b_dec= args[2]->val_decimal(&b_buf);
2117
2137
    if (!args[1]->null_value && !args[2]->null_value)
2118
 
      return (int64_t) ((my_decimal_cmp(dec, a_dec) >= 0 &&
 
2138
      return (longlong) ((my_decimal_cmp(dec, a_dec) >= 0 &&
2119
2139
                          my_decimal_cmp(dec, b_dec) <= 0) != negated);
2120
2140
    if (args[1]->null_value && args[2]->null_value)
2121
2141
      null_value=1;
2132
2152
    a= args[1]->val_real();
2133
2153
    b= args[2]->val_real();
2134
2154
    if (!args[1]->null_value && !args[2]->null_value)
2135
 
      return (int64_t) ((value >= a && value <= b) != negated);
 
2155
      return (longlong) ((value >= a && value <= b) != negated);
2136
2156
    if (args[1]->null_value && args[2]->null_value)
2137
2157
      null_value=1;
2138
2158
    else if (args[1]->null_value)
2144
2164
      null_value= value >= a;
2145
2165
    }
2146
2166
  }
2147
 
  return (int64_t) (!null_value && negated);
 
2167
  return (longlong) (!null_value && negated);
2148
2168
}
2149
2169
 
2150
2170
 
2166
2186
{
2167
2187
  agg_result_type(&hybrid_type, args, 2);
2168
2188
  maybe_null=args[1]->maybe_null;
2169
 
  decimals= cmax(args[0]->decimals, args[1]->decimals);
 
2189
  decimals= max(args[0]->decimals, args[1]->decimals);
2170
2190
  unsigned_flag= args[0]->unsigned_flag && args[1]->unsigned_flag;
2171
2191
 
2172
2192
  if (hybrid_type == DECIMAL_RESULT || hybrid_type == INT_RESULT) 
2177
2197
    int len1= args[1]->max_length - args[1]->decimals
2178
2198
      - (args[1]->unsigned_flag ? 0 : 1);
2179
2199
 
2180
 
    max_length= cmax(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
 
2200
    max_length= max(len0, len1) + decimals + (unsigned_flag ? 0 : 1);
2181
2201
  }
2182
2202
  else
2183
 
    max_length= cmax(args[0]->max_length, args[1]->max_length);
 
2203
    max_length= max(args[0]->max_length, args[1]->max_length);
2184
2204
 
2185
2205
  switch (hybrid_type) {
2186
2206
  case STRING_RESULT:
2194
2214
    break;
2195
2215
  case ROW_RESULT:
2196
2216
  default:
2197
 
    assert(0);
 
2217
    DBUG_ASSERT(0);
2198
2218
  }
2199
2219
  cached_field_type= agg_field_type(args, 2);
2200
2220
}
2201
2221
 
2202
2222
 
2203
 
uint32_t Item_func_ifnull::decimal_precision() const
 
2223
uint Item_func_ifnull::decimal_precision() const
2204
2224
{
2205
 
  int max_int_part=cmax(args[0]->decimal_int_part(),args[1]->decimal_int_part());
2206
 
  return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
 
2225
  int max_int_part=max(args[0]->decimal_int_part(),args[1]->decimal_int_part());
 
2226
  return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2207
2227
}
2208
2228
 
2209
2229
 
2212
2232
  return cached_field_type;
2213
2233
}
2214
2234
 
2215
 
Field *Item_func_ifnull::tmp_table_field(Table *table)
 
2235
Field *Item_func_ifnull::tmp_table_field(TABLE *table)
2216
2236
{
2217
2237
  return tmp_table_field_from_field_type(table, 0);
2218
2238
}
2220
2240
double
2221
2241
Item_func_ifnull::real_op()
2222
2242
{
2223
 
  assert(fixed == 1);
 
2243
  DBUG_ASSERT(fixed == 1);
2224
2244
  double value= args[0]->val_real();
2225
2245
  if (!args[0]->null_value)
2226
2246
  {
2233
2253
  return value;
2234
2254
}
2235
2255
 
2236
 
int64_t
 
2256
longlong
2237
2257
Item_func_ifnull::int_op()
2238
2258
{
2239
 
  assert(fixed == 1);
2240
 
  int64_t value=args[0]->val_int();
 
2259
  DBUG_ASSERT(fixed == 1);
 
2260
  longlong value=args[0]->val_int();
2241
2261
  if (!args[0]->null_value)
2242
2262
  {
2243
2263
    null_value=0;
2252
2272
 
2253
2273
my_decimal *Item_func_ifnull::decimal_op(my_decimal *decimal_value)
2254
2274
{
2255
 
  assert(fixed == 1);
 
2275
  DBUG_ASSERT(fixed == 1);
2256
2276
  my_decimal *value= args[0]->val_decimal(decimal_value);
2257
2277
  if (!args[0]->null_value)
2258
2278
  {
2269
2289
String *
2270
2290
Item_func_ifnull::str_op(String *str)
2271
2291
{
2272
 
  assert(fixed == 1);
 
2292
  DBUG_ASSERT(fixed == 1);
2273
2293
  String *res  =args[0]->val_str(str);
2274
2294
  if (!args[0]->null_value)
2275
2295
  {
2314
2334
bool
2315
2335
Item_func_if::fix_fields(THD *thd, Item **ref)
2316
2336
{
2317
 
  assert(fixed == 0);
 
2337
  DBUG_ASSERT(fixed == 0);
2318
2338
  args[0]->top_level_item();
2319
2339
 
2320
2340
  if (Item_func::fix_fields(thd, ref))
2331
2351
Item_func_if::fix_length_and_dec()
2332
2352
{
2333
2353
  maybe_null=args[1]->maybe_null || args[2]->maybe_null;
2334
 
  decimals= cmax(args[1]->decimals, args[2]->decimals);
 
2354
  decimals= max(args[1]->decimals, args[2]->decimals);
2335
2355
  unsigned_flag=args[1]->unsigned_flag && args[2]->unsigned_flag;
2336
2356
 
2337
2357
  enum Item_result arg1_type=args[1]->result_type();
2375
2395
    int len2= args[2]->max_length - args[2]->decimals
2376
2396
      - (args[2]->unsigned_flag ? 0 : 1);
2377
2397
 
2378
 
    max_length=cmax(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
 
2398
    max_length=max(len1, len2) + decimals + (unsigned_flag ? 0 : 1);
2379
2399
  }
2380
2400
  else
2381
 
    max_length= cmax(args[1]->max_length, args[2]->max_length);
 
2401
    max_length= max(args[1]->max_length, args[2]->max_length);
2382
2402
}
2383
2403
 
2384
2404
 
2385
 
uint32_t Item_func_if::decimal_precision() const
 
2405
uint Item_func_if::decimal_precision() const
2386
2406
{
2387
 
  int precision=(cmax(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
 
2407
  int precision=(max(args[1]->decimal_int_part(),args[2]->decimal_int_part())+
2388
2408
                 decimals);
2389
 
  return cmin(precision, DECIMAL_MAX_PRECISION);
 
2409
  return min(precision, DECIMAL_MAX_PRECISION);
2390
2410
}
2391
2411
 
2392
2412
 
2393
2413
double
2394
2414
Item_func_if::val_real()
2395
2415
{
2396
 
  assert(fixed == 1);
 
2416
  DBUG_ASSERT(fixed == 1);
2397
2417
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2398
2418
  double value= arg->val_real();
2399
2419
  null_value=arg->null_value;
2400
2420
  return value;
2401
2421
}
2402
2422
 
2403
 
int64_t
 
2423
longlong
2404
2424
Item_func_if::val_int()
2405
2425
{
2406
 
  assert(fixed == 1);
 
2426
  DBUG_ASSERT(fixed == 1);
2407
2427
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2408
 
  int64_t value=arg->val_int();
 
2428
  longlong value=arg->val_int();
2409
2429
  null_value=arg->null_value;
2410
2430
  return value;
2411
2431
}
2413
2433
String *
2414
2434
Item_func_if::val_str(String *str)
2415
2435
{
2416
 
  assert(fixed == 1);
 
2436
  DBUG_ASSERT(fixed == 1);
2417
2437
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2418
2438
  String *res=arg->val_str(str);
2419
2439
  if (res)
2426
2446
my_decimal *
2427
2447
Item_func_if::val_decimal(my_decimal *decimal_value)
2428
2448
{
2429
 
  assert(fixed == 1);
 
2449
  DBUG_ASSERT(fixed == 1);
2430
2450
  Item *arg= args[0]->val_bool() ? args[1] : args[2];
2431
2451
  my_decimal *value= arg->val_decimal(decimal_value);
2432
2452
  null_value= arg->null_value;
2465
2485
double
2466
2486
Item_func_nullif::val_real()
2467
2487
{
2468
 
  assert(fixed == 1);
 
2488
  DBUG_ASSERT(fixed == 1);
2469
2489
  double value;
2470
2490
  if (!cmp.compare())
2471
2491
  {
2477
2497
  return value;
2478
2498
}
2479
2499
 
2480
 
int64_t
 
2500
longlong
2481
2501
Item_func_nullif::val_int()
2482
2502
{
2483
 
  assert(fixed == 1);
2484
 
  int64_t value;
 
2503
  DBUG_ASSERT(fixed == 1);
 
2504
  longlong value;
2485
2505
  if (!cmp.compare())
2486
2506
  {
2487
2507
    null_value=1;
2495
2515
String *
2496
2516
Item_func_nullif::val_str(String *str)
2497
2517
{
2498
 
  assert(fixed == 1);
 
2518
  DBUG_ASSERT(fixed == 1);
2499
2519
  String *res;
2500
2520
  if (!cmp.compare())
2501
2521
  {
2511
2531
my_decimal *
2512
2532
Item_func_nullif::val_decimal(my_decimal * decimal_value)
2513
2533
{
2514
 
  assert(fixed == 1);
 
2534
  DBUG_ASSERT(fixed == 1);
2515
2535
  my_decimal *res;
2516
2536
  if (!cmp.compare())
2517
2537
  {
2552
2572
           failed
2553
2573
*/
2554
2574
 
2555
 
Item *Item_func_case::find_item(String *str __attribute__((unused)))
 
2575
Item *Item_func_case::find_item(String *str)
2556
2576
{
2557
 
  uint32_t value_added_map= 0;
 
2577
  uint value_added_map= 0;
2558
2578
 
2559
2579
  if (first_expr_num == -1)
2560
2580
  {
2561
 
    for (uint32_t i=0 ; i < ncases ; i+=2)
 
2581
    for (uint i=0 ; i < ncases ; i+=2)
2562
2582
    {
2563
2583
      // No expression between CASE and the first WHEN
2564
2584
      if (args[i]->val_bool())
2569
2589
  else
2570
2590
  {
2571
2591
    /* Compare every WHEN argument with it and return the first match */
2572
 
    for (uint32_t i=0 ; i < ncases ; i+=2)
 
2592
    for (uint i=0 ; i < ncases ; i+=2)
2573
2593
    {
2574
2594
      cmp_type= item_cmp_type(left_result_type, args[i]->result_type());
2575
 
      assert(cmp_type != ROW_RESULT);
2576
 
      assert(cmp_items[(uint)cmp_type]);
 
2595
      DBUG_ASSERT(cmp_type != ROW_RESULT);
 
2596
      DBUG_ASSERT(cmp_items[(uint)cmp_type]);
2577
2597
      if (!(value_added_map & (1<<(uint)cmp_type)))
2578
2598
      {
2579
2599
        cmp_items[(uint)cmp_type]->store_value(args[first_expr_num]);
2592
2612
 
2593
2613
String *Item_func_case::val_str(String *str)
2594
2614
{
2595
 
  assert(fixed == 1);
 
2615
  DBUG_ASSERT(fixed == 1);
2596
2616
  String *res;
2597
2617
  Item *item=find_item(str);
2598
2618
 
2608
2628
}
2609
2629
 
2610
2630
 
2611
 
int64_t Item_func_case::val_int()
 
2631
longlong Item_func_case::val_int()
2612
2632
{
2613
 
  assert(fixed == 1);
 
2633
  DBUG_ASSERT(fixed == 1);
2614
2634
  char buff[MAX_FIELD_WIDTH];
2615
2635
  String dummy_str(buff,sizeof(buff),default_charset());
2616
2636
  Item *item=find_item(&dummy_str);
2617
 
  int64_t res;
 
2637
  longlong res;
2618
2638
 
2619
2639
  if (!item)
2620
2640
  {
2628
2648
 
2629
2649
double Item_func_case::val_real()
2630
2650
{
2631
 
  assert(fixed == 1);
 
2651
  DBUG_ASSERT(fixed == 1);
2632
2652
  char buff[MAX_FIELD_WIDTH];
2633
2653
  String dummy_str(buff,sizeof(buff),default_charset());
2634
2654
  Item *item=find_item(&dummy_str);
2647
2667
 
2648
2668
my_decimal *Item_func_case::val_decimal(my_decimal *decimal_value)
2649
2669
{
2650
 
  assert(fixed == 1);
 
2670
  DBUG_ASSERT(fixed == 1);
2651
2671
  char buff[MAX_FIELD_WIDTH];
2652
2672
  String dummy_str(buff, sizeof(buff), default_charset());
2653
2673
  Item *item= find_item(&dummy_str);
2671
2691
    buff should match stack usage from
2672
2692
    Item_func_case::val_int() -> Item_func_case::find_item()
2673
2693
  */
2674
 
  unsigned char buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(int64_t)*2];
 
2694
  uchar buff[MAX_FIELD_WIDTH*2+sizeof(String)*2+sizeof(String*)*2+sizeof(double)*2+sizeof(longlong)*2];
2675
2695
  bool res= Item_func::fix_fields(thd, ref);
2676
2696
  /*
2677
2697
    Call check_stack_overrun after fix_fields to be sure that stack variable
2678
2698
    is not optimized away
2679
2699
  */
2680
2700
  if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
2681
 
    return true;                                // Fatal error flag is set!
 
2701
    return TRUE;                                // Fatal error flag is set!
2682
2702
  return res;
2683
2703
}
2684
2704
 
2693
2713
 
2694
2714
void Item_func_case::agg_num_lengths(Item *arg)
2695
2715
{
2696
 
  uint32_t len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
 
2716
  uint len= my_decimal_length_to_precision(arg->max_length, arg->decimals,
2697
2717
                                           arg->unsigned_flag) - arg->decimals;
2698
2718
  set_if_bigger(max_length, len); 
2699
2719
  set_if_bigger(decimals, arg->decimals);
2704
2724
void Item_func_case::fix_length_and_dec()
2705
2725
{
2706
2726
  Item **agg;
2707
 
  uint32_t nagg;
2708
 
  uint32_t found_types= 0;
 
2727
  uint nagg;
 
2728
  uint found_types= 0;
2709
2729
  if (!(agg= (Item**) sql_alloc(sizeof(Item*)*(ncases+1))))
2710
2730
    return;
2711
2731
  
2732
2752
  */
2733
2753
  if (first_expr_num != -1)
2734
2754
  {
2735
 
    uint32_t i;
 
2755
    uint i;
2736
2756
    agg[0]= args[first_expr_num];
2737
2757
    left_result_type= agg[0]->result_type();
2738
2758
 
2746
2766
    {
2747
2767
      if (found_types & (1 << i) && !cmp_items[i])
2748
2768
      {
2749
 
        assert((Item_result)i != ROW_RESULT);
 
2769
        DBUG_ASSERT((Item_result)i != ROW_RESULT);
2750
2770
        if ((Item_result)i == STRING_RESULT &&
2751
2771
            agg_arg_charsets(cmp_collation, agg, nagg, MY_COLL_CMP_CONV, 1))
2752
2772
          return;
2763
2783
  
2764
2784
  max_length=0;
2765
2785
  decimals=0;
2766
 
  unsigned_flag= true;
 
2786
  unsigned_flag= TRUE;
2767
2787
  if (cached_result_type == STRING_RESULT)
2768
2788
  {
2769
 
    for (uint32_t i= 0; i < ncases; i+= 2)
 
2789
    for (uint i= 0; i < ncases; i+= 2)
2770
2790
      agg_str_lengths(args[i + 1]);
2771
2791
    if (else_expr_num != -1)
2772
2792
      agg_str_lengths(args[else_expr_num]);
2773
2793
  }
2774
2794
  else
2775
2795
  {
2776
 
    for (uint32_t i= 0; i < ncases; i+= 2)
 
2796
    for (uint i= 0; i < ncases; i+= 2)
2777
2797
      agg_num_lengths(args[i + 1]);
2778
2798
    if (else_expr_num != -1) 
2779
2799
      agg_num_lengths(args[else_expr_num]);
2783
2803
}
2784
2804
 
2785
2805
 
2786
 
uint32_t Item_func_case::decimal_precision() const
 
2806
uint Item_func_case::decimal_precision() const
2787
2807
{
2788
2808
  int max_int_part=0;
2789
 
  for (uint32_t i=0 ; i < ncases ; i+=2)
 
2809
  for (uint i=0 ; i < ncases ; i+=2)
2790
2810
    set_if_bigger(max_int_part, args[i+1]->decimal_int_part());
2791
2811
 
2792
2812
  if (else_expr_num != -1) 
2793
2813
    set_if_bigger(max_int_part, args[else_expr_num]->decimal_int_part());
2794
 
  return cmin(max_int_part + decimals, DECIMAL_MAX_PRECISION);
 
2814
  return min(max_int_part + decimals, DECIMAL_MAX_PRECISION);
2795
2815
}
2796
2816
 
2797
2817
 
2808
2828
    args[first_expr_num]->print(str, query_type);
2809
2829
    str->append(' ');
2810
2830
  }
2811
 
  for (uint32_t i=0 ; i < ncases ; i+=2)
 
2831
  for (uint i=0 ; i < ncases ; i+=2)
2812
2832
  {
2813
2833
    str->append(STRING_WITH_LEN("when "));
2814
2834
    args[i]->print(str, query_type);
2828
2848
 
2829
2849
void Item_func_case::cleanup()
2830
2850
{
2831
 
  uint32_t i;
 
2851
  uint i;
 
2852
  DBUG_ENTER("Item_func_case::cleanup");
2832
2853
  Item_func::cleanup();
2833
2854
  for (i= 0; i <= (uint)DECIMAL_RESULT; i++)
2834
2855
  {
2835
2856
    delete cmp_items[i];
2836
2857
    cmp_items[i]= 0;
2837
2858
  }
2838
 
  return;
 
2859
  DBUG_VOID_RETURN;
2839
2860
}
2840
2861
 
2841
2862
 
2845
2866
 
2846
2867
String *Item_func_coalesce::str_op(String *str)
2847
2868
{
2848
 
  assert(fixed == 1);
 
2869
  DBUG_ASSERT(fixed == 1);
2849
2870
  null_value=0;
2850
 
  for (uint32_t i=0 ; i < arg_count ; i++)
 
2871
  for (uint i=0 ; i < arg_count ; i++)
2851
2872
  {
2852
2873
    String *res;
2853
2874
    if ((res=args[i]->val_str(str)))
2857
2878
  return 0;
2858
2879
}
2859
2880
 
2860
 
int64_t Item_func_coalesce::int_op()
 
2881
longlong Item_func_coalesce::int_op()
2861
2882
{
2862
 
  assert(fixed == 1);
 
2883
  DBUG_ASSERT(fixed == 1);
2863
2884
  null_value=0;
2864
 
  for (uint32_t i=0 ; i < arg_count ; i++)
 
2885
  for (uint i=0 ; i < arg_count ; i++)
2865
2886
  {
2866
 
    int64_t res=args[i]->val_int();
 
2887
    longlong res=args[i]->val_int();
2867
2888
    if (!args[i]->null_value)
2868
2889
      return res;
2869
2890
  }
2873
2894
 
2874
2895
double Item_func_coalesce::real_op()
2875
2896
{
2876
 
  assert(fixed == 1);
 
2897
  DBUG_ASSERT(fixed == 1);
2877
2898
  null_value=0;
2878
 
  for (uint32_t i=0 ; i < arg_count ; i++)
 
2899
  for (uint i=0 ; i < arg_count ; i++)
2879
2900
  {
2880
2901
    double res= args[i]->val_real();
2881
2902
    if (!args[i]->null_value)
2888
2909
 
2889
2910
my_decimal *Item_func_coalesce::decimal_op(my_decimal *decimal_value)
2890
2911
{
2891
 
  assert(fixed == 1);
 
2912
  DBUG_ASSERT(fixed == 1);
2892
2913
  null_value= 0;
2893
 
  for (uint32_t i= 0; i < arg_count; i++)
 
2914
  for (uint i= 0; i < arg_count; i++)
2894
2915
  {
2895
2916
    my_decimal *res= args[i]->val_decimal(decimal_value);
2896
2917
    if (!args[i]->null_value)
2923
2944
    break;
2924
2945
  case ROW_RESULT:
2925
2946
  default:
2926
 
    assert(0);
 
2947
    DBUG_ASSERT(0);
2927
2948
  }
2928
2949
}
2929
2950
 
2932
2953
****************************************************************************/
2933
2954
 
2934
2955
/*
2935
 
  Determine which of the signed int64_t arguments is bigger
 
2956
  Determine which of the signed longlong arguments is bigger
2936
2957
 
2937
2958
  SYNOPSIS
2938
2959
    cmp_longs()
2940
2961
      b_val     right argument
2941
2962
 
2942
2963
  DESCRIPTION
2943
 
    This function will compare two signed int64_t arguments
 
2964
    This function will compare two signed longlong arguments
2944
2965
    and will return -1, 0, or 1 if left argument is smaller than,
2945
2966
    equal to or greater than the right argument.
2946
2967
 
2949
2970
    0           left argument is equal to the right argument.
2950
2971
    1           left argument is greater than the right argument.
2951
2972
*/
2952
 
static inline int cmp_longs (int64_t a_val, int64_t b_val)
 
2973
static inline int cmp_longs (longlong a_val, longlong b_val)
2953
2974
{
2954
2975
  return a_val < b_val ? -1 : a_val == b_val ? 0 : 1;
2955
2976
}
2956
2977
 
2957
2978
 
2958
2979
/*
2959
 
  Determine which of the unsigned int64_t arguments is bigger
 
2980
  Determine which of the unsigned longlong arguments is bigger
2960
2981
 
2961
2982
  SYNOPSIS
2962
2983
    cmp_ulongs()
2964
2985
      b_val     right argument
2965
2986
 
2966
2987
  DESCRIPTION
2967
 
    This function will compare two unsigned int64_t arguments
 
2988
    This function will compare two unsigned longlong arguments
2968
2989
    and will return -1, 0, or 1 if left argument is smaller than,
2969
2990
    equal to or greater than the right argument.
2970
2991
 
2973
2994
    0           left argument is equal to the right argument.
2974
2995
    1           left argument is greater than the right argument.
2975
2996
*/
2976
 
static inline int cmp_ulongs (uint64_t a_val, uint64_t b_val)
 
2997
static inline int cmp_ulongs (ulonglong a_val, ulonglong b_val)
2977
2998
{
2978
2999
  return a_val < b_val ? -1 : a_val == b_val ? 0 : 1;
2979
3000
}
2980
3001
 
2981
3002
 
2982
3003
/*
2983
 
  Compare two integers in IN value list format (packed_int64_t) 
 
3004
  Compare two integers in IN value list format (packed_longlong) 
2984
3005
 
2985
3006
  SYNOPSIS
2986
 
    cmp_int64_t()
 
3007
    cmp_longlong()
2987
3008
      cmp_arg   an argument passed to the calling function (my_qsort2)
2988
3009
      a         left argument
2989
3010
      b         right argument
2993
3014
    format and will return -1, 0, or 1 if left argument is smaller than,
2994
3015
    equal to or greater than the right argument.
2995
3016
    It's used in sorting the IN values list and finding an element in it.
2996
 
    Depending on the signedness of the arguments cmp_int64_t() will
 
3017
    Depending on the signedness of the arguments cmp_longlong() will
2997
3018
    compare them as either signed (using cmp_longs()) or unsigned (using
2998
3019
    cmp_ulongs()).
2999
3020
 
3002
3023
    0           left argument is equal to the right argument.
3003
3024
    1           left argument is greater than the right argument.
3004
3025
*/
3005
 
int cmp_int64_t(void *cmp_arg __attribute__((unused)),
3006
 
                 in_int64_t::packed_int64_t *a,
3007
 
                 in_int64_t::packed_int64_t *b)
 
3026
int cmp_longlong(void *cmp_arg, 
 
3027
                 in_longlong::packed_longlong *a,
 
3028
                 in_longlong::packed_longlong *b)
3008
3029
{
3009
3030
  if (a->unsigned_flag != b->unsigned_flag)
3010
3031
  { 
3012
3033
      One of the args is unsigned and is too big to fit into the 
3013
3034
      positive signed range. Report no match.
3014
3035
    */  
3015
 
    if ((a->unsigned_flag && ((uint64_t) a->val) > (uint64_t) INT64_MAX) ||
3016
 
        (b->unsigned_flag && ((uint64_t) b->val) > (uint64_t) INT64_MAX))
 
3036
    if ((a->unsigned_flag && ((ulonglong) a->val) > (ulonglong) LONGLONG_MAX) ||
 
3037
        (b->unsigned_flag && ((ulonglong) b->val) > (ulonglong) LONGLONG_MAX))
3017
3038
      return a->unsigned_flag ? 1 : -1;
3018
3039
    /*
3019
3040
      Although the signedness differs both args can fit into the signed 
3022
3043
    return cmp_longs (a->val, b->val);
3023
3044
  }
3024
3045
  if (a->unsigned_flag)
3025
 
    return cmp_ulongs ((uint64_t) a->val, (uint64_t) b->val);
 
3046
    return cmp_ulongs ((ulonglong) a->val, (ulonglong) b->val);
3026
3047
  else
3027
3048
    return cmp_longs (a->val, b->val);
3028
3049
}
3029
3050
 
3030
 
static int cmp_double(void *cmp_arg __attribute__((unused)), double *a,double *b)
 
3051
static int cmp_double(void *cmp_arg, double *a,double *b)
3031
3052
{
3032
3053
  return *a < *b ? -1 : *a == *b ? 0 : 1;
3033
3054
}
3034
3055
 
3035
 
static int cmp_row(void *cmp_arg __attribute__((unused)), cmp_item_row *a, cmp_item_row *b)
 
3056
static int cmp_row(void *cmp_arg, cmp_item_row *a, cmp_item_row *b)
3036
3057
{
3037
3058
  return a->compare(b);
3038
3059
}
3039
3060
 
3040
3061
 
3041
 
static int cmp_decimal(void *cmp_arg __attribute__((unused)), my_decimal *a, my_decimal *b)
 
3062
static int cmp_decimal(void *cmp_arg, my_decimal *a, my_decimal *b)
3042
3063
{
3043
3064
  /*
3044
3065
    We need call of fixing buffer pointer, because fast sort just copy
3052
3073
 
3053
3074
int in_vector::find(Item *item)
3054
3075
{
3055
 
  unsigned char *result=get_value(item);
 
3076
  uchar *result=get_value(item);
3056
3077
  if (!result || !used_count)
3057
3078
    return 0;                           // Null value
3058
3079
 
3059
 
  uint32_t start,end;
 
3080
  uint start,end;
3060
3081
  start=0; end=used_count-1;
3061
3082
  while (start != end)
3062
3083
  {
3063
 
    uint32_t mid=(start+end+1)/2;
 
3084
    uint mid=(start+end+1)/2;
3064
3085
    int res;
3065
3086
    if ((res=(*compare)(collation, base+mid*size, result)) == 0)
3066
3087
      return 1;
3072
3093
  return (int) ((*compare)(collation, base+start*size, result) == 0);
3073
3094
}
3074
3095
 
3075
 
in_string::in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs)
 
3096
in_string::in_string(uint elements,qsort2_cmp cmp_func, CHARSET_INFO *cs)
3076
3097
  :in_vector(elements, sizeof(String), cmp_func, cs),
3077
3098
   tmp(buff, sizeof(buff), &my_charset_bin)
3078
3099
{}
3082
3103
  if (base)
3083
3104
  {
3084
3105
    // base was allocated with help of sql_alloc => following is OK
3085
 
    for (uint32_t i=0 ; i < count ; i++)
 
3106
    for (uint i=0 ; i < count ; i++)
3086
3107
      ((String*) base)[i].free();
3087
3108
  }
3088
3109
}
3089
3110
 
3090
 
void in_string::set(uint32_t pos,Item *item)
 
3111
void in_string::set(uint pos,Item *item)
3091
3112
{
3092
3113
  String *str=((String*) base)+pos;
3093
3114
  String *res=item->val_str(str);
3102
3123
  }
3103
3124
  if (!str->charset())
3104
3125
  {
3105
 
    const CHARSET_INFO *cs;
 
3126
    CHARSET_INFO *cs;
3106
3127
    if (!(cs= item->collation.collation))
3107
3128
      cs= &my_charset_bin;              // Should never happen for STR items
3108
3129
    str->set_charset(cs);
3110
3131
}
3111
3132
 
3112
3133
 
3113
 
unsigned char *in_string::get_value(Item *item)
 
3134
uchar *in_string::get_value(Item *item)
3114
3135
{
3115
 
  return (unsigned char*) item->val_str(&tmp);
 
3136
  return (uchar*) item->val_str(&tmp);
3116
3137
}
3117
3138
 
3118
 
in_row::in_row(uint32_t elements, Item * item __attribute__((unused)))
 
3139
in_row::in_row(uint elements, Item * item)
3119
3140
{
3120
3141
  base= (char*) new cmp_item_row[count= elements];
3121
3142
  size= sizeof(cmp_item_row);
3134
3155
    delete [] (cmp_item_row*) base;
3135
3156
}
3136
3157
 
3137
 
unsigned char *in_row::get_value(Item *item)
 
3158
uchar *in_row::get_value(Item *item)
3138
3159
{
3139
3160
  tmp.store_value(item);
3140
3161
  if (item->is_null())
3141
3162
    return 0;
3142
 
  return (unsigned char *)&tmp;
 
3163
  return (uchar *)&tmp;
3143
3164
}
3144
3165
 
3145
 
void in_row::set(uint32_t pos, Item *item)
 
3166
void in_row::set(uint pos, Item *item)
3146
3167
{
 
3168
  DBUG_ENTER("in_row::set");
 
3169
  DBUG_PRINT("enter", ("pos: %u  item: 0x%lx", pos, (ulong) item));
3147
3170
  ((cmp_item_row*) base)[pos].store_value_by_template(&tmp, item);
3148
 
  return;
 
3171
  DBUG_VOID_RETURN;
3149
3172
}
3150
3173
 
3151
 
in_int64_t::in_int64_t(uint32_t elements)
3152
 
  :in_vector(elements,sizeof(packed_int64_t),(qsort2_cmp) cmp_int64_t, 0)
 
3174
in_longlong::in_longlong(uint elements)
 
3175
  :in_vector(elements,sizeof(packed_longlong),(qsort2_cmp) cmp_longlong, 0)
3153
3176
{}
3154
3177
 
3155
 
void in_int64_t::set(uint32_t pos,Item *item)
 
3178
void in_longlong::set(uint pos,Item *item)
3156
3179
{
3157
 
  struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
 
3180
  struct packed_longlong *buff= &((packed_longlong*) base)[pos];
3158
3181
  
3159
3182
  buff->val= item->val_int();
3160
3183
  buff->unsigned_flag= item->unsigned_flag;
3161
3184
}
3162
3185
 
3163
 
unsigned char *in_int64_t::get_value(Item *item)
 
3186
uchar *in_longlong::get_value(Item *item)
3164
3187
{
3165
3188
  tmp.val= item->val_int();
3166
3189
  if (item->null_value)
3167
3190
    return 0;
3168
3191
  tmp.unsigned_flag= item->unsigned_flag;
3169
 
  return (unsigned char*) &tmp;
 
3192
  return (uchar*) &tmp;
3170
3193
}
3171
3194
 
3172
 
void in_datetime::set(uint32_t pos,Item *item)
 
3195
void in_datetime::set(uint pos,Item *item)
3173
3196
{
3174
3197
  Item **tmp_item= &item;
3175
3198
  bool is_null;
3176
 
  struct packed_int64_t *buff= &((packed_int64_t*) base)[pos];
 
3199
  struct packed_longlong *buff= &((packed_longlong*) base)[pos];
3177
3200
 
3178
3201
  buff->val= get_datetime_value(thd, &tmp_item, 0, warn_item, &is_null);
3179
3202
  buff->unsigned_flag= 1L;
3180
3203
}
3181
3204
 
3182
 
unsigned char *in_datetime::get_value(Item *item)
 
3205
uchar *in_datetime::get_value(Item *item)
3183
3206
{
3184
3207
  bool is_null;
3185
3208
  Item **tmp_item= lval_cache ? &lval_cache : &item;
3187
3210
  if (item->null_value)
3188
3211
    return 0;
3189
3212
  tmp.unsigned_flag= 1L;
3190
 
  return (unsigned char*) &tmp;
 
3213
  return (uchar*) &tmp;
3191
3214
}
3192
3215
 
3193
 
in_double::in_double(uint32_t elements)
 
3216
in_double::in_double(uint elements)
3194
3217
  :in_vector(elements,sizeof(double),(qsort2_cmp) cmp_double, 0)
3195
3218
{}
3196
3219
 
3197
 
void in_double::set(uint32_t pos,Item *item)
 
3220
void in_double::set(uint pos,Item *item)
3198
3221
{
3199
3222
  ((double*) base)[pos]= item->val_real();
3200
3223
}
3201
3224
 
3202
 
unsigned char *in_double::get_value(Item *item)
 
3225
uchar *in_double::get_value(Item *item)
3203
3226
{
3204
3227
  tmp= item->val_real();
3205
3228
  if (item->null_value)
3206
3229
    return 0;                                   /* purecov: inspected */
3207
 
  return (unsigned char*) &tmp;
 
3230
  return (uchar*) &tmp;
3208
3231
}
3209
3232
 
3210
3233
 
3211
 
in_decimal::in_decimal(uint32_t elements)
 
3234
in_decimal::in_decimal(uint elements)
3212
3235
  :in_vector(elements, sizeof(my_decimal),(qsort2_cmp) cmp_decimal, 0)
3213
3236
{}
3214
3237
 
3215
3238
 
3216
 
void in_decimal::set(uint32_t pos, Item *item)
 
3239
void in_decimal::set(uint pos, Item *item)
3217
3240
{
3218
3241
  /* as far as 'item' is constant, we can store reference on my_decimal */
3219
3242
  my_decimal *dec= ((my_decimal *)base) + pos;
3226
3249
}
3227
3250
 
3228
3251
 
3229
 
unsigned char *in_decimal::get_value(Item *item)
 
3252
uchar *in_decimal::get_value(Item *item)
3230
3253
{
3231
3254
  my_decimal *result= item->val_decimal(&val);
3232
3255
  if (item->null_value)
3233
3256
    return 0;
3234
 
  return (unsigned char *)result;
 
3257
  return (uchar *)result;
3235
3258
}
3236
3259
 
3237
3260
 
3238
3261
cmp_item* cmp_item::get_comparator(Item_result type,
3239
 
                                   const CHARSET_INFO * const cs)
 
3262
                                   CHARSET_INFO *cs)
3240
3263
{
3241
3264
  switch (type) {
3242
3265
  case STRING_RESULT:
3250
3273
  case DECIMAL_RESULT:
3251
3274
    return new cmp_item_decimal;
3252
3275
  default:
3253
 
    assert(0);
 
3276
    DBUG_ASSERT(0);
3254
3277
    break;
3255
3278
  }
3256
3279
  return 0; // to satisfy compiler :)
3280
3303
 
3281
3304
cmp_item_row::~cmp_item_row()
3282
3305
{
 
3306
  DBUG_ENTER("~cmp_item_row");
 
3307
  DBUG_PRINT("enter",("this: 0x%lx", (long) this));
3283
3308
  if (comparators)
3284
3309
  {
3285
 
    for (uint32_t i= 0; i < n; i++)
 
3310
    for (uint i= 0; i < n; i++)
3286
3311
    {
3287
3312
      if (comparators[i])
3288
3313
        delete comparators[i];
3289
3314
    }
3290
3315
  }
3291
 
  return;
 
3316
  DBUG_VOID_RETURN;
3292
3317
}
3293
3318
 
3294
3319
 
3301
3326
 
3302
3327
void cmp_item_row::store_value(Item *item)
3303
3328
{
 
3329
  DBUG_ENTER("cmp_item_row::store_value");
3304
3330
  n= item->cols();
3305
3331
  alloc_comparators();
3306
3332
  if (comparators)
3307
3333
  {
3308
3334
    item->bring_value();
3309
3335
    item->null_value= 0;
3310
 
    for (uint32_t i=0; i < n; i++)
 
3336
    for (uint i=0; i < n; i++)
3311
3337
    {
3312
3338
      if (!comparators[i])
3313
3339
        if (!(comparators[i]=
3318
3344
      item->null_value|= item->element_index(i)->null_value;
3319
3345
    }
3320
3346
  }
3321
 
  return;
 
3347
  DBUG_VOID_RETURN;
3322
3348
}
3323
3349
 
3324
3350
 
3335
3361
  {
3336
3362
    item->bring_value();
3337
3363
    item->null_value= 0;
3338
 
    for (uint32_t i=0; i < n; i++)
 
3364
    for (uint i=0; i < n; i++)
3339
3365
    {
3340
3366
      if (!(comparators[i]= tmpl->comparators[i]->make_same()))
3341
3367
        break;                                  // new failed
3357
3383
  }
3358
3384
  bool was_null= 0;
3359
3385
  arg->bring_value();
3360
 
  for (uint32_t i=0; i < n; i++)
 
3386
  for (uint i=0; i < n; i++)
3361
3387
  {
3362
3388
    if (comparators[i]->cmp(arg->element_index(i)))
3363
3389
    {
3373
3399
int cmp_item_row::compare(cmp_item *c)
3374
3400
{
3375
3401
  cmp_item_row *l_cmp= (cmp_item_row *) c;
3376
 
  for (uint32_t i=0; i < n; i++)
 
3402
  for (uint i=0; i < n; i++)
3377
3403
  {
3378
3404
    int res;
3379
3405
    if ((res= comparators[i]->compare(l_cmp->comparators[i])))
3505
3531
}
3506
3532
 
3507
3533
 
3508
 
static int srtcmp_in(const CHARSET_INFO * const cs, const String *x,const String *y)
 
3534
static int srtcmp_in(CHARSET_INFO *cs, const String *x,const String *y)
3509
3535
{
3510
3536
  return cs->coll->strnncollsp(cs,
3511
 
                               (unsigned char *) x->ptr(),x->length(),
3512
 
                               (unsigned char *) y->ptr(),y->length(), 0);
 
3537
                               (uchar *) x->ptr(),x->length(),
 
3538
                               (uchar *) y->ptr(),y->length(), 0);
3513
3539
}
3514
3540
 
3515
3541
 
3518
3544
  Item **arg, **arg_end;
3519
3545
  bool const_itm= 1;
3520
3546
  THD *thd= current_thd;
3521
 
  bool datetime_found= false;
3522
 
  /* true <=> arguments values will be compared as DATETIMEs. */
3523
 
  bool compare_as_datetime= false;
 
3547
  bool datetime_found= FALSE;
 
3548
  /* TRUE <=> arguments values will be compared as DATETIMEs. */
 
3549
  bool compare_as_datetime= FALSE;
3524
3550
  Item *date_arg= 0;
3525
 
  uint32_t found_types= 0;
3526
 
  uint32_t type_cnt= 0, i;
 
3551
  uint found_types= 0;
 
3552
  uint type_cnt= 0, i;
3527
3553
  Item_result cmp_type= STRING_RESULT;
3528
3554
  left_result_type= args[0]->result_type();
3529
3555
  if (!(found_types= collect_cmp_types(args, arg_count)))
3551
3577
    if (cmp_type == STRING_RESULT && 
3552
3578
        agg_arg_charsets(cmp_collation, args, arg_count, MY_COLL_CMP_CONV, 1))
3553
3579
      return;
3554
 
    arg_types_compatible= true;
 
3580
    arg_types_compatible= TRUE;
3555
3581
  }
3556
3582
  if (type_cnt == 1)
3557
3583
  {
3579
3605
    /* All DATE/DATETIME fields/functions has the STRING result type. */
3580
3606
    if (cmp_type == STRING_RESULT || cmp_type == ROW_RESULT)
3581
3607
    {
3582
 
      uint32_t col, cols= args[0]->cols();
 
3608
      uint col, cols= args[0]->cols();
3583
3609
 
3584
3610
      for (col= 0; col < cols; col++)
3585
3611
      {
3586
 
        bool skip_column= false;
 
3612
        bool skip_column= FALSE;
3587
3613
        /*
3588
3614
          Check that all items to be compared has the STRING result type and at
3589
3615
          least one of them is a DATE/DATETIME item.
3594
3620
                      arg[0]->element_index(col));
3595
3621
          if (itm->result_type() != STRING_RESULT)
3596
3622
          {
3597
 
            skip_column= true;
 
3623
            skip_column= TRUE;
3598
3624
            break;
3599
3625
          }
3600
3626
          else if (itm->is_datetime())
3601
3627
          {
3602
 
            datetime_found= true;
 
3628
            datetime_found= TRUE;
3603
3629
            /*
3604
3630
              Internally all DATE/DATETIME values are converted to the DATETIME
3605
3631
              type. So try to find a DATETIME item to issue correct warnings.
3606
3632
            */
3607
3633
            if (!date_arg)
3608
3634
              date_arg= itm;
3609
 
            else if (itm->field_type() == DRIZZLE_TYPE_DATETIME)
 
3635
            else if (itm->field_type() == MYSQL_TYPE_DATETIME)
3610
3636
            {
3611
3637
              date_arg= itm;
3612
3638
              /* All arguments are already checked to have the STRING result. */
3629
3655
            *cmp= new cmp_item_datetime(date_arg);
3630
3656
            /* Reset variables for the next column. */
3631
3657
            date_arg= 0;
3632
 
            datetime_found= false;
 
3658
            datetime_found= FALSE;
3633
3659
          }
3634
3660
          else
3635
 
            compare_as_datetime= true;
 
3661
            compare_as_datetime= TRUE;
3636
3662
        }
3637
3663
      }
3638
3664
    }
3639
3665
  }
3640
3666
  /*
3641
 
    Row item with NULLs inside can return NULL or false =>
 
3667
    Row item with NULLs inside can return NULL or FALSE =>
3642
3668
    they can't be processed as static
3643
3669
  */
3644
3670
  if (type_cnt == 1 && const_itm && !nulls_in_row())
3659
3685
          cmp_type != INT_RESULT)
3660
3686
      {
3661
3687
        Item_field *field_item= (Item_field*) (args[0]->real_item());
3662
 
        if (field_item->field->can_be_compared_as_int64_t())
 
3688
        if (field_item->field->can_be_compared_as_longlong())
3663
3689
        {
3664
 
          bool all_converted= true;
 
3690
          bool all_converted= TRUE;
3665
3691
          for (arg=args+1, arg_end=args+arg_count; arg != arg_end ; arg++)
3666
3692
          {
3667
3693
            if (!convert_constant_item (thd, field_item, &arg[0]))
3668
 
              all_converted= false;
 
3694
              all_converted= FALSE;
3669
3695
          }
3670
3696
          if (all_converted)
3671
3697
            cmp_type= INT_RESULT;
3677
3703
                            cmp_collation.collation);
3678
3704
        break;
3679
3705
      case INT_RESULT:
3680
 
        array= new in_int64_t(arg_count-1);
 
3706
        array= new in_longlong(arg_count-1);
3681
3707
        break;
3682
3708
      case REAL_RESULT:
3683
3709
        array= new in_double(arg_count-1);
3694
3720
        array= new in_decimal(arg_count - 1);
3695
3721
        break;
3696
3722
      default:
3697
 
        assert(0);
 
3723
        DBUG_ASSERT(0);
3698
3724
        return;
3699
3725
      }
3700
3726
    }
3701
3727
    if (array && !(thd->is_fatal_error))                // If not EOM
3702
3728
    {
3703
 
      uint32_t j=0;
3704
 
      for (uint32_t i=1 ; i < arg_count ; i++)
 
3729
      uint j=0;
 
3730
      for (uint i=1 ; i < arg_count ; i++)
3705
3731
      {
3706
3732
        array->set(j,args[i]);
3707
3733
        if (!args[i]->null_value)                       // Skip NULL values
3776
3802
    Value of the function
3777
3803
*/
3778
3804
 
3779
 
int64_t Item_func_in::val_int()
 
3805
longlong Item_func_in::val_int()
3780
3806
{
3781
3807
  cmp_item *in_item;
3782
 
  assert(fixed == 1);
3783
 
  uint32_t value_added_map= 0;
 
3808
  DBUG_ASSERT(fixed == 1);
 
3809
  uint value_added_map= 0;
3784
3810
  if (array)
3785
3811
  {
3786
3812
    int tmp=array->find(args[0]);
3787
3813
    null_value=args[0]->null_value || (!tmp && have_null);
3788
 
    return (int64_t) (!null_value && tmp != negated);
 
3814
    return (longlong) (!null_value && tmp != negated);
3789
3815
  }
3790
3816
 
3791
 
  for (uint32_t i= 1 ; i < arg_count ; i++)
 
3817
  for (uint i= 1 ; i < arg_count ; i++)
3792
3818
  {
3793
3819
    Item_result cmp_type= item_cmp_type(left_result_type, args[i]->result_type());
3794
3820
    in_item= cmp_items[(uint)cmp_type];
3795
 
    assert(in_item);
 
3821
    DBUG_ASSERT(in_item);
3796
3822
    if (!(value_added_map & (1 << (uint)cmp_type)))
3797
3823
    {
3798
3824
      in_item->store_value(args[0]);
3802
3828
      value_added_map|= 1 << (uint)cmp_type;
3803
3829
    }
3804
3830
    if (!in_item->cmp(args[i]) && !args[i]->null_value)
3805
 
      return (int64_t) (!negated);
 
3831
      return (longlong) (!negated);
3806
3832
    have_null|= args[i]->null_value;
3807
3833
  }
3808
3834
 
3809
3835
  null_value= have_null;
3810
 
  return (int64_t) (!null_value && negated);
 
3836
  return (longlong) (!null_value && negated);
3811
3837
}
3812
3838
 
3813
3839
 
3814
 
int64_t Item_func_bit_or::val_int()
 
3840
longlong Item_func_bit_or::val_int()
3815
3841
{
3816
 
  assert(fixed == 1);
3817
 
  uint64_t arg1= (uint64_t) args[0]->val_int();
 
3842
  DBUG_ASSERT(fixed == 1);
 
3843
  ulonglong arg1= (ulonglong) args[0]->val_int();
3818
3844
  if (args[0]->null_value)
3819
3845
  {
3820
3846
    null_value=1; /* purecov: inspected */
3821
3847
    return 0; /* purecov: inspected */
3822
3848
  }
3823
 
  uint64_t arg2= (uint64_t) args[1]->val_int();
 
3849
  ulonglong arg2= (ulonglong) args[1]->val_int();
3824
3850
  if (args[1]->null_value)
3825
3851
  {
3826
3852
    null_value=1;
3827
3853
    return 0;
3828
3854
  }
3829
3855
  null_value=0;
3830
 
  return (int64_t) (arg1 | arg2);
 
3856
  return (longlong) (arg1 | arg2);
3831
3857
}
3832
3858
 
3833
3859
 
3834
 
int64_t Item_func_bit_and::val_int()
 
3860
longlong Item_func_bit_and::val_int()
3835
3861
{
3836
 
  assert(fixed == 1);
3837
 
  uint64_t arg1= (uint64_t) args[0]->val_int();
 
3862
  DBUG_ASSERT(fixed == 1);
 
3863
  ulonglong arg1= (ulonglong) args[0]->val_int();
3838
3864
  if (args[0]->null_value)
3839
3865
  {
3840
3866
    null_value=1; /* purecov: inspected */
3841
3867
    return 0; /* purecov: inspected */
3842
3868
  }
3843
 
  uint64_t arg2= (uint64_t) args[1]->val_int();
 
3869
  ulonglong arg2= (ulonglong) args[1]->val_int();
3844
3870
  if (args[1]->null_value)
3845
3871
  {
3846
3872
    null_value=1; /* purecov: inspected */
3847
3873
    return 0; /* purecov: inspected */
3848
3874
  }
3849
3875
  null_value=0;
3850
 
  return (int64_t) (arg1 & arg2);
 
3876
  return (longlong) (arg1 & arg2);
3851
3877
}
3852
3878
 
3853
3879
Item_cond::Item_cond(THD *thd, Item_cond *item)
3870
3896
 
3871
3897
 
3872
3898
bool
3873
 
Item_cond::fix_fields(THD *thd, Item **ref __attribute__((unused)))
 
3899
Item_cond::fix_fields(THD *thd, Item **ref)
3874
3900
{
3875
 
  assert(fixed == 0);
 
3901
  DBUG_ASSERT(fixed == 0);
3876
3902
  List_iterator<Item> li(list);
3877
3903
  Item *item;
3878
3904
  void *orig_thd_marker= thd->thd_marker;
3879
 
  unsigned char buff[sizeof(char*)];                    // Max local vars in function
 
3905
  uchar buff[sizeof(char*)];                    // Max local vars in function
3880
3906
  not_null_tables_cache= used_tables_cache= 0;
3881
3907
  const_item_cache= 1;
3882
3908
 
3889
3915
  and_tables_cache= ~(table_map) 0;
3890
3916
 
3891
3917
  if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
3892
 
    return true;                                // Fatal error flag is set!
 
3918
    return TRUE;                                // Fatal error flag is set!
3893
3919
  /*
3894
3920
    The following optimization reduces the depth of an AND-OR tree.
3895
3921
    E.g. a WHERE clause like
3923
3949
    if ((!item->fixed &&
3924
3950
         item->fix_fields(thd, li.ref())) ||
3925
3951
        (item= *li.ref())->check_cols(1))
3926
 
      return true; /* purecov: inspected */
 
3952
      return TRUE; /* purecov: inspected */
3927
3953
    used_tables_cache|=     item->used_tables();
3928
3954
    if (item->const_item())
3929
3955
      and_tables_cache= (table_map) 0;
3932
3958
      tmp_table_map= item->not_null_tables();
3933
3959
      not_null_tables_cache|= tmp_table_map;
3934
3960
      and_tables_cache&= tmp_table_map;
3935
 
      const_item_cache= false;
 
3961
      const_item_cache= FALSE;
3936
3962
    }  
3937
3963
    with_sum_func=          with_sum_func || item->with_sum_func;
3938
3964
    with_subselect|=        item->with_subselect;
3943
3969
  thd->thd_marker= orig_thd_marker;
3944
3970
  fix_length_and_dec();
3945
3971
  fixed= 1;
3946
 
  return false;
 
3972
  return FALSE;
3947
3973
}
3948
3974
 
3949
3975
 
3950
 
void Item_cond::fix_after_pullout(st_select_lex *new_parent, Item **ref __attribute__((unused)))
 
3976
void Item_cond::fix_after_pullout(st_select_lex *new_parent, Item **ref)
3951
3977
{
3952
3978
  List_iterator<Item> li(list);
3953
3979
  Item *item;
3973
3999
      tmp_table_map= item->not_null_tables();
3974
4000
      not_null_tables_cache|= tmp_table_map;
3975
4001
      and_tables_cache&= tmp_table_map;
3976
 
      const_item_cache= false;
 
4002
      const_item_cache= FALSE;
3977
4003
    }  
3978
4004
  }
3979
4005
}
3980
4006
 
3981
4007
 
3982
 
bool Item_cond::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
4008
bool Item_cond::walk(Item_processor processor, bool walk_subquery, uchar *arg)
3983
4009
{
3984
4010
  List_iterator_fast<Item> li(list);
3985
4011
  Item *item;
4008
4034
    Item returned as the result of transformation of the root node 
4009
4035
*/
4010
4036
 
4011
 
Item *Item_cond::transform(Item_transformer transformer, unsigned char *arg)
 
4037
Item *Item_cond::transform(Item_transformer transformer, uchar *arg)
4012
4038
{
4013
4039
  List_iterator<Item> li(list);
4014
4040
  Item *item;
4036
4062
  callback functions.
4037
4063
  
4038
4064
    First the function applies the analyzer to the root node of
4039
 
    the Item_func object. Then if the analyzer succeeeds (returns true)
 
4065
    the Item_func object. Then if the analyzer succeeeds (returns TRUE)
4040
4066
    the function recursively applies the compile method to member
4041
4067
    item of the condition list.
4042
4068
    If the call of the method for a member item returns a new item
4055
4081
    Item returned as the result of transformation of the root node 
4056
4082
*/
4057
4083
 
4058
 
Item *Item_cond::compile(Item_analyzer analyzer, unsigned char **arg_p,
4059
 
                         Item_transformer transformer, unsigned char *arg_t)
 
4084
Item *Item_cond::compile(Item_analyzer analyzer, uchar **arg_p,
 
4085
                         Item_transformer transformer, uchar *arg_t)
4060
4086
{
4061
4087
  if (!(this->*analyzer)(arg_p))
4062
4088
    return 0;
4069
4095
      The same parameter value of arg_p must be passed
4070
4096
      to analyze any argument of the condition formula.
4071
4097
    */   
4072
 
    unsigned char *arg_v= *arg_p;
 
4098
    uchar *arg_v= *arg_p;
4073
4099
    Item *new_item= item->compile(analyzer, &arg_v, transformer, arg_t);
4074
4100
    if (new_item && new_item != item)
4075
4101
      li.replace(new_item);
4124
4150
  List_iterator<Item> li(list);
4125
4151
  Item *item;
4126
4152
  while ((item= li++))
4127
 
    item->split_sum_func2(thd, ref_pointer_array, fields, li.ref(), true);
 
4153
    item->split_sum_func2(thd, ref_pointer_array, fields, li.ref(), TRUE);
4128
4154
}
4129
4155
 
4130
4156
 
4181
4207
      if (!(new_item= new Item_func_not(item)))
4182
4208
        return;                                 // Fatal OEM error
4183
4209
    }
4184
 
    li.replace(new_item);
 
4210
    VOID(li.replace(new_item));
4185
4211
  }
4186
4212
}
4187
4213
 
4206
4232
*/
4207
4233
 
4208
4234
 
4209
 
int64_t Item_cond_and::val_int()
 
4235
longlong Item_cond_and::val_int()
4210
4236
{
4211
 
  assert(fixed == 1);
 
4237
  DBUG_ASSERT(fixed == 1);
4212
4238
  List_iterator_fast<Item> li(list);
4213
4239
  Item *item;
4214
4240
  null_value= 0;
4217
4243
    if (!item->val_bool())
4218
4244
    {
4219
4245
      if (abort_on_null || !(null_value= item->null_value))
4220
 
        return 0;                               // return false
 
4246
        return 0;                               // return FALSE
4221
4247
    }
4222
4248
  }
4223
4249
  return null_value ? 0 : 1;
4224
4250
}
4225
4251
 
4226
4252
 
4227
 
int64_t Item_cond_or::val_int()
 
4253
longlong Item_cond_or::val_int()
4228
4254
{
4229
 
  assert(fixed == 1);
 
4255
  DBUG_ASSERT(fixed == 1);
4230
4256
  List_iterator_fast<Item> li(list);
4231
4257
  Item *item;
4232
4258
  null_value=0;
4285
4311
}
4286
4312
 
4287
4313
 
4288
 
int64_t Item_func_isnull::val_int()
 
4314
longlong Item_func_isnull::val_int()
4289
4315
{
4290
 
  assert(fixed == 1);
 
4316
  DBUG_ASSERT(fixed == 1);
4291
4317
  /*
4292
4318
    Handle optimization if the argument can't be null
4293
4319
    This has to be here because of the test in update_used_tables().
4297
4323
  return args[0]->is_null() ? 1: 0;
4298
4324
}
4299
4325
 
4300
 
int64_t Item_is_not_null_test::val_int()
 
4326
longlong Item_is_not_null_test::val_int()
4301
4327
{
4302
 
  assert(fixed == 1);
 
4328
  DBUG_ASSERT(fixed == 1);
 
4329
  DBUG_ENTER("Item_is_not_null_test::val_int");
4303
4330
  if (!used_tables_cache && !with_subselect)
4304
4331
  {
4305
4332
    owner->was_null|= (!cached_value);
4306
 
    return(cached_value);
 
4333
    DBUG_PRINT("info", ("cached: %ld", (long) cached_value));
 
4334
    DBUG_RETURN(cached_value);
4307
4335
  }
4308
4336
  if (args[0]->is_null())
4309
4337
  {
 
4338
    DBUG_PRINT("info", ("null"));
4310
4339
    owner->was_null|= 1;
4311
 
    return(0);
 
4340
    DBUG_RETURN(0);
4312
4341
  }
4313
4342
  else
4314
 
    return(1);
 
4343
    DBUG_RETURN(1);
4315
4344
}
4316
4345
 
4317
4346
/**
4322
4351
  if (!args[0]->maybe_null)
4323
4352
  {
4324
4353
    used_tables_cache= 0;                       /* is always true */
4325
 
    cached_value= (int64_t) 1;
 
4354
    cached_value= (longlong) 1;
4326
4355
  }
4327
4356
  else
4328
4357
  {
4330
4359
    if (!(used_tables_cache=args[0]->used_tables()) && !with_subselect)
4331
4360
    {
4332
4361
      /* Remember if the value is always NULL or never NULL */
4333
 
      cached_value= (int64_t) !args[0]->is_null();
 
4362
      cached_value= (longlong) !args[0]->is_null();
4334
4363
    }
4335
4364
  }
4336
4365
}
4337
4366
 
4338
4367
 
4339
 
int64_t Item_func_isnotnull::val_int()
 
4368
longlong Item_func_isnotnull::val_int()
4340
4369
{
4341
 
  assert(fixed == 1);
 
4370
  DBUG_ASSERT(fixed == 1);
4342
4371
  return args[0]->is_null() ? 0 : 1;
4343
4372
}
4344
4373
 
4351
4380
}
4352
4381
 
4353
4382
 
4354
 
int64_t Item_func_like::val_int()
 
4383
longlong Item_func_like::val_int()
4355
4384
{
4356
 
  assert(fixed == 1);
 
4385
  DBUG_ASSERT(fixed == 1);
4357
4386
  String* res = args[0]->val_str(&tmp_value1);
4358
4387
  if (args[0]->null_value)
4359
4388
  {
4401
4430
 
4402
4431
bool Item_func_like::fix_fields(THD *thd, Item **ref)
4403
4432
{
4404
 
  assert(fixed == 0);
 
4433
  DBUG_ASSERT(fixed == 0);
4405
4434
  if (Item_bool_func2::fix_fields(thd, ref) ||
4406
4435
      escape_item->fix_fields(thd, &escape_item))
4407
 
    return true;
 
4436
    return TRUE;
4408
4437
 
4409
4438
  if (!escape_item->const_during_execution())
4410
4439
  {
4411
4440
    my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
4412
 
    return true;
 
4441
    return TRUE;
4413
4442
  }
4414
4443
  
4415
4444
  if (escape_item->const_item())
4418
4447
    String *escape_str= escape_item->val_str(&tmp_value1);
4419
4448
    if (escape_str)
4420
4449
    {
4421
 
      if (escape_used_in_parsing && escape_str->numchars() > 1)
 
4450
      if (escape_used_in_parsing && (
 
4451
             (((thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) &&
 
4452
                escape_str->numchars() != 1) ||
 
4453
               escape_str->numchars() > 1)))
4422
4454
      {
4423
4455
        my_error(ER_WRONG_ARGUMENTS,MYF(0),"ESCAPE");
4424
 
        return true;
 
4456
        return TRUE;
4425
4457
      }
4426
4458
 
4427
4459
      if (use_mb(cmp.cmp_collation.collation))
4428
4460
      {
4429
 
        const CHARSET_INFO * const cs= escape_str->charset();
 
4461
        CHARSET_INFO *cs= escape_str->charset();
4430
4462
        my_wc_t wc;
4431
4463
        int rc= cs->cset->mb_wc(cs, &wc,
4432
 
                                (const unsigned char*) escape_str->ptr(),
4433
 
                                (const unsigned char*) escape_str->ptr() +
 
4464
                                (const uchar*) escape_str->ptr(),
 
4465
                                (const uchar*) escape_str->ptr() +
4434
4466
                                               escape_str->length());
4435
4467
        escape= (int) (rc > 0 ? wc : '\\');
4436
4468
      }
4441
4473
          code instead of Unicode code as "escape" argument.
4442
4474
          Convert to "cs" if charset of escape differs.
4443
4475
        */
4444
 
        const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
4445
 
        uint32_t unused;
 
4476
        CHARSET_INFO *cs= cmp.cmp_collation.collation;
 
4477
        uint32 unused;
4446
4478
        if (escape_str->needs_conversion(escape_str->length(),
4447
4479
                                         escape_str->charset(), cs, &unused))
4448
4480
        {
4449
4481
          char ch;
4450
 
          uint32_t errors;
4451
 
          uint32_t cnvlen= copy_and_convert(&ch, 1, cs, escape_str->ptr(),
 
4482
          uint errors;
 
4483
          uint32 cnvlen= copy_and_convert(&ch, 1, cs, escape_str->ptr(),
4452
4484
                                          escape_str->length(),
4453
4485
                                          escape_str->charset(), &errors);
4454
4486
          escape= cnvlen ? ch : '\\';
4464
4496
      We could also do boyer-more for non-const items, but as we would have to
4465
4497
      recompute the tables for each row it's not worth it.
4466
4498
    */
4467
 
    if (args[1]->const_item() && !use_strnxfrm(collation.collation)) 
 
4499
    if (args[1]->const_item() && !use_strnxfrm(collation.collation) &&
 
4500
       !(specialflag & SPECIAL_NO_NEW_FUNC))
4468
4501
    {
4469
4502
      String* res2 = args[1]->val_str(&tmp_value2);
4470
4503
      if (!res2)
4471
 
        return false;                           // Null argument
 
4504
        return FALSE;                           // Null argument
4472
4505
      
4473
4506
      const size_t len   = res2->length();
4474
4507
      const char*  first = res2->ptr();
4490
4523
      {
4491
4524
        pattern     = first + 1;
4492
4525
        pattern_len = (int) len - 2;
 
4526
        DBUG_PRINT("info", ("Initializing pattern: '%s'", first));
4493
4527
        int *suff = (int*) thd->alloc((int) (sizeof(int)*
4494
4528
                                      ((pattern_len + 1)*2+
4495
4529
                                      alphabet_size)));
4497
4531
        bmBc      = bmGs + pattern_len + 1;
4498
4532
        turboBM_compute_good_suffix_shifts(suff);
4499
4533
        turboBM_compute_bad_character_shifts();
 
4534
        DBUG_PRINT("info",("done"));
4500
4535
      }
4501
4536
    }
4502
4537
  }
4503
 
  return false;
 
4538
  return FALSE;
4504
4539
}
4505
4540
 
4506
4541
void Item_func_like::cleanup()
4507
4542
{
4508
 
  canDoTurboBM= false;
 
4543
  canDoTurboBM= FALSE;
4509
4544
  Item_bool_func2::cleanup();
4510
4545
}
4511
4546
 
4512
4547
#ifdef LIKE_CMP_TOUPPER
4513
 
#define likeconv(cs,A) (unsigned char) (cs)->toupper(A)
 
4548
#define likeconv(cs,A) (uchar) (cs)->toupper(A)
4514
4549
#else
4515
 
#define likeconv(cs,A) (unsigned char) (cs)->sort_order[(unsigned char) (A)]
 
4550
#define likeconv(cs,A) (uchar) (cs)->sort_order[(uchar) (A)]
4516
4551
#endif
4517
4552
 
4518
4553
 
4526
4561
  int            f = 0;
4527
4562
  int            g = plm1;
4528
4563
  int *const splm1 = suff + plm1;
4529
 
  const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
 
4564
  CHARSET_INFO  *cs= cmp.cmp_collation.collation;
4530
4565
 
4531
4566
  *splm1 = pattern_len;
4532
4567
 
4541
4576
      else
4542
4577
      {
4543
4578
        if (i < g)
4544
 
          g = i; // g = cmin(i, g)
 
4579
          g = i; // g = min(i, g)
4545
4580
        f = i;
4546
4581
        while (g >= 0 && pattern[g] == pattern[g + plm1 - f])
4547
4582
          g--;
4560
4595
      else
4561
4596
      {
4562
4597
        if (i < g)
4563
 
          g = i; // g = cmin(i, g)
 
4598
          g = i; // g = min(i, g)
4564
4599
        f = i;
4565
4600
        while (g >= 0 &&
4566
4601
               likeconv(cs, pattern[g]) == likeconv(cs, pattern[g + plm1 - f]))
4626
4661
  int *end = bmBc + alphabet_size;
4627
4662
  int j;
4628
4663
  const int plm1 = pattern_len - 1;
4629
 
  const CHARSET_INFO *const cs= cmp.cmp_collation.collation;
 
4664
  CHARSET_INFO  *cs= cmp.cmp_collation.collation;
4630
4665
 
4631
4666
  for (i = bmBc; i < end; i++)
4632
4667
    *i = pattern_len;
4634
4669
  if (!cs->sort_order)
4635
4670
  {
4636
4671
    for (j = 0; j < plm1; j++)
4637
 
      bmBc[(uint) (unsigned char) pattern[j]] = plm1 - j;
 
4672
      bmBc[(uint) (uchar) pattern[j]] = plm1 - j;
4638
4673
  }
4639
4674
  else
4640
4675
  {
4658
4693
  int shift = pattern_len;
4659
4694
  int j     = 0;
4660
4695
  int u     = 0;
4661
 
  const CHARSET_INFO * const cs= cmp.cmp_collation.collation;
 
4696
  CHARSET_INFO  *cs= cmp.cmp_collation.collation;
4662
4697
 
4663
4698
  const int plm1=  pattern_len - 1;
4664
4699
  const int tlmpl= text_len - pattern_len;
4680
4715
 
4681
4716
      register const int v = plm1 - i;
4682
4717
      turboShift = u - v;
4683
 
      bcShift    = bmBc[(uint) (unsigned char) text[i + j]] - plm1 + i;
4684
 
      shift      = (turboShift > bcShift) ? turboShift : bcShift;
4685
 
      shift      = (shift > bmGs[i]) ? shift : bmGs[i];
 
4718
      bcShift    = bmBc[(uint) (uchar) text[i + j]] - plm1 + i;
 
4719
      shift      = max(turboShift, bcShift);
 
4720
      shift      = max(shift, bmGs[i]);
4686
4721
      if (shift == bmGs[i])
4687
 
        u = (pattern_len - shift < v) ? pattern_len - shift : v;
 
4722
        u = min(pattern_len - shift, v);
4688
4723
      else
4689
4724
      {
4690
4725
        if (turboShift < bcShift)
4691
 
          shift = cmax(shift, u + 1);
 
4726
          shift = max(shift, u + 1);
4692
4727
        u = 0;
4693
4728
      }
4694
4729
      j+= shift;
4712
4747
      register const int v = plm1 - i;
4713
4748
      turboShift = u - v;
4714
4749
      bcShift    = bmBc[(uint) likeconv(cs, text[i + j])] - plm1 + i;
4715
 
      shift      = (turboShift > bcShift) ? turboShift : bcShift;
4716
 
      shift      = cmax(shift, bmGs[i]);
 
4750
      shift      = max(turboShift, bcShift);
 
4751
      shift      = max(shift, bmGs[i]);
4717
4752
      if (shift == bmGs[i])
4718
 
        u = (pattern_len - shift < v) ? pattern_len - shift : v;
 
4753
        u = min(pattern_len - shift, v);
4719
4754
      else
4720
4755
      {
4721
4756
        if (turboShift < bcShift)
4722
 
          shift = cmax(shift, u + 1);
 
4757
          shift = max(shift, u + 1);
4723
4758
        u = 0;
4724
4759
      }
4725
4760
      j+= shift;
4745
4780
    very fast to use.
4746
4781
*/
4747
4782
 
4748
 
int64_t Item_cond_xor::val_int()
 
4783
longlong Item_cond_xor::val_int()
4749
4784
{
4750
 
  assert(fixed == 1);
 
4785
  DBUG_ASSERT(fixed == 1);
4751
4786
  List_iterator<Item> li(list);
4752
4787
  Item *item;
4753
4788
  int result=0; 
4761
4796
      return 0;
4762
4797
    }
4763
4798
  }
4764
 
  return (int64_t) result;
 
4799
  return (longlong) result;
4765
4800
}
4766
4801
 
4767
4802
/**
4790
4825
    NULL if we cannot apply NOT transformation (see Item::neg_transformer()).
4791
4826
*/
4792
4827
 
4793
 
Item *Item_func_not::neg_transformer(THD *thd __attribute__((unused)))  /* NOT(x)  ->  x */
 
4828
Item *Item_func_not::neg_transformer(THD *thd)  /* NOT(x)  ->  x */
4794
4829
{
4795
4830
  return args[0];
4796
4831
}
4797
4832
 
4798
4833
 
4799
 
Item *Item_bool_rowready_func2::neg_transformer(THD *thd __attribute__((unused)))
 
4834
Item *Item_bool_rowready_func2::neg_transformer(THD *thd)
4800
4835
{
4801
4836
  Item *item= negated_item();
4802
4837
  return item;
4806
4841
/**
4807
4842
  a IS NULL  ->  a IS NOT NULL.
4808
4843
*/
4809
 
Item *Item_func_isnull::neg_transformer(THD *thd __attribute__((unused)))
 
4844
Item *Item_func_isnull::neg_transformer(THD *thd)
4810
4845
{
4811
4846
  Item *item= new Item_func_isnotnull(args[0]);
4812
4847
  return item;
4816
4851
/**
4817
4852
  a IS NOT NULL  ->  a IS NULL.
4818
4853
*/
4819
 
Item *Item_func_isnotnull::neg_transformer(THD *thd __attribute__((unused)))
 
4854
Item *Item_func_isnotnull::neg_transformer(THD *thd)
4820
4855
{
4821
4856
  Item *item= new Item_func_isnull(args[0]);
4822
4857
  return item;
4841
4876
}
4842
4877
 
4843
4878
 
4844
 
Item *Item_func_nop_all::neg_transformer(THD *thd __attribute__((unused)))
 
4879
Item *Item_func_nop_all::neg_transformer(THD *thd)
4845
4880
{
4846
4881
  /* "NOT (e $cmp$ ANY (SELECT ...)) -> e $rev_cmp$" ALL (SELECT ...) */
4847
4882
  Item_func_not_all *new_item= new Item_func_not_all(args[0]);
4848
4883
  Item_allany_subselect *allany= (Item_allany_subselect*)args[0];
4849
 
  allany->func= allany->func_creator(false);
 
4884
  allany->func= allany->func_creator(FALSE);
4850
4885
  allany->all= !allany->all;
4851
4886
  allany->upper_item= new_item;
4852
4887
  return new_item;
4853
4888
}
4854
4889
 
4855
 
Item *Item_func_not_all::neg_transformer(THD *thd __attribute__((unused)))
 
4890
Item *Item_func_not_all::neg_transformer(THD *thd)
4856
4891
{
4857
4892
  /* "NOT (e $cmp$ ALL (SELECT ...)) -> e $rev_cmp$" ANY (SELECT ...) */
4858
4893
  Item_func_nop_all *new_item= new Item_func_nop_all(args[0]);
4859
4894
  Item_allany_subselect *allany= (Item_allany_subselect*)args[0];
4860
4895
  allany->all= !allany->all;
4861
 
  allany->func= allany->func_creator(true);
 
4896
  allany->func= allany->func_creator(TRUE);
4862
4897
  allany->upper_item= new_item;
4863
4898
  return new_item;
4864
4899
}
4903
4938
*/
4904
4939
Item *Item_bool_rowready_func2::negated_item()
4905
4940
{
4906
 
  assert(0);
 
4941
  DBUG_ASSERT(0);
4907
4942
  return 0;
4908
4943
}
4909
4944
 
4959
4994
  fields.push_back(f);
4960
4995
}
4961
4996
 
4962
 
uint32_t Item_equal::members()
 
4997
uint Item_equal::members()
4963
4998
{
4964
4999
  return fields.elements;
4965
5000
}
5046
5081
    Item_field **ref1= it.ref();
5047
5082
    Item_field *item2;
5048
5083
 
5049
 
    swap= false;
 
5084
    swap= FALSE;
5050
5085
    while ((item2= it++))
5051
5086
    {
5052
5087
      Item_field **ref2= it.ref();
5055
5090
        Item_field *item= *ref1;
5056
5091
        *ref1= *ref2;
5057
5092
        *ref2= item;
5058
 
        swap= true;
 
5093
        swap= TRUE;
5059
5094
      }
5060
5095
      else
5061
5096
      {
5092
5127
  }
5093
5128
}
5094
5129
 
5095
 
bool Item_equal::fix_fields(THD *thd __attribute__((unused)), Item **ref __attribute__((unused)))
 
5130
bool Item_equal::fix_fields(THD *thd, Item **ref)
5096
5131
{
5097
5132
  List_iterator_fast<Item_field> li(fields);
5098
5133
  Item *item;
5127
5162
  }
5128
5163
}
5129
5164
 
5130
 
int64_t Item_equal::val_int()
 
5165
longlong Item_equal::val_int()
5131
5166
{
5132
5167
  Item_field *item_field;
5133
5168
  if (cond_false)
5156
5191
                                      item->collation.collation);
5157
5192
}
5158
5193
 
5159
 
bool Item_equal::walk(Item_processor processor, bool walk_subquery, unsigned char *arg)
 
5194
bool Item_equal::walk(Item_processor processor, bool walk_subquery, uchar *arg)
5160
5195
{
5161
5196
  List_iterator_fast<Item_field> it(fields);
5162
5197
  Item *item;
5168
5203
  return Item_func::walk(processor, walk_subquery, arg);
5169
5204
}
5170
5205
 
5171
 
Item *Item_equal::transform(Item_transformer transformer, unsigned char *arg)
 
5206
Item *Item_equal::transform(Item_transformer transformer, uchar *arg)
5172
5207
{
5173
5208
  List_iterator<Item_field> it(fields);
5174
5209
  Item *item;