~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.h

Merged embedded-innodb-index-lookup into embedded-innodb-delete-row.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#pragma once
 
20
#ifndef DRIZZLED_ITEM_CMPFUNC_H
 
21
#define DRIZZLED_ITEM_CMPFUNC_H
21
22
 
22
23
/* compare and test functions */
23
24
 
24
 
#include <drizzled/common.h>
25
 
#include <drizzled/comp_creator.h>
26
 
#include <drizzled/function/math/int.h>
27
 
#include <drizzled/function/numhybrid.h>
28
 
#include <drizzled/item/decimal.h>
29
 
#include <drizzled/item/float.h>
30
 
#include <drizzled/item/function/boolean.h>
31
 
#include <drizzled/item/int.h>
32
 
#include <drizzled/item/row.h>
33
 
#include <drizzled/item/string.h>
34
 
#include <drizzled/item/sum.h>
35
 
#include <drizzled/qsort_cmp.h>
 
25
#include "drizzled/comp_creator.h"
 
26
#include "drizzled/item/row.h"
 
27
#include "drizzled/item/sum.h"
 
28
#include "drizzled/item/int.h"
 
29
#include "drizzled/item/float.h"
 
30
#include "drizzled/item/decimal.h"
 
31
#include "drizzled/function/math/int.h"
 
32
#include "drizzled/function/numhybrid.h"
 
33
#include "drizzled/session.h"
 
34
#include "drizzled/common.h"
 
35
#include "drizzled/qsort_cmp.h"
36
36
 
37
 
namespace drizzled {
 
37
namespace drizzled
 
38
{
38
39
 
39
40
extern Item_result item_cmp_type(Item_result a,Item_result b);
 
41
class Item_bool_func2;
 
42
class Arg_comparator;
 
43
class Item_sum_hybrid;
 
44
class Item_row;
40
45
 
41
46
typedef int (Arg_comparator::*arg_cmp_func)();
42
47
 
43
48
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
44
49
 
45
 
int64_t get_datetime_value(Session *session, 
46
 
                           Item ***item_arg, 
47
 
                           Item **cache_arg,
48
 
                           Item *warn_item, 
49
 
                           bool *is_null);
 
50
uint64_t get_datetime_value(Session *session, 
 
51
                            Item ***item_arg, 
 
52
                            Item **cache_arg,
 
53
                            Item *warn_item, 
 
54
                            bool *is_null);
50
55
 
51
56
class Arg_comparator: public memory::SqlAlloc
52
57
{
62
67
  bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
63
68
  enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
64
69
                            CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
65
 
  int64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
66
 
                            Item *warn_item, bool *is_null);
 
70
  uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
 
71
                              Item *warn_item, bool *is_null);
67
72
public:
68
73
  DTCollation cmp_collation;
69
74
 
70
 
  Arg_comparator();
71
 
 
72
 
  Arg_comparator(Item **a1, Item **a2);
 
75
  Arg_comparator(): session(0), a_cache(0), b_cache(0) {};
 
76
  Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), session(0),
 
77
    a_cache(0), b_cache(0) {};
73
78
 
74
79
  int set_compare_func(Item_bool_func2 *owner, Item_result type);
75
80
  inline int set_compare_func(Item_bool_func2 *owner_arg)
111
116
  int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
112
117
 
113
118
  static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
114
 
                                                      int64_t *const_val_arg);
 
119
                                                      uint64_t *const_val_arg);
115
120
 
116
121
  void set_datetime_cmp_func(Item **a1, Item **b1);
117
122
  static arg_cmp_func comparator_matrix [5][2];
119
124
  friend class Item_func;
120
125
};
121
126
 
 
127
class Item_bool_func :public Item_int_func
 
128
{
 
129
public:
 
130
  Item_bool_func() :Item_int_func() {}
 
131
  Item_bool_func(Item *a) :Item_int_func(a) {}
 
132
  Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
 
133
  Item_bool_func(Session *session, Item_bool_func *item) :Item_int_func(session, item) {}
 
134
  bool is_bool_func() { return 1; }
 
135
  void fix_length_and_dec() { decimals=0; max_length=1; }
 
136
  uint32_t decimal_precision() const { return 1; }
 
137
};
 
138
 
122
139
 
123
140
/**
124
141
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
125
142
  boolean predicates.
126
143
*/
127
144
 
128
 
class Item_func_truth : public item::function::Boolean
 
