~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_cmpfunc.h

  • Committer: Mark Atwood
  • Date: 2008-10-03 01:39:40 UTC
  • mto: This revision was merged to the branch mainline in revision 437.
  • Revision ID: mark@fallenpegasus.com-20081003013940-mvefjo725dltz41h
rename logging_noop to logging_query

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, Inc.
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
 
 */
19
 
 
20
 
#ifndef DRIZZLED_ITEM_CMPFUNC_H
21
 
#define DRIZZLED_ITEM_CMPFUNC_H
 
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 */
 
15
 
22
16
 
23
17
/* compare and test functions */
24
18
 
25
 
#include <drizzled/common.h>
26
 
#include <drizzled/comp_creator.h>
27
 
#include <drizzled/function/math/int.h>
28
 
#include <drizzled/function/numhybrid.h>
29
 
#include <drizzled/item/decimal.h>
30
 
#include <drizzled/item/float.h>
31
 
#include <drizzled/item/function/boolean.h>
32
 
#include <drizzled/item/int.h>
33
 
#include <drizzled/item/row.h>
34
 
#include <drizzled/item/string.h>
35
 
#include <drizzled/item/sum.h>
36
 
#include <drizzled/qsort_cmp.h>
37
 
 
38
 
namespace drizzled
39
 
{
 
19
#ifdef USE_PRAGMA_INTERFACE
 
20
#pragma interface                       /* gcc class implementation */
 
21
#endif
40
22
 
41
23
extern Item_result item_cmp_type(Item_result a,Item_result b);
42
 
 
43
24
class Item_bool_func2;
44
25
class Arg_comparator;
45
 
class Item_sum_hybrid;
46
 
class Item_row;
47
 
class Session;
48
26
 
49
27
typedef int (Arg_comparator::*arg_cmp_func)();
50
28
 
51
 
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
52
 
 
53
 
int64_t get_datetime_value(Session *session, 
54
 
                           Item ***item_arg, 
55
 
                           Item **cache_arg,
56
 
                           Item *warn_item, 
57
 
                           bool *is_null);
58
 
 
59
 
class Arg_comparator: public memory::SqlAlloc
 
29
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg); 
 
30
 
 
31
class Arg_comparator: public Sql_alloc
60
32
{
61
33
  Item **a, **b;
62
34
  arg_cmp_func func;
64
36
  Arg_comparator *comparators;   // used only for compare_row()
65
37
  double precision;
66
38
  /* Fields used in DATE/DATETIME comparison. */
67
 
  Session *session;
 
39
  THD *thd;
68
40
  enum_field_types a_type, b_type; // Types of a and b items
69
41
  Item *a_cache, *b_cache;         // Cached values of a and b items
70
42
  bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
71
43
  enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
72
44
                            CMP_DATE_WITH_STR, CMP_STR_WITH_DATE };
73
 
  int64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
74
 
                            Item *warn_item, bool *is_null);
 
45
  uint64_t (*get_value_func)(THD *thd, Item ***item_arg, Item **cache_arg,
 
46
                              Item *warn_item, bool *is_null);
75
47
public:
76
48
  DTCollation cmp_collation;
77
49
 
78
 
  Arg_comparator();
79
 
 
80
 
  Arg_comparator(Item **a1, Item **a2);
 
50
  Arg_comparator(): thd(0), a_cache(0), b_cache(0) {};
 
51
  Arg_comparator(Item **a1, Item **a2): a(a1), b(a2), thd(0),
 
52
    a_cache(0), b_cache(0) {};
81
53
 
82
54
  int set_compare_func(Item_bool_func2 *owner, Item_result type);
83
55
  inline int set_compare_func(Item_bool_func2 *owner_arg)
119
91
  int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
120
92
 
121
93
  static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
122
 
                                                      int64_t *const_val_arg);
 
94
                                                      uint64_t *const_val_arg);
123
95
 
124
96
  void set_datetime_cmp_func(Item **a1, Item **b1);
125
97
  static arg_cmp_func comparator_matrix [5][2];
127
99
  friend class Item_func;
128
100
};
129
101
 
 
102
class Item_bool_func :public Item_int_func
 
103
{
 
104
public:
 
105
  Item_bool_func() :Item_int_func() {}
 
106
  Item_bool_func(Item *a) :Item_int_func(a) {}
 
107
  Item_bool_func(Item *a,Item *b) :Item_int_func(a,b) {}
 
108
  Item_bool_func(THD *thd, Item_bool_func *item) :Item_int_func(thd, item) {}
 
109
  bool is_bool_func() { return 1; }
 
110
  void fix_length_and_dec() { decimals=0; max_length=1; }
 
111
  uint decimal_precision() const { return 1; }
 
112
};
 
113
 
130
114
 
131
115
/**
132
116
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
133
117
  boolean predicates.
134
118
*/
135
119
 
136
 
class Item_func_truth : public item::function::Boolean
 
120
class Item_func_truth : public Item_bool_func
137
121
{
138
122
public:
139
123
  virtual bool val_bool();
143
127
 
144
128
protected:
145
129
  Item_func_truth(Item *a, bool a_value, bool a_affirmative)
146
 
  : item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
 
130
  : Item_bool_func(a), value(a_value), affirmative(a_affirmative)
147
131
  {}
148
132
 
149
133
  ~Item_func_truth()
232
216
    placed into a separate class called 'Item_in_optimizer'.
233
217
*/
234
218
 
235
 
class Item_in_optimizer: public item::function::Boolean
 
219
class Item_in_optimizer: public Item_bool_func
236
220
{
237
221
protected:
238
222
  Item_cache *cache;
239
223
  bool save_cache;
240
 
  /*
 
224
  /* 
241
225
    Stores the value of "NULL IN (SELECT ...)" for uncorrelated subqueries:
242
226
      UNKNOWN - "NULL in (SELECT ...)" has not yet been evaluated
243
227
      FALSE   - result is FALSE
246
230
  bool result_for_null_param;
247
231
public:
248
232
  Item_in_optimizer(Item *a, Item_in_subselect *b):
249
 
    item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
 
233
    Item_bool_func(a, my_reinterpret_cast(Item *)(b)), cache(0),
250
234
    save_cache(0), result_for_null_param(UNKNOWN)
251
235
  { with_subselect= true; }
252
 
  bool fix_fields(Session *, Item **);
253
 
  bool fix_left(Session *session, Item **ref);
 
236
  bool fix_fields(THD *, Item **);
 
237
  bool fix_left(THD *thd, Item **ref);
254
238
  bool is_null();
255
239
  int64_t val_int();
256
240
  void cleanup();
257
241
  const char *func_name() const { return "<in_optimizer>"; }
258
242
  Item_cache **get_cache() { return &cache; }
259
243
  void keep_top_level_cache();
260
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
244
  Item *transform(Item_transformer transformer, uchar *arg);
 
245
};
 
246
 
 
247
class Comp_creator
 
248
{
 
249
public:
 
250
  Comp_creator() {}                           /* Remove gcc warning */
 
251
  virtual ~Comp_creator() {}                  /* Remove gcc warning */
 
252
  virtual Item_bool_func2* create(Item *a, Item *b) const = 0;
 
253
  virtual const char* symbol(bool invert) const = 0;
 
254
  virtual bool eqne_op() const = 0;
 
255
  virtual bool l_op() const = 0;
261
256
};
262
257
 
263
258
class Eq_creator :public Comp_creator
269
264
  virtual const char* symbol(bool invert) const { return invert? "<>" : "="; }
270
265
  virtual bool eqne_op() const { return 1; }
271
266
  virtual bool l_op() const { return 0; }
272
 
  static const Eq_creator *instance();
273
267
};
274
268
 
