~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_sum.h

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 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 */
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
15
19
 
16
20
 
17
21
/* classes for sum functions */
18
22
 
19
 
#ifdef USE_PRAGMA_INTERFACE
20
 
#pragma interface                       /* gcc class implementation */
21
 
#endif
22
23
 
23
24
#include <mysys/my_tree.h>
24
25
 
225
226
  enum Sumfunctype
226
227
  { COUNT_FUNC, COUNT_DISTINCT_FUNC, SUM_FUNC, SUM_DISTINCT_FUNC, AVG_FUNC,
227
228
    AVG_DISTINCT_FUNC, MIN_FUNC, MAX_FUNC, STD_FUNC,
228
 
    VARIANCE_FUNC, SUM_BIT_FUNC, UDF_SUM_FUNC, GROUP_CONCAT_FUNC
 
229
    VARIANCE_FUNC, SUM_BIT_FUNC, GROUP_CONCAT_FUNC
229
230
  };
230
231
 
231
232
  Item **args, *tmp_args[2];
232
233
  Item **ref_by; /* pointer to a ref to the object used to register it */
233
234
  Item_sum *next; /* next in the circular chain of registered objects  */
234
 
  uint arg_count;
 
235
  uint32_t arg_count;
235
236
  Item_sum *in_sum_func;  /* embedding set function if any */ 
236
237
  st_select_lex * aggr_sel; /* select where the function is aggregated       */ 
237
238
  int8_t nest_level;        /* number of the nesting level of the set function */
272
273
  }
273
274
  Item_sum(List<Item> &list);
274
275
  //Copy constructor, need to perform subselects with temporary tables
275
 
  Item_sum(THD *thd, Item_sum *item);
 
276
  Item_sum(Session *session, Item_sum *item);
276
277
  enum Type type() const { return SUM_FUNC_ITEM; }
277
278
  virtual enum Sumfunctype sum_func () const=0;
278
279
 
363
364
  */
364
365
  void no_rows_in_result() { clear(); }
365
366
 
366
 
  virtual bool setup(THD *thd __attribute__((unused))) {return 0;}
 
367
  virtual bool setup(Session *session __attribute__((unused))) {return 0;}
367
368
  virtual void make_unique(void) {}
368
 
  Item *get_tmp_table_item(THD *thd);
 
369
  Item *get_tmp_table_item(Session *session);
369
370
  virtual Field *create_tmp_field(bool group, Table *table,
370
 
                                  uint convert_blob_length);
371
 
  bool walk(Item_processor processor, bool walk_subquery, uchar *argument);
372
 
  bool init_sum_func_check(THD *thd);
373
 
  bool check_sum_func(THD *thd, Item **ref);
374
 
  bool register_sum_func(THD *thd, Item **ref);
 
371
                                  uint32_t convert_blob_length);
 
372
  bool walk(Item_processor processor, bool walk_subquery, unsigned char *argument);
 
373
  bool init_sum_func_check(Session *session);
 
374
  bool check_sum_func(Session *session, Item **ref);
 
375
  bool register_sum_func(Session *session, Item **ref);
375
376
  st_select_lex *depended_from() 
376
377
    { return (nest_level == aggr_level ? 0 : aggr_sel); }
377
378
};
394
395
  Item_sum_num(Item *a, Item* b) :Item_sum(a,b),is_evaluated(false) {}
395
396
  Item_sum_num(List<Item> &list) 
396
397
    :Item_sum(list), is_evaluated(false) {}
397
 
  Item_sum_num(THD *thd, Item_sum_num *item) 
398
 
    :Item_sum(thd, item),is_evaluated(item->is_evaluated) {}
399
 
  bool fix_fields(THD *, Item **);
400
 
  int64_t val_int()
401
 
  {
402
 
    assert(fixed == 1);
403
 
    return (int64_t) rint(val_real());             /* Real as default */
404
 
  }
 
398
  Item_sum_num(Session *session, Item_sum_num *item) 
 
399
    :Item_sum(session, item),is_evaluated(item->is_evaluated) {}
 
