~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item/cmpfunc.h

  • Committer: Andrew Hutchings
  • Date: 2010-10-20 15:31:27 UTC
  • mto: This revision was merged to the branch mainline in revision 1907.
  • Revision ID: andrew@linuxjedi.co.uk-20101020153127-w9djuz9omzezg2kz
Add error message for global sort buffer constraint

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
27
27
#include "drizzled/item/sum.h"
28
28
#include "drizzled/item/int.h"
29
29
#include "drizzled/item/float.h"
30
 
#include "drizzled/item/string.h"
31
30
#include "drizzled/item/decimal.h"
32
31
#include "drizzled/function/math/int.h"
33
32
#include "drizzled/function/numhybrid.h"
 
33
#include "drizzled/session.h"
34
34
#include "drizzled/common.h"
35
35
#include "drizzled/qsort_cmp.h"
36
 
#include "drizzled/item/function/boolean.h"
37
36
 
38
37
namespace drizzled
39
38
{
40
39
 
41
40
extern Item_result item_cmp_type(Item_result a,Item_result b);
42
 
 
43
41
class Item_bool_func2;
44
42
class Arg_comparator;
45
43
class Item_sum_hybrid;
46
44
class Item_row;
47
 
class Session;
48
45
 
49
46
typedef int (Arg_comparator::*arg_cmp_func)();
50
47
 
51
48
typedef int (*Item_field_cmpfunc)(Item_field *f1, Item_field *f2, void *arg);
52
49
 
53
 
int64_t get_datetime_value(Session *session, 
54
 
                           Item ***item_arg, 
55
 
                           Item **cache_arg,
56
 
                           Item *warn_item, 
57
 
                           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);
58
55
 
59
56
class Arg_comparator: public memory::SqlAlloc
60
57
{
70
67
  bool is_nulls_eq;                // TRUE <=> compare for the EQUAL_FUNC
71
68
  enum enum_date_cmp_type { CMP_DATE_DFLT= 0, CMP_DATE_WITH_DATE,
72
69
                            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);
 
70
  uint64_t (*get_value_func)(Session *session, Item ***item_arg, Item **cache_arg,
 
71
                              Item *warn_item, bool *is_null);
75
72
public:
76
73
  DTCollation cmp_collation;
77
74
 
78
 
  Arg_comparator():
79
 
    session(current_session),
80
 
    a_cache(0),
81
 
    b_cache(0)
82
 
  {};
83
 
 
84
 
  Arg_comparator(Item **a1, Item **a2):
85
 
    a(a1),
86
 
    b(a2),
87
 
    session(current_session),
88
 
    a_cache(0),
89
 
    b_cache(0)
90
 
  {};
 
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) {};
91
78
 
92
79
  int set_compare_func(Item_bool_func2 *owner, Item_result type);
93
80
  inline int set_compare_func(Item_bool_func2 *owner_arg)
129
116
  int compare_datetime();        // compare args[0] & args[1] as DATETIMEs
130
117
 
131
118
  static enum enum_date_cmp_type can_compare_as_dates(Item *a, Item *b,
132
 
                                                      int64_t *const_val_arg);
 
119
                                                      uint64_t *const_val_arg);
133
120
 
134
121
  void set_datetime_cmp_func(Item **a1, Item **b1);
135
122
  static arg_cmp_func comparator_matrix [5][2];
137
124
  friend class Item_func;
138
125
};
139
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
 
140
139
 
141
140
/**
142
141
  Abstract Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
143
142
  boolean predicates.
144
143
*/
145
144
 
146
 
class Item_func_truth : public item::function::Boolean
 
