~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/item_cmpfunc.h

  • Committer: Monty Taylor
  • Date: 2008-07-05 11:20:18 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: monty@inaugust.com-20080705112018-fr12kkmgphtu7m29
Changes so that removal of duplicate curr_dir from my_sys.h work.

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