275
269
class Ne_creator :public Comp_creator
281
275
  virtual const char* symbol(bool invert) const { return invert? "=" : "<>"; }
282
276
  virtual bool eqne_op() const { return 1; }
283
277
  virtual bool l_op() const { return 0; }
284
 
  static const Ne_creator *instance();
285
278
};
286
279
 
287
280
class Gt_creator :public Comp_creator
293
286
  virtual const char* symbol(bool invert) const { return invert? "<=" : ">"; }
294
287
  virtual bool eqne_op() const { return 0; }
295
288
  virtual bool l_op() const { return 0; }
296
 
  static const Gt_creator *instance();
297
289
};
298
290
 
299
291
class Lt_creator :public Comp_creator
305
297
  virtual const char* symbol(bool invert) const { return invert? ">=" : "<"; }
306
298
  virtual bool eqne_op() const { return 0; }
307
299
  virtual bool l_op() const { return 1; }
308
 
  static const Lt_creator *instance();
309
300
};
310
301
 
311
302
class Ge_creator :public Comp_creator
317
308
  virtual const char* symbol(bool invert) const { return invert? "<" : ">="; }
318
309
  virtual bool eqne_op() const { return 0; }
319
310
  virtual bool l_op() const { return 0; }
320
 
  static const Ge_creator *instance();
321
311
};
322
312
 
323
313
class Le_creator :public Comp_creator
329
319
  virtual const char* symbol(bool invert) const { return invert? ">" : "<="; }
330
320
  virtual bool eqne_op() const { return 0; }
331
321
  virtual bool l_op() const { return 1; }
332
 
  static const Le_creator *instance();
333
322
};
334
323
 
335
324
class Item_bool_func2 :public Item_int_func
359
348
  bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); }
360
349
  bool is_bool_func() { return 1; }
361
350
  const CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; }
362
 
  uint32_t decimal_precision() const { return 1; }
 
351
  uint decimal_precision() const { return 1; }
363
352
  void top_level_item() { abort_on_null= true; }
364
353
 
365
354
  friend class  Arg_comparator;
372
361
  {
373
362
    allowed_arg_cols= 0;  // Fetch this value from first argument
374
363
  }
375
 
  Item *neg_transformer(Session *session);
 
364
  Item *neg_transformer(THD *thd);
376
365
  virtual Item *negated_item();
377
 
  bool subst_argument_checker(unsigned char **)
 
366
  bool subst_argument_checker(uchar **arg __attribute__((unused)))
378
367
  { return true; }
379
368
};
380
369
 
381
 
class Item_func_not :public item::function::Boolean
 
370
class Item_func_not :public Item_bool_func
382
371
{
383
372
public:
384
 
  Item_func_not(Item *a) :item::function::Boolean(a) {}
 
373
  Item_func_not(Item *a) :Item_bool_func(a) {}
385
374
  int64_t val_int();
386
375
  enum Functype functype() const { return NOT_FUNC; }
387
376
  const char *func_name() const { return "not"; }
388
 
  Item *neg_transformer(Session *session);
 
377
  Item *neg_transformer(THD *thd);
389
378
  virtual void print(String *str, enum_query_type query_type);
390
379
};
391
380
 
394
383
/*
395
384
  trigcond<param>(arg) ::= param? arg : TRUE
396
385
 
397
 
  The class Item_func_trig_cond is used for guarded predicates
 
386
  The class Item_func_trig_cond is used for guarded predicates 
398
387
  which are employed only for internal purposes.
399
388
  A guarded predicate is an object consisting of an a regular or
400
 
  a guarded predicate P and a pointer to a boolean guard variable g.
 
389
  a guarded predicate P and a pointer to a boolean guard variable g. 
401
390
  A guarded predicate P/g is evaluated to true if the value of the
402
391
  guard g is false, otherwise it is evaluated to the same value that
403
392
  the predicate P: val(P/g)= g ? val(P):true.
409
398
  the objects consisting of three elements: a predicate P, a pointer
410
399
  to a variable g and a firing value s with following evaluation
411
400
  rule: val(P/g,s)= g==s? val(P) : true. It will allow us to build only
412
 
  one item for the objects of the form P/g1/g2...
 
401
  one item for the objects of the form P/g1/g2... 
413
402
 
414
403
  Objects of this class are built only for query execution after
415
404
  the execution plan has been already selected. That's why this
416
 
  class needs only val_int out of generic methods.
417
 
 
 
405
  class needs only val_int out of generic methods. 
 
406
 
418
407
  Current uses of Item_func_trig_cond objects:
419
408
   - To wrap selection conditions when executing outer joins
420
409
   - To wrap condition that is pushed down into subquery
421
410
*/
422
411
 
423
 
class Item_func_trig_cond: public item::function::Boolean
 
412
class Item_func_trig_cond: public Item_bool_func
424
413
{
425
414
  bool *trig_var;
426
415
public:
427
 
  Item_func_trig_cond(Item *a, bool *f) : item::function::Boolean(a) { trig_var= f; }
 
416
  Item_func_trig_cond(Item *a, bool *f) : Item_bool_func(a) { trig_var= f; }
428
417
  int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
429
418
  enum Functype functype() const { return TRIG_COND_FUNC; };
430
419
  const char *func_name() const { return "trigcond"; };
457
446
  void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; };
458
447
  void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; };
459
448
  bool empty_underlying_subquery();
460
 
  Item *neg_transformer(Session *session);
 
449
  Item *neg_transformer(THD *thd);
461
450
};
462
451
 
463
452
 
468
457
  Item_func_nop_all(Item *a) :Item_func_not_all(a) {}
469
458
  int64_t val_int();