145
class Item_func_truth : public Item_bool_func
147
146
{
148
147
public:
149
148
  virtual bool val_bool();
153
152
 
154
153
protected:
155
154
  Item_func_truth(Item *a, bool a_value, bool a_affirmative)
156
 
  : item::function::Boolean(a), value(a_value), affirmative(a_affirmative)
 
155
  : Item_bool_func(a), value(a_value), affirmative(a_affirmative)
157
156
  {}
158
157
 
159
158
  ~Item_func_truth()
242
241
    placed into a separate class called 'Item_in_optimizer'.
243
242
*/
244
243
 
245
 
class Item_in_optimizer: public item::function::Boolean
 
244
class Item_in_optimizer: public Item_bool_func
246
245
{
247
246
protected:
248
247
  Item_cache *cache;
256
255
  bool result_for_null_param;
257
256
public:
258
257
  Item_in_optimizer(Item *a, Item_in_subselect *b):
259
 
    item::function::Boolean(a, reinterpret_cast<Item *>(b)), cache(0),
 
258
    Item_bool_func(a, reinterpret_cast<Item *>(b)), cache(0),
260
259
    save_cache(0), result_for_null_param(UNKNOWN)
261
260
  { with_subselect= true; }
262
261
  bool fix_fields(Session *, Item **);
388
387
  { return true; }
389
388
};
390
389
 
391
 
class Item_func_not :public item::function::Boolean
 
390
class Item_func_not :public Item_bool_func
392
391
{
393
392
public:
394
 
  Item_func_not(Item *a) :item::function::Boolean(a) {}
 
393
  Item_func_not(Item *a) :Item_bool_func(a) {}
395
394
  int64_t val_int();
396
395
  enum Functype functype() const { return NOT_FUNC; }
397
396
  const char *func_name() const { return "not"; }
430
429
   - To wrap condition that is pushed down into subquery
431
430
*/
432
431
 
433
 
class Item_func_trig_cond: public item::function::Boolean
 
432
class Item_func_trig_cond: public Item_bool_func
434
433
{
435
434
  bool *trig_var;
436
435
public:
437
 
  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; }
438
437
  int64_t val_int() { return *trig_var ? args[0]->val_int() : 1; }
439
438
  enum Functype functype() const { return TRIG_COND_FUNC; };
440
439
  const char *func_name() const { return "trigcond"; };
651
650
{
652
651
  Item_result type;
653
652
  double dbl;
654
 
  type::Decimal dec;
 
653
  my_decimal dec;
655
654
};
656
655
 
657
656
class Item_func_interval :public Item_int_func
682
681
  double real_op();
683
682
  int64_t int_op();
684
683
  String *str_op(String *);
685
 
  type::Decimal *decimal_op(type::Decimal *);
 
684
  my_decimal *decimal_op(my_decimal *);
686
685
  void fix_length_and_dec();
687
686
  void find_num_type() {}
688
687
  enum Item_result result_type () const { return hybrid_type; }
701
700
  double real_op();
702
701
  int64_t int_op();
703
702
  String *str_op(String *str);
704
 
  type::Decimal *decimal_op(type::Decimal *);
 
703
  my_decimal *decimal_op(my_decimal *);
705
704
  enum_field_types field_type() const;
706
705
  void fix_length_and_dec();
707
706
  const char *func_name() const { return "ifnull"; }
725
724
  double val_real();
726
725
  int64_t val_int();
727
726
  String *val_str(String *str);
728
 
  type::Decimal *val_decimal(type::Decimal *);
 
727
  my_decimal *val_decimal(my_decimal *);
729
728
  enum Item_result result_type () const { return cached_result_type; }
730
729
  enum_field_types field_type() const { return cached_field_type; }
731
730
  bool fix_fields(Session *, Item **);
745
744
  double val_real();
746
745
  int64_t val_int();
747
746
  String *val_str(String *str);
748
 
  type::Decimal *val_decimal(type::Decimal *);
 
747
  my_decimal *val_decimal(my_decimal *);
749
748
  enum Item_result result_type () const { return cached_result_type; }
750
749
  void fix_length_and_dec();
751
750
  uint32_t decimal_precision() const { return args[0]->decimal_precision(); }
920
919
 
921
920
class in_decimal :public in_vector
922
921
{
923
 
  type::Decimal val;
 
922
  my_decimal val;
924
923
public:
925
924
  in_decimal(uint32_t elements);
926
925
  void set(uint32_t pos, Item *item);
931
930
  }
932
931
  void value_to_item(uint32_t pos, Item *item)
933
932
  {
934
 
    type::Decimal *dec= ((type::Decimal *)base) + pos;
 
933
    my_decimal *dec= ((my_decimal *)base) + pos;
935
934
    Item_decimal *item_dec= (Item_decimal*)item;
936
935
    item_dec->set_decimal_value(dec);
937
936
  }
948
947
{
949
948
public:
950
949
  const CHARSET_INFO *cmp_charset;
951
 
 
952
 
  cmp_item()
953
 
  {
954
 
    cmp_charset= &my_charset_bin;
955
 
  }
956
 
 
 
950
  cmp_item() { cmp_charset= &my_charset_bin; }
957
951
  virtual ~cmp_item() {}
958
952
  virtual void store_value(Item *item)= 0;
959
953
  virtual int cmp(Item *item)= 0;
1044
1038
*/
1045
1039
class cmp_item_datetime :public cmp_item
1046
1040
{
1047
 
  int64_t value;
1048
 
 
 
1041
  uint64_t value;
1049
1042
public:
1050
1043
  Session *session;
1051
1044
  /* Item used for issuing warnings. */
1085
1078
 
1086
1079
class cmp_item_decimal :public cmp_item
1087
1080
{
1088
 
  type::Decimal value;
 
1081
  my_decimal value;
1089
1082
public:
1090
1083
  cmp_item_decimal() {}                       /* Remove gcc warning */
1091
1084
  void store_value(Item *item);
1156
1149
  Item_result cmp_type;
1157
1150
  DTCollation cmp_collation;
1158
1151
  enum_field_types cached_field_type;
1159
 
  cmp_item *cmp_items[DECIMAL_RESULT+1]; /* For all result types */
 
1152
  cmp_item *cmp_items[5]; /* For all result types */
1160
1153
  cmp_item *case_item;
1161
1154
public:
1162
1155
  Item_func_case(List<Item> &list, Item *first_expr_arg, Item *else_expr_arg)
1180
1173
  double val_real();
1181
1174
  int64_t val_int();
1182
1175
  String *val_str(String *);
1183
 
  type::Decimal *val_decimal(type::Decimal *);
 
1176
  my_decimal *val_decimal(my_decimal *);
1184
1177
  bool fix_fields(Session *session, Item **ref);
1185
1178
  void fix_length_and_dec();
1186
1179
  uint32_t decimal_precision() const;
1241
1234
  uint32_t decimal_precision() const { return 1; }
1242
1235
  void cleanup()
1243
1236
  {
 
1237
    uint32_t i;
1244
1238
    Item_int_func::cleanup();
1245
1239
    delete array;
1246
1240
    array= 0;
1247
 
    for (int i= STRING_RESULT; i <= DECIMAL_RESULT; i++)
 
1241
    for (i= 0; i <= (uint32_t)DECIMAL_RESULT + 1; i++)
1248
1242
    {
1249
1243
      delete cmp_items[i];
1250
1244
      cmp_items[i]= 0;
1292
1286
 
1293
1287
/* Functions used by where clause */
1294
1288
 
1295
 
class Item_func_isnull :public item::function::Boolean
 
1289
class Item_func_isnull :public Item_bool_func
1296
1290
{
1297
1291
protected:
1298
1292
  int64_t cached_value;
1299
1293
public:
1300
 
  Item_func_isnull(Item *a) :item::function::Boolean(a) {}
 
1294
  Item_func_isnull(Item *a) :Item_bool_func(a) {}
1301
1295
  int64_t val_int();
1302
1296
  enum Functype functype() const { return ISNULL_FUNC; }
1303
1297
  void fix_length_and_dec()
1359
1353
};
1360
1354
 
1361
1355
 
1362
 
class Item_func_isnotnull :public item::function::Boolean
 
1356
class Item_func_isnotnull :public Item_bool_func
1363
1357
{
1364
1358
  bool abort_on_null;
1365
1359
public:
1366
 
  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) {}
1367
1361
  int64_t val_int();
1368
1362
  enum Functype functype() const { return ISNOTNULL_FUNC; }
1369
1363
  void fix_length_and_dec()
1423
1417
 
1424
1418
typedef class Item COND;
1425
1419
 
1426
 
class Item_cond :public item::function::Boolean
 
1420
class Item_cond :public Item_bool_func
1427
1421
{
1428
1422
protected:
1429
1423
  List<Item> list;
1435
1429
  using Item::split_sum_func;
1436
1430
 
1437
1431
  /* Item_cond() is only used to create top level items */
1438
 
  Item_cond(): item::function::Boolean(), abort_on_null(1)
 
1432
  Item_cond(): Item_bool_func(), abort_on_null(1)
1439
1433
  { const_item_cache=0; }
1440
1434
  Item_cond(Item *i1,Item *i2)
1441
 
    :item::function::Boolean(), abort_on_null(0)
 
1435
    :Item_bool_func(), abort_on_null(0)
1442
1436
  {
1443
1437
    list.push_back(i1);
1444
1438
    list.push_back(i2);
1445
1439
  }
1446
1440
  Item_cond(Session *session, Item_cond *item);
1447
1441
  Item_cond(List<Item> &nlist)
1448
 
    :item::function::Boolean(), list(nlist), abort_on_null(0) {}
 
1442
    :Item_bool_func(), list(nlist), abort_on_null(0) {}
1449
1443
  bool add(Item *item) { return list.push_back(item); }
1450
1444
  bool add_at_head(Item *item) { return list.push_front(item); }
1451
1445
  void add_at_head(List<Item> *nlist) { list.prepand(nlist); }
1549
1543
  object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
1550
1544
*/
1551
1545
 
1552
 
class Item_equal: public item::function::Boolean
 
1546
class Item_equal: public Item_bool_func
1553
1547
{
1554
1548
  List<Item_field> fields; /* list of equal field items                    */
1555
1549
  Item *const_item;        /* optional constant item equal to fields items */
1556
1550
  cmp_item *eval_item;
1557
1551
  bool cond_false;
1558
 
 
1559
1552
public:
1560
 
  inline Item_equal() :
1561
 
    item::function::Boolean(),
1562
 
    const_item(0),
1563
 
    eval_item(0),
1564
 
    cond_false(0)
1565
 
  {
1566
 
    const_item_cache=0;
1567
 
  }
1568
 
 
 
1553
  inline Item_equal()
 
1554
    : Item_bool_func(), const_item(0), eval_item(0), cond_false(0)
 
1555
  { const_item_cache=0 ;}
1569
1556
  Item_equal(Item_field *f1, Item_field *f2);
1570
1557
  Item_equal(Item *c, Item_field *f);
1571
1558
  Item_equal(Item_equal *item_equal);