~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_sum.h

  • Committer: Brian Aker
  • Date: 2008-09-04 19:31:00 UTC
  • Revision ID: brian@tangent.org-20080904193100-l849hgghfy4urj43
Changing default character set from this point on.

Show diffs side-by-side

added added

removed removed

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