470
459
  const char *func_name() const { return "<nop>"; }
471
 
  Item *neg_transformer(Session *session);
 
460
  Item *neg_transformer(THD *thd);
472
461
};
473
462
 
474
463
 
495
484
  enum Functype rev_functype() const { return EQUAL_FUNC; }
496
485
  cond_result eq_cmp_result() const { return COND_TRUE; }
497
486
  const char *func_name() const { return "<=>"; }
498
 
  Item *neg_transformer(Session *) { return 0; }
 
487
  Item *neg_transformer(THD *thd __attribute__((unused))) { return 0; }
499
488
};
500
489
 
501
490
 
558
547
  int64_t val_int();
559
548
  enum Functype functype() const { return NE_FUNC; }
560
549
  cond_result eq_cmp_result() const { return COND_FALSE; }
561
 
  optimize_type select_optimize() const { return OPTIMIZE_KEY; }
 
550
  optimize_type select_optimize() const { return OPTIMIZE_KEY; } 
562
551
  const char *func_name() const { return "<>"; }
563
552
  Item *negated_item();
564
553
};
586
575
public:
587
576
  inline void negate() { negated= !negated; }
588
577
  inline void top_level_item() { pred_level= 1; }
589
 
  Item *neg_transformer(Session *)
 
578
  Item *neg_transformer(THD *thd __attribute__((unused)))
590
579
  {
591
580
    negated= !negated;
592
581
    return this;
593
582
  }
594
583
  bool eq(const Item *item, bool binary_cmp) const;
595
 
  bool subst_argument_checker(unsigned char **)
 
584
  bool subst_argument_checker(uchar **arg __attribute__((unused)))
596
585
  { return true; }
597
586
};
598
587
 
613
602
  optimize_type select_optimize() const { return OPTIMIZE_KEY; }
614
603
  enum Functype functype() const   { return BETWEEN; }
615
604
  const char *func_name() const { return "between"; }
616
 
  bool fix_fields(Session *, Item **);
 
605
  bool fix_fields(THD *, Item **);
617
606
  void fix_length_and_dec();
618
607
  virtual void print(String *str, enum_query_type query_type);
619
608
  bool is_bool_func() { return 1; }
620
609
  const CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
621
 
  uint32_t decimal_precision() const { return 1; }
 
610
  uint decimal_precision() const { return 1; }
622
611
};
623
612
 
624
613
 
641
630
{
642
631
  Item_result type;
643
632
  double dbl;
644
 
  type::Decimal dec;
 
633
  my_decimal dec;
645
634
};
646
635
 
647
636
class Item_func_interval :public Item_int_func
658
647
  int64_t val_int();
659
648
  void fix_length_and_dec();
660
649
  const char *func_name() const { return "interval"; }
661
 
  uint32_t decimal_precision() const { return 2; }
 
650
  uint decimal_precision() const { return 2; }
662
651
};
663
652
 
664
653
 
672
661
  double real_op();
673
662
  int64_t int_op();
674
663
  String *str_op(String *);
675
 
  type::Decimal *decimal_op(type::Decimal *);
 
664
  my_decimal *decimal_op(my_decimal *);
676
665
  void fix_length_and_dec();
677
666
  void find_num_type() {}
678
667
  enum Item_result result_type () const { return hybrid_type; }
691
680
  double real_op();
692
681
  int64_t int_op();
693
682
  String *str_op(String *str);
694
 
  type::Decimal *decimal_op(type::Decimal *);
 
683
  my_decimal *decimal_op(my_decimal *);
695
684
  enum_field_types field_type() const;
696
685
  void fix_length_and_dec();
697
686
  const char *func_name() const { return "ifnull"; }
698
 
  Field *tmp_table_field()
699
 
  {
700
 
    return Item_func::tmp_table_field();
701
 
  }
702
687
  Field *tmp_table_field(Table *table);
703
 
  uint32_t decimal_precision() const;
 
688
  uint decimal_precision() const;
704
689
};
705
690
 
706
691
 
715
700
  double val_real();
716
701
  int64_t val_int();
717
702
  String *val_str(String *str);
718
 
  type::Decimal *val_decimal(type::Decimal *);
 
703
  my_decimal *val_decimal(my_decimal *);
719
704
  enum Item_result result_type () const { return cached_result_type; }
720
705
  enum_field_types field_type() const { return cached_field_type; }
721
 
  bool fix_fields(Session *, Item **);
 
706
  bool fix_fields(THD *, Item **);
722
707
  void fix_length_and_dec();
723
 
  uint32_t decimal_precision() const;
 
708
  uint decimal_precision() const;
724
709
  const char *func_name() const { return "if"; }
725
710
};
726
711
 
735
720
  double val_real();
736
721
  int64_t val_int();
737
722
  String *val_str(String *str);
738
 
  type::Decimal *val_decimal(type::Decimal *);
 
723
  my_decimal *val_decimal(my_decimal *);
739
724
  enum Item_result result_type () const { return cached_result_type; }
740
725
  void fix_length_and_dec();
741
 
  uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
 
726
  uint decimal_precision() const { return args[0]->decimal_precision(); }
742
727
  const char *func_name() const { return "nullif"; }
743
728
 
744
729
  virtual inline void print(String *str, enum_query_type query_type)
756
741
 
757
742
/* A vector of values of some type  */
758
743
 
759
 
class in_vector :public memory::SqlAlloc
 