400
  bool fix_fields(Session *, Item **);
 
401
  int64_t val_int();
405
402
  String *val_str(String*str);
406
403
  my_decimal *val_decimal(my_decimal *);
407
404
  void reset_field();
413
410
public:
414
411
  Item_sum_int(Item *item_par) :Item_sum_num(item_par) {}
415
412
  Item_sum_int(List<Item> &list) :Item_sum_num(list) {}
416
 
  Item_sum_int(THD *thd, Item_sum_int *item) :Item_sum_num(thd, item) {}
 
413
  Item_sum_int(Session *session, Item_sum_int *item) :Item_sum_num(session, item) {}
417
414
  double val_real() { assert(fixed == 1); return (double) val_int(); }
418
415
  String *val_str(String*str);
419
416
  my_decimal *val_decimal(my_decimal *);
429
426
  Item_result hybrid_type;
430
427
  double sum;
431
428
  my_decimal dec_buffs[2];
432
 
  uint curr_dec_buff;
 
429
  uint32_t curr_dec_buff;
433
430
  void fix_length_and_dec();
434
431
 
435
432
public:
436
433
  Item_sum_sum(Item *item_par) :Item_sum_num(item_par) {}
437
 
  Item_sum_sum(THD *thd, Item_sum_sum *item);
 
434
  Item_sum_sum(Session *session, Item_sum_sum *item);
438
435
  enum Sumfunctype sum_func () const {return SUM_FUNC;}
439
436
  void clear();
440
437
  bool add();
447
444
  void update_field();
448
445
  void no_rows_in_result() {}
449
446
  const char *func_name() const { return "sum("; }
450
 
  Item *copy_or_same(THD* thd);
 
447
  Item *copy_or_same(Session* session);
451
448
};
452
449
 
453
450
 
466
463
  Unique *tree;
467
464
  Table *table;
468
465
  enum enum_field_types table_field_type;
469
 
  uint tree_key_length;
 
466
  uint32_t tree_key_length;
470
467
protected:
471
 
  Item_sum_distinct(THD *thd, Item_sum_distinct *item);
 
468
  Item_sum_distinct(Session *session, Item_sum_distinct *item);
472
469
public:
473
470
  Item_sum_distinct(Item *item_par);
474
471
  ~Item_sum_distinct();
475
472
 
476
 
  bool setup(THD *thd);
 
473
  bool setup(Session *session);
477
474
  void clear();
478
475
  void cleanup();
479
476
  bool add();
504
501
class Item_sum_sum_distinct :public Item_sum_distinct
505
502
{
506
503
private:
507
 
  Item_sum_sum_distinct(THD *thd, Item_sum_sum_distinct *item)
508
 
    :Item_sum_distinct(thd, item) {}
 
504
  Item_sum_sum_distinct(Session *session, Item_sum_sum_distinct *item)
 
505
    :Item_sum_distinct(session, item) {}
509
506
public:
510
507
  Item_sum_sum_distinct(Item *item_arg) :Item_sum_distinct(item_arg) {}
511
508
 
512
509
  enum Sumfunctype sum_func () const { return SUM_DISTINCT_FUNC; }
513
510
  const char *func_name() const { return "sum(distinct "; }
514
 
  Item *copy_or_same(THD* thd) { return new Item_sum_sum_distinct(thd, this); }
 
511
  Item *copy_or_same(Session* session) { return new Item_sum_sum_distinct(session, this); }
515
512
};
516
513
 
517
514
 