145
class Item_func_truth : public Item_bool_func
129
146
{
130
147
public:
131
148
  virtual bool val_bool();
132
149
  virtual int64_t val_int();
133
150
  virtual void fix_length_and_dec();
134
 
  virtual void print(String *str);
 
151
  virtual void print(String *str, enum_query_type query_type);
135
152
 
136
153
protected:
137
154
  Item_func_truth(Item *a, bool a_value, bool a_affirmative)
138
 
  : item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
 
155
  : Item_bool_func(a), value(a_value), affirmative(a_affirmative)
139
156
  {}
140
157
 
 
158
  ~Item_func_truth()
 
159
  {}
141
160
private:
142
161
  /**
143
162
    True for <code>X IS [NOT] TRUE</code>,
159
178
{
160
179
public:
161
180
  Item_func_istrue(Item *a) : Item_func_truth(a, true, true) {}
 
181
  ~Item_func_istrue() {}
162
182
  virtual const char* func_name() const { return "istrue"; }
163
183
};
164
184
 
171
191
{
172
192
public:
173
193
  Item_func_isnottrue(Item *a) : Item_func_truth(a, true, false) {}
 
194
  ~Item_func_isnottrue() {}
174
195
  virtual const char* func_name() const { return "isnottrue"; }
175
196
};
176
197
 
183
204
{
184
205
public:
185
206
  Item_func_isfalse(Item *a) : Item_func_truth(a, false, true) {}
 
207
  ~Item_func_isfalse() {}
186
208
  virtual const char* func_name() const { return "isfalse"; }
187
209
};
188
210
 
195
217
{
196
218
public:
197
219
  Item_func_isnotfalse(Item *a) : Item_func_truth(a, false, false) {}
 
220
  ~Item_func_isnotfalse() {}
198
221
  virtual const char* func_name() const { return "isnotfalse"; }
199
222
};
200
223
 
201
224
 
 
225
class Item_cache;
202
226
#define UNKNOWN ((bool)-1)
203
227
 
204
228
 
217
241
    placed into a separate class called 'Item_in_optimizer'.
218
242
*/
219
243
 
220
 
class Item_in_optimizer: public item::function::Boolean
 
244
class Item_in_optimizer: public Item_bool_func
221
245
{
222
246
protected:
223
247
  Item_cache *cache;
231
255
  bool result_for_null_param;
232
256
public:
233
257
  Item_in_optimizer(Item *a, Item_in_subselect *b):
234
 
    item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
 
258
    Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
235
259
    save_cache(0), result_for_null_param(UNKNOWN)
236
260
  { with_subselect= true; }
237
261
  bool fix_fields(Session *, Item **);
248
272
class Eq_creator :public Comp_creator
249
273
{
250
274
public:
 
275
  Eq_creator() {}                             /* Remove gcc warning */
 
276
  virtual ~Eq_creator() {}                    /* Remove gcc warning */
251
277
  virtual Item_bool_func2* create(Item *a, Item *b) const;
252
278
  virtual const char* symbol(bool invert) const { return invert? "<>" : "="; }
253
279
  virtual bool eqne_op() const { return 1; }
258
284
class Ne_creator :public Comp_creator
259
285
{
260
286
public:
 
287
  Ne_creator() {}                             /* Remove gcc warning */
 
288
  virtual ~Ne_creator() {}                    /* Remove gcc warning */
261
289
  virtual Item_bool_func2* create(Item *a, Item *b) const;
262
290
  virtual const char* symbol(bool invert) const { return invert? "=" : "<>"; }
263
291
  virtual bool eqne_op() const { return 1; }
268
296
class Gt_creator :public Comp_creator
269
297
{
270
298
public:
 
299
  Gt_creator() {}                             /* Remove gcc warning */
 
300
  virtual ~Gt_creator() {}                    /* Remove gcc warning */
271
301
  virtual Item_bool_func2* create(Item *a, Item *b) const;
272
302
  virtual const char* symbol(bool invert) const { return invert? "<=" : ">"; }
273
303
  virtual bool eqne_op() const { return 0; }
278
308
class Lt_creator :public Comp_creator
279
309
{
280
310
public:
 
311
  Lt_creator() {}                             /* Remove gcc warning */
 
312
  virtual ~Lt_creator() {}                    /* Remove gcc warning */
281
313
  virtual Item_bool_func2* create(Item *a, Item *b) const;
282
314
  virtual const char* symbol(bool invert) const { return invert? ">=" : "<"; }
283
315
  virtual bool eqne_op() const { return 0; }
288
320
class Ge_creator :public Comp_creator
289
321
{
290
322
public:
 
323
  Ge_creator() {}                             /* Remove gcc warning */
 
324
  virtual ~Ge_creator() {}                    /* Remove gcc warning */
291
325
  virtual Item_bool_func2* create(Item *a, Item *b) const;
292
326
  virtual const char* symbol(bool invert) const { return invert? "<" : ">="; }
293
327
  virtual bool eqne_op() const { return 0; }
298
332
class Le_creator :public Comp_creator
299
333
{
300
334
public:
 
335
  Le_creator() {}                             /* Remove gcc warning */
 
336
  virtual ~Le_creator() {}                    /* Remove gcc warning */
301
337
  virtual Item_bool_func2* create(Item *a, Item *b) const;
302
338
  virtual const char* symbol(bool invert) const { return invert? ">" : "<="; }
303
339
  virtual bool eqne_op() const { return 0; }
324
360
  virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; }
325
361
  bool have_rev_func() const { return rev_functype() != UNKNOWN_FUNC; }
326
362
 
327
 
  virtual inline void print(String *str)
 
363
  virtual inline void print(String *str, enum_query_type query_type)
328
364
  {
329
 
    Item_func::print_op(str);
 
365
    Item_func::print_op(str, query_type);
330
366
  }
331
367
 
332
368
  bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
333
369
  bool is_bool_func() { return 1; }
334
 
  const charset_info_st *compare_collation() { return cmp.cmp_collation.collation; }
 
370
  const CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; }
335
371
  uint32_t decimal_precision() const { return 1; }
336
372
  void top_level_item() { abort_on_null= true; }
337
373
 
351
387
  { return true; }
352
388
};
353
389
 
354
 
class Item_func_not :public item::function::Boolean
 
390
class Item_func_not :public Item_bool_func
355
391
{
356
392
public:
357
 
  Item_func_not(Item *a) :item::function::Boolean(a) {}
 
393
  Item_func_not(Item *a) :Item_bool_func(a) {}
358
394
  int64_t val_int();
359
395
  enum Functype functype() const { return NOT_FUNC; }
360
396
  const char *func_name() const { return "not"; }
361
397
  Item *neg_transformer(Session *session);
362
 
  virtual void print(String *str);
 
398
  virtual void print(String *str, enum_query_type query_type);
363
399
};
364
400
 
 
401
class Item_maxmin_subselect;
 
402
 
365
403
/*
366
404
  trigcond<param>(arg) ::= param? arg : TRUE
367
405
 
391
429
   - To wrap condition that is pushed down into subquery
392
430
*/
393
431
 
394
 
class Item_func_trig_cond: public item::function::Boolean
 
432
class Item_func_trig_cond: public Item_bool_func
395
433
{
396
434
  bool *trig_var;
397
435
public:
398
 
  Item_func_trig_cond(Item *a, bool *f) : item::function::Boolean(a) { trig_var= f; }
 
436
  Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
399
437
  int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
400
438
  enum Functype functype() const { return TRIG_COND_FUNC; };
401
439
  const char *func_name() const { return "trigcond"; };
424
462
  int64_t val_int();
425
463
  enum Functype functype() const { return NOT_ALL_FUNC; }
426
464
  const char *func_name() const { return "<not>"; }
427
 
  virtual void print(String *str);
 
465
  virtual void print(String *str, enum_query_type query_type);
428
466
  void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; };
429
467
  void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; };
430
468
  bool empty_underlying_subquery();
586
624
  const char *func_name() const { return "between"; }
587
625
  bool fix_fields(Session *, Item **);
588
626
  void fix_length_and_dec();
589
 
  virtual void print(String *str);
 
627
  virtual void print(String *str, enum_query_type query_type);
590
628
  bool is_bool_func() { return 1; }
591
 
  const charset_info_st *compare_collation() { return cmp_collation.collation; }
 
629
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
592
630
  uint32_t decimal_precision() const { return 1; }
593
631
};
594
632
 
601
639
  optimize_type select_optimize() const { return OPTIMIZE_NONE; }
602
640
  const char *func_name() const { return "strcmp"; }
603
641
 
604
 
  virtual inline void print(String *str)
 
642
  virtual inline void print(String *str, enum_query_type query_type)
605
643
  {
606
 
    Item_func::print(str);
 
644
    Item_func::print(str, query_type);
607
645
  }
608
646
};
609
647
 
612
650
{
613
651
  Item_result type;
614
652
  double dbl;
615
 
  type::Decimal dec;
 
653
  my_decimal dec;
616
654
};
617
655
 
618
656
class Item_func_interval :public Item_int_func
643
681
  double real_op();
644
682
  int64_t int_op();
645
683
  String *str_op(String *);
646
 
  type::Decimal *decimal_op(type::Decimal *);
 
684
  my_decimal *decimal_op(my_decimal *);
647
685
  void fix_length_and_dec();
648
686
  void find_num_type() {}
649
687
  enum Item_result result_type () const { return hybrid_type; }
662
700
  double real_op();
663
701
  int64_t int_op();
664
702
  String *str_op(String *str);
665
 
  type::Decimal *decimal_op(type::Decimal *);
 
703
  my_decimal *decimal_op(my_decimal *);
666
704
  enum_field_types field_type() const;
667
705
  void fix_length_and_dec();
668
706
  const char *func_name() const { return "ifnull"; }
677
715
 
678
716
class Item_func_if :public Item_func
679
717
{
680
 
  Item_result cached_result_type;
 
718
  enum Item_result cached_result_type;
681
719
  enum_field_types cached_field_type;
682
 
 
683
720
public:
684
 
  Item_func_if(Item *a, Item *b, Item *c) :
685
 
    Item_func(a,b,c),
686
 
    cached_result_type(INT_RESULT)
 
721
  Item_func_if(Item *a,Item *b,Item *c)
 
722
    :Item_func(a,b,c), cached_result_type(INT_RESULT)
687
723
  {}
688
 
 
689
724
  double val_real();
690
725
  int64_t val_int();
691
726
  String *val_str(String *str);
692
 
  type::Decimal *val_decimal(type::Decimal *);
693
 
  Item_result result_type () const { return cached_result_type; }
 
727
  my_decimal *val_decimal(my_decimal *);
 
728
  enum Item_result result_type () const { return cached_result_type; }
694
729
  enum_field_types field_type() const { return cached_field_type; }
695
730
  bool fix_fields(Session *, Item **);
696
731
  void fix_length_and_dec();
709
744
  double val_real();
710
745
  int64_t val_int();
711
746
  String *val_str(String *str);
712
 
  type::Decimal *val_decimal(type::Decimal *);
 
747
  my_decimal *val_decimal(my_decimal *);
713
748
  enum Item_result result_type () const { return cached_result_type; }
714
749
  void fix_length_and_dec();
715
750
  uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
716
751
  const char *func_name() const { return "nullif"; }
717
752
 
718
 
  virtual inline void print(String *str)
 
753
  virtual inline void print(String *str, enum_query_type query_type)
719
754
  {
720
 
    Item_func::print(str);
 
755
    Item_func::print(str, query_type);
721
756
  }
722
757
 
723
758
  table_map not_null_tables() const { return 0; }
736
771
  char *base;
737
772
  uint32_t size;
738
773
  qsort2_cmp compare;
739
 
  const charset_info_st *collation;
 
774
  const CHARSET_INFO *collation;
740
775
  uint32_t count;
741
776
  uint32_t used_count;
742
777
  in_vector() {}
743
778
  in_vector(uint32_t elements,uint32_t element_length,qsort2_cmp cmp_func,
744
 
            const charset_info_st * const cmp_coll)
 
779
            const CHARSET_INFO * const cmp_coll)
745
780
    :base((char*) memory::sql_calloc(elements*element_length)),
746
781
     size(element_length), compare(cmp_func), collation(cmp_coll),
747
782
     count(elements), used_count(elements) {}
784
819
  char buff[STRING_BUFFER_USUAL_SIZE];
785
820
  String tmp;
786
821
public:
787
 
  in_string(uint32_t elements,qsort2_cmp cmp_func, const charset_info_st * const cs);
 
822
  in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs);
788
823
  ~in_string();
789
824
  void set(uint32_t pos,Item *item);
790
825
  unsigned char *get_value(Item *item);
854
889
  /* Cache for the left item. */
855
890
  Item *lval_cache;
856
891
 
857
 
  in_datetime(Item *warn_item_arg, uint32_t elements);
858
 
 
 
892
  in_datetime(Item *warn_item_arg, uint32_t elements)
 
893
    :in_int64_t(elements), session(current_session), warn_item(warn_item_arg),
 
894
     lval_cache(0) {};
859
895
  void set(uint32_t pos,Item *item);
860
896
  unsigned char *get_value(Item *item);
861
897
  friend int cmp_int64_t(void *cmp_arg, packed_int64_t *a,packed_int64_t *b);
883
919
 
884
920
class in_decimal :public in_vector
885
921
{
886
 
  type::Decimal val;
 
922
  my_decimal val;
887
923
public:
888
924
  in_decimal(uint32_t elements);
889
925
  void set(uint32_t pos, Item *item);
894
930
  }
895
931
  void value_to_item(uint32_t pos, Item *item)
896
932
  {
897
 
    type::Decimal *dec= ((type::Decimal *)base) + pos;
 
933
    my_decimal *dec= ((my_decimal *)base) + pos;
898
934
    Item_decimal *item_dec= (Item_decimal*)item;
899
935
    item_dec->set_decimal_value(dec);
900
936
  }
910
946
class cmp_item :public memory::SqlAlloc
911
947
{
912
948
public:
913
 
  const charset_info_st *cmp_charset;
914
 
 
915
 
  cmp_item()
916
 
  {
917
 
    cmp_charset= &my_charset_bin;
918
 
  }
919
 
 
 
949
  const CHARSET_INFO *cmp_charset;
 
950
  cmp_item() { cmp_charset= &my_charset_bin; }
920
951
  virtual ~cmp_item() {}
921
952
  virtual void store_value(Item *item)= 0;
922
953
  virtual int cmp(Item *item)= 0;
923
954
  // for optimized IN with row
924
955
  virtual int compare(cmp_item *item)= 0;
925
 
  static cmp_item* get_comparator(Item_result type, const charset_info_st * const cs);
 
956
  static cmp_item* get_comparator(Item_result type, const CHARSET_INFO * const cs);
926
957
  virtual cmp_item *make_same()= 0;
927
958
  virtual void store_value_by_template(cmp_item *, Item *item)
928
959
  {
936
967
  String *value_res;
937
968
public:
938
969
  cmp_item_string () {}
939
 
  cmp_item_string (const charset_info_st * const cs) { cmp_charset= cs; }
940
 
  void set_charset(const charset_info_st * const cs) { cmp_charset= cs; }
 
970
  cmp_item_string (const CHARSET_INFO * const cs) { cmp_charset= cs; }
 
971
  void set_charset(const CHARSET_INFO * const cs) { cmp_charset= cs; }
941
972
  friend class cmp_item_sort_string;
942
973
  friend class cmp_item_sort_string_in_static;
943
974
};
950
981
public:
951
982
  cmp_item_sort_string():
952
983
    cmp_item_string() {}
953
 
  cmp_item_sort_string(const charset_info_st * const cs):
 
984
  cmp_item_sort_string(const CHARSET_INFO * const cs):
954
985
    cmp_item_string(cs),
955
986
    value(value_buff, sizeof(value_buff), cs) {}
956
987
  void store_value(Item *item)
971
1002
    return sortcmp(value_res, l_cmp->value_res, cmp_charset);
972
1003
  }
973
1004
  cmp_item *make_same();
974
 
  void set_charset(const charset_info_st * const cs)
 
1005
  void set_charset(const CHARSET_INFO * const cs)
975
1006
  {
976
1007
    cmp_charset= cs;
977
1008
    value.set_quick(value_buff, sizeof(value_buff), cs);
982
1013
{
983
1014
  int64_t value;
984
1015
public:
 
1016
  cmp_item_int() {}                           /* Remove gcc warning */
985
1017
  void store_value(Item *item)
986
1018
  {
987
1019
    value= item->val_int();
1006
1038
*/
1007
1039
class cmp_item_datetime :public cmp_item
1008
1040
{
1009
 
  int64_t value;
1010
 
 
 
1041
  uint64_t value;
1011
1042
public:
1012
1043
  Session *session;
1013
1044
  /* Item used for issuing warnings. */
1015
1046
  /* Cache for the left item. */
1016
1047
  Item *lval_cache;
1017
1048
 
1018
 
  cmp_item_datetime(Item *warn_item_arg);
1019
 
 
 
1049
  cmp_item_datetime(Item *warn_item_arg)
 
1050
    :session(current_session), warn_item(warn_item_arg), lval_cache(0) {}
1020
1051
  void store_value(Item *item);
1021
1052
  int cmp(Item *arg);
1022
1053
  int compare(cmp_item *ci);
1027
1058
{
1028
1059
  double value;
1029
1060
public:
 
1061
  cmp_item_real() {}                          /* Remove gcc warning */
1030
1062
  void store_value(Item *item)
1031
1063
  {
1032
1064
    value= item->val_real();
1046
1078
 
1047
1079
class cmp_item_decimal :public cmp_item
1048
1080
{
1049
 
  type::Decimal value;
 
1081
  my_decimal value;
1050
1082
public:
 
1083
  cmp_item_decimal() {}                       /* Remove gcc warning */
1051
1084
  void store_value(Item *item);
1052
1085
  int cmp(Item *arg);
1053
1086
  int compare(cmp_item *c);
1065
1098
 protected:
1066
1099
  String value;
1067
1100
public:
1068
 
  cmp_item_sort_string_in_static(const charset_info_st * const cs):
 
1101
  cmp_item_sort_string_in_static(const CHARSET_INFO * const cs):
1069
1102
    cmp_item_string(cs) {}
1070
1103
  void store_value(Item *item)
1071
1104
  {
1116
1149
  Item_result cmp_type;
1117
1150
  DTCollation cmp_collation;
1118
1151
  enum_field_types cached_field_type;
1119
 
  cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
 
1152
  cmp_item *cmp_items[5]; /* For all result types */
1120
1153
  cmp_item *case_item;
1121
1154
public:
1122
1155
  Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1123
1156
    :Item_func(), first_expr_num(-1), else_expr_num(-1),
1124
1157
    cached_result_type(INT_RESULT), left_result_type(INT_RESULT), case_item(0)
1125
1158
  {
1126
 
    ncases= list.size();
 
1159
    ncases= list.elements;
1127
1160
    if (first_expr_arg)
1128
1161
    {
1129
 
      first_expr_num= list.size();
 
1162
      first_expr_num= list.elements;
1130
1163
      list.push_back(first_expr_arg);
1131
1164
    }
1132
1165
    if (else_expr_arg)
1133
1166
    {
1134
 
      else_expr_num= list.size();
 
1167
      else_expr_num= list.elements;
1135
1168
      list.push_back(else_expr_arg);
1136
1169
    }
1137
1170
    set_arguments(list);
1140
1173
  double val_real();
1141
1174
  int64_t val_int();
1142
1175
  String *val_str(String *);
1143
 
  type::Decimal *val_decimal(type::Decimal *);
 
1176
  my_decimal *val_decimal(my_decimal *);
1144
1177
  bool fix_fields(Session *session, Item **ref);
1145
1178
  void fix_length_and_dec();
1146
1179
  uint32_t decimal_precision() const;
1148
1181
  enum Item_result result_type () const { return cached_result_type; }
1149
1182
  enum_field_types field_type() const { return cached_field_type; }
1150
1183
  const char *func_name() const { return "case"; }
1151
 
  virtual void print(String *str);
 
1184
  virtual void print(String *str, enum_query_type query_type);
1152
1185
  Item *find_item(String *str);
1153
 
  const charset_info_st *compare_collation() { return cmp_collation.collation; }
 
1186
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
1154
1187
  void cleanup();
1155
1188
  void agg_str_lengths(Item *arg);
1156
1189
  void agg_num_lengths(Item *arg);
1201
1234
  uint32_t decimal_precision() const { return 1; }
1202
1235
  void cleanup()
1203
1236
  {
 
1237
    uint32_t i;
1204
1238
    Item_int_func::cleanup();
1205
1239
    delete array;
1206
1240
    array= 0;
1207
 
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
1241
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT + 1; i++)
1208
1242
    {
1209
1243
      delete cmp_items[i];
1210
1244
      cmp_items[i]= 0;
1213
1247
  }
1214
1248
  optimize_type select_optimize() const
1215
1249
    { return OPTIMIZE_KEY; }
1216
 
  virtual void print(String *str);
 
1250
  virtual void print(String *str, enum_query_type query_type);
1217
1251
  enum Functype functype() const { return IN_FUNC; }
1218
1252
  const char *func_name() const { return " IN "; }
1219
1253
  bool nulls_in_row();
1220
1254
  bool is_bool_func() { return 1; }
1221
 
  const charset_info_st *compare_collation() { return cmp_collation.collation; }
 
1255
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
1222
1256
};
1223
1257
 
1224
1258
class cmp_item_row :public cmp_item
1252
1286
 
1253
1287
/* Functions used by where clause */
1254
1288
 
1255
 
class Item_func_isnull :public item::function::Boolean
 
1289
class Item_func_isnull :public Item_bool_func
1256
1290
{
1257
1291
protected:
1258
1292
  int64_t cached_value;
1259
1293
public:
1260
 
  Item_func_isnull(Item *a) :item::function::Boolean(a) {}
 
1294
  Item_func_isnull(Item *a) :Item_bool_func(a) {}
1261
1295
  int64_t val_int();
1262
1296
  enum Functype functype() const { return ISNULL_FUNC; }
1263
1297
  void fix_length_and_dec()
1289
1323
  table_map not_null_tables() const { return 0; }
1290
1324
  optimize_type select_optimize() const { return OPTIMIZE_NULL; }
1291
1325
  Item *neg_transformer(Session *session);
1292
 
  const charset_info_st *compare_collation() { return args[0]->collation.collation; }
 
1326
  const CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
1293
1327
};
1294
1328
 
1295
1329
/* Functions used by HAVING for rewriting IN subquery */
1296
1330
 
 
1331
class Item_in_subselect;
 
1332
 
1297
1333
/*
1298
1334
  This is like IS NOT NULL but it also remembers if it ever has
1299
1335
  encountered a NULL.
1317
1353
};
1318
1354
 
1319
1355
 
1320
 
class Item_func_isnotnull :public item::function::Boolean
 
1356
class Item_func_isnotnull :public Item_bool_func
1321
1357
{
1322
1358
  bool abort_on_null;
1323
1359
public:
1324
 
  Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
 
1360
  Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1325
1361
  int64_t val_int();
1326
1362
  enum Functype functype() const { return ISNOTNULL_FUNC; }
1327
1363
  void fix_length_and_dec()
1333
1369
  table_map not_null_tables() const
1334
1370
  { return abort_on_null ? not_null_tables_cache : 0; }
1335
1371
  Item *neg_transformer(Session *session);
1336
 
  virtual void print(String *str);
1337
 
  const charset_info_st *compare_collation() { return args[0]->collation.collation; }
 
1372
  virtual void print(String *str, enum_query_type query_type);
 
1373
  const CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
1338
1374
  void top_level_item() { abort_on_null=1; }
1339
1375
};
1340
1376
 
1379
1415
};
1380
1416
 
1381
1417
 
1382
 
class Item_cond :public item::function::Boolean
 
1418
typedef class Item COND;
 
1419
 
 
1420
class Item_cond :public Item_bool_func
1383
1421
{
1384
1422
protected:
1385
1423
  List<Item> list;
1391
1429
  using Item::split_sum_func;
1392
1430
 
1393
1431
  /* Item_cond() is only used to create top level items */
1394
 
  Item_cond(): item::function::Boolean(), abort_on_null(1)
 
1432
  Item_cond(): Item_bool_func(), abort_on_null(1)
1395
1433
  { const_item_cache=0; }
1396
1434
  Item_cond(Item *i1,Item *i2)
1397
 
    :item::function::Boolean(), abort_on_null(0)
 
1435
    :Item_bool_func(), abort_on_null(0)
1398
1436
  {
1399
1437
    list.push_back(i1);
1400
1438
    list.push_back(i2);
1401
1439
  }
1402
1440
  Item_cond(Session *session, Item_cond *item);
1403
1441
  Item_cond(List<Item> &nlist)
1404
 
    :item::function::Boolean(), list(nlist), abort_on_null(0) {}
1405
 
  void add(Item *item) { list.push_back(item); }
1406
 
  void add_at_head(Item *item) { list.push_front(item); }
 
1442
    :Item_bool_func(), list(nlist), abort_on_null(0) {}
 
1443
  bool add(Item *item) { return list.push_back(item); }
 
1444
  bool add_at_head(Item *item) { return list.push_front(item); }
1407
1445
  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1408
1446
  bool fix_fields(Session *, Item **ref);
1409
1447
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
1412
1450
  List<Item>* argument_list() { return &list; }
1413
1451
  table_map used_tables() const;
1414
1452
  void update_used_tables();
1415
 
  virtual void print(String *str);
 
1453
  virtual void print(String *str, enum_query_type query_type);
1416
1454
  void split_sum_func(Session *session, Item **ref_pointer_array, List<Item> &fields);
1417
1455
  friend int setup_conds(Session *session, TableList *tables, TableList *leaves,
1418
1456
                         COND **conds);
1505
1543
  object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1506
1544
*/
1507
1545
 
1508
 
class Item_equal: public item::function::Boolean
 
1546
class Item_equal: public Item_bool_func
1509
1547
{
 
1548
  List<Item_field> fields; /* list of equal field items                    */
 
1549
  Item *const_item;        /* optional constant item equal to fields items */
 
1550
  cmp_item *eval_item;
 
1551
  bool cond_false;
1510
1552
public:
1511
 
  typedef List<Item_field> fields_t;
1512
 
 
1513
 
  Item_equal() :
1514
 
    const_item(0),
1515
 
    eval_item(0),
1516
 
    cond_false(0)
1517
 
  {
1518
 
    const_item_cache=0;
1519
 
  }
1520
 
 
1521
 
  fields_t::iterator begin()
1522
 
  {
1523
 
    return fields.begin();
1524
 
  }
1525
 
 
 
1553
  inline Item_equal()
 
1554
    : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
1555
  { const_item_cache=0 ;}
1526
1556
  Item_equal(Item_field *f1, Item_field *f2);
1527
1557
  Item_equal(Item *c, Item_field *f);
1528
1558
  Item_equal(Item_equal *item_equal);
1531
1561
  void add(Item_field *f);
1532
1562
  uint32_t members();
1533
1563
  bool contains(Field *field);
1534
 
  Item_field* get_first() { return &fields.front(); }
 
1564
  Item_field* get_first() { return fields.head(); }
1535
1565
  void merge(Item_equal *item);
1536
1566
  void update_const();
1537
1567
  enum Functype functype() const { return MULT_EQUAL_FUNC; }
1539
1569
  const char *func_name() const { return "multiple equal"; }
1540
1570
  optimize_type select_optimize() const { return OPTIMIZE_EQUAL; }
1541
1571
  void sort(Item_field_cmpfunc cmp, void *arg);
 
1572
  friend class Item_equal_iterator;
1542
1573
  void fix_length_and_dec();
1543
1574
  bool fix_fields(Session *session, Item **ref);
1544
1575
  void update_used_tables();
1545
1576
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
1546
1577
  Item *transform(Item_transformer transformer, unsigned char *arg);
1547
 
  virtual void print(String *str);
1548
 
  const charset_info_st *compare_collation()
1549
 
  { return fields.front().collation.collation; }
1550
 
private:
1551
 
  fields_t fields; /* list of equal field items                    */
1552
 
  Item *const_item;        /* optional constant item equal to fields items */
1553
 
  cmp_item *eval_item;
1554
 
  bool cond_false;
1555
 
 
 
1578
  virtual void print(String *str, enum_query_type query_type);
 
1579
  const CHARSET_INFO *compare_collation()
 
1580
  { return fields.head()->collation.collation; }
1556
1581
};
1557
1582
 
1558
1583
class COND_EQUAL: public memory::SqlAlloc
1569
1594
  }
1570
1595
};
1571
1596
 
1572
 
typedef List<Item_field>::iterator Item_equal_iterator;
 
1597
 
 
1598
class Item_equal_iterator : public List_iterator_fast<Item_field>
 
1599
{
 
1600
public:
 
1601
  inline Item_equal_iterator(Item_equal &item_equal)
 
1602
    :List_iterator_fast<Item_field> (item_equal.fields)
 
1603
  {}
 
1604
  inline Item_field* operator++(int)
 
1605
  {
 
1606
    Item_field *item= (*(List_iterator_fast<Item_field> *) this)++;
 
1607
    return  item;
 
1608
  }
 
1609
  inline void rewind(void)
 
1610
  {
 
1611
    List_iterator_fast<Item_field>::rewind();
 
1612
  }
 
1613
};
1573
1614
 
1574
1615
class Item_cond_and :public Item_cond
1575
1616
{
1589
1630
  Item* copy_andor_structure(Session *session)
1590
1631
  {
1591
1632
    Item_cond_and *item;
1592
 
    item= new Item_cond_and(session, this);
1593
 
    item->copy_andor_arguments(session, this);
 
1633
    if ((item= new Item_cond_and(session, this)))
 
1634
       item->copy_andor_arguments(session, this);
1594
1635
    return item;
1595
1636
  }
1596
1637
  Item *neg_transformer(Session *session);
1619
1660
  Item* copy_andor_structure(Session *session)
1620
1661
  {
1621
1662
    Item_cond_or *item;
1622
 
    item= new Item_cond_or(session, this);
1623
 
    item->copy_andor_arguments(session, this);
 
1663
    if ((item= new Item_cond_or(session, this)))
 
1664
      item->copy_andor_arguments(session, this);
1624
1665
    return item;
1625
1666
  }
1626
1667
  Item *neg_transformer(Session *session);
1669
1710
 
1670
1711
} /* namespace drizzled */
1671
1712
 
 
1713
#endif /* DRIZZLED_ITEM_CMPFUNC_H */