744
class in_vector :public Sql_alloc
760
745
{
761
746
public:
762
747
  char *base;
763
 
  uint32_t size;
 
748
  uint size;
764
749
  qsort2_cmp compare;
765
750
  const CHARSET_INFO *collation;
766
 
  uint32_t count;
767
 
  uint32_t used_count;
 
751
  uint count;
 
752
  uint used_count;
768
753
  in_vector() {}
769
 
  in_vector(uint32_t elements,uint32_t element_length,qsort2_cmp cmp_func,
 
754
  in_vector(uint elements,uint element_length,qsort2_cmp cmp_func, 
770
755
            const CHARSET_INFO * const cmp_coll)
771
 
    :base((char*) memory::sql_calloc(elements*element_length)),
 
756
    :base((char*) sql_calloc(elements*element_length)),
772
757
     size(element_length), compare(cmp_func), collation(cmp_coll),
773
758
     count(elements), used_count(elements) {}
774
759
  virtual ~in_vector() {}
775
 
  virtual void set(uint32_t pos,Item *item)=0;
776
 
  virtual unsigned char *get_value(Item *item)=0;
777
 
  void sort();
 
760
  virtual void set(uint pos,Item *item)=0;
 
761
  virtual uchar *get_value(Item *item)=0;
 
762
  void sort()
 
763
  {
 
764
    my_qsort2(base,used_count,size,compare, (void *) collation);
 
765
  }
778
766
  int find(Item *item);
779
 
 
780
 
  /*
 
767
  
 
768
  /* 
781
769
    Create an instance of Item_{type} (e.g. Item_decimal) constant object
782
770
    which type allows it to hold an element of this vector without any
783
771
    conversions.
786
774
    for every array element you get (i.e. this implements "FlyWeight" pattern)
787
775
  */
788
776
  virtual Item* create_item() { return NULL; }
789
 
 
 
777
  
790
778
  /*
791
779
    Store the value at position #pos into provided item object
792
780
    SYNOPSIS
795
783
        item  Constant item to store value into. The item must be of the same
796
784
              type that create_item() returns.
797
785
  */
798
 
  virtual void value_to_item(uint32_t, Item *) { }
799
 
 
 
786
  virtual void value_to_item(uint pos __attribute__((unused)),
 
787
                             Item *item __attribute__((unused))) { }
 
788
  
800
789
  /* Compare values number pos1 and pos2 for equality */
801
 
  bool compare_elems(uint32_t pos1, uint32_t pos2)
 
790
  bool compare_elems(uint pos1, uint pos2)
802
791
  {
803
792
    return test(compare(collation, base + pos1*size, base + pos2*size));
804
793
  }
810
799
  char buff[STRING_BUFFER_USUAL_SIZE];
811
800
  String tmp;
812
801
public:
813
 
  in_string(uint32_t elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs);
 
802
  in_string(uint elements,qsort2_cmp cmp_func, const CHARSET_INFO * const cs);
814
803
  ~in_string();
815
 
  void set(uint32_t pos,Item *item);
816
 
  unsigned char *get_value(Item *item);
 
804
  void set(uint pos,Item *item);
 
805
  uchar *get_value(Item *item);
817
806
  Item* create_item()
818
 
  {
 
807
  { 
819
808
    return new Item_string(collation);
820
809
  }
821
 
  void value_to_item(uint32_t pos, Item *item)
822
 
  {
 
810
  void value_to_item(uint pos, Item *item)
 
811
  {    
823
812
    String *str=((String*) base)+pos;
824
813
    Item_string *to= (Item_string*)item;
825
814
    to->str_value= *str;
832
821
protected:
833
822
  /*
834
823
    Here we declare a temporary variable (tmp) of the same type as the
835
 
    elements of this vector. tmp is used in finding if a given value is in
836
 
    the list.
 
824
    elements of this vector. tmp is used in finding if a given value is in 
 
825
    the list. 
837
826
  */
838
 
  struct packed_int64_t
 
827
  struct packed_int64_t 
839
828
  {
840
829
    int64_t val;
841
830
    int64_t unsigned_flag;  // Use int64_t, not bool, to preserve alignment
842
831
  } tmp;
843
832
public:
844
 
  in_int64_t(uint32_t elements);
845
 
  void set(uint32_t pos,Item *item);
846
 
  unsigned char *get_value(Item *item);
847
 
 
 
833
  in_int64_t(uint elements);
 
834
  void set(uint pos,Item *item);
 
835
  uchar *get_value(Item *item);
 
836
  
848
837
  Item* create_item()
849
 
  {
850
 
    /*
851
 
      We're created a signed INT, this may not be correct in
 
838
  { 
 
839
    /* 
 
840
      We're created a signed INT, this may not be correct in 
852
841
      general case (see BUG#19342).
853
842
    */
854
843
    return new Item_int((int64_t)0);
855
844
  }
856
 
  void value_to_item(uint32_t pos, Item *item)
 
845
  void value_to_item(uint pos, Item *item)
857
846
  {
858
847
    ((Item_int*) item)->value= ((packed_int64_t*) base)[pos].val;
859
848
    ((Item_int*) item)->unsigned_flag= (bool)
874
863
class in_datetime :public in_int64_t
875
864
{
876
865
public:
877
 
  Session *session;
 
866
  THD *thd;
878
867
  /* An item used to issue warnings. */
879
868
  Item *warn_item;
880
869
  /* Cache for the left item. */
881
870
  Item *lval_cache;
882
871
 
883
 
  in_datetime(Item *warn_item_arg, uint32_t elements);
884
 
 
885
 
  void set(uint32_t pos,Item *item);
886
 
  unsigned char *get_value(Item *item);
 
872
  in_datetime(Item *warn_item_arg, uint elements)
 
873
    :in_int64_t(elements), thd(current_thd), warn_item(warn_item_arg),
 
874
     lval_cache(0) {};
 
875
  void set(uint pos,Item *item);
 
876
  uchar *get_value(Item *item);
887
877
  friend int cmp_int64_t(void *cmp_arg, packed_int64_t *a,packed_int64_t *b);
888
878
};
889
879
 
892
882
{
893
883
  double tmp;
894
884
public:
895
 
  in_double(uint32_t elements);
896
 
  void set(uint32_t pos,Item *item);
897
 
  unsigned char *get_value(Item *item);
 
885
  in_double(uint elements);
 
886
  void set(uint pos,Item *item);
 
887
  uchar *get_value(Item *item);
898
888
  Item *create_item()
899
 
  {
 
889
  { 
900
890
    return new Item_float(0.0, 0);
901
891
  }
902
 
  void value_to_item(uint32_t pos, Item *item)
 
892
  void value_to_item(uint pos, Item *item)
903
893
  {
904
894
    ((Item_float*)item)->value= ((double*) base)[pos];
905
895
  }
909
899
 
910
900
class in_decimal :public in_vector
911
901
{
912
 
  type::Decimal val;
 
902
  my_decimal val;
913
903
public:
914
 
  in_decimal(uint32_t elements);
915
 
  void set(uint32_t pos, Item *item);
916
 
  unsigned char *get_value(Item *item);
 
904
  in_decimal(uint elements);
 
905
  void set(uint pos, Item *item);
 
906
  uchar *get_value(Item *item);
917
907
  Item *create_item()
918
 
  {
 
908
  { 
919
909
    return new Item_decimal(0, false);
920
910
  }
921
 
  void value_to_item(uint32_t pos, Item *item)
 
911
  void value_to_item(uint pos, Item *item)
922
912
  {
923
 
    type::Decimal *dec= ((type::Decimal *)base) + pos;
 
913
    my_decimal *dec= ((my_decimal *)base) + pos;
924
914
    Item_decimal *item_dec= (Item_decimal*)item;
925
915
    item_dec->set_decimal_value(dec);
926
916
  }
933
923
** Classes for easy comparing of non const items
934
924
*/
935
925
 
936
 
class cmp_item :public memory::SqlAlloc
 
926
class cmp_item :public Sql_alloc
937
927
{
938
928
public:
939
929
  const CHARSET_INFO *cmp_charset;
940
 
 
941
 
  cmp_item()
942
 
  {
943
 
    cmp_charset= &my_charset_bin;
944
 
  }
945
 
 
 
930
  cmp_item() { cmp_charset= &my_charset_bin; }
946
931
  virtual ~cmp_item() {}
947
932
  virtual void store_value(Item *item)= 0;
948
933
  virtual int cmp(Item *item)= 0;
950
935
  virtual int compare(cmp_item *item)= 0;
951
936
  static cmp_item* get_comparator(Item_result type, const CHARSET_INFO * const cs);
952
937
  virtual cmp_item *make_same()= 0;
953
 
  virtual void store_value_by_template(cmp_item *, Item *item)
 
938
  virtual void store_value_by_template(cmp_item *tmpl  __attribute__((unused)),
 
939
                                       Item *item)
954
940
  {
955
941
    store_value(item);
956
942
  }
957
943
};
958
944
 
959
 
class cmp_item_string :public cmp_item
 
945
class cmp_item_string :public cmp_item 
960
946
{
961
947
protected:
962
948
  String *value_res;
995
981
  {
996
982
    cmp_item_string *l_cmp= (cmp_item_string *) ci;
997
983
    return sortcmp(value_res, l_cmp->value_res, cmp_charset);
998
 
  }
 
984
  } 
999
985
  cmp_item *make_same();
1000
986
  void set_charset(const CHARSET_INFO * const cs)
1001
987
  {
1033
1019
*/
1034
1020
class cmp_item_datetime :public cmp_item
1035
1021
{
1036
 
  int64_t value;
1037
 
 
 
1022
  uint64_t value;
1038
1023
public:
1039
 
  Session *session;
 
1024
  THD *thd;
1040
1025
  /* Item used for issuing warnings. */
1041
1026
  Item *warn_item;
1042
1027
  /* Cache for the left item. */
1043
1028
  Item *lval_cache;
1044
1029
 
1045
 
  cmp_item_datetime(Item *warn_item_arg);
1046
 
 
 
1030
  cmp_item_datetime(Item *warn_item_arg)
 
1031
    :thd(current_thd), warn_item(warn_item_arg), lval_cache(0) {}
1047
1032
  void store_value(Item *item);
1048
1033
  int cmp(Item *arg);
1049
1034
  int compare(cmp_item *ci);
1074
1059
 
1075
1060
class cmp_item_decimal :public cmp_item
1076
1061
{
1077
 
  type::Decimal value;
 
1062
  my_decimal value;
1078
1063
public:
1079
1064
  cmp_item_decimal() {}                       /* Remove gcc warning */
1080
1065
  void store_value(Item *item);
1084
1069
};
1085
1070
 
1086
1071
 
1087
 
/*
 
1072
/* 
1088
1073
   cmp_item for optimized IN with row (right part string, which never
1089
1074
   be changed)
1090
1075
*/
1100
1085
  {
1101
1086
    value_res= item->val_str(&value);
1102
1087
  }
1103
 
  int cmp(Item *)
 
1088
  int cmp(Item *item __attribute__((unused)))
1104
1089
  {
1105
1090
    // Should never be called
1106
1091
    assert(0);
1122
1107
  The class Item_func_case is the CASE ... WHEN ... THEN ... END function
1123
1108
  implementation.
1124
1109
 
1125
 
  When there is no expression between CASE and the first WHEN
 
1110
  When there is no expression between CASE and the first WHEN 
1126
1111
  (the CASE expression) then this function simple checks all WHEN expressions
1127
1112
  one after another. When some WHEN expression evaluated to TRUE then the
1128
1113
  value of the corresponding THEN expression is returned.
1141
1126
  int first_expr_num, else_expr_num;
1142
1127
  enum Item_result cached_result_type, left_result_type;
1143
1128
  String tmp_value;
1144
 
  uint32_t ncases;
 
1129
  uint ncases;
1145
1130
  Item_result cmp_type;
1146
1131
  DTCollation cmp_collation;
1147
1132
  enum_field_types cached_field_type;
1148
 
  cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
 
1133
  cmp_item *cmp_items[5]; /* For all result types */
1149
1134
  cmp_item *case_item;
1150
1135
public:
1151
1136
  Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1169
1154
  double val_real();
1170
1155
  int64_t val_int();
1171
1156
  String *val_str(String *);
1172
 
  type::Decimal *val_decimal(type::Decimal *);
1173
 
  bool fix_fields(Session *session, Item **ref);
 
1157
  my_decimal *val_decimal(my_decimal *);
 
1158
  bool fix_fields(THD *thd, Item **ref);
1174
1159
  void fix_length_and_dec();
1175
 
  uint32_t decimal_precision() const;
 
1160
  uint decimal_precision() const;
1176
1161
  table_map not_null_tables() const { return 0; }
1177
1162
  enum Item_result result_type () const { return cached_result_type; }
1178
1163
  enum_field_types field_type() const { return cached_field_type; }
1202
1187
class Item_func_in :public Item_func_opt_neg
1203
1188
{
1204
1189
public:
1205
 
  /*
 
1190
  /* 
1206
1191
    an array of values when the right hand arguments of IN
1207
 
    are all SQL constant and there are no nulls
 
1192
    are all SQL constant and there are no nulls 
1208
1193
  */
1209
1194
  in_vector *array;
1210
1195
  bool have_null;
1211
 
  /*
 
1196
  /* 
1212
1197
    true when all arguments of the IN clause are of compatible types
1213
1198
    and can be used safely as comparisons for key conditions
1214
1199
  */
1225
1210
    allowed_arg_cols= 0;  // Fetch this value from first argument
1226
1211
  }
1227
1212
  int64_t val_int();
1228
 
  bool fix_fields(Session *, Item **);
 
1213
  bool fix_fields(THD *, Item **);
1229
1214
  void fix_length_and_dec();
1230
 
  uint32_t decimal_precision() const { return 1; }
 
1215
  uint decimal_precision() const { return 1; }
1231
1216
  void cleanup()
1232
1217
  {
 
1218
    uint i;
1233
1219
    Item_int_func::cleanup();
1234
1220
    delete array;
1235
1221
    array= 0;
1236
 
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
1222
    for (i= 0; i <= (uint)DECIMAL_RESULT + 1; i++)
1237
1223
    {
1238
1224
      delete cmp_items[i];
1239
1225
      cmp_items[i]= 0;
1253
1239
class cmp_item_row :public cmp_item
1254
1240
{
1255
1241
  cmp_item **comparators;
1256
 
  uint32_t n;
 
1242
  uint n;
1257
1243
public:
1258
1244
  cmp_item_row(): comparators(0), n(0) {}
1259
1245
  ~cmp_item_row();
1271
1257
{
1272
1258
  cmp_item_row tmp;
1273
1259
public:
1274
 
  in_row(uint32_t elements, Item *);
 
1260
  in_row(uint elements, Item *);
1275
1261
  ~in_row();
1276
 
  void set(uint32_t pos,Item *item);
1277
 
  unsigned char *get_value(Item *item);
 
1262
  void set(uint pos,Item *item);
 
1263
  uchar *get_value(Item *item);
1278
1264
  friend void Item_func_in::fix_length_and_dec();
1279
1265
  Item_result result_type() { return ROW_RESULT; }
1280
1266
};
1281
1267
 
1282
1268
/* Functions used by where clause */
1283
1269
 
1284
 
class Item_func_isnull :public item::function::Boolean
 
1270
class Item_func_isnull :public Item_bool_func
1285
1271
{
1286
1272
protected:
1287
1273
  int64_t cached_value;
1288
1274
public:
1289
 
  Item_func_isnull(Item *a) :item::function::Boolean(a) {}
 
1275
  Item_func_isnull(Item *a) :Item_bool_func(a) {}
1290
1276
  int64_t val_int();
1291
1277
  enum Functype functype() const { return ISNULL_FUNC; }
1292
1278
  void fix_length_and_dec()
1317
1303
  }
1318
1304
  table_map not_null_tables() const { return 0; }
1319
1305
  optimize_type select_optimize() const { return OPTIMIZE_NULL; }
1320
 
  Item *neg_transformer(Session *session);
 
1306
  Item *neg_transformer(THD *thd);
1321
1307
  const CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
1322
1308
};
1323
1309
 
1325
1311
 
1326
1312
class Item_in_subselect;
1327
1313
 
1328
 
/*
 
1314
/* 
1329
1315
  This is like IS NOT NULL but it also remembers if it ever has
1330
1316
  encountered a NULL.
1331
1317
*/
1348
1334
};
1349
1335
 
1350
1336
 
1351
 
class Item_func_isnotnull :public item::function::Boolean
 
1337
class Item_func_isnotnull :public Item_bool_func
1352
1338
{
1353
1339
  bool abort_on_null;
1354
1340
public:
1355
 
  Item_func_isnotnull(Item *a) :item::function::Boolean(a), abort_on_null(0) {}
 
1341
  Item_func_isnotnull(Item *a) :Item_bool_func(a), abort_on_null(0) {}
1356
1342
  int64_t val_int();
1357
1343
  enum Functype functype() const { return ISNOTNULL_FUNC; }
1358
1344
  void fix_length_and_dec()
1363
1349
  optimize_type select_optimize() const { return OPTIMIZE_NULL; }
1364
1350
  table_map not_null_tables() const
1365
1351
  { return abort_on_null ? not_null_tables_cache : 0; }
1366
 
  Item *neg_transformer(Session *session);
 
1352
  Item *neg_transformer(THD *thd);
1367
1353
  virtual void print(String *str, enum_query_type query_type);
1368
1354
  const CHARSET_INFO *compare_collation() { return args[0]->collation.collation; }
1369
1355
  void top_level_item() { abort_on_null=1; }
1388
1374
  enum { alphabet_size = 256 };
1389
1375
 
1390
1376
  Item *escape_item;
1391
 
 
 
1377
  
1392
1378
  bool escape_used_in_parsing;
1393
1379
 
1394
 
 
1395
1380
public:
1396
 
 
1397
 
  char *escape;
 
1381
  int escape;
1398
1382
 
1399
1383
  Item_func_like(Item *a,Item *b, Item *escape_arg, bool escape_used)
1400
 
    :Item_bool_func2(a,b), canDoTurboBM(false), pattern(0), pattern_len(0),
 
1384
    :Item_bool_func2(a,b), canDoTurboBM(false), pattern(0), pattern_len(0), 
1401
1385
     bmGs(0), bmBc(0), escape_item(escape_arg),
1402
 
     escape_used_in_parsing(escape_used), escape(NULL) {}
 
1386
     escape_used_in_parsing(escape_used) {}
1403
1387
  int64_t val_int();
1404
1388
  enum Functype functype() const { return LIKE_FUNC; }
1405
1389
  optimize_type select_optimize() const;
1406
1390
  cond_result eq_cmp_result() const { return COND_TRUE; }
1407
1391
  const char *func_name() const { return "like"; }
1408
 
  bool fix_fields(Session *session, Item **ref);
 
1392
  bool fix_fields(THD *thd, Item **ref);
1409
1393
  void cleanup();
1410
1394
};
1411
1395
 
1412
1396
 
1413
1397
typedef class Item COND;
1414
1398
 
1415
 
class Item_cond :public item::function::Boolean
 
1399
class Item_cond :public Item_bool_func
1416
1400
{
1417
1401
protected:
1418
1402
  List<Item> list;
1420
1404
  table_map and_tables_cache;
1421
1405
 
1422
1406
public:
1423
 
 
1424
 
  using Item::split_sum_func;
1425
 
 
1426
1407
  /* Item_cond() is only used to create top level items */
1427
 
  Item_cond(): item::function::Boolean(), abort_on_null(1)
 
1408
  Item_cond(): Item_bool_func(), abort_on_null(1)
1428
1409
  { const_item_cache=0; }
1429
1410
  Item_cond(Item *i1,Item *i2)
1430
 
    :item::function::Boolean(), abort_on_null(0)
 
1411
    :Item_bool_func(), abort_on_null(0)
1431
1412
  {
1432
1413
    list.push_back(i1);
1433
1414
    list.push_back(i2);
1434
1415
  }
1435
 
  Item_cond(Session *session, Item_cond *item);
 
1416
  Item_cond(THD *thd, Item_cond *item);
1436
1417
  Item_cond(List<Item> &nlist)
1437
 
    :item::function::Boolean(), list(nlist), abort_on_null(0) {}
 
1418
    :Item_bool_func(), list(nlist), abort_on_null(0) {}
1438
1419
  bool add(Item *item) { return list.push_back(item); }
1439
1420
  bool add_at_head(Item *item) { return list.push_front(item); }
1440
1421
  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1441
 
  bool fix_fields(Session *, Item **ref);
1442
 
  void fix_after_pullout(Select_Lex *new_parent, Item **ref);
 
1422
  bool fix_fields(THD *, Item **ref);
 
1423
  void fix_after_pullout(st_select_lex *new_parent, Item **ref);
1443
1424
 
1444
1425
  enum Type type() const { return COND_ITEM; }
1445
1426
  List<Item>* argument_list() { return &list; }
1446
1427
  table_map used_tables() const;
1447
1428
  void update_used_tables();
1448
1429
  virtual void print(String *str, enum_query_type query_type);
1449
 
  void split_sum_func(Session *session, Item **ref_pointer_array, List<Item> &fields);
1450
 
  friend int setup_conds(Session *session, TableList *tables, TableList *leaves,
 
1430
  void split_sum_func(THD *thd, Item **ref_pointer_array, List<Item> &fields);
 
1431
  friend int setup_conds(THD *thd, TableList *tables, TableList *leaves,
1451
1432
                         COND **conds);
1452
1433
  void top_level_item() { abort_on_null=1; }
1453
 
  void copy_andor_arguments(Session *session, Item_cond *item);
1454
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
1455
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
1434
  void copy_andor_arguments(THD *thd, Item_cond *item);
 
1435
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
 
1436
  Item *transform(Item_transformer transformer, uchar *arg);
1456
1437
  void traverse_cond(Cond_traverser, void *arg, traverse_order order);
1457
 
  void neg_arguments(Session *session);
 
1438
  void neg_arguments(THD *thd);
1458
1439
  enum_field_types field_type() const { return DRIZZLE_TYPE_LONGLONG; }
1459
 
  bool subst_argument_checker(unsigned char **)
 
1440
  bool subst_argument_checker(uchar **arg __attribute__((unused)))
1460
1441
  { return true; }
1461
 
  Item *compile(Item_analyzer analyzer, unsigned char **arg_p,
1462
 
                Item_transformer transformer, unsigned char *arg_t);
 
1442
  Item *compile(Item_analyzer analyzer, uchar **arg_p,
 
1443
                Item_transformer transformer, uchar *arg_t);
1463
1444
};
1464
1445
 
1465
1446
 
1480
1461
  A conjunction of the predicates f2=f1 and f3=f1 and f3=f2 will be
1481
1462
  substituted for the item representing the same multiple equality
1482
1463
  f1=f2=f3.
1483
 
  An item Item_equal(f1,f2) can appear instead of a conjunction of
 
1464
  An item Item_equal(f1,f2) can appear instead of a conjunction of 
1484
1465
  f2=f1 and f1=f2, or instead of just the predicate f1=f2.
1485
1466
 
1486
 
  An item of the class Item_equal inherits equalities from outer
 
1467
  An item of the class Item_equal inherits equalities from outer 
1487
1468
  conjunctive levels.
1488
1469
 
1489
1470
  Suppose we have a where condition of the following form:
1494
1475
    f1=f3 will be substituted for Item_equal(f1,f2,f3,f4,f5);
1495
1476
 
1496
1477
  An object of the class Item_equal can contain an optional constant
1497
 
  item c. Then it represents a multiple equality of the form
 
1478
  item c. Then it represents a multiple equality of the form 
1498
1479
  c=f1=...=fk.
1499
1480
 
1500
1481
  Objects of the class Item_equal are used for the following:
1509
1490
  It also can give us additional index scans and can allow us to
1510
1491
  improve selectivity estimates.
1511
1492
 
1512
 
  3. An object Item_equal(t1.f1,...,tk.fk) is used to optimize the
1513
 
  selected execution plan for the query: if table ti is accessed
 
1493
  3. An object Item_equal(t1.f1,...,tk.fk) is used to optimize the 
 
1494
  selected execution plan for the query: if table ti is accessed 
1514
1495
  before the table tj then in any predicate P in the where condition
1515
1496
  the occurrence of tj.fj is substituted for ti.fi. This can allow
1516
1497
  an evaluation of the predicate at an earlier step.
1517
1498
 
1518
 
  When feature 1 is supported they say that join transitive closure
 
1499
  When feature 1 is supported they say that join transitive closure 
1519
1500
  is employed.
1520
1501
  When feature 2 is supported they say that search argument transitive
1521
1502
  closure is employed.
1524
1505
  We do not just add predicates, we rather dynamically replace some
1525
1506
  predicates that can not be used to access tables in the investigated
1526
1507
  plan for those, obtained by substitution of some fields for equal fields,
1527
 
  that can be used.
 
1508
  that can be used.     
1528
1509
 
1529
1510
  Prepared Statements/Stored Procedures note: instances of class
1530
1511
  Item_equal are created only at the time a PS/SP is executed and
1538
1519
  object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1539
1520
*/
1540
1521
 
1541
 
class Item_equal: public item::function::Boolean
 
1522
class Item_equal: public Item_bool_func
1542
1523
{
 
1524
  List<Item_field> fields; /* list of equal field items                    */
 
1525
  Item *const_item;        /* optional constant item equal to fields items */
 
1526
  cmp_item *eval_item;
 
1527
  bool cond_false;
1543
1528
public:
1544
 
  typedef List<Item_field> fields_t;
1545
 
 
1546
 
  Item_equal() :
1547
 
    const_item(0),
1548
 
    eval_item(0),
1549
 
    cond_false(0)
1550
 
  {
1551
 
    const_item_cache=0;
1552
 
  }
1553
 
 
1554
 
  fields_t::iterator begin()
1555
 
  {
1556
 
    return fields.begin();
1557
 
  }
1558
 
 
 
1529
  inline Item_equal()
 
1530
    : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
1531
  { const_item_cache=0 ;}
1559
1532
  Item_equal(Item_field *f1, Item_field *f2);
1560
1533
  Item_equal(Item *c, Item_field *f);
1561
1534
  Item_equal(Item_equal *item_equal);
1562
1535
  inline Item* get_const() { return const_item; }
1563
1536
  void add(Item *c);
1564
1537
  void add(Item_field *f);
1565
 
  uint32_t members();
 
1538
  uint members();
1566
1539
  bool contains(Field *field);
1567
1540
  Item_field* get_first() { return fields.head(); }
1568
1541
  void merge(Item_equal *item);
1569
1542
  void update_const();
1570
1543
  enum Functype functype() const { return MULT_EQUAL_FUNC; }
1571
 
  int64_t val_int();
 
1544
  int64_t val_int(); 
1572
1545
  const char *func_name() const { return "multiple equal"; }
1573
1546
  optimize_type select_optimize() const { return OPTIMIZE_EQUAL; }
1574
1547
  void sort(Item_field_cmpfunc cmp, void *arg);
1575
1548
  friend class Item_equal_iterator;
1576
1549
  void fix_length_and_dec();
1577
 
  bool fix_fields(Session *session, Item **ref);
 
1550
  bool fix_fields(THD *thd, Item **ref);
1578
1551
  void update_used_tables();
1579
 
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *arg);
1580
 
  Item *transform(Item_transformer transformer, unsigned char *arg);
 
1552
  bool walk(Item_processor processor, bool walk_subquery, uchar *arg);
 
1553
  Item *transform(Item_transformer transformer, uchar *arg);
1581
1554
  virtual void print(String *str, enum_query_type query_type);
1582
 
  const CHARSET_INFO *compare_collation()
 
1555
  const CHARSET_INFO *compare_collation() 
1583
1556
  { return fields.head()->collation.collation; }
1584
 
private:
1585
 
  fields_t fields; /* list of equal field items                    */
1586
 
  Item *const_item;        /* optional constant item equal to fields items */
1587
 
  cmp_item *eval_item;
1588
 
  bool cond_false;
1589
 
 
1590
 
};
1591
 
 
1592
 
class COND_EQUAL: public memory::SqlAlloc
 
1557
}; 
 
1558
 
 
1559
class COND_EQUAL: public Sql_alloc
1593
1560
{
1594
1561
public:
1595
 
  uint32_t max_members;               /* max number of members the current level
1596
 
                                     list and all lower level lists */
 
1562
  uint max_members;               /* max number of members the current level
 
1563
                                     list and all lower level lists */ 
1597
1564
  COND_EQUAL *upper_levels;       /* multiple equalities of upper and levels */
1598
 
  List<Item_equal> current_level; /* list of multiple equalities of
 
1565
  List<Item_equal> current_level; /* list of multiple equalities of 
1599
1566
                                     the current and level           */
1600
1567
  COND_EQUAL()
1601
 
  {
 
1568
  { 
1602
1569
    upper_levels= 0;
1603
1570
  }
1604
1571
};
1605
1572
 
1606
1573
 
1607
 
class Item_equal_iterator : public List<Item_field>::iterator
 
1574
class Item_equal_iterator : public List_iterator_fast<Item_field>
1608
1575
{
1609
1576
public:
1610
 
  inline Item_equal_iterator(Item_equal &item_equal)
1611
 
    :List<Item_field>::iterator (item_equal.fields.begin() )
 
1577
  inline Item_equal_iterator(Item_equal &item_equal) 
 
1578
    :List_iterator_fast<Item_field> (item_equal.fields)
1612
1579
  {}
1613
1580
  inline Item_field* operator++(int)
1614
 
  {
1615
 
    Item_field *item= (*(List<Item_field>::iterator *) this)++;
 
1581
  { 
 
1582
    Item_field *item= (*(List_iterator_fast<Item_field> *) this)++;
1616
1583
    return  item;
1617
1584
  }
 
1585
  inline void rewind(void) 
 
1586
  { 
 
1587
    List_iterator_fast<Item_field>::rewind();
 
1588
  }
1618
1589
};
1619
1590
 
1620
1591
class Item_cond_and :public Item_cond
1621
1592
{
1622
1593
public:
1623
 
  COND_EQUAL cond_equal;  /* contains list of Item_equal objects for
 
1594
  COND_EQUAL cond_equal;  /* contains list of Item_equal objects for 
1624
1595
                             the current and level and reference
1625
 
                             to multiple equalities of upper and levels */
 
1596
                             to multiple equalities of upper and levels */  
1626
1597
  Item_cond_and() :Item_cond() {}
1627
1598
  Item_cond_and(Item *i1,Item *i2) :Item_cond(i1,i2) {}
1628
 
  Item_cond_and(Session *session, Item_cond_and *item) :Item_cond(session, item) {}
 
1599
  Item_cond_and(THD *thd, Item_cond_and *item) :Item_cond(thd, item) {}
1629
1600
  Item_cond_and(List<Item> &list_arg): Item_cond(list_arg) {}
1630
1601
  enum Functype functype() const { return COND_AND_FUNC; }
1631
1602
  int64_t val_int();
1632
1603
  const char *func_name() const { return "and"; }
1633
1604
  table_map not_null_tables() const
1634
1605
  { return abort_on_null ? not_null_tables_cache: and_tables_cache; }
1635
 
  Item* copy_andor_structure(Session *session)
 
1606
  Item* copy_andor_structure(THD *thd)
1636
1607
  {
1637
1608
    Item_cond_and *item;
1638
 
    if ((item= new Item_cond_and(session, this)))
1639
 
       item->copy_andor_arguments(session, this);
 
1609
    if ((item= new Item_cond_and(thd, this)))
 
1610
       item->copy_andor_arguments(thd, this);
1640
1611
    return item;
1641
1612
  }
1642
 
  Item *neg_transformer(Session *session);
 
1613
  Item *neg_transformer(THD *thd);
1643
1614
};
1644
1615
 
1645
1616
inline bool is_cond_and(Item *item)
1656
1627
public:
1657
1628
  Item_cond_or() :Item_cond() {}
1658
1629
  Item_cond_or(Item *i1,Item *i2) :Item_cond(i1,i2) {}
1659
 
  Item_cond_or(Session *session, Item_cond_or *item) :Item_cond(session, item) {}
 
1630
  Item_cond_or(THD *thd, Item_cond_or *item) :Item_cond(thd, item) {}
1660
1631
  Item_cond_or(List<Item> &list_arg): Item_cond(list_arg) {}
1661
1632
  enum Functype functype() const { return COND_OR_FUNC; }
1662
1633
  int64_t val_int();
1663
1634
  const char *func_name() const { return "or"; }
1664
1635
  table_map not_null_tables() const { return and_tables_cache; }
1665
 
  Item* copy_andor_structure(Session *session)
 
1636
  Item* copy_andor_structure(THD *thd)
1666
1637
  {
1667
1638
    Item_cond_or *item;
1668
 
    if ((item= new Item_cond_or(session, this)))
1669
 
      item->copy_andor_arguments(session, this);
 
1639
    if ((item= new Item_cond_or(thd, this)))
 
1640
      item->copy_andor_arguments(thd, this);
1670
1641
    return item;
1671
1642
  }
1672
 
  Item *neg_transformer(Session *session);
 
1643
  Item *neg_transformer(THD *thd);
1673
1644
};
1674
1645
 
1675
1646
inline bool is_cond_or(Item *item)
1699
1670
  void top_level_item() {}
1700
1671
};
1701
1672
 
1702
 
enum_field_types agg_field_type(Item **items, uint32_t nitems);
1703
 
 
1704
1673
 
1705
1674
/* Some useful inline functions */
1706
1675
 
1712
1681
}
1713
1682
 
1714
1683
Item *and_expressions(Item *a, Item *b, Item **org_item);
1715
 
 
1716
 
} /* namespace drizzled */
1717
 
 
1718
 
#endif /* DRIZZLED_ITEM_CMPFUNC_H */