520
517
class Item_sum_avg_distinct: public Item_sum_distinct
521
518
{
522
519
private:
523
 
  Item_sum_avg_distinct(THD *thd, Item_sum_avg_distinct *original)
524
 
    :Item_sum_distinct(thd, original) {}
 
520
  Item_sum_avg_distinct(Session *session, Item_sum_avg_distinct *original)
 
521
    :Item_sum_distinct(session, original) {}
525
522
public:
526
 
  uint prec_increment;
 
523
  uint32_t prec_increment;
527
524
  Item_sum_avg_distinct(Item *item_arg) : Item_sum_distinct(item_arg) {}
528
525
 
529
526
  void fix_length_and_dec();
530
527
  virtual void calculate_val_and_count();
531
528
  enum Sumfunctype sum_func () const { return AVG_DISTINCT_FUNC; }
532
529
  const char *func_name() const { return "avg(distinct "; }
533
 
  Item *copy_or_same(THD* thd) { return new Item_sum_avg_distinct(thd, this); }
 
530
  Item *copy_or_same(Session* session) { return new Item_sum_avg_distinct(session, this); }
534
531
};
535
532
 
536
533
 
542
539
  Item_sum_count(Item *item_par)
543
540
    :Item_sum_int(item_par),count(0)
544
541
  {}
545
 
  Item_sum_count(THD *thd, Item_sum_count *item)
546
 
    :Item_sum_int(thd, item), count(item->count)
 
542
  Item_sum_count(Session *session, Item_sum_count *item)
 
543
    :Item_sum_int(session, item), count(item->count)
547
544
  {}
548
545
  enum Sumfunctype sum_func () const { return COUNT_FUNC; }
549
546
  void clear();
559
556
  void cleanup();
560
557
  void update_field();
561
558
  const char *func_name() const { return "count("; }
562
 
  Item *copy_or_same(THD* thd);
 
559
  Item *copy_or_same(Session* session);
563
560
};
564
561
 
565
562
 
588
585
    (to correctly free resources)
589
586
  */
590
587
  Item_sum_count_distinct *original;
591
 
  uint tree_key_length;
 
588
  uint32_t tree_key_length;
592
589
 
593
590
 
594
591
  bool always_null;             // Set to 1 if the result is always NULL
595
592
 
596
593
 
597
 
  friend int composite_key_cmp(void* arg, uchar* key1, uchar* key2);
598
 
  friend int simple_str_key_cmp(void* arg, uchar* key1, uchar* key2);
 
594
  friend int composite_key_cmp(void* arg, unsigned char* key1, unsigned char* key2);
 
595
  friend int simple_str_key_cmp(void* arg, unsigned char* key1, unsigned char* key2);
599
596
 
600
597
public:
601
598
  Item_sum_count_distinct(List<Item> &list)
603
600
     force_copy_fields(0), tree(0), count(0),
604
601
     original(0), always_null(false)
605
602
  { quick_group= 0; }
606
 
  Item_sum_count_distinct(THD *thd, Item_sum_count_distinct *item)
607
 
    :Item_sum_int(thd, item), table(item->table),
 
603
  Item_sum_count_distinct(Session *session, Item_sum_count_distinct *item)
 
604
    :Item_sum_int(session, item), table(item->table),
608
605
     field_lengths(item->field_lengths),
609
606
     tmp_table_param(item->tmp_table_param),
610
607
     force_copy_fields(0), tree(item->tree), count(item->count), 
622
619
  void reset_field() { return ;}                // Never called
623
620
  void update_field() { return ; }              // Never called
624
621
  const char *func_name() const { return "count(distinct "; }
625
 
  bool setup(THD *thd);
 
622
  bool setup(Session *session);
626
623
  void make_unique();
627
 
  Item *copy_or_same(THD* thd);
 
624
  Item *copy_or_same(Session* session);
628
625
  void no_rows_in_result() {}
629
626
};
630
627
 
638
635
public:
639
636
  Field *field;
640
637
  Item_result hybrid_type;
641
 
  uint f_precision, f_scale, dec_bin_size;
642
 
  uint prec_increment;
 
638
  uint32_t f_precision, f_scale, dec_bin_size;
 
639
  uint32_t prec_increment;
643
640
  Item_avg_field(Item_result res_type, Item_sum_avg *item);
644
641
  enum Type type() const { return FIELD_AVG_ITEM; }
645
642
  double val_real();
