~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_cmpfunc.h

  • Committer: Brian Aker
  • Date: 2008-07-07 14:25:25 UTC
  • mto: (77.1.25 codestyle)
  • mto: This revision was merged to the branch mainline in revision 82.
  • Revision ID: brian@tangent.org-20080707142525-xzy2nl3ie2ebwfln
LL() cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
 
21
17
/* compare and test functions */
22
18
 
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
23
22
 
24
23
extern Item_result item_cmp_type(Item_result a,Item_result b);
25
24
class Item_bool_func2;
43
42
  bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
44
43
  enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
45
44
                            CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
46
 
  uint64_t (*get_value_func)(THD *thd, Item ***item_arg, Item **cache_arg,
 
45
  ulonglong (*get_value_func)(THD *thd, Item ***item_arg, Item **cache_arg,
47
46
                              Item *warn_item, bool *is_null);
48
47
public:
49
48
  DTCollation cmp_collation;
92
91
  int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
93
92
 
94
93
  static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
95
 
                                                      uint64_t *const_val_arg);
 
94
                                                      ulonglong *const_val_arg);
96
95
 
97
96
  void set_datetime_cmp_func(Item **a1, Item **b1);
98
97
  static arg_cmp_func comparator_matrix [5][2];
109
108
  Item_bool_func(THD *thd, Item_bool_func *item) :Item_int_func(thd, item) {}
110
109
  bool is_bool_func() { return 1; }
111
110
  void fix_length_and_dec() { decimals=0; max_length=1; }
112
 
  uint32_t decimal_precision() const { return 1; }
 
111
  uint decimal_precision() const { return 1; }
113
112
};
114
113
 
115
114
 
122
121
{
123
122
public:
124
123
  virtual bool val_bool();
125
 
  virtual int64_t val_int();
 
124
  virtual longlong val_int();
126
125
  virtual void fix_length_and_dec();
127
126
  virtual void print(String *str, enum_query_type query_type);
128
127
 
199
198
 
200
199
 
201
200
class Item_cache;
202
 
#define UNKNOWN ((bool)-1)
 
201
#define UNKNOWN ((my_bool)-1)
203
202
 
204
203
 
205
204
/*
228
227
      FALSE   - result is FALSE
229
228
      TRUE    - result is NULL
230
229
  */
231
 
  bool result_for_null_param;
 
230
  my_bool result_for_null_param;
232
231
public:
233
232
  Item_in_optimizer(Item *a, Item_in_subselect *b):
234
 
    Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
 
233
    Item_bool_func(a, my_reinterpret_cast(Item *)(b)), cache(0),
235
234
    save_cache(0), result_for_null_param(UNKNOWN)
236
 
  { with_subselect= true; }
 
235
  { with_subselect= TRUE; }
237
236
  bool fix_fields(THD *, Item **);
238
237
  bool fix_left(THD *thd, Item **ref);
239
238
  bool is_null();
240
 
  int64_t val_int();
 
239
  longlong val_int();
241
240
  void cleanup();
242
241
  const char *func_name() const { return "<in_optimizer>"; }
243
242
  Item_cache **get_cache() { return &cache; }
244
243
  void keep_top_level_cache();
245
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
244
  Item *transform(Item_transformer transformer, uchar *arg);
246
245
};
247
246
 
248
247
class Comp_creator
331
330
 
332
331
public:
333
332
  Item_bool_func2(Item *a,Item *b)
334
 
    :Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1), abort_on_null(false) {}
 
333
    :Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1), abort_on_null(FALSE) {}
335
334
  void fix_length_and_dec();
336
335
  void set_cmp_func()
337
336
  {
348
347
 
349
348
  bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
350
349
  bool is_bool_func() { return 1; }
351
 
  const CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; }
352
 
  uint32_t decimal_precision() const { return 1; }
353
 
  void top_level_item() { abort_on_null= true; }
 
350
  CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; }
 
351
  uint decimal_precision() const { return 1; }
 
352
  void top_level_item() { abort_on_null= TRUE; }
354
353
 
355
354
  friend class  Arg_comparator;
356
355
};
364
363
  }
365
364
  Item *neg_transformer(THD *thd);
366
365
  virtual Item *negated_item();
367
 
  bool subst_argument_checker(unsigned char **arg __attribute__((unused)))
368
 
  { return true; }
 
366
  bool subst_argument_checker(uchar **arg) { return TRUE; }
369
367
};
370
368
 