661
658
{
662
659
public:
663
660
  uint64_t count;
664
 
  uint prec_increment;
665
 
  uint f_precision, f_scale, dec_bin_size;
 
661
  uint32_t prec_increment;
 
662
  uint32_t f_precision, f_scale, dec_bin_size;
666
663
 
667
664
  Item_sum_avg(Item *item_par) :Item_sum_sum(item_par), count(0) {}
668
 
  Item_sum_avg(THD *thd, Item_sum_avg *item)
669
 
    :Item_sum_sum(thd, item), count(item->count),
 
665
  Item_sum_avg(Session *session, Item_sum_avg *item)
 
666
    :Item_sum_sum(session, item), count(item->count),
670
667
    prec_increment(item->prec_increment) {}
671
668
 
672
669
  void fix_length_and_dec();
675
672
  bool add();
676
673
  double val_real();
677
674
  // In SPs we might force the "wrong" type with select into a declare variable
678
 
  int64_t val_int() { return (int64_t) rint(val_real()); }
 
675
  int64_t val_int();
679
676
  my_decimal *val_decimal(my_decimal *);
680
677
  String *val_str(String *str);
681
678
  void reset_field();
684
681
  { return new Item_avg_field(hybrid_type, this); }
685
682
  void no_rows_in_result() {}
686
683
  const char *func_name() const { return "avg("; }
687
 
  Item *copy_or_same(THD* thd);
688
 
  Field *create_tmp_field(bool group, Table *table, uint convert_blob_length);
 
684
  Item *copy_or_same(Session* session);
 
685
  Field *create_tmp_field(bool group, Table *table, uint32_t convert_blob_length);
689
686
  void cleanup()
690
687
  {
691
688
    count= 0;
700
697
public:
701
698
  Field *field;
702
699
  Item_result hybrid_type;
703
 
  uint f_precision0, f_scale0;
704
 
  uint f_precision1, f_scale1;
705
 
  uint dec_bin_size0, dec_bin_size1;
706
 
  uint sample;
707
 
  uint prec_increment;
 
700
  uint32_t f_precision0, f_scale0;
 
701
  uint32_t f_precision1, f_scale1;
 
702
  uint32_t dec_bin_size0, dec_bin_size1;
 
703
  uint32_t sample;
 
704
  uint32_t prec_increment;
708
705
  Item_variance_field(Item_sum_variance *item);
709
706
  enum Type type() const {return FIELD_VARIANCE_ITEM; }
710
707
  double val_real();
711
 
  int64_t val_int()
712
 
  { /* can't be fix_fields()ed */ return (int64_t) rint(val_real()); }
 
708
  int64_t val_int();
713
709
  String *val_str(String *str)
714
710
  { return val_string_from_real(str); }
715
711
  my_decimal *val_decimal(my_decimal *dec_buf)
754
750
  int cur_dec;
755
751
  double recurrence_m, recurrence_s;    /* Used in recurrence relation. */
756
752
  uint64_t count;
757
 
  uint f_precision0, f_scale0;
758
 
  uint f_precision1, f_scale1;
759
 
  uint dec_bin_size0, dec_bin_size1;
760
 
  uint sample;
761
 
  uint prec_increment;
 
753
  uint32_t f_precision0, f_scale0;
 
754
  uint32_t f_precision1, f_scale1;
 
755
  uint32_t dec_bin_size0, dec_bin_size1;
 
756
  uint32_t sample;
 
757
  uint32_t prec_increment;
762
758
 
763
 
  Item_sum_variance(Item *item_par, uint sample_arg) :Item_sum_num(item_par),
 
759
  Item_sum_variance(Item *item_par, uint32_t sample_arg) :Item_sum_num(item_par),
764
760
    hybrid_type(REAL_RESULT), count(0), sample(sample_arg)
765
761
    {}
766
 
  Item_sum_variance(THD *thd, Item_sum_variance *item);
 
762
  Item_sum_variance(Session *session, Item_sum_variance *item);
767
763
  enum Sumfunctype sum_func () const { return VARIANCE_FUNC; }
768
764
  void clear();
769
765
  bool add();
770
766
  double val_real();
 
767
  int64_t val_int();
771
768
  my_decimal *val_decimal(my_decimal *);
772
769
  void reset_field();
773
770
  void update_field();
776
773
  void no_rows_in_result() {}
777
774
  const char *func_name() const
778
775
    { return sample ? "var_samp(" : "variance("; }
779
 
  Item *copy_or_same(THD* thd);
780
 
  Field *create_tmp_field(bool group, Table *table, uint convert_blob_length);
 
776
  Item *copy_or_same(Session* session);
 
777
  Field *create_tmp_field(bool group, Table *table, uint32_t convert_blob_length);
781
778
  enum Item_result result_type () const { return REAL_RESULT; }
782
779
  void cleanup()
783
780
  {
806
803
class Item_sum_std :public Item_sum_variance
807
804
{
808
805
  public:
809
 
  Item_sum_std(Item *item_par, uint sample_arg)
 
806
  Item_sum_std(Item *item_par, uint32_t sample_arg)
810
807
    :Item_sum_variance(item_par, sample_arg) {}
811
 
  Item_sum_std(THD *thd, Item_sum_std *item)
812
 
    :Item_sum_variance(thd, item)
 
808
  Item_sum_std(Session *session, Item_sum_std *item)
 
809
    :Item_sum_variance(session, item)
813
810
    {}
814
811
  enum Sumfunctype sum_func () const { return STD_FUNC; }
815
812
  double val_real();
816
813
  Item *result_item(Field *field __attribute__((unused)))
817
814
    { return new Item_std_field(this); }
818
815
  const char *func_name() const { return "std("; }
819
 
  Item *copy_or_same(THD* thd);
 
816
  Item *copy_or_same(Session* session);
820
817
  enum Item_result result_type () const { return REAL_RESULT; }
821
818
  enum_field_types field_type() const { return DRIZZLE_TYPE_DOUBLE;}
822
819
};
841
838
    hybrid_type(INT_RESULT), hybrid_field_type(DRIZZLE_TYPE_LONGLONG),
842
839
    cmp_sign(sign), was_values(true)
843
840
  { collation.set(&my_charset_bin); }
844
 
  Item_sum_hybrid(THD *thd, Item_sum_hybrid *item);
845
 
  bool fix_fields(THD *, Item **);
 
841
  Item_sum_hybrid(Session *session, Item_sum_hybrid *item);
 
842
  bool fix_fields(Session *, Item **);
846
843
  void clear();
847
844
  double val_real();
848
845
  int64_t val_int();
861
858
  bool any_value() { return was_values; }
862
859
  void no_rows_in_result();
863
860
  Field *create_tmp_field(bool group, Table *table,
864
 
                          uint convert_blob_length);
 
861
                          uint32_t convert_blob_length);
865
862
};
866
863
 
867
864
 
869
866
{
870
867
public:
871
868
  Item_sum_min(Item *item_par) :Item_sum_hybrid(item_par,1) {}
872
 
  Item_sum_min(THD *thd, Item_sum_min *item) :Item_sum_hybrid(thd, item) {}
 
869
  Item_sum_min(Session *session, Item_sum_min *item) :Item_sum_hybrid(session, item) {}
873
870
  enum Sumfunctype sum_func () const {return MIN_FUNC;}
874
871
 
875
872
  bool add();
876
873
  const char *func_name() const { return "min("; }
877
 
  Item *copy_or_same(THD* thd);
 
874
  Item *copy_or_same(Session* session);
878
875
};
879
876
 
880
877
 
882
879
{
883
880
public:
884
881
  Item_sum_max(Item *item_par) :Item_sum_hybrid(item_par,-1) {}
885
 
  Item_sum_max(THD *thd, Item_sum_max *item) :Item_sum_hybrid(thd, item) {}
 
882
  Item_sum_max(Session *session, Item_sum_max *item) :Item_sum_hybrid(session, item) {}
886
883
  enum Sumfunctype sum_func () const {return MAX_FUNC;}
887
884
 
888
885
  bool add();
889
886
  const char *func_name() const { return "max("; }
890
 
  Item *copy_or_same(THD* thd);
 
887
  Item *copy_or_same(Session* session);
891
888
};
892
889
 
893
890
 
899
896
public:
900
897
  Item_sum_bit(Item *item_par,uint64_t reset_arg)
901
898
    :Item_sum_int(item_par),reset_bits(reset_arg),bits(reset_arg) {}
902
 
  Item_sum_bit(THD *thd, Item_sum_bit *item):
903
 
    Item_sum_int(thd, item), reset_bits(item->reset_bits), bits(item->bits) {}
 
899
  Item_sum_bit(Session *session, Item_sum_bit *item):
 
900
    Item_sum_int(session, item), reset_bits(item->reset_bits), bits(item->bits) {}
904
901
  enum Sumfunctype sum_func () const {return SUM_BIT_FUNC;}
905
902
  void clear();
906
903
  int64_t val_int();
919
916
class Item_sum_or :public Item_sum_bit
920
917
{
921
918
public:
922
 
  Item_sum_or(Item *item_par) :Item_sum_bit(item_par,0LL) {}
923
 
  Item_sum_or(THD *thd, Item_sum_or *item) :Item_sum_bit(thd, item) {}
 
919
  Item_sum_or(Item *item_par) :Item_sum_bit(item_par,0) {}
 
920
  Item_sum_or(Session *session, Item_sum_or *item) :Item_sum_bit(session, item) {}
924
921
  bool add();
925
922
  const char *func_name() const { return "bit_or("; }
926
 
  Item *copy_or_same(THD* thd);
 
923
  Item *copy_or_same(Session* session);
927
924
};
928
925
 
929
926
 
931
928
{
932
929
  public:
933
930
  Item_sum_and(Item *item_par) :Item_sum_bit(item_par, UINT64_MAX) {}
934
 
  Item_sum_and(THD *thd, Item_sum_and *item) :Item_sum_bit(thd, item) {}
 
931
  Item_sum_and(Session *session, Item_sum_and *item) :Item_sum_bit(session, item) {}
935
932
  bool add();
936
933
  const char *func_name() const { return "bit_and("; }
937
 
  Item *copy_or_same(THD* thd);
 
934
  Item *copy_or_same(Session* session);
938
935
};
939
936
 
940
937
class Item_sum_xor :public Item_sum_bit
941
938
{
942
939
  public:
943
 
  Item_sum_xor(Item *item_par) :Item_sum_bit(item_par,0LL) {}
944
 
  Item_sum_xor(THD *thd, Item_sum_xor *item) :Item_sum_bit(thd, item) {}
 
940
  Item_sum_xor(Item *item_par) :Item_sum_bit(item_par,0) {}
 
941
  Item_sum_xor(Session *session, Item_sum_xor *item) :Item_sum_bit(session, item) {}
945
942
  bool add();
946
943
  const char *func_name() const { return "bit_xor("; }
947
 
  Item *copy_or_same(THD* thd);
948
 
};
949
 
 
950
 
 
951
 
/*
952
 
  User defined aggregates
953
 
*/
954
 
 
955
 
class Item_udf_sum : public Item_sum
956
 
{
957
 
protected:
958
 
  udf_handler udf;
959
 
 
960
 
public:
961
 
  Item_udf_sum(udf_func *udf_arg)
962
 
    :Item_sum(), udf(udf_arg)
963
 
  { quick_group=0; }
964
 
  Item_udf_sum(udf_func *udf_arg, List<Item> &list)
965
 
    :Item_sum(list), udf(udf_arg)
966
 
  { quick_group=0;}
967
 
  Item_udf_sum(THD *thd, Item_udf_sum *item)
968
 
    :Item_sum(thd, item), udf(item->udf)
969
 
  { udf.not_original= true; }
970
 
  const char *func_name() const { return udf.name(); }
971
 
  bool fix_fields(THD *thd, Item **ref)
972
 
  {
973
 
    assert(fixed == 0);
974
 
 
975
 
    if (init_sum_func_check(thd))
976
 
      return true;
977
 
 
978
 
    fixed= 1;
979
 
    if (udf.fix_fields(thd, this, this->arg_count, this->args))
980
 
      return true;
981
 
 
982
 
    return check_sum_func(thd, ref);
983
 
  }
984
 
  enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
985
 
  virtual bool have_field_update(void) const { return 0; }
986
 
 
987
 
  void clear();
988
 
  bool add();
989
 
  void reset_field() {};
990
 
  void update_field() {};
991
 
  void cleanup();
992
 
  virtual void print(String *str, enum_query_type query_type);
993
 
};
994
 
 
995
 
 
996
 
class Item_sum_udf_float :public Item_udf_sum
997
 
{
998
 
 public:
999
 
  Item_sum_udf_float(udf_func *udf_arg)
1000
 
    :Item_udf_sum(udf_arg) {}
1001
 
  Item_sum_udf_float(udf_func *udf_arg, List<Item> &list)
1002
 
    :Item_udf_sum(udf_arg, list) {}
1003
 
  Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
1004
 
    :Item_udf_sum(thd, item) {}
1005
 
  int64_t val_int()
1006
 
  {
1007
 
    assert(fixed == 1);
1008
 
    return (int64_t) rint(Item_sum_udf_float::val_real());
1009
 
  }
1010
 
  double val_real();
1011
 
  String *val_str(String*str);
1012
 
  my_decimal *val_decimal(my_decimal *);
1013
 
  void fix_length_and_dec() { fix_num_length_and_dec(); }
1014
 
  Item *copy_or_same(THD* thd);
1015
 
};
1016
 
 
1017
 
 
1018
 
class Item_sum_udf_int :public Item_udf_sum
1019
 
{
1020
 
public:
1021
 
  Item_sum_udf_int(udf_func *udf_arg)
1022
 
    :Item_udf_sum(udf_arg) {}
1023
 
  Item_sum_udf_int(udf_func *udf_arg, List<Item> &list)
1024
 
    :Item_udf_sum(udf_arg, list) {}
1025
 
  Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
1026
 
    :Item_udf_sum(thd, item) {}
1027
 
  int64_t val_int();
1028
 
  double val_real()
1029
 
    { assert(fixed == 1); return (double) Item_sum_udf_int::val_int(); }
1030
 
  String *val_str(String*str);
1031
 
  my_decimal *val_decimal(my_decimal *);
1032
 
  enum Item_result result_type () const { return INT_RESULT; }
1033
 
  void fix_length_and_dec() { decimals=0; max_length=21; }
1034
 
  Item *copy_or_same(THD* thd);
1035
 
};
1036
 
 
1037
 
 
1038
 
class Item_sum_udf_str :public Item_udf_sum
1039
 
{
1040
 
public:
1041
 
  Item_sum_udf_str(udf_func *udf_arg)
1042
 
    :Item_udf_sum(udf_arg) {}
1043
 
  Item_sum_udf_str(udf_func *udf_arg, List<Item> &list)
1044
 
    :Item_udf_sum(udf_arg,list) {}
1045
 
  Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
1046
 
    :Item_udf_sum(thd, item) {}
1047
 
  String *val_str(String *);
1048
 
  double val_real()
1049
 
  {
1050
 
    int err_not_used;
1051
 
    char *end_not_used;
1052
 
    String *res;
1053
 
    res=val_str(&str_value);
1054
 
    return res ? my_strntod(res->charset(),(char*) res->ptr(),res->length(),
1055
 
                            &end_not_used, &err_not_used) : 0.0;
1056
 
  }
1057
 
  int64_t val_int()
1058
 
  {
1059
 
    int err_not_used;
1060
 
    char *end;
1061
 
    String *res;
1062
 
    const CHARSET_INFO *cs;
1063
 
 
1064
 
    if (!(res= val_str(&str_value)))
1065
 
      return 0;                                 /* Null value */
1066
 
    cs= res->charset();
1067
 
    end= (char*) res->ptr()+res->length();
1068
 
    return cs->cset->strtoll10(cs, res->ptr(), &end, &err_not_used);
1069
 
  }
1070
 
  my_decimal *val_decimal(my_decimal *dec);
1071
 
  enum Item_result result_type () const { return STRING_RESULT; }
1072
 
  void fix_length_and_dec();
1073
 
  Item *copy_or_same(THD* thd);
1074
 
};
1075
 
 
1076
 
 
1077
 
class Item_sum_udf_decimal :public Item_udf_sum
1078
 
{
1079
 
public:
1080
 
  Item_sum_udf_decimal(udf_func *udf_arg)
1081
 
    :Item_udf_sum(udf_arg) {}
1082
 
  Item_sum_udf_decimal(udf_func *udf_arg, List<Item> &list)
1083
 
    :Item_udf_sum(udf_arg, list) {}
1084
 
  Item_sum_udf_decimal(THD *thd, Item_sum_udf_decimal *item)
1085
 
    :Item_udf_sum(thd, item) {}
1086
 
  String *val_str(String *);
1087
 
  double val_real();
1088
 
  int64_t val_int();
1089
 
  my_decimal *val_decimal(my_decimal *);
1090
 
  enum Item_result result_type () const { return DECIMAL_RESULT; }
1091
 
  void fix_length_and_dec() { fix_num_length_and_dec(); }
1092
 
  Item *copy_or_same(THD* thd);
1093
 
};
 
944
  Item *copy_or_same(Session* session);
 
945
};
 
946
 
 
947
 
1094
948
 
1095
949
class DRIZZLE_ERROR;
1096
950
 
1115
969
  order_st **order;
1116
970
  Name_resolution_context *context;
1117
971
  /** The number of ORDER BY items. */
1118
 
  uint arg_count_order;
 
972
  uint32_t arg_count_order;
1119
973
  /** The number of selected items, aka the expr list. */
1120
 
  uint arg_count_field;
1121
 
  uint count_cut_values;
 
974
  uint32_t arg_count_field;
 
975
  uint32_t count_cut_values;
1122
976
  bool distinct;
1123
977
  bool warning_for_row;
1124
978
  bool always_null;
1134
988
                                                const void* key2);
1135
989
  friend int group_concat_key_cmp_with_order(void* arg, const void* key1,
1136
990
                                             const void* key2);
1137
 
  friend int dump_leaf_key(uchar* key,
 
991
  friend int dump_leaf_key(unsigned char* key,
1138
992
                           element_count count __attribute__((unused)),
1139
993
                           Item_func_group_concat *group_concat_item);
1140
994
 
1143
997
                         bool is_distinct, List<Item> *is_select,
1144
998
                         SQL_LIST *is_order, String *is_separator);
1145
999
 
1146
 
  Item_func_group_concat(THD *thd, Item_func_group_concat *item);
 
1000
  Item_func_group_concat(Session *session, Item_func_group_concat *item);
1147
1001
  ~Item_func_group_concat();
1148
1002
  void cleanup();
1149
1003
 
1161
1015
  bool add();
1162
1016
  void reset_field() { assert(0); }        // not used
1163
1017
  void update_field() { assert(0); }       // not used
1164
 
  bool fix_fields(THD *,Item **);
1165
 
  bool setup(THD *thd);
 
1018
  bool fix_fields(Session *,Item **);
 
1019
  bool setup(Session *session);
1166
1020
  void make_unique();
1167
1021
  double val_real()
1168
1022
  {
1184
1038
    return val_decimal_from_string(decimal_value);
1185
1039
  }
1186
1040
  String* val_str(String* str);
1187
 
  Item *copy_or_same(THD* thd);
 
1041
  Item *copy_or_same(Session* session);
1188
1042
  void no_rows_in_result() {}
1189
1043
  virtual void print(String *str, enum_query_type query_type);
1190
 
  virtual bool change_context_processor(uchar *cntx)
 
1044
  virtual bool change_context_processor(unsigned char *cntx)
1191
1045
    { context= (Name_resolution_context *)cntx; return false; }
1192
1046
};