371
369
class Item_func_not :public Item_bool_func
372
370
{
373
371
public:
374
372
  Item_func_not(Item *a) :Item_bool_func(a) {}
375
 
  int64_t val_int();
 
373
  longlong val_int();
376
374
  enum Functype functype() const { return NOT_FUNC; }
377
375
  const char *func_name() const { return "not"; }
378
376
  Item *neg_transformer(THD *thd);
415
413
  bool *trig_var;
416
414
public:
417
415
  Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
418
 
  int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
 
416
  longlong val_int() { return *trig_var ? args[0]->val_int() : 1; }
419
417
  enum Functype functype() const { return TRIG_COND_FUNC; };
420
418
  const char *func_name() const { return "trigcond"; };
421
 
  bool const_item() const { return false; }
 
419
  bool const_item() const { return FALSE; }
422
420
  bool *get_trig_var() { return trig_var; }
423
421
  /* The following is needed for ICP: */
424
422
  table_map used_tables() const { return args[0]->used_tables(); }
440
438
    {}
441
439
  virtual void top_level_item() { abort_on_null= 1; }
442
440
  bool top_level() { return abort_on_null; }
443
 
  int64_t val_int();
 
441
  longlong val_int();
444
442
  enum Functype functype() const { return NOT_ALL_FUNC; }
445
443
  const char *func_name() const { return "<not>"; }
446
444
  virtual void print(String *str, enum_query_type query_type);
456
454
public:
457
455
 
458
456
  Item_func_nop_all(Item *a) :Item_func_not_all(a) {}
459
 
  int64_t val_int();
 
457
  longlong val_int();
460
458
  const char *func_name() const { return "<nop>"; }
461
459
  Item *neg_transformer(THD *thd);
462
460
};
466
464
{
467
465
public:
468
466
  Item_func_eq(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {}
469
 
  int64_t val_int();
 
467
  longlong val_int();
470
468
  enum Functype functype() const { return EQ_FUNC; }
471
469
  enum Functype rev_functype() const { return EQ_FUNC; }
472
470
  cond_result eq_cmp_result() const { return COND_TRUE; }
478
476
{
479
477
public:
480
478
  Item_func_equal(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {};
481
 
  int64_t val_int();
 
479
  longlong val_int();
482
480
  void fix_length_and_dec();
483
481
  table_map not_null_tables() const { return 0; }
484
482
  enum Functype functype() const { return EQUAL_FUNC; }
485
483
  enum Functype rev_functype() const { return EQUAL_FUNC; }
486
484
  cond_result eq_cmp_result() const { return COND_TRUE; }
487
485
  const char *func_name() const { return "<=>"; }
488
 
  Item *neg_transformer(THD *thd __attribute__((unused))) { return 0; }
 
486
  Item *neg_transformer(THD *thd) { return 0; }
489
487
};
490
488
 
491
489
 
493
491
{
494
492
public:
495
493
  Item_func_ge(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {};
496
 
  int64_t val_int();
 
494
  longlong val_int();
497
495
  enum Functype functype() const { return GE_FUNC; }
498
496
  enum Functype rev_functype() const { return LE_FUNC; }
499
497
  cond_result eq_cmp_result() const { return COND_TRUE; }
506
504
{
507
505
public:
508
506
  Item_func_gt(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {};
509
 
  int64_t val_int();
 
507
  longlong val_int();
510
508
  enum Functype functype() const { return GT_FUNC; }
511
509
  enum Functype rev_functype() const { return LT_FUNC; }
512
510
  cond_result eq_cmp_result() const { return COND_FALSE; }
519
517
{
520
518
public:
521
519
  Item_func_le(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {};
522
 
  int64_t val_int();
 
520
  longlong val_int();
523
521
  enum Functype functype() const { return LE_FUNC; }
524
522
  enum Functype rev_functype() const { return GE_FUNC; }
525
523
  cond_result eq_cmp_result() const { return COND_TRUE; }
532
530
{
533
531
public:
534
532
  Item_func_lt(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {}
535
 
  int64_t val_int();
 
533
  longlong val_int();
536
534
  enum Functype functype() const { return LT_FUNC; }
537
535
  enum Functype rev_functype() const { return GT_FUNC; }
538
536
  cond_result eq_cmp_result() const { return COND_FALSE; }
545
543
{
546
544
public:
547
545
  Item_func_ne(Item *a,Item *b) :Item_bool_rowready_func2(a,b) {}
548
 
  int64_t val_int();
 
546
  longlong val_int();
549
547
  enum Functype functype() const { return NE_FUNC; }
550
548
  cond_result eq_cmp_result() const { return COND_FALSE; }
551
549
  optimize_type select_optimize() const { return OPTIMIZE_KEY; } 
576
574
public:
577
575
  inline void negate() { negated= !negated; }
578
576
  inline void top_level_item() { pred_level= 1; }
579
 
  Item *neg_transformer(THD *thd __attribute__((unused)))
 
577
  Item *neg_transformer(THD *thd)
580
578
  {
581
579
    negated= !negated;
582
580
    return this;
583
581
  }
584
582
  bool eq(const Item *item, bool binary_cmp) const;
585
 
  bool subst_argument_checker(unsigned char **arg __attribute__((unused)))
586
 
  { return true; }
 
583
  bool subst_argument_checker(uchar **arg) { return TRUE; }
587
584
};
588
585
 
589
586
 
598
595
  /* Comparators used for DATE/DATETIME comparison. */
599
596
  Arg_comparator ge_cmp, le_cmp;
600
597
  Item_func_between(Item *a, Item *b, Item *c)
601
 
    :Item_func_opt_neg(a, b, c), compare_as_dates(false) {}
602
 
  int64_t val_int();
 
598
    :Item_func_opt_neg(a, b, c), compare_as_dates(FALSE) {}
 
599
  longlong val_int();
603
600
  optimize_type select_optimize() const { return OPTIMIZE_KEY; }
604
601
  enum Functype functype() const   { return BETWEEN; }
605
602
  const char *func_name() const { return "between"; }
607
604
  void fix_length_and_dec();
608
605
  virtual void print(String *str, enum_query_type query_type);
609
606
  bool is_bool_func() { return 1; }
610
 
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
611
 
  uint32_t decimal_precision() const { return 1; }
 
607
  CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
 
608
  uint decimal_precision() const { return 1; }
612
609
};
613
610
 
614
611
 
616
613
{
617
614
public:
618
615
  Item_func_strcmp(Item *a,Item *b) :Item_bool_func2(a,b) {}
619
 
  int64_t val_int();
 
616
  longlong val_int();
620
617
  optimize_type select_optimize() const { return OPTIMIZE_NONE; }
621
618
  const char *func_name() const { return "strcmp"; }
622
619
 
637
634
class Item_func_interval :public Item_int_func
638
635
{
639
636
  Item_row *row;
640
 
  bool use_decimal_comparison;
 
637
  my_bool use_decimal_comparison;
641
638
  interval_range *intervals;
642
639
public:
643
640
  Item_func_interval(Item_row *a)
645
642
  {
646
643
    allowed_arg_cols= 0;    // Fetch this value from first argument
647
644
  }
648
 
  int64_t val_int();
 
645
  longlong val_int();
649
646
  void fix_length_and_dec();
650
647
  const char *func_name() const { return "interval"; }
651
 
  uint32_t decimal_precision() const { return 2; }
 
648
  uint decimal_precision() const { return 2; }
652
649
};
653
650
 
654
651
 
660
657
public:
661
658
  Item_func_coalesce(List<Item> &list) :Item_func_numhybrid(list) {}
662
659
  double real_op();
663
 
  int64_t int_op();
 
660
  longlong int_op();
664
661
  String *str_op(String *);
665
662
  my_decimal *decimal_op(my_decimal *);
666
663
  void fix_length_and_dec();
679
676
public:
680
677
  Item_func_ifnull(Item *a, Item *b) :Item_func_coalesce(a,b) {}
681
678
  double real_op();
682
 
  int64_t int_op();
 
679
  longlong int_op();
683
680
  String *str_op(String *str);
684
681
  my_decimal *decimal_op(my_decimal *);
685
682
  enum_field_types field_type() const;
686
683
  void fix_length_and_dec();
687
684
  const char *func_name() const { return "ifnull"; }
688
 
  Field *tmp_table_field(Table *table);
689
 
  uint32_t decimal_precision() const;
 
685
  Field *tmp_table_field(TABLE *table);
 
686
  uint decimal_precision() const;
690
687
};
691
688
 
692
689
 
699
696
    :Item_func(a,b,c), cached_result_type(INT_RESULT)
700
697
  {}
701
698
  double val_real();
702
 
  int64_t val_int();
 
699
  longlong val_int();
703
700
  String *val_str(String *str);
704
701
  my_decimal *val_decimal(my_decimal *);
705
702
  enum Item_result result_type () const { return cached_result_type; }
706
703
  enum_field_types field_type() const { return cached_field_type; }
707
704
  bool fix_fields(THD *, Item **);
708
705
  void fix_length_and_dec();
709
 
  uint32_t decimal_precision() const;
 
706
  uint decimal_precision() const;
710
707
  const char *func_name() const { return "if"; }
711
708
};
712
709
 
719
716
    :Item_bool_func2(a,b), cached_result_type(INT_RESULT)
720
717
  {}
721
718
  double val_real();
722
 
  int64_t val_int();
 
719
  longlong val_int();
723
720
  String *val_str(String *str);
724
721
  my_decimal *val_decimal(my_decimal *);
725
722
  enum Item_result result_type () const { return cached_result_type; }
726
723
  void fix_length_and_dec();
727
 
  uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
 
724
  uint decimal_precision() const { return args[0]->decimal_precision(); }
728
725
  const char *func_name() const { return "nullif"; }
729
726
 
730
727
  virtual inline void print(String *str, enum_query_type query_type)
746
743
{
747
744
public:
748
745
  char *base;
749
 
  uint32_t size;
 
746
  uint size;
750
747
  qsort2_cmp compare;
751
 
  const CHARSET_INFO *collation;
752
 
  uint32_t count;
753
 
  uint32_t used_count;
 
748
  CHARSET_INFO *collation;
 
749
  uint count;
 
750
  uint used_count;
754
751
  in_vector() {}
755
 
  in_vector(uint32_t elements,uint32_t element_length,qsort2_cmp cmp_func, 
756
 
            const CHARSET_INFO * const cmp_coll)
 
752
  in_vector(uint elements,uint element_length,qsort2_cmp cmp_func, 
 
753
            CHARSET_INFO *cmp_coll)
757
754
    :base((char*) sql_calloc(elements*element_length)),
758
755
     size(element_length), compare(cmp_func), collation(cmp_coll),
759
756
     count(elements), used_count(elements) {}
760
757
  virtual ~in_vector() {}
761
 
  virtual void set(uint32_t pos,Item *item)=0;
762
 
  virtual unsigned char *get_value(Item *item)=0;
 
758
  virtual void set(uint pos,Item *item)=0;
 
759
  virtual uchar *get_value(Item *item)=0;
763
760
  void sort()
764
761
  {
765
 
    my_qsort2(base,used_count,size,compare, (void *) collation);
 
762
    my_qsort2(base,used_count,size,compare,collation);
766
763
  }
767
764
  int find(Item *item);
768
765
  
784
781
        item  Constant item to store value into. The item must be of the same
785
782
              type that create_item() returns.
786
783
  */
787
 
  virtual void value_to_item(uint32_t pos __attribute__((unused)),
788
 
                             Item *item __attribute__((unused))) { }
 
784
  virtual void value_to_item(uint pos, Item *item) { }
789
785
  
790
786
  /* Compare values number pos1 and pos2 for equality */
791
 
  bool compare_elems(uint32_t pos1, uint32_t pos2)
 
787
  bool compare_elems(uint pos1, uint pos2)
792
788
  {
793
789
    return test(compare(collation, base + pos1*size, base + pos2*size));
794
790
  }
800
796
  char buff[STRING_BUFFER_USUAL_SIZE];
801
797
  String tmp;
802
798
public:
803
 
  in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs);
 
799
  in_string(uint elements,qsort2_cmp cmp_func, CHARSET_INFO *cs);
804
800
  ~in_string();
805
 
  void set(uint32_t pos,Item *item);
806
 
  unsigned char *get_value(Item *item);
 
801
  void set(uint pos,Item *item);
 
802
  uchar *get_value(Item *item);
807
803
  Item* create_item()
808
804
  { 
809
805
    return new Item_string(collation);
810
806
  }
811
 
  void value_to_item(uint32_t pos, Item *item)
 
807
  void value_to_item(uint pos, Item *item)
812
808
  {    
813
809
    String *str=((String*) base)+pos;
814
810
    Item_string *to= (Item_string*)item;
817
813
  Item_result result_type() { return STRING_RESULT; }
818
814
};
819
815
 
820
 
class in_int64_t :public in_vector
 
816
class in_longlong :public in_vector
821
817
{
822
818
protected:
823
819
  /*
825
821
    elements of this vector. tmp is used in finding if a given value is in 
826
822
    the list. 
827
823
  */
828
 
  struct packed_int64_t 
 
824
  struct packed_longlong 
829
825
  {
830
 
    int64_t val;
831
 
    int64_t unsigned_flag;  // Use int64_t, not bool, to preserve alignment
 
826
    longlong val;
 
827
    longlong unsigned_flag;  // Use longlong, not bool, to preserve alignment
832
828
  } tmp;
833
829
public:
834
 
  in_int64_t(uint32_t elements);
835
 
  void set(uint32_t pos,Item *item);
836
 
  unsigned char *get_value(Item *item);
 
830
  in_longlong(uint elements);
 
831
  void set(uint pos,Item *item);
 
832
  uchar *get_value(Item *item);
837
833
  
838
834
  Item* create_item()
839
835
  { 
841
837
      We're created a signed INT, this may not be correct in 
842
838
      general case (see BUG#19342).
843
839
    */
844
 
    return new Item_int((int64_t)0);
 
840
    return new Item_int((longlong)0);
845
841
  }
846
 
  void value_to_item(uint32_t pos, Item *item)
 
842
  void value_to_item(uint pos, Item *item)
847
843
  {
848
 
    ((Item_int*) item)->value= ((packed_int64_t*) base)[pos].val;
849
 
    ((Item_int*) item)->unsigned_flag= (bool)
850
 
      ((packed_int64_t*) base)[pos].unsigned_flag;
 
844
    ((Item_int*) item)->value= ((packed_longlong*) base)[pos].val;
 
845
    ((Item_int*) item)->unsigned_flag= (my_bool)
 
846
      ((packed_longlong*) base)[pos].unsigned_flag;
851
847
  }
852
848
  Item_result result_type() { return INT_RESULT; }
853
849
 
854
 
  friend int cmp_int64_t(void *cmp_arg, packed_int64_t *a,packed_int64_t *b);
 
850
  friend int cmp_longlong(void *cmp_arg, packed_longlong *a,packed_longlong *b);
855
851
};
856
852
 
857
853
 
861
857
  If the left item is a constant one then its value is cached in the
862
858
  lval_cache variable.
863
859
*/
864
 
class in_datetime :public in_int64_t
 
860
class in_datetime :public in_longlong
865
861
{
866
862
public:
867
863
  THD *thd;
870
866
  /* Cache for the left item. */
871
867
  Item *lval_cache;
872
868
 
873
 
  in_datetime(Item *warn_item_arg, uint32_t elements)
874
 
    :in_int64_t(elements), thd(current_thd), warn_item(warn_item_arg),
 
869
  in_datetime(Item *warn_item_arg, uint elements)
 
870
    :in_longlong(elements), thd(current_thd), warn_item(warn_item_arg),
875
871
     lval_cache(0) {};
876
 
  void set(uint32_t pos,Item *item);
877
 
  unsigned char *get_value(Item *item);
878
 
  friend int cmp_int64_t(void *cmp_arg, packed_int64_t *a,packed_int64_t *b);
 
872
  void set(uint pos,Item *item);
 
873
  uchar *get_value(Item *item);
 
874
  friend int cmp_longlong(void *cmp_arg, packed_longlong *a,packed_longlong *b);
879
875
};
880
876
 
881
877
 
883
879
{
884
880
  double tmp;
885
881
public:
886
 
  in_double(uint32_t elements);
887
 
  void set(uint32_t pos,Item *item);
888
 
  unsigned char *get_value(Item *item);
 
882
  in_double(uint elements);
 
883
  void set(uint pos,Item *item);
 
884
  uchar *get_value(Item *item);
889
885
  Item *create_item()
890
886
  { 
891
887
    return new Item_float(0.0, 0);
892
888
  }
893
 
  void value_to_item(uint32_t pos, Item *item)
 
889
  void value_to_item(uint pos, Item *item)
894
890
  {
895
891
    ((Item_float*)item)->value= ((double*) base)[pos];
896
892
  }
902
898
{
903
899
  my_decimal val;
904
900
public:
905
 
  in_decimal(uint32_t elements);
906
 
  void set(uint32_t pos, Item *item);
907
 
  unsigned char *get_value(Item *item);
 
901
  in_decimal(uint elements);
 
902
  void set(uint pos, Item *item);
 
903
  uchar *get_value(Item *item);
908
904
  Item *create_item()
909
905
  { 
910
 
    return new Item_decimal(0, false);
 
906
    return new Item_decimal(0, FALSE);
911
907
  }
912
 
  void value_to_item(uint32_t pos, Item *item)
 
908
  void value_to_item(uint pos, Item *item)
913
909
  {
914
910
    my_decimal *dec= ((my_decimal *)base) + pos;
915
911
    Item_decimal *item_dec= (Item_decimal*)item;
927
923
class cmp_item :public Sql_alloc
928
924
{
929
925
public:
930
 
  const CHARSET_INFO *cmp_charset;
 
926
  CHARSET_INFO *cmp_charset;
931
927
  cmp_item() { cmp_charset= &my_charset_bin; }
932
928
  virtual ~cmp_item() {}
933
929
  virtual void store_value(Item *item)= 0;
934
930
  virtual int cmp(Item *item)= 0;
935
931
  // for optimized IN with row
936
932
  virtual int compare(cmp_item *item)= 0;
937
 
  static cmp_item* get_comparator(Item_result type, const CHARSET_INFO * const cs);
 
933
  static cmp_item* get_comparator(Item_result type, CHARSET_INFO *cs);
938
934
  virtual cmp_item *make_same()= 0;
939
 
  virtual void store_value_by_template(cmp_item *tmpl  __attribute__((unused)),
940
 
                                       Item *item)
 
935
  virtual void store_value_by_template(cmp_item *tmpl, Item *item)
941
936
  {
942
937
    store_value(item);
943
938
  }
949
944
  String *value_res;
950
945
public:
951
946
  cmp_item_string () {}
952
 
  cmp_item_string (const CHARSET_INFO * const cs) { cmp_charset= cs; }
953
 
  void set_charset(const CHARSET_INFO * const cs) { cmp_charset= cs; }
 
947
  cmp_item_string (CHARSET_INFO *cs) { cmp_charset= cs; }
 
948
  void set_charset(CHARSET_INFO *cs) { cmp_charset= cs; }
954
949
  friend class cmp_item_sort_string;
955
950
  friend class cmp_item_sort_string_in_static;
956
951
};
963
958
public:
964
959
  cmp_item_sort_string():
965
960
    cmp_item_string() {}
966
 
  cmp_item_sort_string(const CHARSET_INFO * const cs):
 
961
  cmp_item_sort_string(CHARSET_INFO *cs):
967
962
    cmp_item_string(cs),
968
963
    value(value_buff, sizeof(value_buff), cs) {}
969
964
  void store_value(Item *item)
984
979
    return sortcmp(value_res, l_cmp->value_res, cmp_charset);
985
980
  } 
986
981
  cmp_item *make_same();
987
 
  void set_charset(const CHARSET_INFO * const cs)
 
982
  void set_charset(CHARSET_INFO *cs)
988
983
  {
989
984
    cmp_charset= cs;
990
985
    value.set_quick(value_buff, sizeof(value_buff), cs);
993
988
 
994
989
class cmp_item_int :public cmp_item
995
990
{
996
 
  int64_t value;
 
991
  longlong value;
997
992
public:
998
993
  cmp_item_int() {}                           /* Remove gcc warning */
999
994
  void store_value(Item *item)
1020
1015
*/
1021
1016
class cmp_item_datetime :public cmp_item
1022
1017
{
1023
 
  uint64_t value;
 
1018
  ulonglong value;
1024
1019
public:
1025
1020
  THD *thd;
1026
1021
  /* Item used for issuing warnings. */
1080
1075
 protected:
1081
1076
  String value;
1082
1077
public:
1083
 
  cmp_item_sort_string_in_static(const CHARSET_INFO * const cs):
 
1078
  cmp_item_sort_string_in_static(CHARSET_INFO *cs):
1084
1079
    cmp_item_string(cs) {}
1085
1080
  void store_value(Item *item)
1086
1081
  {
1087
1082
    value_res= item->val_str(&value);
1088
1083
  }
1089
 
  int cmp(Item *item __attribute__((unused)))
 
1084
  int cmp(Item *item)
1090
1085
  {
1091
1086
    // Should never be called
1092
 
    assert(0);
 
1087
    DBUG_ASSERT(0);
1093
1088
    return 1;
1094
1089
  }
1095
1090
  int compare(cmp_item *ci)
1127
1122
  int first_expr_num, else_expr_num;
1128
1123
  enum Item_result cached_result_type, left_result_type;
1129
1124
  String tmp_value;
1130
 
  uint32_t ncases;
 
1125
  uint ncases;
1131
1126
  Item_result cmp_type;
1132
1127
  DTCollation cmp_collation;
1133
1128
  enum_field_types cached_field_type;
1150
1145
      list.push_back(else_expr_arg);
1151
1146
    }
1152
1147
    set_arguments(list);
1153
 
    memset(&cmp_items, 0, sizeof(cmp_items));
 
1148
    bzero(&cmp_items, sizeof(cmp_items));
1154
1149
  }
1155
1150
  double val_real();
1156
 
  int64_t val_int();
 
1151
  longlong val_int();
1157
1152
  String *val_str(String *);
1158
1153
  my_decimal *val_decimal(my_decimal *);
1159
1154
  bool fix_fields(THD *thd, Item **ref);
1160
1155
  void fix_length_and_dec();
1161
 
  uint32_t decimal_precision() const;
 
1156
  uint decimal_precision() const;
1162
1157
  table_map not_null_tables() const { return 0; }
1163
1158
  enum Item_result result_type () const { return cached_result_type; }
1164
1159
  enum_field_types field_type() const { return cached_field_type; }
1165
1160
  const char *func_name() const { return "case"; }
1166
1161
  virtual void print(String *str, enum_query_type query_type);
1167
1162
  Item *find_item(String *str);
1168
 
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
 
1163
  CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
1169
1164
  void cleanup();
1170
1165
  void agg_str_lengths(Item *arg);
1171
1166
  void agg_num_lengths(Item *arg);
1205
1200
 
1206
1201
  Item_func_in(List<Item> &list)
1207
1202
    :Item_func_opt_neg(list), array(0), have_null(0),
1208
 
    arg_types_compatible(false)
 
1203
    arg_types_compatible(FALSE)
1209
1204
  {
1210
 
    memset(&cmp_items, 0, sizeof(cmp_items));
 
1205
    bzero(&cmp_items, sizeof(cmp_items));
1211
1206
    allowed_arg_cols= 0;  // Fetch this value from first argument
1212
1207
  }
1213
 
  int64_t val_int();
 
1208
  longlong val_int();
1214
1209
  bool fix_fields(THD *, Item **);
1215
1210
  void fix_length_and_dec();
1216
 
  uint32_t decimal_precision() const { return 1; }
 
1211
  uint decimal_precision() const { return 1; }
1217
1212
  void cleanup()
1218
1213
  {
1219
 
    uint32_t i;
 
1214
    uint i;
 
1215
    DBUG_ENTER("Item_func_in::cleanup");
1220
1216
    Item_int_func::cleanup();
1221
1217
    delete array;
1222
1218
    array= 0;
1225
1221
      delete cmp_items[i];
1226
1222
      cmp_items[i]= 0;
1227
1223
    }
1228
 
    return;
 
1224
    DBUG_VOID_RETURN;
1229
1225
  }
1230
1226
  optimize_type select_optimize() const
1231
1227
    { return OPTIMIZE_KEY; }
1234
1230
  const char *func_name() const { return " IN "; }
1235
1231
  bool nulls_in_row();
1236
1232
  bool is_bool_func() { return 1; }
1237
 
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
 
1233
  CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
1238
1234
};
1239
1235
 
1240
1236
class cmp_item_row :public cmp_item
1241
1237
{
1242
1238
  cmp_item **comparators;
1243
 
  uint32_t n;
 
1239
  uint n;
1244
1240
public:
1245
1241
  cmp_item_row(): comparators(0), n(0) {}
1246
1242
  ~cmp_item_row();
1258
1254
{
1259
1255
  cmp_item_row tmp;
1260
1256
public:
1261
 
  in_row(uint32_t elements, Item *);
 
1257
  in_row(uint elements, Item *);
1262
1258
  ~in_row();
1263
 
  void set(uint32_t pos,Item *item);
1264
 
  unsigned char *get_value(Item *item);
 
1259
  void set(uint pos,Item *item);
 
1260
  uchar *get_value(Item *item);
1265
1261
  friend void Item_func_in::fix_length_and_dec();
1266
1262
  Item_result result_type() { return ROW_RESULT; }
1267
1263
};
1271
1267
class Item_func_isnull :public Item_bool_func
1272
1268
{
1273
1269
protected:
1274
 
  int64_t cached_value;
 
1270
  longlong cached_value;
1275
1271
public:
1276
1272
  Item_func_isnull(Item *a) :Item_bool_func(a) {}
1277
 
  int64_t val_int();
 
1273
  longlong val_int();
1278
1274
  enum Functype functype() const { return ISNULL_FUNC; }
1279
1275
  void fix_length_and_dec()
1280
1276
  {
1289
1285
    {
1290
1286
      used_tables_cache= 0;                     /* is always false */
1291
1287
      const_item_cache= 1;
1292
 
      cached_value= (int64_t) 0;
 
1288
      cached_value= (longlong) 0;
1293
1289
    }
1294
1290
    else
1295
1291
    {
1298
1294
          !with_subselect)
1299
1295
      {
1300
1296
        /* Remember if the value is always NULL or never NULL */
1301
 
        cached_value= (int64_t) args[0]->is_null();
 
1297
        cached_value= (longlong) args[0]->is_null();
1302
1298
      }
1303
1299
    }
1304
1300
  }
1305
1301
  table_map not_null_tables() const { return 0; }
1306
1302
  optimize_type select_optimize() const { return OPTIMIZE_NULL; }
1307
1303
  Item *neg_transformer(THD *thd);
1308
 
  const CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
 
1304
  CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
1309
1305
};
1310
1306
 
1311
1307
/* Functions used by HAVING for rewriting IN subquery */
1324
1320
    :Item_func_isnull(a), owner(ow)
1325
1321
  {}
1326
1322
  enum Functype functype() const { return ISNOTNULLTEST_FUNC; }
1327
 
  int64_t val_int();
 
1323
  longlong val_int();
1328
1324
  const char *func_name() const { return "<is_not_null_test>"; }
1329
1325
  void update_used_tables();
1330
1326
  /*
1340
1336
  bool abort_on_null;
1341
1337
public:
1342
1338
  Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1343
 
  int64_t val_int();
 
1339
  longlong val_int();
1344
1340
  enum Functype functype() const { return ISNOTNULL_FUNC; }
1345
1341
  void fix_length_and_dec()
1346
1342
  {
1352
1348
  { return abort_on_null ? not_null_tables_cache : 0; }
1353
1349
  Item *neg_transformer(THD *thd);
1354
1350
  virtual void print(String *str, enum_query_type query_type);
1355
 
  const CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
 
1351
  CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
1356
1352
  void top_level_item() { abort_on_null=1; }
1357
1353
};
1358
1354
 
1382
1378
  int escape;
1383
1379
 
1384
1380
  Item_func_like(Item *a,Item *b, Item *escape_arg, bool escape_used)
1385
 
    :Item_bool_func2(a,b), canDoTurboBM(false), pattern(0), pattern_len(0), 
 
1381
    :Item_bool_func2(a,b), canDoTurboBM(FALSE), pattern(0), pattern_len(0), 
1386
1382
     bmGs(0), bmBc(0), escape_item(escape_arg),
1387
1383
     escape_used_in_parsing(escape_used) {}
1388
 
  int64_t val_int();
 
1384
  longlong val_int();
1389
1385
  enum Functype functype() const { return LIKE_FUNC; }
1390
1386
  optimize_type select_optimize() const;
1391
1387
  cond_result eq_cmp_result() const { return COND_TRUE; }
1429
1425
  void update_used_tables();
1430
1426
  virtual void print(String *str, enum_query_type query_type);
1431
1427
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
1432
 
  friend int setup_conds(THD *thd, TableList *tables, TableList *leaves,
 
1428
  friend int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
1433
1429
                         COND **conds);
1434
1430
  void top_level_item() { abort_on_null=1; }
1435
1431
  void copy_andor_arguments(THD *thd, Item_cond *item);
1436
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
1437
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
1432
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
 
1433
  Item *transform(Item_transformer transformer, uchar *arg);
1438
1434
  void traverse_cond(Cond_traverser, void *arg, traverse_order order);
1439
1435
  void neg_arguments(THD *thd);
1440
 
  enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1441
 
  bool subst_argument_checker(unsigned char **arg __attribute__((unused)))
1442
 
  { return true; }
1443
 
  Item *compile(Item_analyzer analyzer, unsigned char **arg_p,
1444
 
                Item_transformer transformer, unsigned char *arg_t);
 
1436
  enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
 
1437
  bool subst_argument_checker(uchar **arg) { return TRUE; }
 
1438
  Item *compile(Item_analyzer analyzer, uchar **arg_p,
 
1439
                Item_transformer transformer, uchar *arg_t);
1445
1440
};
1446
1441
 
1447
1442
 
1536
1531
  inline Item* get_const() { return const_item; }
1537
1532
  void add(Item *c);
1538
1533
  void add(Item_field *f);
1539
 
  uint32_t members();
 
1534
  uint members();
1540
1535
  bool contains(Field *field);
1541
1536
  Item_field* get_first() { return fields.head(); }
1542
1537
  void merge(Item_equal *item);
1543
1538
  void update_const();
1544
1539
  enum Functype functype() const { return MULT_EQUAL_FUNC; }
1545
 
  int64_t val_int(); 
 
1540
  longlong val_int(); 
1546
1541
  const char *func_name() const { return "multiple equal"; }
1547
1542
  optimize_type select_optimize() const { return OPTIMIZE_EQUAL; }
1548
1543
  void sort(Item_field_cmpfunc cmp, void *arg);
1550
1545
  void fix_length_and_dec();
1551
1546
  bool fix_fields(THD *thd, Item **ref);
1552
1547
  void update_used_tables();
1553
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
1554
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
1548
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
 
1549
  Item *transform(Item_transformer transformer, uchar *arg);
1555
1550
  virtual void print(String *str, enum_query_type query_type);
1556
 
  const CHARSET_INFO *compare_collation() 
 
1551
  CHARSET_INFO *compare_collation() 
1557
1552
  { return fields.head()->collation.collation; }
1558
1553
}; 
1559
1554
 
1560
1555
class COND_EQUAL: public Sql_alloc
1561
1556
{
1562
1557
public:
1563
 
  uint32_t max_members;               /* max number of members the current level
 
1558
  uint max_members;               /* max number of members the current level
1564
1559
                                     list and all lower level lists */ 
1565
1560
  COND_EQUAL *upper_levels;       /* multiple equalities of upper and levels */
1566
1561
  List<Item_equal> current_level; /* list of multiple equalities of 
1600
1595
  Item_cond_and(THD *thd, Item_cond_and *item) :Item_cond(thd, item) {}
1601
1596
  Item_cond_and(List<Item> &list_arg): Item_cond(list_arg) {}
1602
1597
  enum Functype functype() const { return COND_AND_FUNC; }
1603
 
  int64_t val_int();
 
1598
  longlong val_int();
1604
1599
  const char *func_name() const { return "and"; }
1605
1600
  table_map not_null_tables() const
1606
1601
  { return abort_on_null ? not_null_tables_cache: and_tables_cache; }
1617
1612
inline bool is_cond_and(Item *item)
1618
1613
{
1619
1614
  if (item->type() != Item::COND_ITEM)
1620
 
    return false;
 
1615
    return FALSE;
1621
1616
 
1622
1617
  Item_cond *cond_item= (Item_cond*) item;
1623
1618
  return (cond_item->functype() == Item_func::COND_AND_FUNC);
1631
1626
  Item_cond_or(THD *thd, Item_cond_or *item) :Item_cond(thd, item) {}
1632
1627
  Item_cond_or(List<Item> &list_arg): Item_cond(list_arg) {}
1633
1628
  enum Functype functype() const { return COND_OR_FUNC; }
1634
 
  int64_t val_int();
 
1629
  longlong val_int();
1635
1630
  const char *func_name() const { return "or"; }
1636
1631
  table_map not_null_tables() const { return and_tables_cache; }
1637
1632
  Item* copy_andor_structure(THD *thd)
1647
1642
inline bool is_cond_or(Item *item)
1648
1643
{
1649
1644
  if (item->type() != Item::COND_ITEM)
1650
 
    return false;
 
1645
    return FALSE;
1651
1646
 
1652
1647
  Item_cond *cond_item= (Item_cond*) item;
1653
1648
  return (cond_item->functype() == Item_func::COND_OR_FUNC);
1666
1661
  enum Functype functype() const { return COND_XOR_FUNC; }
1667
1662
  /* TODO: remove the next line when implementing XOR optimization */
1668
1663
  enum Type type() const { return FUNC_ITEM; }
1669
 
  int64_t val_int();
 
1664
  longlong val_int();
1670
1665
  const char *func_name() const { return "xor"; }
1671
1666
  void top_level_item() {}
1672
1667
};