MySQL  8.0.19
Source Code Documentation
item_sum.h
Go to the documentation of this file.
1 #ifndef ITEM_SUM_INCLUDED
2 #define ITEM_SUM_INCLUDED
3 
4 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 /* classes for sum functions */
27 
28 #include <limits.h>
29 #include <math.h>
30 #include <stddef.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <map>
34 #include <memory>
35 #include <string>
36 
37 #include "field_types.h" // enum_field_types
38 #include "m_ctype.h"
39 #include "m_string.h"
40 #include "my_alloc.h"
41 #include "my_compiler.h"
42 #include "my_dbug.h"
43 #include "my_inttypes.h"
44 #include "my_sys.h"
45 #include "my_table_map.h"
46 #include "my_time.h"
47 #include "my_tree.h" // TREE
49 #include "mysql_time.h"
50 #include "mysqld_error.h"
51 #include "sql/enum_query_type.h"
52 #include "sql/item.h" // Item_result_field
53 #include "sql/item_func.h" // Item_int_func
54 #include "sql/mem_root_array.h"
55 #include "sql/my_decimal.h"
57 #include "sql/parse_tree_nodes.h" // PT_window
58 #include "sql/sql_base.h"
59 #include "sql/sql_const.h"
60 #include "sql/sql_list.h"
61 #include "sql/sql_udf.h" // udf_handler
62 #include "sql/window_lex.h"
63 #include "sql_string.h"
64 #include "template_utils.h"
65 
66 class Field;
67 class Item_sum;
68 class Json_array;
69 class Json_object;
70 class Json_wrapper;
71 class PT_item_list;
72 class SELECT_LEX;
73 class THD;
74 class Temp_table_param;
75 class Window;
76 struct ORDER;
77 struct TABLE;
79 
80 /**
81  The abstract base class for the Aggregator_* classes.
82  It implements the data collection functions (setup/add/clear)
83  as either pass-through to the real functionality or
84  as collectors into an Unique (for distinct) structure.
85 
86  Note that update_field/reset_field are not in that
87  class, because they're simply not called when
88  GROUP BY/DISTINCT can be handled with help of index on grouped
89  fields (allow_group_via_temp_table is false);
90 */
91 
92 class Aggregator {
93  friend class Item_sum;
94  friend class Item_sum_sum;
95  friend class Item_sum_count;
96  friend class Item_sum_avg;
97 
98  /*
99  All members are protected as this class is not usable outside of an
100  Item_sum descendant.
101  */
102  protected:
103  /* the aggregate function class to act on */
105 
106  public:
107  Aggregator(Item_sum *arg) : item_sum(arg) {}
108  virtual ~Aggregator() {}
109 
111  virtual Aggregator_type Aggrtype() = 0;
112 
113  /**
114  Called before adding the first row.
115  Allocates and sets up the internal aggregation structures used,
116  e.g. the Unique instance used to calculate distinct.
117  */
118  virtual bool setup(THD *) = 0;
119 
120  /**
121  Called when we need to wipe out all the data from the aggregator :
122  all the values acumulated and all the state.
123  Cleans up the internal structures and resets them to their initial state.
124  */
125  virtual void clear() = 0;
126 
127  /**
128  Called when there's a new value to be aggregated.
129  Updates the internal state of the aggregator to reflect the new value.
130  */
131  virtual bool add() = 0;
132 
133  /**
134  Called when there are no more data and the final value is to be retrieved.
135  Finalises the state of the aggregator, so the final result can be retrieved.
136  */
137  virtual void endup() = 0;
138 
139  /** Decimal value of being-aggregated argument */
141  /** Floating point value of being-aggregated argument */
142  virtual double arg_val_real() = 0;
143  /**
144  NULLness of being-aggregated argument.
145 
146  @param use_null_value Optimization: to determine if the argument is NULL
147  we must, in the general case, call is_null() on it, which itself might
148  call val_*() on it, which might be costly. If you just have called
149  arg_val*(), you can pass use_null_value=true; this way, arg_is_null()
150  might avoid is_null() and instead do a cheap read of the Item's null_value
151  (updated by arg_val*()).
152  */
153  virtual bool arg_is_null(bool use_null_value) = 0;
154 };
155 
156 /**
157  Class Item_sum is the base class used for special expressions that SQL calls
158  'set functions'. These expressions are formed with the help of aggregate
159  functions such as SUM, MAX, GROUP_CONCAT etc.
160  Class Item_sum is also the base class for Window functions; the text below
161  first documents set functions, then window functions.
162 
163  GENERAL NOTES
164 
165  A set function cannot be used in all positions where expressions are accepted.
166  There are some quite explicable restrictions for the use of set functions.
167 
168  In the query:
169 
170  SELECT AVG(b) FROM t1 WHERE SUM(b) > 20 GROUP by a
171 
172  the set function AVG(b) is valid, while the usage of SUM(b) is invalid.
173  A WHERE condition must contain expressions that can be evaluated for each row
174  of the table. Yet the expression SUM(b) can be evaluated only for each group
175  of rows with the same value of column a.
176  In the query:
177 
178  SELECT AVG(b) FROM t1 WHERE c > 30 GROUP BY a HAVING SUM(b) > 20
179 
180  both set function expressions AVG(b) and SUM(b) are valid.
181 
182  We can say that in a query without nested selects an occurrence of a
183  set function in an expression of the SELECT list or/and in the HAVING
184  clause is valid, while in the WHERE clause, FROM clause or GROUP BY clause
185  it is invalid.
186 
187  The general rule to detect whether a set function is valid in a query with
188  nested subqueries is much more complicated.
189 
190  Consider the following query:
191 
192  SELECT t1.a FROM t1 GROUP BY t1.a
193  HAVING t1.a > ALL (SELECT t2.c FROM t2 WHERE SUM(t1.b) < t2.c).
194 
195  The set function SUM(b) is used here in the WHERE clause of the subquery.
196  Nevertheless it is valid since it is contained in the HAVING clause of the
197  outer query. The expression SUM(t1.b) is evaluated for each group defined
198  in the main query, not for groups of the subquery.
199 
200  The problem of finding the query where to aggregate a particular
201  set function is not so simple as it seems to be.
202 
203  In the query:
204  SELECT t1.a FROM t1 GROUP BY t1.a
205  HAVING t1.a > ALL(SELECT t2.c FROM t2 GROUP BY t2.c
206  HAVING SUM(t1.a) < t2.c)
207 
208  the set function can be evaluated in both the outer and the inner query block.
209  If we evaluate SUM(t1.a) for the outer query then we get the value of t1.a
210  multiplied by the cardinality of a group in table t1. In this case,
211  SUM(t1.a) is used as a constant value in each correlated subquery.
212  But SUM(t1.a) can also be evaluated for the inner query.
213  In this case t1.a will be a constant value for each correlated subquery and
214  summation is performed for each group of table t2.
215  (Here it makes sense to remind that the query
216 
217  SELECT c FROM t GROUP BY a HAVING SUM(1) < a
218 
219  is quite valid in our SQL).
220 
221  So depending on what query block we assign the set function to we
222  can get different results.
223 
224  The general rule to detect the query block Q where a set function will be
225  aggregated (evaluated) can be formulated as follows.
226 
227  Reference: SQL2011 @<set function specification@> syntax rules 6 and 7.
228 
229  Consider a set function S(E) where E is an expression which contains
230  column references C1, ..., Cn. Resolve all column references Ci against
231  the query block Qi containing the set function S(E). Let Q be the innermost
232  query block of all query blocks Qi. (It should be noted here that S(E)
233  in no way can be aggregated in the query block containing the subquery Q,
234  otherwise S(E) would refer to at least one unbound column reference).
235  If S(E) is used in a construct of Q where set functions are allowed then
236  we aggregate S(E) in Q.
237  Otherwise:
238  - if ANSI SQL mode is enabled (MODE_ANSI), then report an error.
239  - otherwise, look for the innermost query block containing S(E) of those
240  where usage of S(E) is allowed. The place of aggregation depends on which
241  clause the subquery is contained within; It will be different when
242  contained in a WHERE clause versus in the select list or in HAVING clause.
243 
244  Let's demonstrate how this rule is applied to the following queries.
245 
246  1. SELECT t1.a FROM t1 GROUP BY t1.a
247  HAVING t1.a > ALL(SELECT t2.b FROM t2 GROUP BY t2.b
248  HAVING t2.b > ALL(SELECT t3.c FROM t3 GROUP BY t3.c
249  HAVING SUM(t1.a+t2.b) < t3.c))
250  For this query the set function SUM(t1.a+t2.b) contains t1.a and t2.b
251  with t1.a defined in the outermost query, and t2.b defined for its
252  subquery. The set function is contained in the HAVING clause of the subquery
253  and can be evaluated in this subquery.
254 
255  2. SELECT t1.a FROM t1 GROUP BY t1.a
256  HAVING t1.a > ALL(SELECT t2.b FROM t2
257  WHERE t2.b > ALL (SELECT t3.c FROM t3 GROUP BY t3.c
258  HAVING SUM(t1.a+t2.b) < t3.c))
259  The set function SUM(t1.a+t2.b) is contained in the WHERE clause of the second
260  query block - the outermost query block where t1.a and t2.b are defined.
261  If we evaluate the function in this subquery we violate the context rules.
262  So we evaluate the function in the third query block (over table t3) where it
263  is used under the HAVING clause; if in ANSI SQL mode, an error is thrown.
264 
265  3. SELECT t1.a FROM t1 GROUP BY t1.a
266  HAVING t1.a > ALL(SELECT t2.b FROM t2
267  WHERE t2.b > ALL (SELECT t3.c FROM t3
268  WHERE SUM(t1.a+t2.b) < t3.c))
269  In this query, evaluation of SUM(t1.a+t2.b) is not valid neither in the second
270  nor in the third query block.
271 
272  Set functions can generally not be nested. In the query
273 
274  SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20
275 
276  the expression SUM(b) is not valid, even though it is contained inside
277  a HAVING clause.
278  However, it is acceptable in the query:
279 
280  SELECT t.1 FROM t1 GROUP BY t1.a HAVING SUM(t1.b) > 20.
281 
282  An argument of a set function does not have to be a simple column reference
283  as seen in examples above. This can be a more complex expression
284 
285  SELECT t1.a FROM t1 GROUP BY t1.a HAVING SUM(t1.b+1) > 20.
286 
287  The expression SUM(t1.b+1) has clear semantics in this context:
288  we sum up the values of t1.b+1 where t1.b varies for all values within a
289  group of rows that contain the same t1.a value.
290 
291  A set function for an outer query yields a constant value within a subquery.
292  So the semantics of the query
293 
294  SELECT t1.a FROM t1 GROUP BY t1.a
295  HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
296  HAVING AVG(t2.c+SUM(t1.b)) > 20)
297 
298  is still clear. For a group of rows with the same value for t1.a, calculate
299  the value of SUM(t1.b) as 's'. This value is substituted in the subquery:
300 
301  SELECT t2.c FROM t2 GROUP BY t2.c HAVING AVG(t2.c+s)
302 
303  By the same reason the following query with a subquery
304 
305  SELECT t1.a FROM t1 GROUP BY t1.a
306  HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
307  HAVING AVG(SUM(t1.b)) > 20)
308  is also valid.
309 
310  IMPLEMENTATION NOTES
311 
312  The member base_select contains a reference to the query block that the
313  set function is contained within.
314 
315  The member aggr_select contains a reference to the query block where the
316  set function is aggregated.
317 
318  The field max_aggr_level holds the maximum of the nest levels of the
319  unbound column references contained in the set function. A column reference
320  is unbound within a set function if it is not bound by any subquery
321  used as a subexpression in this function. A column reference is bound by
322  a subquery if it is a reference to the column by which the aggregation
323  of some set function that is used in the subquery is calculated.
324  For the set function used in the query
325 
326  SELECT t1.a FROM t1 GROUP BY t1.a
327  HAVING t1.a > ALL(SELECT t2.b FROM t2 GROUP BY t2.b
328  HAVING t2.b > ALL(SELECT t3.c FROM t3 GROUP BY t3.c
329  HAVING SUM(t1.a+t2.b) < t3.c))
330 
331  the value of max_aggr_level is equal to 1 since t1.a is bound in the main
332  query, and t2.b is bound by the first subquery whose nest level is 1.
333  Obviously a set function cannot be aggregated in a subquery whose
334  nest level is less than max_aggr_level. (Yet it can be aggregated in the
335  subqueries whose nest level is greater than max_aggr_level.)
336  In the query
337  SELECT t1.a FROM t1 HAVING AVG(t1.a+(SELECT MIN(t2.c) FROM t2))
338 
339  the value of the max_aggr_level for the AVG set function is 0 since
340  the reference t2.c is bound in the subquery.
341 
342  If a set function contains no column references (like COUNT(*)),
343  max_aggr_level is -1.
344 
345  The field 'max_sum_func_level' is to contain the maximum of the
346  nest levels of the set functions that are used as subexpressions of
347  the arguments of the given set function, but not aggregated in any
348  subquery within this set function. A nested set function s1 can be
349  used within set function s0 only if s1.max_sum_func_level <
350  s0.max_sum_func_level. Set function s1 is considered as nested
351  for set function s0 if s1 is not calculated in any subquery
352  within s0.
353 
354  A set function that is used as a subexpression in an argument of another
355  set function refers to the latter via the field 'in_sum_func'.
356 
357  The condition imposed on the usage of set functions are checked when
358  we traverse query subexpressions with the help of the recursive method
359  fix_fields. When we apply this method to an object of the class
360  Item_sum, first, on the descent, we call the method init_sum_func_check
361  that initialize members used at checking. Then, on the ascent, we
362  call the method check_sum_func that validates the set function usage
363  and reports an error if it is invalid.
364  The method check_sum_func serves to link the items for the set functions
365  that are aggregated in the containing query blocks. Circular chains of such
366  functions are attached to the corresponding SELECT_LEX structures
367  through the field inner_sum_func_list.
368 
369  Exploiting the fact that the members mentioned above are used in one
370  recursive function we could have allocated them on the thread stack.
371  Yet we don't do it now.
372 
373  It is assumed that the nesting level of subqueries does not exceed 63
374  (valid nesting levels are stored in a 64-bit bitmap called nesting_map).
375  The assumption is enforced in LEX::new_query().
376 
377  WINDOW FUNCTIONS
378 
379  Most set functions (e.g. SUM, COUNT, AVG) can also be used as window
380  functions. In that case, notable differences compared to set functions are:
381  - not using any Aggregator
382  - not supporting DISTINCT
383  - val_*() does more than returning the function's current value: it
384  first accumulates the function's argument into the function's
385  state. Execution (e.g. end_write_wf()) manipulates temporary tables which
386  contain input for WFs; each input row is passed to copy_funcs() which calls
387  the WF's val_*() to accumulate it.
388 */
389 
390 class Item_sum : public Item_result_field {
392 
393  friend class Aggregator_distinct;
394  friend class Aggregator_simple;
395 
396  protected:
397  /**
398  Aggregator class instance. Not set initially. Allocated only after
399  it is determined if the incoming data are already distinct.
400  */
402 
403  /**
404  If sum is a window function, this field contains the window.
405  */
407  /**
408  True if we have already resolved this window functions window reference.
409  Used in execution of prepared statement to avoid re-resolve.
410  */
412 
413  private:
414  /**
415  Used in making ROLLUP. Set for the ROLLUP copies of the original
416  Item_sum and passed to create_tmp_field() to cause it to work
417  over the temp table buffer that is referenced by
418  Item_result_field::result_field.
419  */
421 
422  /**
423  Indicates how the aggregate function was specified by the parser :
424  true if it was written as AGGREGATE(DISTINCT),
425  false if it was AGGREGATE()
426  */
428 
429  public:
430  bool has_force_copy_fields() const { return force_copy_fields; }
431  bool has_with_distinct() const { return with_distinct; }
432 
433  enum Sumfunctype {
434  COUNT_FUNC, // COUNT
435  COUNT_DISTINCT_FUNC, // COUNT (DISTINCT)
436  SUM_FUNC, // SUM
437  SUM_DISTINCT_FUNC, // SUM (DISTINCT)
438  AVG_FUNC, // AVG
439  AVG_DISTINCT_FUNC, // AVG (DISTINCT)
440  MIN_FUNC, // MIN
441  MAX_FUNC, // MAX
442  STD_FUNC, // STD/STDDEV/STDDEV_POP
443  VARIANCE_FUNC, // VARIANCE/VAR_POP and VAR_SAMP
444  SUM_BIT_FUNC, // BIT_AND, BIT_OR and BIT_XOR
445  UDF_SUM_FUNC, // user defined functions
446  GROUP_CONCAT_FUNC, // GROUP_CONCAT
447  JSON_AGG_FUNC, // JSON_ARRAYAGG and JSON_OBJECTAGG
448  ROW_NUMBER_FUNC, // Window functions
457  };
458 
459  /**
460  @note most member variables below serve only for grouped aggregate
461  functions.
462  */
463 
464  /**
465  For a group aggregate which is aggregated into an outer query
466  block; none, or just the first or both cells may be non-zero. They are
467  filled with references to the group aggregate (for example if it is the
468  argument of a function; it is then a pointer to that function's args[i]
469  pointer). "ref_by" stands for "referenced by".
470  */
471  Item **ref_by[2];
472  Item_sum *next_sum; ///< next in the circular chain of registered objects
473  Item_sum *in_sum_func; ///< the containing set function if any
474  SELECT_LEX *base_select; ///< query block where function is placed
475  /**
476  For a group aggregate, query block where function is aggregated. For a
477  window function, nullptr, as such function is always aggregated in
478  base_select, as it mustn't contain any outer reference.
479  */
481  int8 max_aggr_level; ///< max level of unbound column references
482  int8
483  max_sum_func_level; ///< max level of aggregation for contained functions
484  bool allow_group_via_temp_table; ///< If incremental update of fields is
485  ///< supported.
486  /**
487  WFs are forbidden when resolving Item_sum; this member is used to restore
488  WF allowance status afterwards.
489  */
491 
492  protected:
497  static ulonglong ram_limitation(THD *thd);
498 
499  public:
500  void mark_as_sum_func();
502 
503  Item_sum(const POS &pos, PT_window *w)
504  : super(pos),
505  m_window(w),
507  next_sum(nullptr),
509  arg_count(0),
510  args(nullptr),
513  init_aggregator();
514  }
515 
517  : m_window(NULL),
519  next_sum(nullptr),
521  arg_count(1),
522  args(tmp_args),
525  args[0] = a;
527  init_aggregator();
528  }
529 
530  Item_sum(const POS &pos, Item *a, PT_window *w)
531  : super(pos),
532  m_window(w),
534  next_sum(nullptr),
536  arg_count(1),
537  args(tmp_args),
540  args[0] = a;
541  init_aggregator();
542  }
543 
544  Item_sum(const POS &pos, Item *a, Item *b, PT_window *w)
545  : super(pos),
546  m_window(w),
548  next_sum(nullptr),
550  arg_count(2),
551  args(tmp_args),
554  args[0] = a;
555  args[1] = b;
556  init_aggregator();
557  }
558 
559  Item_sum(const POS &pos, PT_item_list *opt_list, PT_window *w);
560 
561  /// Copy constructor, need to perform subqueries with temporary tables
562  Item_sum(THD *thd, const Item_sum *item);
563 
564  bool itemize(Parse_context *pc, Item **res) override;
565  Type type() const override { return SUM_FUNC_ITEM; }
566  virtual enum Sumfunctype sum_func() const = 0;
567 
568  /**
569  Resets the aggregate value to its default and aggregates the current
570  value of its attribute(s).
571  */
572  inline bool reset_and_add() {
574  return aggregator_add();
575  }
576 
577  /*
578  Called when new group is started and results are being saved in
579  a temporary table. Similarly to reset_and_add() it resets the
580  value to its default and aggregates the value of its
581  attribute(s), but must also store it in result_field.
582  This set of methods (result_item(), reset_field, update_field()) of
583  Item_sum is used only if allow_group_via_temp_table is true. Otherwise
584  copy_or_same() is used to obtain a copy of this item.
585  */
586  virtual void reset_field() = 0;
587  /*
588  Called for each new value in the group, when temporary table is in use.
589  Similar to add(), but uses temporary table field to obtain current value,
590  Updated value is then saved in the field.
591  */
592  virtual void update_field() = 0;
593  virtual bool keep_field_type() const { return false; }
594  bool resolve_type(THD *) override;
595  virtual Item *result_item(Field *field) { return new Item_field(field); }
596  table_map used_tables() const override { return used_tables_cache; }
597  void update_used_tables() override;
598  void fix_after_pullout(SELECT_LEX *parent_select,
599  SELECT_LEX *removed_select) override;
601  bool is_null() override { return null_value; }
602  void make_const() {
603  used_tables_cache = 0;
604  forced_const = true;
605  }
606  void print(const THD *thd, String *str,
607  enum_query_type query_type) const override;
608  void fix_num_length_and_dec();
609  bool eq(const Item *item, bool binary_cmp) const override;
610  /**
611  Mark an aggregate as having no rows.
612 
613  This function is called by the execution engine to assign 'NO ROWS
614  FOUND' value to an aggregate item, when the underlying result set
615  has no rows. Such value, in a general case, may be different from
616  the default value of the item after 'clear()': e.g. a numeric item
617  may be initialized to 0 by clear() and to NULL by
618  no_rows_in_result().
619  */
620  void no_rows_in_result() override {
624  }
625  virtual void make_unique() { force_copy_fields = true; }
626  virtual Field *create_tmp_field(bool group, TABLE *table);
627  bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
628  bool clean_up_after_removal(uchar *arg) override;
629  bool aggregate_check_group(uchar *arg) override;
630  bool aggregate_check_distinct(uchar *arg) override;
631  bool has_aggregate_ref_in_group_by(uchar *arg) override;
632  bool init_sum_func_check(THD *thd);
633  bool check_sum_func(THD *thd, Item **ref);
634 
635  Item *get_arg(uint i) { return args[i]; }
636  Item *set_arg(uint i, THD *thd, Item *new_val);
637  uint get_arg_count() const { return arg_count; }
638  /// @todo delete this when we no longer support temporary transformations
639  Item **get_arg_ptr(uint i) { return &args[i]; }
640 
641  bool fix_fields(THD *thd, Item **ref) override;
642 
643  /* Initialization of distinct related members */
645  aggr = NULL;
646  with_distinct = false;
647  force_copy_fields = false;
648  }
649 
650  /**
651  Called to initialize the aggregator.
652  */
653 
654  inline bool aggregator_setup(THD *thd) { return aggr->setup(thd); }
655 
656  /**
657  Called to cleanup the aggregator.
658  */
659 
660  inline void aggregator_clear() { aggr->clear(); }
661 
662  /**
663  Called to add value to the aggregator.
664  */
665 
666  inline bool aggregator_add() { return aggr->add(); }
667 
668  /* stores the declared DISTINCT flag (from the parser) */
669  void set_distinct(bool distinct) {
670  with_distinct = distinct;
672  }
673 
674  /*
675  Set the type of aggregation : DISTINCT or not.
676 
677  May be called multiple times.
678  */
679 
681 
682  virtual void clear() = 0;
683  virtual bool add() = 0;
684  virtual bool setup(THD *) { return false; }
685 
686  /**
687  Only relevant for aggregates qua window functions. Checks semantics after
688  windows have been set up and checked. Window functions have specific
689  requirements on the window specifications.
690 
691  @param thd Current thread
692  @param select The current select
693  @param [out] reqs Holds collected requirements from this wf
694 
695  @returns true if error
696  */
697  virtual bool check_wf_semantics(THD *thd, SELECT_LEX *select,
699 
700  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
701  List<Item> &fields) override;
702 
703  void cleanup() override;
704 
705  const Window *window() const { return down_cast<Window *>(m_window); }
706  bool reset_wf_state(uchar *arg) override;
707 
708  /**
709  All aggregates are framing, i.e. they work on the window's frame. If none
710  is defined, the frame is by default the entire partition, unless ORDER BY
711  is defined, in which case it is the set of rows from the start of the
712  partition to and including the peer set of the current row.
713 
714  Some window functions are not framing, i.e. they always work on the entire
715  partition. For such window functions, the method is overridden to
716  return false.
717  */
718  virtual bool framing() const { return true; }
719 
720  /**
721  Only for framing window functions. True if this function only needs to
722  read one row per frame.
723  */
724  virtual bool uses_only_one_row() const { return false; }
725 
726  /**
727  Return true if we need to make two passes over the rows in the partition -
728  either because we need the cardinality of it (and we need to read all
729  rows to detect the next partition), or we need to have all partition rows
730  available to evaluate the window function for some other reason, e.g.
731  we may need the last row in the partition in the frame buffer to be able
732  to evaluate LEAD.
733  */
734  virtual bool needs_card() const { return false; }
735 
736  /**
737  Common initial actions for window functions. For non-buffered processing
738  ("on-the-fly"), check partition change and possible reset partition
739  state. In this case return false.
740  For buffered processing, if windowing state m_do_copy_null is true, set
741  null_value to true and return true.
742 
743  @return true if case two above holds, else false
744  */
745  bool wf_common_init();
746 
747  protected:
748  /*
749  Raise an error (ER_NOT_SUPPORTED_YET) with the detail that this
750  function is not yet supported as a window function.
751  */
753  char buff[STRING_BUFFER_USUAL_SIZE];
754  snprintf(buff, sizeof(buff), "%s as window function", func_name());
755  my_error(ER_NOT_SUPPORTED_YET, MYF(0), buff);
756  }
757 };
758 
759 class Unique;
760 
761 /**
762  The distinct aggregator.
763  Implements AGGFN (DISTINCT ..)
764  Collects all the data into an Unique (similarly to what Item_sum_distinct
765  does currently) and then (if applicable) iterates over the list of
766  unique values and pumps them back into its object
767 */
768 
770  friend class Item_sum_sum;
771 
772  /*
773  flag to prevent consecutive runs of endup(). Normally in endup there are
774  expensive calculations (like walking the distinct tree for example)
775  which we must do only once if there are no data changes.
776  We can re-use the data for the second and subsequent val_xxx() calls.
777  endup_done set to true also means that the calculated values for
778  the aggregate functions are correct and don't need recalculation.
779  */
781 
782  /*
783  Used depending on the type of the aggregate function and the presence of
784  blob columns in it:
785  - For COUNT(DISTINCT) and no blob fields this points to a real temporary
786  table. It's used as a hash table.
787  - For AVG/SUM(DISTINCT) or COUNT(DISTINCT) with blob fields only the
788  in-memory data structure of a temporary table is constructed.
789  It's used by the Field classes to transform data into row format.
790  */
792 
793  /*
794  An array of field lengths on row allocated and used only for
795  COUNT(DISTINCT) with multiple columns and no blobs. Used in
796  Aggregator_distinct::composite_key_cmp (called from Unique to compare
797  nodes
798  */
800 
801  /*
802  Used in conjunction with 'table' to support the access to Field classes
803  for COUNT(DISTINCT). Needed by copy_fields()/copy_funcs().
804  */
806 
807  /*
808  If there are no blobs in the COUNT(DISTINCT) arguments, we can use a tree,
809  which is faster than heap table. In that case, we still use the table
810  to help get things set up, but we insert nothing in it.
811  For AVG/SUM(DISTINCT) we always use this tree (as it takes a single
812  argument) to get the distinct rows.
813  */
815 
816  /*
817  The length of the temp table row. Must be a member of the class as it
818  gets passed down to simple_raw_key_cmp () as a compare function argument
819  to Unique. simple_raw_key_cmp () is used as a fast comparison function
820  when the entire row can be binary compared.
821  */
823 
826  /**
827  Set to true if the result is known to be always NULL.
828  If set deactivates creation and usage of the temporary table (in the
829  'table' member) and the Unique instance (in the 'tree' member) as well as
830  the calculation of the final value on the first call to
831  @c Item_sum::val_xxx(),
832  @c Item_avg::val_xxx(),
833  @c Item_count::val_xxx().
834  */
836  /**
837  Set to true if count distinct is on only const items. Distinct on a const
838  value will always be the constant itself. And count distinct of the same
839  would always be 1. Similar to CONST_NULL, it avoids creation of temporary
840  table and the Unique instance.
841  */
843  } const_distinct;
844 
845  /**
846  When feeding back the data in endup() from Unique/temp table back to
847  Item_sum::add() methods we must read the data from Unique (and not
848  recalculate the functions that are given as arguments to the aggregate
849  function.
850  This flag is to tell the arg_*() methods to take the data from the Unique
851  instead of calling the relevant val_..() method.
852  */
854 
855  public:
857  : Aggregator(sum),
858  table(NULL),
860  tree(NULL),
863  ~Aggregator_distinct() override;
865 
866  bool setup(THD *) override;
867  void clear() override;
868  bool add() override;
869  void endup() override;
871  double arg_val_real() override;
872  bool arg_is_null(bool use_null_value) override;
873 
874  bool unique_walk_function(void *element);
875  static int composite_key_cmp(const void *arg, const void *a, const void *b);
876 };
877 
878 /**
879  The pass-through aggregator.
880  Implements AGGFN (DISTINCT ..) by knowing it gets distinct data on input.
881  So it just pumps them back to the Item_sum descendant class.
882 */
884  public:
887 
888  bool setup(THD *thd) override { return item_sum->setup(thd); }
889  void clear() override { item_sum->clear(); }
890  bool add() override { return item_sum->add(); }
891  void endup() override {}
893  double arg_val_real() override;
894  bool arg_is_null(bool use_null_value) override;
895 };
896 
897 class Item_sum_num : public Item_sum {
898  typedef Item_sum super;
899 
900  protected:
901  /*
902  val_xxx() functions may be called several times during the execution of a
903  query. Derived classes that require extensive calculation in val_xxx()
904  maintain cache of aggregate value. This variable governs the validity of
905  that cache.
906  */
908 
909  public:
910  Item_sum_num(const POS &pos, Item *item_par, PT_window *window)
911  : Item_sum(pos, item_par, window), is_evaluated(false) {}
912 
914  : Item_sum(pos, list, w), is_evaluated(false) {}
915 
917  : Item_sum(thd, item), is_evaluated(item->is_evaluated) {}
918  bool fix_fields(THD *, Item **) override;
919  longlong val_int() override {
920  DBUG_ASSERT(fixed == 1);
921  return llrint_with_overflow_check(val_real()); /* Real as default */
922  }
923  String *val_str(String *str) override;
924  my_decimal *val_decimal(my_decimal *) override;
925  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
926  return get_date_from_numeric(ltime, fuzzydate); /* Decimal or real */
927  }
928  bool get_time(MYSQL_TIME *ltime) override {
929  return get_time_from_numeric(ltime); /* Decimal or real */
930  }
931  void reset_field() override;
932 };
933 
934 class Item_sum_int : public Item_sum_num {
935  public:
936  Item_sum_int(const POS &pos, Item *item_par, PT_window *w)
937  : Item_sum_num(pos, item_par, w) {
939  }
940 
942  : Item_sum_num(pos, list, w) {
944  }
945 
946  Item_sum_int(THD *thd, Item_sum_int *item) : Item_sum_num(thd, item) {
948  }
949 
950  bool resolve_type(THD *) override {
951  maybe_null = false;
952  for (uint i = 0; i < arg_count; i++) {
953  maybe_null |= args[i]->maybe_null;
954  }
955  null_value = false;
956  return false;
957  }
958  double val_real() override {
960  return static_cast<double>(val_int());
961  }
962  String *val_str(String *str) override;
963  my_decimal *val_decimal(my_decimal *) override;
964  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
965  return get_date_from_int(ltime, fuzzydate);
966  }
967  bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
968  enum Item_result result_type() const override { return INT_RESULT; }
969 };
970 
971 class Item_sum_sum : public Item_sum_num {
972  protected:
974  double sum;
977  bool resolve_type(THD *thd) override;
978  /**
979  Execution state: this is for counting rows entering and leaving the window
980  frame, see #m_frame_null_count.
981  */
983 
984  /**
985  Execution state: this is for counting NULLs of rows entering and leaving
986  the window frame, when we use optimized inverse-based computations. By
987  comparison with m_count we can know how many non-NULLs are in the frame.
988  */
990 
991  public:
992  Item_sum_sum(const POS &pos, Item *item_par, bool distinct, PT_window *window)
993  : Item_sum_num(pos, item_par, window),
995  m_count(0),
996  m_frame_null_count(0) {
997  set_distinct(distinct);
998  }
999 
1000  Item_sum_sum(THD *thd, Item_sum_sum *item);
1001  enum Sumfunctype sum_func() const override {
1003  }
1004  void clear() override;
1005  bool add() override;
1006  double val_real() override;
1007  longlong val_int() override;
1008  String *val_str(String *str) override;
1009  my_decimal *val_decimal(my_decimal *) override;
1010  enum Item_result result_type() const override { return hybrid_type; }
1011  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
1012  Window_evaluation_requirements *reqs) override;
1013  void reset_field() override;
1014  void update_field() override;
1015  void no_rows_in_result() override {}
1016  const char *func_name() const override { return "sum"; }
1017  Item *copy_or_same(THD *thd) override;
1018 };
1019 
1022 
1023  friend class Aggregator_distinct;
1024 
1025  void clear() override;
1026  bool add() override;
1027  void cleanup() override;
1028 
1029  public:
1030  Item_sum_count(const POS &pos, Item *item_par, PT_window *w)
1031  : Item_sum_int(pos, item_par, w), count(0) {}
1032 
1033  /**
1034  Constructs an instance for COUNT(DISTINCT)
1035 
1036  @param pos Position of token in the parser.
1037  @param list A list of the arguments to the aggregate function
1038  @param w A window, if COUNT is used as a windowing function
1039 
1040  This constructor is called by the parser only for COUNT (DISTINCT).
1041  */
1042 
1044  : Item_sum_int(pos, list, w), count(0) {
1045  set_distinct(true);
1046  }
1048  : Item_sum_int(thd, item), count(item->count) {}
1049  enum Sumfunctype sum_func() const override {
1051  }
1052  bool resolve_type(THD *) override {
1053  maybe_null = false;
1054  null_value = false;
1055  return false;
1056  }
1057  void no_rows_in_result() override { count = 0; }
1058  void make_const(longlong count_arg) {
1059  count = count_arg;
1061  }
1062  longlong val_int() override;
1063  void reset_field() override;
1064  void update_field() override;
1065  const char *func_name() const override { return "count"; }
1066  Item *copy_or_same(THD *thd) override;
1067 };
1068 
1069 /* Item to get the value of a stored sum function */
1070 
1071 class Item_sum_avg;
1072 class Item_sum_bit;
1073 
1074 /**
1075  This is used in connection which a parent Item_sum:
1076  - which can produce different result types (is "hybrid")
1077  - which stores function's value into a temporary table's column (one
1078  row per group).
1079  - which stores in the column some internal piece of information which should
1080  not be returned to the user, so special implementations are needed.
1081 */
1083  protected:
1084  /// The tmp table's column containing the value of the set function.
1086  /// Stores the Item's result type.
1088 
1089  public:
1090  enum Item_result result_type() const override { return hybrid_type; }
1091  bool mark_field_in_map(uchar *arg) override {
1092  /*
1093  Filesort (find_all_keys) over a temporary table collects the columns it
1094  needs.
1095  */
1096  return Item::mark_field_in_map(pointer_cast<Mark_field *>(arg), field);
1097  }
1100  pointer_cast<Check_function_as_value_generator_parameters *>(args);
1101  func_arg->banned_function_name = func_name();
1102  return true;
1103  }
1104 };
1105 
1106 /**
1107  Common abstract class for:
1108  Item_avg_field
1109  Item_variance_field
1110 */
1112  public:
1113  longlong val_int() override {
1114  /* can't be fix_fields()ed */
1116  }
1117  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1118  return get_date_from_numeric(ltime, fuzzydate); /* Decimal or real */
1119  }
1120  bool get_time(MYSQL_TIME *ltime) override {
1121  return get_time_from_numeric(ltime); /* Decimal or real */
1122  }
1123  bool is_null() override {
1124  /*
1125  TODO : Implement error handling for this function as
1126  update_null_value() can return error.
1127  */
1128  (void)update_null_value();
1129  return null_value;
1130  }
1131 };
1132 
1134  public:
1137  Item_avg_field(Item_result res_type, Item_sum_avg *item);
1138  enum Type type() const override { return FIELD_AVG_ITEM; }
1139  double val_real() override;
1140  my_decimal *val_decimal(my_decimal *) override;
1141  String *val_str(String *) override;
1142  bool resolve_type(THD *) override { return false; }
1143  const char *func_name() const override {
1144  DBUG_ASSERT(0);
1145  return "avg_field";
1146  }
1147 };
1148 
1149 /// This is used in connection with an Item_sum_bit, @see Item_sum_hybrid_field
1151  protected:
1153 
1154  public:
1157  longlong val_int() override;
1158  double val_real() override;
1159  my_decimal *val_decimal(my_decimal *) override;
1160  String *val_str(String *) override;
1161  bool resolve_type(THD *) override { return false; }
1162  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1163  bool get_time(MYSQL_TIME *ltime) override;
1164  enum Type type() const override { return FIELD_BIT_ITEM; }
1165  const char *func_name() const override {
1166  DBUG_ASSERT(0);
1167  return "sum_bit_field";
1168  }
1169 };
1170 
1171 /// Common abstraction for Item_sum_json_array and Item_sum_json_object
1172 class Item_sum_json : public Item_sum {
1173  typedef Item_sum super;
1174 
1175  protected:
1176  /// String used when reading JSON binary values or JSON text values.
1178  /// String used for converting JSON text values to utf8mb4 charset.
1180  /// Wrapper around the container (object/array) which accumulates the value.
1182 
1183  /**
1184  Construct an Item_sum_json instance.
1185 
1186  @param wrapper a wrapper around the Json_array or Json_object that contains
1187  the aggregated result
1188  @param parent_args arguments to forward to Item_sum's constructor
1189  */
1190  template <typename... Args>
1192  Args &&... parent_args);
1193 
1194  public:
1195  ~Item_sum_json() override;
1196  bool fix_fields(THD *thd, Item **pItem) override;
1197  enum Sumfunctype sum_func() const override { return JSON_AGG_FUNC; }
1198  Item_result result_type() const override { return STRING_RESULT; }
1199 
1200  double val_real() override;
1201  longlong val_int() override;
1202  String *val_str(String *str) override;
1203  bool val_json(Json_wrapper *wr) override;
1204  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
1205  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1206  bool get_time(MYSQL_TIME *ltime) override;
1207 
1208  void reset_field() override;
1209  void update_field() override;
1210 
1211  bool check_wf_semantics(THD *thd MY_ATTRIBUTE((unused)),
1212  SELECT_LEX *select MY_ATTRIBUTE((unused)),
1214  MY_ATTRIBUTE((unused))) override;
1215 };
1216 
1217 /// Implements aggregation of values into an array.
1219  /// Accumulates the final value.
1221 
1222  public:
1223  Item_sum_json_array(THD *thd, Item_sum *item,
1226  Item_sum_json_array(const POS &pos, Item *a, PT_window *w,
1229  ~Item_sum_json_array() override;
1230  const char *func_name() const override { return "json_arrayagg"; }
1231  void clear() override;
1232  bool add() override;
1233  Item *copy_or_same(THD *thd) override;
1234 };
1235 
1236 /// Implements aggregation of values into an object.
1238  /// Accumulates the final value.
1240  /// Buffer used to get the value of the key.
1242  /**
1243  Map of keys in Json_object and the count for each key
1244  within a window frame. It is used in handling rows
1245  leaving a window frame when rows are not sorted
1246  according to the key in Json_object.
1247  */
1248  std::map<std::string, int> m_key_map;
1249  /**
1250  If window provides ordering on the key in Json_object,
1251  a key_map is not needed to handle rows leaving a window
1252  frame. In this case, process_buffered_windowing_record()
1253  will set flags when a key/value pair can be removed from
1254  the Json_object.
1255  */
1256  bool m_optimize{false};
1257 
1258  public:
1259  Item_sum_json_object(THD *thd, Item_sum *item,
1262  Item_sum_json_object(const POS &pos, Item *a, Item *b, PT_window *w,
1265  ~Item_sum_json_object() override;
1266  const char *func_name() const override { return "json_objectagg"; }
1267  void clear() override;
1268  bool add() override;
1269  Item *copy_or_same(THD *thd) override;
1270  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
1271  Window_evaluation_requirements *reqs) override;
1272 };
1273 
1275  public:
1280  double m_avg;
1281 
1282  Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
1283  : Item_sum_sum(pos, item_par, distinct, w) {}
1284 
1286  : Item_sum_sum(thd, item), prec_increment(item->prec_increment) {}
1287 
1288  bool resolve_type(THD *thd) override;
1289  enum Sumfunctype sum_func() const override {
1291  }
1292  void clear() override;
1293  bool add() override;
1294  double val_real() override;
1295  // In SPs we might force the "wrong" type with select into a declare variable
1297  my_decimal *val_decimal(my_decimal *) override;
1298  String *val_str(String *str) override;
1299  void reset_field() override;
1300  void update_field() override;
1301  Item *result_item(Field *) override {
1302  return new Item_avg_field(hybrid_type, this);
1303  }
1304  void no_rows_in_result() override {}
1305  const char *func_name() const override { return "avg"; }
1306  Item *copy_or_same(THD *thd) override;
1307  Field *create_tmp_field(bool group, TABLE *table) override;
1308  void cleanup() override {
1309  m_count = 0;
1310  m_frame_null_count = 0;
1312  }
1313 };
1314 
1315 class Item_sum_variance;
1316 
1318  protected:
1320 
1321  public:
1323  enum Type type() const override { return FIELD_VARIANCE_ITEM; }
1324  double val_real() override;
1325  String *val_str(String *str) override { return val_string_from_real(str); }
1326  my_decimal *val_decimal(my_decimal *dec_buf) override {
1327  return val_decimal_from_real(dec_buf);
1328  }
1329  bool resolve_type(THD *) override { return false; }
1330  const char *func_name() const override {
1331  DBUG_ASSERT(0);
1332  return "variance_field";
1333  }
1336  pointer_cast<Check_function_as_value_generator_parameters *>(args);
1337  func_arg->err_code = func_arg->get_unnamed_function_error_code();
1338  return true;
1339  }
1340 };
1341 
1342 /*
1343  variance(a) =
1344 
1345  = sum (ai - avg(a))^2 / count(a) )
1346  = sum (ai^2 - 2*ai*avg(a) + avg(a)^2) / count(a)
1347  = (sum(ai^2) - sum(2*ai*avg(a)) + sum(avg(a)^2))/count(a) =
1348  = (sum(ai^2) - 2*avg(a)*sum(a) + count(a)*avg(a)^2)/count(a) =
1349  = (sum(ai^2) - 2*sum(a)*sum(a)/count(a) + count(a)*sum(a)^2/count(a)^2
1350  )/count(a) = = (sum(ai^2) - 2*sum(a)^2/count(a) + sum(a)^2/count(a)
1351  )/count(a) = = (sum(ai^2) - sum(a)^2/count(a))/count(a)
1352 
1353  But, this falls prey to catastrophic cancellation.
1354  Instead, we use recurrence formulas in Algorithm I mentoned below
1355  for group aggregates.
1356 
1357  Algorithm I:
1358  M_{1} = x_{1}, ~ M_{k} = M_{k-1} + (x_{k} - M_{k-1}) / k newline
1359  S_{1} = 0, ~ S_{k} = S_{k-1} + (x_{k} - M_{k-1}) times (x_{k} - M_{k}) newline
1360  for 2 <= k <= n newline
1361  ital variance = S_{n} / (n-1)
1362 
1363  For aggregate window functions algorithm I cannot be optimized for
1364  moving frames since M_{i} changes for every row. So we use the
1365  following algorithm.
1366 
1367  Algorithm II:
1368 
1369  K = 0
1370  n = 0
1371  ex = 0
1372  ex2 = 0
1373 
1374  def add_sample(x):
1375  if (n == 0):
1376  K = x
1377  n = n + 1
1378  ex += x - K
1379  ex2 += (x - K) * (x - K)
1380 
1381  def remove_sample(x):
1382  n = n - 1
1383  ex -= (x - K)
1384  ex2 -= (x - K) * (x - K)
1385 
1386  def variance():
1387  return (ex2 - (ex*ex)/n) / (n-1)
1388 
1389  This formula facilitates incremental computation enabling us to
1390  optimize in case of moving window frames. The optimized codepath is taken
1391  only when windowing_use_high_precision is set to false. By default,
1392  aggregate window functions take the non-optimized codepath.
1393  Note:
1394  Results could differ between optimized and non-optimized code path.
1395  Hence algorithm II is used only when user sets
1396  windowing_use_high_precision to false.
1397 */
1398 
1400  bool resolve_type(THD *) override;
1401 
1402  public:
1404  /**
1405  Used in recurrence relation.
1406  */
1412  /**
1413  If set, uses a algorithm II mentioned in the class description
1414  to calculate the variance which helps in optimizing windowing
1415  functions in presence of frames.
1416  */
1417  bool optimize;
1418 
1419  Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg,
1420  PT_window *w)
1421  : Item_sum_num(pos, item_par, w),
1423  count(0),
1424  sample(sample_arg),
1425  optimize(false) {}
1426 
1428  enum Sumfunctype sum_func() const override { return VARIANCE_FUNC; }
1429  void clear() override;
1430  bool add() override;
1431  double val_real() override;
1432  my_decimal *val_decimal(my_decimal *) override;
1433  void reset_field() override;
1434  void update_field() override;
1435  Item *result_item(Field *) override { return new Item_variance_field(this); }
1436  void no_rows_in_result() override {}
1437  const char *func_name() const override {
1438  return sample ? "var_samp" : "variance";
1439  }
1440  Item *copy_or_same(THD *thd) override;
1441  Field *create_tmp_field(bool group, TABLE *table) override;
1442  enum Item_result result_type() const override { return REAL_RESULT; }
1443  void cleanup() override {
1444  count = 0;
1446  }
1447  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
1448  Window_evaluation_requirements *reqs) override;
1449 };
1450 
1451 class Item_sum_std;
1452 
1454  public:
1456  enum Type type() const override { return FIELD_STD_ITEM; }
1457  double val_real() override;
1458  my_decimal *val_decimal(my_decimal *) override;
1459  enum Item_result result_type() const override { return REAL_RESULT; }
1460  const char *func_name() const override {
1461  DBUG_ASSERT(0);
1462  return "std_field";
1463  }
1466  pointer_cast<Check_function_as_value_generator_parameters *>(args);
1467  func_arg->err_code = func_arg->get_unnamed_function_error_code();
1468  return true;
1469  }
1470 };
1471 
1472 /*
1473  standard_deviation(a) = sqrt(variance(a))
1474 */
1475 
1477  public:
1478  Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
1479  : Item_sum_variance(pos, item_par, sample_arg, w) {}
1480 
1481  Item_sum_std(THD *thd, Item_sum_std *item) : Item_sum_variance(thd, item) {}
1482  enum Sumfunctype sum_func() const override { return STD_FUNC; }
1483  double val_real() override;
1484  Item *result_item(Field *) override { return new Item_std_field(this); }
1485  const char *func_name() const override {
1486  return sample ? "stddev_samp" : "std";
1487  }
1488  Item *copy_or_same(THD *thd) override;
1489  enum Item_result result_type() const override { return REAL_RESULT; }
1490 };
1491 
1492 // This class is a string or number function depending on num_func
1493 class Arg_comparator;
1494 
1495 /**
1496  Abstract base class for the MIN and MAX aggregate functions.
1497 */
1498 class Item_sum_hybrid : public Item_sum {
1499  typedef Item_sum super;
1500 
1501  private:
1502  /**
1503  Tells if this is the MIN function (true) or the MAX function (false).
1504  */
1505  const bool m_is_min;
1506  /*
1507  For window functions MIN/MAX with optimized code path, no comparisons
1508  are needed beyond NULL detection: MIN/MAX are then roughly equivalent to
1509  FIRST/LAST_VALUE. For this case, 'value' is the value of
1510  the window function a priori taken from args[0], while arg_cache is used to
1511  remember the value from the previous row. NULLs need a bit of careful
1512  treatment.
1513  */
1517  bool was_values; // Set if we have found at least one row (for max/min only)
1518  /**
1519  Set to true if the window is ordered ascending.
1520  */
1522  /**
1523  Set to true when min/max can be optimized using window's ordering.
1524  */
1526  /**
1527  For min() - Set to true when results are ordered in ascending and
1528  false when descending.
1529  For max() - Set to true when results are ordered in descending and
1530  false when ascending.
1531  Valid only when m_optimize is true.
1532  */
1533  bool m_want_first; ///< Want first non-null value, else last non_null value
1534  /**
1535  Execution state: keeps track if this is the first row in the frame
1536  when buffering is not needed.
1537  Valid only when m_optimize is true.
1538  */
1540 
1541  /**
1542  Execution state: keeps track of at which row we saved a non-null last
1543  value.
1544  */
1546 
1547  /**
1548  This function implements the optimized version of retrieving min/max
1549  value. When we have "ordered ASC" results in a window, min will always
1550  be the first value in the result set (neglecting the NULL's) and max
1551  will always be the last value (or the other way around, if ordered DESC).
1552  It is based on the implementation of FIRST_VALUE/LAST_VALUE, except for
1553  the NULL handling.
1554 
1555  @return true if computation yielded a NULL or error
1556  */
1557  bool compute();
1558 
1559  /**
1560  MIN/MAX function setup.
1561 
1562  Setup cache/comparator of MIN/MAX functions. When called by the
1563  copy_or_same() function, the value_arg parameter contains the calculated
1564  value of the original MIN/MAX object, and it is saved in this object's
1565  cache.
1566 
1567  @param item the argument of the MIN/MAX function
1568  @param value_arg the calculated value of the MIN/MAX function
1569  @return false on success, true on error
1570  */
1571  bool setup_hybrid(Item *item, Item *value_arg);
1572 
1573  /** Create a clone of this object. */
1574  virtual Item_sum_hybrid *clone_hybrid(THD *thd) const = 0;
1575 
1576  protected:
1577  Item_sum_hybrid(Item *item_par, bool is_min)
1578  : Item_sum(item_par),
1579  m_is_min(is_min),
1580  value(0),
1581  arg_cache(0),
1582  cmp(0),
1584  was_values(true),
1586  m_optimize(false),
1588  m_cnt(0),
1591  }
1592 
1593  Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
1594  : Item_sum(pos, item_par, w),
1595  m_is_min(is_min),
1596  value(0),
1597  arg_cache(0),
1598  cmp(0),
1600  was_values(true),
1602  m_optimize(false),
1604  m_cnt(0),
1607  }
1608 
1610  : Item_sum(thd, item),
1611  m_is_min(item->m_is_min),
1612  value(item->value),
1613  arg_cache(0),
1614  hybrid_type(item->hybrid_type),
1615  was_values(item->was_values),
1617  m_optimize(item->m_optimize),
1618  m_want_first(item->m_want_first),
1619  m_cnt(item->m_cnt),
1620  m_saved_last_value_at(0) {}
1621 
1622  public:
1623  bool fix_fields(THD *, Item **) override;
1624  void clear() override;
1625  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
1626  List<Item> &fields) override;
1627  double val_real() override;
1628  longlong val_int() override;
1629  longlong val_time_temporal() override;
1630  longlong val_date_temporal() override;
1631  my_decimal *val_decimal(my_decimal *) override;
1632  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1633  bool get_time(MYSQL_TIME *ltime) override;
1634  void reset_field() override;
1635  String *val_str(String *) override;
1636  bool val_json(Json_wrapper *wr) override;
1637  bool keep_field_type() const override { return true; }
1638  enum Item_result result_type() const override { return hybrid_type; }
1639  void update_field() override;
1640  void cleanup() override;
1641  bool any_value() { return was_values; }
1642  void no_rows_in_result() override;
1643  Field *create_tmp_field(bool group, TABLE *table) override;
1644  bool uses_only_one_row() const override { return m_optimize; }
1645  bool add() override;
1646  Item *copy_or_same(THD *thd) override;
1647  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
1648  Window_evaluation_requirements *r) override;
1649 
1650  private:
1651  /*
1652  These functions check if the value on the current row exceeds the maximum or
1653  minimum value seen so far, and update the current max/min stored in
1654  result_field, if needed.
1655  */
1656  void min_max_update_str_field();
1660  void min_max_update_int_field();
1662 };
1663 
1665  public:
1666  Item_sum_min(Item *item_par) : Item_sum_hybrid(item_par, true) {}
1667  Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
1668  : Item_sum_hybrid(pos, item_par, true, w) {}
1669  Item_sum_min(THD *thd, const Item_sum_min *item)
1670  : Item_sum_hybrid(thd, item) {}
1671  enum Sumfunctype sum_func() const override { return MIN_FUNC; }
1672  const char *func_name() const override { return "min"; }
1673 
1674  private:
1675  Item_sum_min *clone_hybrid(THD *thd) const override;
1676 };
1677 
1679  public:
1680  Item_sum_max(Item *item_par) : Item_sum_hybrid(item_par, false) {}
1681  Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
1682  : Item_sum_hybrid(pos, item_par, false, w) {}
1683  Item_sum_max(THD *thd, const Item_sum_max *item)
1684  : Item_sum_hybrid(thd, item) {}
1685  enum Sumfunctype sum_func() const override { return MAX_FUNC; }
1686  const char *func_name() const override { return "max"; }
1687 
1688  private:
1689  Item_sum_max *clone_hybrid(THD *thd) const override;
1690 };
1691 
1692 /**
1693  Base class used to implement BIT_AND, BIT_OR and BIT_XOR.
1694 
1695  Each of them is both a set function and a framing window function.
1696 */
1697 class Item_sum_bit : public Item_sum {
1698  typedef Item_sum super;
1699  /// Stores the neutral element for function
1701  /// Stores the result value for the INT_RESULT
1703  /// Stores the result value for the STRING_RESULT
1705  /// Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT
1707  /// Buffer used to avoid String allocation in the constructor
1708  const char initial_value_buff_storage[1] = {0};
1709 
1710  /**
1711  Execution state (windowing): this is for counting rows entering and leaving
1712  the window frame, see #m_frame_null_count.
1713  */
1715 
1716  /**
1717  Execution state (windowing): this is for counting NULLs of rows entering
1718  and leaving the window frame, when we use optimized inverse-based
1719  computations. By comparison with m_count we can know how many non-NULLs are
1720  in the frame.
1721  */
1723 
1724  /**
1725  Execution state (windowing): Used for AND, OR to be able to invert window
1726  functions in optimized mode.
1727 
1728  For the optimized code path of BIT_XXX wfs, we keep track of the number of
1729  bit values (0's or 1's; see below) seen in a frame using a 64 bits counter
1730  pr bit. This lets us compute the value of OR by just inspecting:
1731 
1732  - the number of 1's in the previous frame
1733  - whether any removed row(s) is a 1
1734  - whether any added row(s) is a 1
1735 
1736  Similarly for AND, we keep track of the number of 0's seen for a particular
1737  bit. To do this trick we need a counter per bit position. This array holds
1738  these counters.
1739 
1740  Note that for XOR, the inverse operation is identical to the operation,
1741  so we don't need the above.
1742  */
1744  /*
1745  Size of allocated array m_digit_cnt.
1746  The size is DIGIT_CNT_CARD (for integer types) or ::max_length * 8 for bit
1747  strings.
1748  */
1750 
1751  static constexpr uint DIGIT_CNT_CARD = sizeof(ulonglong) * 8;
1752 
1753  protected:
1754  bool m_is_xor; ///< true iff BIT_XOR
1755 
1756  public:
1757  Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg,
1758  PT_window *w)
1759  : Item_sum(pos, item_par, w),
1760  reset_bits(reset_arg),
1761  bits(reset_arg),
1763  m_count(0),
1764  m_frame_null_count(0),
1765  m_digit_cnt(nullptr),
1766  m_digit_cnt_card(0),
1767  m_is_xor(false) {}
1768 
1769  /// Copy constructor, used for executing subqueries with temporary tables
1771  : Item_sum(thd, item),
1772  reset_bits(item->reset_bits),
1773  bits(item->bits),
1775  hybrid_type(item->hybrid_type),
1776  m_count(item->m_count),
1778  m_digit_cnt(nullptr),
1779  m_digit_cnt_card(0),
1780  m_is_xor(item->m_is_xor) {
1781  /*
1782  This constructor should only be called during the Optimize stage.
1783  Asserting that the item was not evaluated yet.
1784  */
1785  DBUG_ASSERT(item->value_buff.length() == 1);
1786  DBUG_ASSERT(item->bits == item->reset_bits);
1787  }
1788 
1789  Item *result_item(Field *) override {
1790  return new Item_sum_bit_field(hybrid_type, this, reset_bits);
1791  }
1792 
1793  enum Sumfunctype sum_func() const override { return SUM_BIT_FUNC; }
1794  enum Item_result result_type() const override { return hybrid_type; }
1795  void clear() override;
1796  longlong val_int() override;
1797  double val_real() override;
1798  String *val_str(String *str) override;
1799  my_decimal *val_decimal(my_decimal *decimal_value) override;
1800  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1801  bool get_time(MYSQL_TIME *ltime) override;
1802  void reset_field() override;
1803  void update_field() override;
1804  bool resolve_type(THD *) override;
1805  bool fix_fields(THD *thd, Item **ref) override;
1806  void cleanup() override {
1807  bits = reset_bits;
1808  // At end of one execution of statement, free buffer to reclaim memory:
1811  }
1812 
1813  /**
1814  Common implementation of Item_sum_or::add, Item_sum_and:add
1815  and Item_sum_xor::add.
1816  */
1817  bool add() override;
1818  /// @returns true iff this is BIT_AND.
1819  inline bool is_and() const { return reset_bits != 0; }
1820 
1821  private:
1822  /**
1823  Accumulate the value of 's1' (if in string mode) or of 'b1' (if in integer
1824  mode). Updates 'value_buff' or 'bits'.
1825 
1826  @param s1 argument to accumulate
1827  @param b1 argument to accumulate
1828 
1829  @returns true if error
1830  */
1831  bool add_bits(const String *s1, ulonglong b1);
1832 
1833  /**
1834  For windowing: perform inverse aggregation. "De-accumulate" the value of
1835  's1' (if in string mode) or of 'b1' (if in integer mode). Updates
1836  'value_buff' or 'bits'.
1837 
1838  For BIT_XOR we simply apply XOR as it's its inverse operation. For BIT_OR
1839  and BIT_AND we do the rest below.
1840 
1841  For each bit in argument, decrement the corresponding bits's counter
1842  ('m_digit_cnt') for that bit as follows: for BIT_AND, decrement the
1843  counter if we see a zero in that bit; for BIT_OR decrement the counter if
1844  we see a 1 in that bit. Next, update 'value_buff' or 'bits' using the
1845  resulting counters: for each bit, for BIT_AND, set bit if we have counter
1846  == 0, i.e. we have no zero bits for that bit in the frame (yet). For
1847  BIT_OR, set bit if we have counter > 0, i.e. at least one row in the frame
1848  has that bit set.
1849 
1850  @param s1 the bits to be inverted from the aggregate value
1851  @param b1 the bits to be inverted from the aggregate value
1852  */
1853  void remove_bits(const String *s1, ulonglong b1);
1854 };
1855 
1857  public:
1858  Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
1859  : Item_sum_bit(pos, item_par, 0LL, w) {}
1860 
1861  Item_sum_or(THD *thd, Item_sum_or *item) : Item_sum_bit(thd, item) {}
1862  const char *func_name() const override { return "bit_or"; }
1863  Item *copy_or_same(THD *thd) override;
1864 };
1865 
1867  public:
1868  Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
1869  : Item_sum_bit(pos, item_par, ULLONG_MAX, w) {}
1870 
1871  Item_sum_and(THD *thd, Item_sum_and *item) : Item_sum_bit(thd, item) {}
1872  const char *func_name() const override { return "bit_and"; }
1873  Item *copy_or_same(THD *thd) override;
1874 };
1875 
1877  public:
1878  Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
1879  : Item_sum_bit(pos, item_par, 0LL, w) {
1880  m_is_xor = true;
1881  }
1882 
1883  Item_sum_xor(THD *thd, Item_sum_xor *item) : Item_sum_bit(thd, item) {}
1884  const char *func_name() const override { return "bit_xor"; }
1885  Item *copy_or_same(THD *thd) override;
1886 };
1887 
1888 /*
1889  User defined aggregates
1890 */
1891 
1892 class Item_udf_sum : public Item_sum {
1893  typedef Item_sum super;
1894 
1895  protected:
1897 
1898  public:
1899  Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1900  : Item_sum(pos, opt_list, NULL), udf(udf_arg) {
1902  }
1904  : Item_sum(thd, item), udf(item->udf) {
1905  udf.not_original = true;
1906  }
1907 
1908  bool itemize(Parse_context *pc, Item **res) override;
1909  const char *func_name() const override { return udf.name(); }
1910  bool fix_fields(THD *thd, Item **ref) override {
1911  DBUG_ASSERT(fixed == 0);
1912 
1913  if (init_sum_func_check(thd)) return true;
1914 
1915  fixed = true;
1916  if (udf.fix_fields(thd, this, this->arg_count, this->args)) return true;
1917 
1918  return check_sum_func(thd, ref);
1919  }
1920  enum Sumfunctype sum_func() const override { return UDF_SUM_FUNC; }
1921 
1922  void clear() override;
1923  bool add() override;
1924  void reset_field() override {}
1925  void update_field() override {}
1926  void cleanup() override;
1927  void print(const THD *thd, String *str,
1928  enum_query_type query_type) const override;
1929 };
1930 
1932  public:
1933  Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1934  : Item_udf_sum(pos, udf_arg, opt_list) {}
1936  : Item_udf_sum(thd, item) {}
1937  longlong val_int() override {
1938  DBUG_ASSERT(fixed == 1);
1939  return (longlong)rint(Item_sum_udf_float::val_real());
1940  }
1941  double val_real() override;
1942  String *val_str(String *str) override;
1943  my_decimal *val_decimal(my_decimal *) override;
1944  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1945  return get_date_from_real(ltime, fuzzydate);
1946  }
1947  bool get_time(MYSQL_TIME *ltime) override {
1948  return get_time_from_real(ltime);
1949  }
1950  bool resolve_type(THD *) override {
1953  return false;
1954  }
1955  Item *copy_or_same(THD *thd) override;
1956 };
1957 
1959  public:
1960  Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1961  : Item_udf_sum(pos, udf_arg, opt_list) {}
1963  : Item_udf_sum(thd, item) {}
1964  longlong val_int() override;
1965  double val_real() override {
1966  DBUG_ASSERT(fixed == 1);
1967  return (double)Item_sum_udf_int::val_int();
1968  }
1969  String *val_str(String *str) override;
1970  my_decimal *val_decimal(my_decimal *) override;
1971  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1972  return get_date_from_int(ltime, fuzzydate);
1973  }
1974  bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
1975  enum Item_result result_type() const override { return INT_RESULT; }
1976  bool resolve_type(THD *) override {
1978  return false;
1979  }
1980  Item *copy_or_same(THD *thd) override;
1981 };
1982 
1984  public:
1985  Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1986  : Item_udf_sum(pos, udf_arg, opt_list) {}
1988  : Item_udf_sum(thd, item) {}
1989  String *val_str(String *) override;
1990  double val_real() override {
1991  int err_not_used;
1992  const char *end_not_used;
1993  String *res;
1994  res = val_str(&str_value);
1995  return res ? my_strntod(res->charset(), res->ptr(), res->length(),
1996  &end_not_used, &err_not_used)
1997  : 0.0;
1998  }
1999  longlong val_int() override {
2000  int err_not_used;
2001  String *res;
2002  const CHARSET_INFO *cs;
2003 
2004  if (!(res = val_str(&str_value))) return 0; /* Null value */
2005  cs = res->charset();
2006  const char *end = res->ptr() + res->length();
2007  return cs->cset->strtoll10(cs, res->ptr(), &end, &err_not_used);
2008  }
2009  my_decimal *val_decimal(my_decimal *dec) override;
2010  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2011  return get_date_from_string(ltime, fuzzydate);
2012  }
2013  bool get_time(MYSQL_TIME *ltime) override {
2014  return get_time_from_string(ltime);
2015  }
2016  enum Item_result result_type() const override { return STRING_RESULT; }
2017  bool resolve_type(THD *) override;
2018  Item *copy_or_same(THD *thd) override;
2019 };
2020 
2022  public:
2024  PT_item_list *opt_list)
2025  : Item_udf_sum(pos, udf_arg, opt_list) {}
2027  : Item_udf_sum(thd, item) {}
2028  String *val_str(String *) override;
2029  double val_real() override;
2030  longlong val_int() override;
2031  my_decimal *val_decimal(my_decimal *) override;
2032  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2033  return get_date_from_decimal(ltime, fuzzydate);
2034  }
2035  bool get_time(MYSQL_TIME *ltime) override {
2036  return get_time_from_decimal(ltime);
2037  }
2038  enum Item_result result_type() const override { return DECIMAL_RESULT; }
2039  bool resolve_type(THD *) override {
2042  return false;
2043  }
2044  Item *copy_or_same(THD *thd) override;
2045 };
2046 
2047 int group_concat_key_cmp_with_distinct(const void *arg, const void *key1,
2048  const void *key2);
2049 int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2050  const void *key2);
2051 int dump_leaf_key(void *key_arg, element_count count MY_ATTRIBUTE((unused)),
2052  void *item_arg);
2053 
2055  typedef Item_sum super;
2056 
2062 
2063  /**
2064  If DISTINCT is used with this GROUP_CONCAT, this member is used to filter
2065  out duplicates.
2066  @see Item_func_group_concat::setup
2067  @see Item_func_group_concat::add
2068  @see Item_func_group_concat::clear
2069  */
2074  /** The number of ORDER BY items. */
2076  /** The number of selected items, aka the expr list. */
2079  /** The maximum permitted result length in bytes as set for
2080  group_concat_max_len system variable */
2082  bool distinct;
2086  /** True if result has been written to output buffer. */
2088  /*
2089  Following is 0 normal object and pointer to original one for copy
2090  (to correctly free resources)
2091  */
2093 
2094  friend int group_concat_key_cmp_with_distinct(const void *arg,
2095  const void *key1,
2096  const void *key2);
2097  friend int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2098  const void *key2);
2099  friend int dump_leaf_key(void *key_arg,
2100  element_count count MY_ATTRIBUTE((unused)),
2101  void *item_arg);
2102 
2103  public:
2104  Item_func_group_concat(const POS &pos, bool is_distinct,
2105  PT_item_list *select_list,
2106  PT_order_list *opt_order_list, String *separator,
2107  PT_window *w);
2108 
2110  ~Item_func_group_concat() override;
2111 
2112  bool itemize(Parse_context *pc, Item **res) override;
2113  void cleanup() override;
2114 
2115  enum Sumfunctype sum_func() const override { return GROUP_CONCAT_FUNC; }
2116  const char *func_name() const override { return "group_concat"; }
2117  Item_result result_type() const override { return STRING_RESULT; }
2118  Field *make_string_field(TABLE *table_arg) override;
2119  void clear() override;
2120  bool add() override;
2121  void reset_field() override { DBUG_ASSERT(0); } // not used
2122  void update_field() override { DBUG_ASSERT(0); } // not used
2123  bool fix_fields(THD *, Item **) override;
2124  bool setup(THD *thd) override;
2125  void make_unique() override;
2126  double val_real() override {
2127  String *res;
2128  res = val_str(&str_value);
2129  return res ? my_atof(res->c_ptr()) : 0.0;
2130  }
2131  longlong val_int() override {
2132  String *res;
2133  int error;
2134  if (!(res = val_str(&str_value))) return (longlong)0;
2135  const char *end_ptr = res->ptr() + res->length();
2136  return my_strtoll10(res->ptr(), &end_ptr, &error);
2137  }
2138  my_decimal *val_decimal(my_decimal *decimal_value) override {
2139  return val_decimal_from_string(decimal_value);
2140  }
2141  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2142  return get_date_from_string(ltime, fuzzydate);
2143  }
2144  bool get_time(MYSQL_TIME *ltime) override {
2145  return get_time_from_string(ltime);
2146  }
2147  String *val_str(String *str) override;
2148  Item *copy_or_same(THD *thd) override;
2149  void no_rows_in_result() override {}
2150  void print(const THD *thd, String *str,
2151  enum_query_type query_type) const override;
2152  bool change_context_processor(uchar *cntx) override {
2153  context = reinterpret_cast<Name_resolution_context *>(cntx);
2154  return false;
2155  }
2156 
2157  bool check_wf_semantics(THD *thd MY_ATTRIBUTE((unused)),
2158  SELECT_LEX *select MY_ATTRIBUTE((unused)),
2160  MY_ATTRIBUTE((unused))) override {
2162  return true;
2163  }
2164 };
2165 
2166 /**
2167  Common parent class for window functions that always work on the entire
2168  partition, even if a frame is defined.
2169 
2170  The subclasses can be divided in two disjoint sub-categories:
2171  - one-pass
2172  - two-pass (requires partition cardinality to be evaluated)
2173  cf. method needs_card.
2174 */
2176  typedef Item_sum super;
2177 
2178  public:
2181  : Item_sum(pos, a, w) {}
2183  : Item_sum(pos, opt_list, w) {}
2185 
2186  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2187  return get_date_from_numeric(ltime, fuzzydate);
2188  }
2189 
2190  bool get_time(MYSQL_TIME *ltime) override {
2191  return get_time_from_numeric(ltime);
2192  }
2193 
2194  void reset_field() override { DBUG_ASSERT(false); }
2195  void update_field() override { DBUG_ASSERT(false); }
2196  bool add() override {
2197  DBUG_ASSERT(false);
2198  return false;
2199  }
2200 
2201  bool fix_fields(THD *thd, Item **items) override;
2202 
2203  bool framing() const override { return false; }
2204 };
2205 
2206 /**
2207  ROW_NUMBER window function, cf. SQL 2003 Section 6.10 <window function>
2208 */
2210  // Execution state variables
2211  ulonglong m_ctr; ///< Increment for each row in partition
2212 
2213  public:
2215  : Item_non_framing_wf(pos, w), m_ctr(0) {
2216  unsigned_flag = true;
2217  }
2218 
2219  const char *func_name() const override { return "row_number"; }
2220  enum Sumfunctype sum_func() const override { return ROW_NUMBER_FUNC; }
2221 
2222  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2224  return false;
2225  }
2226 
2227  longlong val_int() override;
2228  double val_real() override;
2229  my_decimal *val_decimal(my_decimal *buff) override;
2230  String *val_str(String *) override;
2231 
2232  void clear() override;
2233 
2234  Item_result result_type() const override { return INT_RESULT; }
2235 
2236  bool check_wf_semantics(THD *thd MY_ATTRIBUTE((unused)),
2237  SELECT_LEX *select MY_ATTRIBUTE((unused)),
2239  MY_ATTRIBUTE((unused))) override {
2240  return false;
2241  }
2242 };
2243 
2244 /**
2245  RANK or DENSE_RANK window function, cf. SQL 2003 Section 6.10 <window
2246  function>
2247 */
2250  bool m_dense; ///< If true, the object represents DENSE_RANK
2251  // Execution state variables
2252  ulonglong m_rank_ctr; ///< Increment when window order columns change
2253  ulonglong m_duplicates; ///< Needed to make RANK different from DENSE_RANK
2254  List<Cached_item> m_previous; ///< Values of previous row's ORDER BY items
2255  public:
2256  Item_rank(const POS &pos, bool dense, PT_window *w)
2257  : Item_non_framing_wf(pos, w),
2258  m_dense(dense),
2259  m_rank_ctr(0),
2260  m_duplicates(0),
2261  m_previous()
2262 
2263  {
2264  unsigned_flag = true;
2265  }
2266 
2267  const char *func_name() const override {
2268  return m_dense ? "dense_rank" : "rank";
2269  }
2270 
2271  enum Sumfunctype sum_func() const override {
2272  return m_dense ? DENSE_RANK_FUNC : RANK_FUNC;
2273  }
2274 
2275  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2277  return false;
2278  }
2279 
2280  longlong val_int() override;
2281  double val_real() override;
2282  my_decimal *val_decimal(my_decimal *buff) override;
2283  String *val_str(String *) override;
2284 
2285  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2286  Window_evaluation_requirements *reqs) override;
2287  /**
2288  Clear state for a new partition
2289  */
2290  void clear() override;
2291  /**
2292  Cleanup after query, free up resources
2293  */
2294  void cleanup() override;
2295  Item_result result_type() const override { return INT_RESULT; }
2296 };
2297 
2298 /**
2299  CUME_DIST window function, cf. SQL 2003 Section 6.10 <window function>
2300 */
2303 
2304  public:
2306 
2307  const char *func_name() const override { return "cume_dist"; }
2308  enum Sumfunctype sum_func() const override { return CUME_DIST_FUNC; }
2309 
2310  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2312  return false;
2313  }
2314 
2315  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2316  Window_evaluation_requirements *reqs) override;
2317 
2318  bool needs_card() const override { return true; }
2319  void clear() override {}
2320  longlong val_int() override;
2321  double val_real() override;
2322  String *val_str(String *) override;
2324  Item_result result_type() const override { return REAL_RESULT; }
2325 };
2326 
2327 /**
2328  PERCENT_RANK window function, cf. SQL 2003 Section 6.10 <window function>
2329 */
2332  // Execution state variables
2333  ulonglong m_rank_ctr; ///< Increment when window order columns change
2334  ulonglong m_peers; ///< Needed to make PERCENT_RANK same for peers
2335  /**
2336  Set when the last peer has been visited. Needed to increment m_rank_ctr.
2337  */
2339 
2340  public:
2342  : Item_non_framing_wf(pos, w),
2343  m_rank_ctr(0),
2344  m_peers(0),
2346 
2347  const char *func_name() const override { return "percent_rank"; }
2348  enum Sumfunctype sum_func() const override { return PERCENT_RANK_FUNC; }
2349 
2350  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2352  return false;
2353  }
2354 
2355  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2356  Window_evaluation_requirements *reqs) override;
2357  bool needs_card() const override { return true; }
2358 
2359  void clear() override;
2360  void cleanup() override;
2361  longlong val_int() override;
2362  double val_real() override;
2363  String *val_str(String *) override;
2365  Item_result result_type() const override { return REAL_RESULT; }
2366 };
2367 
2368 /**
2369  NTILE window function, cf. SQL 2011 Section 6.10 <window function>
2370 */
2374 
2375  public:
2376  Item_ntile(const POS &pos, Item *a, PT_window *w)
2377  : Item_non_framing_wf(pos, a, w), m_value(0) {
2378  unsigned_flag = true;
2379  }
2380 
2381  const char *func_name() const override { return "ntile"; }
2382  enum Sumfunctype sum_func() const override { return NTILE_FUNC; }
2383 
2384  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2386  return false;
2387  }
2388 
2389  bool fix_fields(THD *thd, Item **items) override;
2390 
2391  longlong val_int() override;
2392  double val_real() override;
2393  my_decimal *val_decimal(my_decimal *buff) override;
2394  String *val_str(String *) override;
2395 
2396  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2397  Window_evaluation_requirements *reqs) override;
2398  Item_result result_type() const override { return INT_RESULT; }
2399  void clear() override {}
2400  bool needs_card() const override { return true; }
2401 };
2402 
2403 /**
2404  LEAD/LAG window functions, cf. SQL 2011 Section 6.10 <window function>
2405 */
2408  bool m_is_lead; ///< if true, the function is LEAD, else LAG
2409  int64 m_n; ///< canonicalized offset value
2413  /**
2414  Execution state: if set, we already have a value for current row.
2415  State is used to avoid interference with other LEAD/LAG functions on
2416  the same window, since they share the same eval loop and they should
2417  trigger evaluation only when they are on the "right" row relative to
2418  current row. For other offsets, return NULL if we don't know the value
2419  for this function yet, or if we do (m_has_value==true), return the
2420  found value.
2421  */
2423  bool m_use_default; ///< execution state: use default value for current row
2425 
2426  public:
2427  Item_lead_lag(const POS &pos, bool lead,
2428  PT_item_list *opt_list, // [0] expr, [1] offset, [2] default
2429  enum_null_treatment null_treatment, PT_window *w)
2430  : Item_non_framing_wf(pos, opt_list, w),
2431  m_null_treatment(null_treatment),
2432  m_is_lead(lead),
2433  m_n(0),
2435  m_value(nullptr),
2436  m_default(nullptr),
2437  m_has_value(false),
2438  m_use_default(false) {}
2439 
2440  const char *func_name() const override {
2441  return (m_is_lead ? "lead" : "lag");
2442  }
2443  enum Sumfunctype sum_func() const override { return LEAD_LAG_FUNC; }
2444 
2445  bool resolve_type(THD *thd) override;
2446  bool fix_fields(THD *thd, Item **items) override;
2447  void clear() override;
2448  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2449  Window_evaluation_requirements *reqs) override;
2450  enum Item_result result_type() const override { return m_hybrid_type; }
2451 
2452  longlong val_int() override;
2453  double val_real() override;
2454  String *val_str(String *str) override;
2455  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2456 
2457  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2458  bool get_time(MYSQL_TIME *ltime) override;
2459  bool val_json(Json_wrapper *wr) override;
2460 
2461  bool needs_card() const override {
2462  /*
2463  A possible optimization here: if LAG, we are only interested in rows we
2464  have already seen, so we might compute the result without reading the
2465  entire partition as soon as we have the current row. Similarly, a small
2466  LEAD value might avoid reading the entire partition also, giving shorter
2467  time to first result. For now, we read the entirely partition for these
2468  window functions - for simplicity.
2469  */
2470  return true;
2471  }
2472 
2473  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2474  List<Item> &fields) override;
2475 
2477  bool has_value() const { return m_has_value; }
2478 
2480  bool use_default() const { return m_use_default; }
2481 
2482  private:
2483  bool setup_lead_lag();
2484  /**
2485  Core logic of LEAD/LAG window functions
2486 
2487  @return true if computation yielded a NULL or error
2488  */
2489  bool compute();
2490 };
2491 
2492 /**
2493  FIRST_VALUE/LAST_VALUE window functions, cf. SQL 2011 Section 6.10 <window
2494  function>
2495 */
2497  bool m_is_first; ///< if true, the function is FIRST_VALUE, else LAST_VALUE
2501  int64 cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2502  typedef Item_sum super;
2503 
2504  public:
2505  Item_first_last_value(const POS &pos, bool first, Item *a,
2506  enum_null_treatment null_treatment, PT_window *w)
2507  : Item_sum(pos, a, w),
2508  m_is_first(first),
2509  m_null_treatment(null_treatment),
2511  m_value(nullptr),
2512  cnt(0) {}
2513 
2514  const char *func_name() const override {
2515  return m_is_first ? "first_value" : "last_value";
2516  }
2517 
2518  enum Sumfunctype sum_func() const override { return FIRST_LAST_VALUE_FUNC; }
2519 
2520  bool resolve_type(THD *thd) override;
2521  bool fix_fields(THD *thd, Item **items) override;
2522  void clear() override;
2523  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2524  Window_evaluation_requirements *reqs) override;
2525  enum Item_result result_type() const override { return m_hybrid_type; }
2526 
2527  longlong val_int() override;
2528  double val_real() override;
2529  String *val_str(String *str) override;
2530  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2531 
2532  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2533  bool get_time(MYSQL_TIME *ltime) override;
2534  bool val_json(Json_wrapper *wr) override;
2535 
2536  void reset_field() override { DBUG_ASSERT(false); }
2537  void update_field() override { DBUG_ASSERT(false); }
2538  bool add() override {
2539  DBUG_ASSERT(false);
2540  return false;
2541  }
2542 
2543  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2544  List<Item> &fields) override;
2545  bool uses_only_one_row() const override { return true; }
2546 
2547  private:
2548  bool setup_first_last();
2549  /**
2550  Core logic of FIRST/LAST_VALUE window functions
2551 
2552  @return true if computation yielded a NULL or error
2553  */
2554  bool compute();
2555 };
2556 
2557 /**
2558  NTH_VALUE window function, cf. SQL 2011 Section 6.10 <window
2559  function>
2560 */
2561 class Item_nth_value : public Item_sum {
2563  int64 m_n; ///< The N of the function
2564  bool m_from_last; ///< true iff FROM_LAST was specified
2568  int64 m_cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2569 
2570  typedef Item_sum super;
2571 
2572  public:
2573  Item_nth_value(const POS &pos, PT_item_list *a, bool from_last,
2574  enum_null_treatment null_treatment, PT_window *w)
2575  : Item_sum(pos, a, w),
2576  m_null_treatment(null_treatment),
2577  m_n(0),
2578  m_from_last(from_last),
2580  m_value(nullptr),
2581  m_cnt(0) {}
2582 
2583  const char *func_name() const override { return "nth_value"; }
2584  enum Sumfunctype sum_func() const override { return NTH_VALUE_FUNC; }
2585 
2586  bool resolve_type(THD *thd) override;
2587  bool fix_fields(THD *thd, Item **items) override;
2588  bool setup_nth();
2589  void clear() override;
2590 
2591  bool check_wf_semantics(THD *thd, SELECT_LEX *select,
2592  Window_evaluation_requirements *reqs) override;
2593 
2594  enum Item_result result_type() const override { return m_hybrid_type; }
2595 
2596  longlong val_int() override;
2597  double val_real() override;
2598  String *val_str(String *str) override;
2599  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2600 
2601  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2602  bool get_time(MYSQL_TIME *ltime) override;
2603  bool val_json(Json_wrapper *wr) override;
2604 
2605  void reset_field() override { DBUG_ASSERT(false); }
2606  void update_field() override { DBUG_ASSERT(false); }
2607  bool add() override {
2608  DBUG_ASSERT(false);
2609  return false;
2610  }
2611 
2612  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2613  List<Item> &fields) override;
2614  bool uses_only_one_row() const override { return true; }
2615 
2616  private:
2617  /**
2618  Core logic of NTH_VALUE window functions
2619 
2620  @return true if computation yielded a NULL or error
2621  */
2622  bool compute();
2623 };
2624 
2625 /**
2626  Class for implementation of the GROUPING function. The GROUPING
2627  function distinguishes super-aggregate rows from regular grouped
2628  rows. GROUP BY extensions such as ROLLUP and CUBE produce
2629  super-aggregate rows where the set of all values is represented
2630  by null. Using the GROUPING function, you can distinguish a null
2631  representing the set of all values in a super-aggregate row from
2632  a NULL in a regular row.
2633 */
2635  public:
2638  }
2639  const char *func_name() const override { return "grouping"; }
2640  enum Functype functype() const override { return GROUPING_FUNC; }
2641  longlong val_int() override;
2642  bool aggregate_check_group(uchar *arg) override;
2643  bool fix_fields(THD *thd, Item **ref) override;
2644  void update_used_tables() override;
2645 };
2646 
2647 #endif /* ITEM_SUM_INCLUDED */
Item_udf_sum
Definition: item_sum.h:1892
Item_nth_value::compute
bool compute()
Core logic of NTH_VALUE window functions.
Definition: item_sum.cc:5097
Item_sum_count::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2068
Item_result_field::llrint_with_overflow_check
longlong llrint_with_overflow_check(double realval)
Definition: item.h:4601
Item_rank::clear
void clear() override
Clear state for a new partition.
Definition: item_sum.cc:4610
Item_sum::SUM_BIT_FUNC
@ SUM_BIT_FUNC
Definition: item_sum.h:444
Item_sum_or
Definition: item_sum.h:1856
Item_sum_bit::val_decimal
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.cc:3010
Item_ntile::m_value
longlong m_value
Definition: item_sum.h:2373
Item_std_field
Definition: item_sum.h:1453
Item_sum_sum::Item_sum_sum
Item_sum_sum(const POS &pos, Item *item_par, bool distinct, PT_window *window)
Definition: item_sum.h:992
Item_cume_dist::val_real
double val_real() override
Definition: item_sum.cc:4648
Item_rank::val_real
double val_real() override
Definition: item_sum.cc:4598
Item_func_group_concat::val_real
double val_real() override
Definition: item_sum.h:2126
Item_nth_value::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5146
Item_sum_avg::f_precision
uint f_precision
Definition: item_sum.h:1277
Aggregator_distinct::field_lengths
uint32 * field_lengths
Definition: item_sum.h:799
Item_udf_sum::itemize
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_sum.cc:3695
Item
Definition: item.h:665
Item_sum_bit::update_field
void update_field() override
Definition: item_sum.cc:3270
Item_sum_num::fix_fields
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1315
Item_sum_num
Definition: item_sum.h:897
Item::set_data_type
void set_data_type(enum_field_types data_type)
Set the data type of the current Item.
Definition: item.h:1010
String::ptr
const char * ptr() const
Definition: sql_string.h:246
THD
Definition: sql_class.h:764
Item_lead_lag::clear
void clear() override
Definition: item_sum.cc:5312
String::charset
const CHARSET_INFO * charset() const
Definition: sql_string.h:237
Item_lead_lag::m_has_value
bool m_has_value
Execution state: if set, we already have a value for current row.
Definition: item_sum.h:2422
Item_sum_hybrid::Item_sum_hybrid
Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
Definition: item_sum.h:1593
parse_tree_nodes.h
Item_sum_num_field
Common abstract class for: Item_avg_field Item_variance_field.
Definition: item_sum.h:1111
Item_sum_udf_str::val_decimal
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:3809
Item_sum_std
Definition: item_sum.h:1476
Item_sum_avg::val_int
longlong val_int() override
Definition: item_sum.h:1296
Mem_root_array< ORDER >
Item_sum_num::reset_field
void reset_field() override
Definition: item_sum.cc:3112
Item_func_grouping::Item_func_grouping
Item_func_grouping(const POS &pos, PT_item_list *a)
Definition: item_sum.h:2636
Item_non_framing_wf::Item_non_framing_wf
Item_non_framing_wf(const POS &pos, PT_window *w)
Definition: item_sum.h:2179
Item_sum_avg::func_name
const char * func_name() const override
Definition: item_sum.h:1305
Item_sum::NTH_VALUE_FUNC
@ NTH_VALUE_FUNC
Definition: item_sum.h:456
field_types.h
This file contains the field type.
Item_percent_rank::super
Item_non_framing_wf super
Definition: item_sum.h:2331
Item_sum_and
Definition: item_sum.h:1866
Aggregator::Aggregator_type
Aggregator_type
Definition: item_sum.h:110
Item_row_number::Item_row_number
Item_row_number(const POS &pos, PT_window *w)
Definition: item_sum.h:2214
template_utils.h
Item_sum_variance::count
ulonglong count
Definition: item_sum.h:1409
Item_sum_json_object::~Item_sum_json_object
~Item_sum_json_object() override
Item_sum_udf_decimal
Definition: item_sum.h:2021
Item_sum_bit::m_frame_null_count
ulonglong m_frame_null_count
Execution state (windowing): this is for counting NULLs of rows entering and leaving the window frame...
Definition: item_sum.h:1722
Item::maybe_null
bool maybe_null
True if this item may be null.
Definition: item.h:2720
Item_sum::init_sum_func_check
bool init_sum_func_check(THD *thd)
Prepare an aggregate function for checking of context.
Definition: item_sum.cc:147
Item_sum_udf_str::Item_sum_udf_str
Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1985
Item_sum_int::result_type
enum Item_result result_type() const override
Definition: item_sum.h:968
Item_sum::Item_sum
Item_sum(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:530
Item_sum_hybrid::m_cnt
int64 m_cnt
Execution state: keeps track if this is the first row in the frame when buffering is not needed.
Definition: item_sum.h:1539
Item_sum_int::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:967
Item_sum::has_force_copy_fields
bool has_force_copy_fields() const
Definition: item_sum.h:430
Item_udf_sum::add
bool add() override
Definition: item_sum.cc:3708
Item_sum::needs_card
virtual bool needs_card() const
Return true if we need to make two passes over the rows in the partition - either because we need the...
Definition: item_sum.h:734
Item_rank::m_rank_ctr
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2252
Item_sum::AVG_FUNC
@ AVG_FUNC
Definition: item_sum.h:438
Item_sum::make_const
void make_const()
Definition: item_sum.h:602
Item_sum::VARIANCE_FUNC
@ VARIANCE_FUNC
Definition: item_sum.h:443
Item_ntile::needs_card
bool needs_card() const override
Return true if we need to make two passes over the rows in the partition - either because we need the...
Definition: item_sum.h:2400
Item_sum::with_distinct
bool with_distinct
Indicates how the aggregate function was specified by the parser : true if it was written as AGGREGAT...
Definition: item_sum.h:427
Item_sum_sum::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1940
Item_udf_sum::udf
udf_handler udf
Definition: item_sum.h:1896
Item_sum_max::func_name
const char * func_name() const override
Definition: item_sum.h:1686
Item_lead_lag::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5299
Item_sum::clear
virtual void clear()=0
Item_sum_bit::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:1342
Json_wrapper
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1141
Item_std_field::val_real
double val_real() override
Definition: item_sum.cc:3639
Item_func_group_concat::val_decimal
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.h:2138
Item_sum_hybrid::min_max_update_real_field
void min_max_update_real_field()
Definition: item_sum.cc:3441
Item_avg_field::val_real
double val_real() override
Definition: item_sum.cc:3507
Item_sum_sum::dec_buffs
my_decimal dec_buffs[2]
Definition: item_sum.h:975
Item::set_grouping_func
void set_grouping_func()
Set the property: this item is a call to GROUPING.
Definition: item.h:2554
Item_sum_bit::add
bool add() override
Common implementation of Item_sum_or::add, Item_sum_and:add and Item_sum_xor::add.
Definition: item_sum.cc:1576
Item_row_number::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2236
Item_sum_bit::Item_sum_bit
Item_sum_bit(THD *thd, Item_sum_bit *item)
Copy constructor, used for executing subqueries with temporary tables.
Definition: item_sum.h:1770
STRING_RESULT
@ STRING_RESULT
not valid for UDFs
Definition: udf_registration_types.h:40
Item_sum_bit::add_bits
bool add_bits(const String *s1, ulonglong b1)
Accumulate the value of 's1' (if in string mode) or of 'b1' (if in integer mode).
Definition: item_sum.cc:1492
Item_avg_field::val_str
String * val_str(String *) override
Definition: item_sum.cc:3537
Unique
Unique – class for unique (removing of duplicates).
Definition: uniques.h:52
NULL
#define NULL
Definition: types.h:55
Item_sum_sum
Definition: item_sum.h:971
Item_sum_udf_float::val_int
longlong val_int() override
Definition: item_sum.h:1937
Item_sum::max_aggr_level
int8 max_aggr_level
max level of unbound column references
Definition: item_sum.h:481
Item_sum::window
const Window * window() const
Definition: item_sum.h:705
Item_sum_bit::m_is_xor
bool m_is_xor
true iff BIT_XOR
Definition: item_sum.h:1754
Item_sum::CUME_DIST_FUNC
@ CUME_DIST_FUNC
Definition: item_sum.h:451
Aggregator_distinct::tree
Unique * tree
Definition: item_sum.h:814
Item_func_grouping::aggregate_check_group
bool aggregate_check_group(uchar *arg) override
This function is expected to check if GROUPING function with its arguments is "group-invariant".
Definition: item_sum.cc:5976
Item_sum_avg::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:2123
Item_sum_udf_str::val_real
double val_real() override
Definition: item_sum.h:1990
Item_lead_lag::m_null_treatment
enum_null_treatment m_null_treatment
Definition: item_sum.h:2407
Item_sum_json_array::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:5743
udf_handler
Definition: sql_udf.h:82
Item_sum_max::Item_sum_max
Item_sum_max(Item *item_par)
Definition: item_sum.h:1680
Temp_table_param
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:74
Item_sum_json
Common abstraction for Item_sum_json_array and Item_sum_json_object.
Definition: item_sum.h:1172
Item_cume_dist::val_decimal
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:4672
Item_func_group_concat::itemize
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_sum.cc:4064
Item_udf_sum::update_field
void update_field() override
Definition: item_sum.h:1925
Aggregator_simple::Aggregator_simple
Aggregator_simple(Item_sum *sum)
Definition: item_sum.h:885
Aggregator::endup
virtual void endup()=0
Called when there are no more data and the final value is to be retrieved.
Item_ntile
NTILE window function, cf.
Definition: item_sum.h:2371
Item::SUM_FUNC_ITEM
@ SUM_FUNC_ITEM
Definition: item.h:705
my_compiler.h
Item_sum_json_object::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:5854
element_count
uint32 element_count
Definition: my_tree.h:51
Aggregator::arg_val_decimal
virtual my_decimal * arg_val_decimal(my_decimal *value)=0
Decimal value of being-aggregated argument.
Item_sum_variance::create_tmp_field
Field * create_tmp_field(bool group, TABLE *table) override
Create a new field to match the type of value we're expected to yield.
Definition: item_sum.cc:2526
Item_rank::m_previous
List< Cached_item > m_previous
Values of previous row's ORDER BY items.
Definition: item_sum.h:2254
Item_sum_avg::dec_bin_size
uint dec_bin_size
Definition: item_sum.h:1277
Item_sum_udf_int::val_int
longlong val_int() override
Definition: item_sum.cc:3779
Item_sum::set_arg
Item * set_arg(uint i, THD *thd, Item *new_val)
Definition: item_sum.cc:753
Item_percent_rank::m_peers
ulonglong m_peers
Needed to make PERCENT_RANK same for peers.
Definition: item_sum.h:2334
CHARSET_INFO
Definition: m_ctype.h:354
Item_rank::result_type
Item_result result_type() const override
Definition: item_sum.h:2295
Item_sum::aggregate_check_group
bool aggregate_check_group(uchar *arg) override
Definition: item_sum.cc:630
Item_func_group_concat::result
String result
Definition: item_sum.h:2058
Item_non_framing_wf::framing
bool framing() const override
All aggregates are framing, i.e.
Definition: item_sum.h:2203
Item_sum::update_used_tables
void update_used_tables() override
Definition: item_sum.cc:690
Item_func_grouping::func_name
const char * func_name() const override
Definition: item_sum.h:2639
Item_rank::val_str
String * val_str(String *) override
Definition: item_sum.cc:4603
Item_ntile::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2384
Item_nth_value::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2584
Item_cume_dist::clear
void clear() override
Definition: item_sum.h:2319
Item_sum_hybrid::cleanup
void cleanup() override
Definition: item_sum.cc:2903
Item_sum_bit::DIGIT_CNT_CARD
static constexpr uint DIGIT_CNT_CARD
Definition: item_sum.h:1751
Item_func_group_concat::make_string_field
Field * make_string_field(TABLE *table_arg) override
Create a field to hold a string value from an item.
Definition: item_sum.cc:4157
Item_nth_value::m_from_last
bool m_from_last
true iff FROM_LAST was specified
Definition: item_sum.h:2564
Item_row_number
ROW_NUMBER window function, cf.
Definition: item_sum.h:2209
Item_sum_variance::reset_field
void reset_field() override
Definition: item_sum.cc:2600
Item_rank::m_dense
bool m_dense
If true, the object represents DENSE_RANK.
Definition: item_sum.h:2250
Item_sum_udf_float::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1944
Item_sum_xor::Item_sum_xor
Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1878
Item_nth_value
NTH_VALUE window function, cf.
Definition: item_sum.h:2561
Item_sum::next_sum
Item_sum * next_sum
next in the circular chain of registered objects
Definition: item_sum.h:472
Aggregator::clear
virtual void clear()=0
Called when we need to wipe out all the data from the aggregator : all the values acumulated and all ...
Item_sum_json::result_type
Item_result result_type() const override
Definition: item_sum.h:1198
Item_sum::aggregator_setup
bool aggregator_setup(THD *thd)
Called to initialize the aggregator.
Definition: item_sum.h:654
Aggregator_distinct::const_distinct
enum Aggregator_distinct::Const_distinct const_distinct
Item_nth_value::clear
void clear() override
Definition: item_sum.cc:5071
Item_avg_field::Item_avg_field
Item_avg_field(Item_result res_type, Item_sum_avg *item)
Definition: item_sum.cc:3488
Item_first_last_value::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4870
Item_lead_lag::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2443
Item_percent_rank::needs_card
bool needs_card() const override
Return true if we need to make two passes over the rows in the partition - either because we need the...
Definition: item_sum.h:2357
Item_sum_hybrid::clone_hybrid
virtual Item_sum_hybrid * clone_hybrid(THD *thd) const =0
Create a clone of this object.
Item_result_field::func_name
virtual const char * func_name() const =0
Item_sum::aggr
Aggregator * aggr
Aggregator class instance.
Definition: item_sum.h:401
Item_non_framing_wf::Item_non_framing_wf
Item_non_framing_wf(const POS &pos, PT_item_list *opt_list, PT_window *w)
Definition: item_sum.h:2182
Item_first_last_value
FIRST_VALUE/LAST_VALUE window functions, cf.
Definition: item_sum.h:2496
Item_percent_rank::val_int
longlong val_int() override
Definition: item_sum.cc:4727
Item_sum::unsupported_as_wf
void unsupported_as_wf()
Definition: item_sum.h:752
pos
char * pos
Definition: do_ctype.cc:76
Item_sum::MAX_FUNC
@ MAX_FUNC
Definition: item_sum.h:441
sql_string.h
Item_sum_avg::super
Item_sum_sum super
Definition: item_sum.h:1278
Item_sum_variance::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1442
Item_sum_udf_float::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1947
Item_sum_num_field::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1117
Window
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:94
Parse_tree_node_tmpl
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:111
my_dbug.h
Item_udf_sum::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1920
Item_sum_bit_field::type
enum Type type() const override
Definition: item_sum.h:1164
Item_sum_json::reset_field
void reset_field() override
Definition: item_sum.cc:5581
Item_sum_udf_str::Item_sum_udf_str
Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
Definition: item_sum.h:1987
Check_function_as_value_generator_parameters::banned_function_name
const char * banned_function_name
the name of the function which is not allowed
Definition: item.h:493
Item_nth_value::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5077
Item_sum::AVG_DISTINCT_FUNC
@ AVG_DISTINCT_FUNC
Definition: item_sum.h:439
String
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:164
Item_sum_hybrid::val_time_temporal
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item_sum.cc:2823
Item_sum_avg::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1289
TABLE
Definition: table.h:1305
Item_variance_field::val_decimal
my_decimal * val_decimal(my_decimal *dec_buf) override
Definition: item_sum.h:1326
Item_func_group_concat::always_null
bool always_null
Definition: item_sum.h:2084
Item_percent_rank::func_name
const char * func_name() const override
Definition: item_sum.h:2347
Item::FIELD_VARIANCE_ITEM
@ FIELD_VARIANCE_ITEM
Definition: item.h:718
Item_sum_hybrid::setup_hybrid
bool setup_hybrid(Item *item, Item *value_arg)
MIN/MAX function setup.
Definition: item_sum.cc:1683
Item_sum_num_field::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1120
Item::Type
Type
Definition: item.h:701
Item_sum_num_field::val_int
longlong val_int() override
Definition: item_sum.h:1113
Item_sum_variance::func_name
const char * func_name() const override
Definition: item_sum.h:1437
Item_percent_rank::val_decimal
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:4739
Item_percent_rank::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2350
Aggregator_simple::setup
bool setup(THD *thd) override
Called before adding the first row.
Definition: item_sum.h:888
Item_ntile::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2382
Item_sum::arg_count
uint arg_count
Definition: item_sum.h:493
window_lex.h
Item::null_value
bool null_value
True if item is null.
Definition: item.h:2721
Item_sum_hybrid::min_max_update_temporal_field
void min_max_update_temporal_field()
Definition: item_sum.cc:3389
Item_sum_and::func_name
const char * func_name() const override
Definition: item_sum.h:1872
my_strtoll10
longlong my_strtoll10(const char *nptr, const char **endptr, int *error)
Definition: my_strtoll10.cc:86
Item_sum::init_aggregator
void init_aggregator()
Definition: item_sum.h:644
longlong
long long int longlong
Definition: my_inttypes.h:54
Item_sum_bit::reset_field
void reset_field() override
Definition: item_sum.cc:3260
Item_avg_field::type
enum Type type() const override
Definition: item_sum.h:1138
Item_ntile::result_type
Item_result result_type() const override
Definition: item_sum.h:2398
Item_first_last_value::setup_first_last
bool setup_first_last()
Definition: item_sum.cc:4899
CHARSET_INFO::cset
MY_CHARSET_HANDLER * cset
Definition: m_ctype.h:386
Item_first_last_value::compute
bool compute()
Core logic of FIRST/LAST_VALUE window functions.
Definition: item_sum.cc:4916
Item_sum_udf_decimal::Item_sum_udf_decimal
Item_sum_udf_decimal(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2023
Item_nth_value::func_name
const char * func_name() const override
Definition: item_sum.h:2583
Item_lead_lag::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5335
Item_lead_lag::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5367
Item_sum_json_array::m_json_array
unique_ptr_destroy_only< Json_array > m_json_array
Accumulates the final value.
Definition: item_sum.h:1220
Item_sum_avg::f_scale
uint f_scale
Definition: item_sum.h:1277
Item_sum_count::update_field
void update_field() override
Definition: item_sum.cc:3323
Item_sum_hybrid::min_max_update_json_field
void min_max_update_json_field()
Definition: item_sum.cc:3407
Item_sum::make_unique
virtual void make_unique()
Definition: item_sum.h:625
Item_sum::mark_as_sum_func
void mark_as_sum_func()
Definition: item_sum.cc:453
Item_sum_variance::add
bool add() override
Definition: item_sum.cc:2549
Item_first_last_value::super
Item_sum super
Definition: item_sum.h:2502
Item_first_last_value::func_name
const char * func_name() const override
Definition: item_sum.h:2514
Item_result_field
Item with result field.
Definition: item.h:4549
Item_sum_bit::bits
ulonglong bits
Stores the result value for the INT_RESULT.
Definition: item_sum.h:1702
Item_sum::JSON_AGG_FUNC
@ JSON_AGG_FUNC
Definition: item_sum.h:447
Item_percent_rank
PERCENT_RANK window function, cf.
Definition: item_sum.h:2330
Item_sum_hybrid::compute
bool compute()
This function implements the optimized version of retrieving min/max value.
Definition: item_sum.cc:2687
group_concat_key_cmp_with_order
int group_concat_key_cmp_with_order(const void *arg, const void *key1, const void *key2)
function of sort for syntax: GROUP_CONCAT(expr,...
Definition: item_sum.cc:3884
Item_sum_variance::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2513
Item_sum::fix_num_length_and_dec
void fix_num_length_and_dec()
Definition: item_sum.cc:481
INVALID_RESULT
@ INVALID_RESULT
Definition: udf_registration_types.h:39
my_tree.h
Item_sum_bit
Base class used to implement BIT_AND, BIT_OR and BIT_XOR.
Definition: item_sum.h:1697
Aggregator_distinct::arg_is_null
bool arg_is_null(bool use_null_value) override
NULLness of being-aggregated argument.
Definition: item_sum.cc:2057
Item_sum_sum::reset_field
void reset_field() override
Definition: item_sum.cc:3205
Item_sum::force_copy_fields
bool force_copy_fields
Used in making ROLLUP.
Definition: item_sum.h:420
Item_sum_hybrid_field::check_function_as_value_generator
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_sum.h:1098
value
const string value("\"Value\"")
Item_func_group_concat::separator
String * separator
Definition: item_sum.h:2059
Item_percent_rank::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4677
Item_first_last_value::m_is_first
bool m_is_first
if true, the function is FIRST_VALUE, else LAST_VALUE
Definition: item_sum.h:2497
Item_func_group_concat
Definition: item_sum.h:2054
Item::get_time_from_numeric
bool get_time_from_numeric(MYSQL_TIME *ltime)
Convert a numeric type to time.
Definition: item.cc:1329
Item_lead_lag::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5239
unique_ptr_destroy_only
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:408
Item_sum::reset_wf_state
bool reset_wf_state(uchar *arg) override
Reset execution state for such window function types as determined by arg.
Definition: item_sum.cc:814
Item::str_value
String str_value
str_values's main purpose is to cache the value in save_in_field
Definition: item.h:2631
Item_sum_json::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5551
Item::collation
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:2638
Item_sum_avg::cleanup
void cleanup() override
Definition: item_sum.h:1308
Item_variance_field::Item_variance_field
Item_variance_field(Item_sum_variance *item)
Definition: item_sum.cc:3666
Item_sum_avg::add
bool add() override
Definition: item_sum.cc:2178
Item_sum_int::Item_sum_int
Item_sum_int(THD *thd, Item_sum_int *item)
Definition: item_sum.h:946
Aggregator
The abstract base class for the Aggregator_* classes.
Definition: item_sum.h:92
Item_sum_variance::clear
void clear() override
Definition: item_sum.cc:2547
udf_func
Definition: sql_udf.h:43
Item_sum_bit::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:2996
Item_func_group_concat::Item_func_group_concat
Item_func_group_concat(const POS &pos, bool is_distinct, PT_item_list *select_list, PT_order_list *opt_order_list, String *separator, PT_window *w)
Constructor of Item_func_group_concat.
Definition: item_sum.cc:4017
Item_sum_int::val_real
double val_real() override
Definition: item_sum.h:958
Item_sum_std::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1484
Aggregator_simple::clear
void clear() override
Called when we need to wipe out all the data from the aggregator : all the values acumulated and all ...
Definition: item_sum.h:889
Item_sum::framing
virtual bool framing() const
All aggregates are framing, i.e.
Definition: item_sum.h:718
Item_sum_hybrid::hybrid_type
Item_result hybrid_type
Definition: item_sum.h:1516
Item_rank::Item_rank
Item_rank(const POS &pos, bool dense, PT_window *w)
Definition: item_sum.h:2256
Item_sum_variance::prec_increment
uint prec_increment
Definition: item_sum.h:1411
Item_nth_value::m_cnt
int64 m_cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2568
Item_sum_hybrid::min_max_update_str_field
void min_max_update_str_field()
Definition: item_sum.cc:3425
Item_sum::max_sum_func_level
int8 max_sum_func_level
max level of aggregation for contained functions
Definition: item_sum.h:483
Item_func_group_concat::group_concat_key_cmp_with_order
friend int group_concat_key_cmp_with_order(const void *arg, const void *key1, const void *key2)
function of sort for syntax: GROUP_CONCAT(expr,...
Definition: item_sum.cc:3884
Item_func_group_concat::update_field
void update_field() override
Definition: item_sum.h:2122
true
#define true
Definition: config_static.h:44
Item_sum_std::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2315
Item_sum_udf_float
Definition: item_sum.h:1931
Item_sum_int::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1311
Item_sum_hybrid::Item_sum_hybrid
Item_sum_hybrid(Item *item_par, bool is_min)
Definition: item_sum.h:1577
Item_row_number::result_type
Item_result result_type() const override
Definition: item_sum.h:2234
DTCollation::set
void set(const DTCollation &dt)
Definition: item.h:186
Item_cache
Definition: item.h:5663
Item_field
Definition: item.h:3329
PT_order_list
Definition: parse_tree_nodes.h:210
Item_udf_sum::reset_field
void reset_field() override
Definition: item_sum.h:1924
Item_sum_json_object::func_name
const char * func_name() const override
Definition: item_sum.h:1266
Item_result
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
Item_sum_count::make_const
void make_const(longlong count_arg)
Definition: item_sum.h:1058
Item_sum_avg::create_tmp_field
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:2154
REAL_RESULT
@ REAL_RESULT
char *
Definition: udf_registration_types.h:41
item_func.h
Item_rank::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2271
Item_first_last_value::Item_first_last_value
Item_first_last_value(const POS &pos, bool first, Item *a, enum_null_treatment null_treatment, PT_window *w)
Definition: item_sum.h:2505
Item_sum_udf_decimal::Item_sum_udf_decimal
Item_sum_udf_decimal(THD *thd, Item_sum_udf_decimal *item)
Definition: item_sum.h:2026
Aggregator_distinct
The distinct aggregator.
Definition: item_sum.h:769
Item_non_framing_wf::add
bool add() override
Definition: item_sum.h:2196
Item_sum::aggregate_check_distinct
bool aggregate_check_distinct(uchar *arg) override
Definition: item_sum.cc:606
Item_sum::cleanup
void cleanup() override
Definition: item_sum.cc:785
Item_cume_dist::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4638
Item_sum::reset_field
virtual void reset_field()=0
Item_first_last_value::update_field
void update_field() override
Definition: item_sum.h:2537
Item_sum_hybrid::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:2863
Item_first_last_value::val_str
String * val_str(String *str) override
Definition: item_sum.cc:4990
Item_lead_lag::set_use_default
void set_use_default(bool value)
Definition: item_sum.h:2479
Item_func_grouping::functype
enum Functype functype() const override
Definition: item_sum.h:2640
Item_sum_count::count
longlong count
Definition: item_sum.h:1021
Item_sum_count::reset_field
void reset_field() override
Definition: item_sum.cc:3223
Item_sum::Item_sum
Item_sum(const POS &pos, PT_window *w)
Definition: item_sum.h:503
Item_nth_value::uses_only_one_row
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2614
Item_int_func
Definition: item_func.h:841
my_alloc.h
String::set
void set(String &str, size_t offset, size_t arg_length)
Definition: sql_string.h:277
Item_sum_hybrid::val_int
longlong val_int() override
Definition: item_sum.cc:2809
Item::mark_field_in_map
virtual bool mark_field_in_map(uchar *arg)
Mark underlying field in read or write map of a table.
Definition: item.h:2119
Item_sum::fix_after_pullout
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
Fix after tables have been moved from one select_lex level to the parent level, e....
Definition: item_sum.cc:706
Item_sum_max::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1685
Arg_comparator
Definition: item_cmpfunc.h:120
Item_std_field::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3647
Item_sum_hybrid::keep_field_type
bool keep_field_type() const override
Definition: item_sum.h:1637
Item_sum_bit_field::reset_bits
ulonglong reset_bits
Definition: item_sum.h:1152
Item_sum_json::Item_sum_json
Item_sum_json(unique_ptr_destroy_only< Json_wrapper > wrapper, Args &&... parent_args)
Construct an Item_sum_json instance.
Definition: item_sum.cc:5443
Item_sum_sum::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1001
Item_ntile::val_int
longlong val_int() override
Definition: item_sum.cc:4774
Item_nth_value::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5184
Item_sum_hybrid::m_is_min
const bool m_is_min
Tells if this is the MIN function (true) or the MAX function (false).
Definition: item_sum.h:1505
Item_first_last_value::reset_field
void reset_field() override
Definition: item_sum.h:2536
Item::val_decimal_from_real
my_decimal * val_decimal_from_real(my_decimal *decimal_value)
Definition: item.cc:298
Item_sum_hybrid::m_nulls_first
bool m_nulls_first
Set to true if the window is ordered ascending.
Definition: item_sum.h:1521
Item_non_framing_wf::update_field
void update_field() override
Definition: item_sum.h:2195
Item_cume_dist::func_name
const char * func_name() const override
Definition: item_sum.h:2307
Item::val_decimal_from_string
my_decimal * val_decimal_from_string(my_decimal *decimal_value)
Definition: item.cc:313
Item_nth_value::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, List< Item > &fields) override
Definition: item_sum.cc:5053
Item_std_field::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1459
Item_func_group_concat::original
Item_func_group_concat * original
Definition: item_sum.h:2092
Item_first_last_value::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:4855
Item_sum::Item_sum
Item_sum(const POS &pos, Item *a, Item *b, PT_window *w)
Definition: item_sum.h:544
Aggregator::arg_val_real
virtual double arg_val_real()=0
Floating point value of being-aggregated argument.
Item_sum_num::Item_sum_num
Item_sum_num(const POS &pos, PT_item_list *list, PT_window *w)
Definition: item_sum.h:913
Item_sum_hybrid::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, List< Item > &fields) override
Definition: item_sum.cc:2892
Item_sum::ROW_NUMBER_FUNC
@ ROW_NUMBER_FUNC
Definition: item_sum.h:448
Item_sum_variance::recurrence_s
double recurrence_s
Definition: item_sum.h:1407
Item_sum_json::val_real
double val_real() override
Definition: item_sum.cc:5521
Item_first_last_value::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:4976
Item_ntile::func_name
const char * func_name() const override
Definition: item_sum.h:2381
Item_percent_rank::val_real
double val_real() override
Definition: item_sum.cc:4701
Item_sum_hybrid::fix_fields
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1634
Item_sum_hybrid::any_value
bool any_value()
Definition: item_sum.h:1641
Item_sum_hybrid::was_values
bool was_values
Definition: item_sum.h:1517
Item_sum_hybrid::reset_field
void reset_field() override
Definition: item_sum.cc:3126
Item_func_group_concat::super
Item_sum super
Definition: item_sum.h:2055
Aggregator_distinct::unique_walk_function
bool unique_walk_function(void *element)
Aggregate a distinct row from the distinct hash table.
Definition: item_sum.cc:2001
Item_sum_sum::clear
void clear() override
Definition: item_sum.cc:1768
Aggregator_distinct::Aggregator_distinct
Aggregator_distinct(Item_sum *sum)
Definition: item_sum.h:856
Item_sum_max::clone_hybrid
Item_sum_max * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:2935
Item_nth_value::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5160
enum_query_type.h
Item_sum_bit::val_real
double val_real() override
Definition: item_sum.cc:3026
Item_sum_num::super
Item_sum super
Definition: item_sum.h:898
Item_sum::uses_only_one_row
virtual bool uses_only_one_row() const
Only for framing window functions.
Definition: item_sum.h:724
Item_sum::SUM_DISTINCT_FUNC
@ SUM_DISTINCT_FUNC
Definition: item_sum.h:437
Item_sum_udf_float::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3734
int64
int64_t int64
Definition: my_inttypes.h:67
Item_sum_avg::update_field
void update_field() override
calc next value and merge it with field_value.
Definition: item_sum.cc:3332
Item_sum_hybrid::clear
void clear() override
Definition: item_sum.cc:2644
Item_variance_field::val_real
double val_real() override
Definition: item_sum.cc:3680
Name_resolution_context
Definition: item.h:389
Item_sum_int::Item_sum_int
Item_sum_int(const POS &pos, PT_item_list *list, PT_window *w)
Definition: item_sum.h:941
my_error
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
Item_func_group_concat::table
TABLE * table
Definition: item_sum.h:2071
Item_sum::RANK_FUNC
@ RANK_FUNC
Definition: item_sum.h:449
MYSQL_TYPE_NEWDECIMAL
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:79
Item_sum_avg::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2147
Item::get_time_from_int
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1304
Item::update_null_value
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:6677
Item_sum_json::val_int
longlong val_int() override
Definition: item_sum.cc:5536
Item_sum_hybrid::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:2919
Item_sum_variance::sample
uint sample
Definition: item_sum.h:1410
Item_func_grouping::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Resolve the fields in the GROUPING function.
Definition: item_sum.cc:5888
Item_sum::sum_func
virtual enum Sumfunctype sum_func() const =0
Item_sum_json_array::func_name
const char * func_name() const override
Definition: item_sum.h:1230
Item_lead_lag::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, List< Item > &fields) override
Definition: item_sum.cc:5275
Aggregator_distinct::CONST_NOT_NULL
@ CONST_NOT_NULL
Set to true if count distinct is on only const items.
Definition: item_sum.h:842
Item_sum_variance::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:2478
Item_lead_lag::compute
bool compute()
Core logic of LEAD/LAG window functions.
Definition: item_sum.cc:5385
Item_cume_dist::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2310
Item_sum_sum::func_name
const char * func_name() const override
Definition: item_sum.h:1016
Item_lead_lag::m_n
int64 m_n
canonicalized offset value
Definition: item_sum.h:2409
Item_cume_dist
CUME_DIST window function, cf.
Definition: item_sum.h:2301
my_inttypes.h
Item_sum_count::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1049
Item_sum_std::Item_sum_std
Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
Definition: item_sum.h:1478
Item_sum_bit::cleanup
void cleanup() override
Definition: item_sum.h:1806
dump_leaf_key
int dump_leaf_key(void *key_arg, element_count count, void *item_arg)
Append data from current leaf to item->result.
Definition: item_sum.cc:3927
Aggregator::SIMPLE_AGGREGATOR
@ SIMPLE_AGGREGATOR
Definition: item_sum.h:110
Item_sum_hybrid::val_str
String * val_str(String *) override
Definition: item_sum.cc:2869
Item_cume_dist::val_str
String * val_str(String *) override
Definition: item_sum.cc:4668
Item_func_group_concat::cleanup
void cleanup() override
Definition: item_sum.cc:4117
Item_sum::forced_const
bool forced_const
Definition: item_sum.h:496
Item_func_grouping::update_used_tables
void update_used_tables() override
Definition: item_sum.cc:5988
Item_lead_lag::val_real
double val_real() override
Definition: item_sum.cc:5327
Item_first_last_value::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:4960
Item_sum_json_object::m_key_map
std::map< std::string, int > m_key_map
Map of keys in Json_object and the count for each key within a window frame.
Definition: item_sum.h:1248
Item_sum_variance::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1435
Item_sum_udf_int::val_str
String * val_str(String *str) override
Definition: item_sum.cc:3787
Item_nth_value::m_hybrid_field_type
enum_field_types m_hybrid_field_type
Definition: item_sum.h:2566
Item_row_number::val_str
String * val_str(String *) override
Definition: item_sum.cc:4536
Item_func_group_concat::setup
bool setup(THD *thd) override
Definition: item_sum.cc:4309
Item_lead_lag::m_use_default
bool m_use_default
execution state: use default value for current row
Definition: item_sum.h:2423
Item_nth_value::setup_nth
bool setup_nth()
Definition: item_sum.cc:5060
m_ctype.h
Item_sum_hybrid_field::field
Field * field
The tmp table's column containing the value of the set function.
Definition: item_sum.h:1085
Item_lead_lag::m_is_lead
bool m_is_lead
if true, the function is LEAD, else LAG
Definition: item_sum.h:2408
Aggregator::setup
virtual bool setup(THD *)=0
Called before adding the first row.
Item_row_number::m_ctr
ulonglong m_ctr
Increment for each row in partition.
Definition: item_sum.h:2211
Item_avg_field::func_name
const char * func_name() const override
Definition: item_sum.h:1143
Item::fixed
bool fixed
True if item has been resolved.
Definition: item.h:2700
Item_sum_udf_str
Definition: item_sum.h:1983
Item_sum_hybrid_field
This is used in connection which a parent Item_sum:
Definition: item_sum.h:1082
enum_null_treatment
enum_null_treatment
Cf.
Definition: window_lex.h:57
Item_func_group_concat::arg_count_order
uint arg_count_order
The number of ORDER BY items.
Definition: item_sum.h:2075
Item_sum_min::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1671
Item_func_group_concat::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2141
Item_sum_hybrid::cmp
Arg_comparator * cmp
Definition: item_sum.h:1515
Item_lead_lag::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5358
Item_sum_json_object::add
bool add() override
Definition: item_sum.cc:5756
Item::get_date_from_real
bool get_date_from_real(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_real() to date in MYSQL_TIME.
Definition: item.cc:1199
Item_sum::aggregator_add
bool aggregator_add()
Called to add value to the aggregator.
Definition: item_sum.h:666
Item_sum::COUNT_DISTINCT_FUNC
@ COUNT_DISTINCT_FUNC
Definition: item_sum.h:435
Item_sum_variance::Item_sum_variance
Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
Definition: item_sum.h:1419
Item_sum_std::val_real
double val_real() override
Definition: item_sum.cc:2306
r
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
Item_sum_bit_field::val_str
String * val_str(String *) override
Definition: item_sum.cc:3604
Item_sum::m_window
PT_window * m_window
If sum is a window function, this field contains the window.
Definition: item_sum.h:406
Item_rank::super
Item_non_framing_wf super
Definition: item_sum.h:2249
Item_sum_hybrid::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2924
Aggregator_simple::Aggrtype
Aggregator_type Aggrtype() override
Definition: item_sum.h:886
int8
int8_t int8
Definition: my_inttypes.h:61
Item_sum_hybrid::val_date_temporal
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item_sum.cc:2831
Item_nth_value::val_real
double val_real() override
Definition: item_sum.cc:5138
Item_lead_lag::m_value
Item_cache * m_value
Definition: item_sum.h:2411
Json_array
Represents a JSON array container, i.e.
Definition: json_dom.h:518
Item_percent_rank::m_rank_ctr
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2333
Item_sum_num_field::is_null
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.h:1123
Item_sum_avg::Item_sum_avg
Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
Definition: item_sum.h:1282
Item_sum_variance::hybrid_type
Item_result hybrid_type
Definition: item_sum.h:1403
Item_sum_avg::clear
void clear() override
Definition: item_sum.cc:2176
Item_sum::itemize
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_sum.cc:87
Item_first_last_value::val_int
longlong val_int() override
Definition: item_sum.cc:4935
Item::get_date_from_int
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1217
Item_lead_lag::Item_lead_lag
Item_lead_lag(const POS &pos, bool lead, PT_item_list *opt_list, enum_null_treatment null_treatment, PT_window *w)
Definition: item_sum.h:2427
Item_sum_count::Item_sum_count
Item_sum_count(const POS &pos, PT_item_list *list, PT_window *w)
Constructs an instance for COUNT(DISTINCT)
Definition: item_sum.h:1043
Item_sum_max::Item_sum_max
Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1681
Item_sum_bit::m_digit_cnt
ulonglong * m_digit_cnt
Execution state (windowing): Used for AND, OR to be able to invert window functions in optimized mode...
Definition: item_sum.h:1743
Aggregator_distinct::add
bool add() override
Process incoming row.
Definition: item_sum.cc:1181
Item_udf_sum::cleanup
void cleanup() override
Definition: item_sum.cc:3714
Item_avg_field::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3522
Item_avg_field
Definition: item_sum.h:1133
Item_sum_hybrid::min_max_update_int_field
void min_max_update_int_field()
Definition: item_sum.cc:3454
Item_sum::used_tables_cache
table_map used_tables_cache
Definition: item_sum.h:495
enum_field_types
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
Item_sum::add_used_tables_for_aggr_func
void add_used_tables_for_aggr_func()
Add used_tables information for aggregate function, based on its aggregated query block.
Definition: item_sum.cc:742
Aggregator_distinct::arg_val_real
double arg_val_real() override
Floating point value of being-aggregated argument.
Definition: item_sum.cc:2052
Item_sum_sum::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:1825
Json_object
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:367
Item_sum_max::Item_sum_max
Item_sum_max(THD *thd, const Item_sum_max *item)
Definition: item_sum.h:1683
Item_ntile::val_real
double val_real() override
Definition: item_sum.cc:4820
Item_sum_udf_int::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3791
Item_sum::has_with_distinct
bool has_with_distinct() const
Definition: item_sum.h:431
Check_function_as_value_generator_parameters::err_code
int err_code
the error code found during check(if any)
Definition: item.h:486
Item_std_field::type
enum Type type() const override
Definition: item_sum.h:1456
Item_sum_json::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5501
Item_udf_sum::Item_udf_sum
Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1899
uint
unsigned int uint
Definition: uca-dump.cc:29
Item_sum_json_object::Item_sum_json_object
Item_sum_json_object(THD *thd, Item_sum *item, unique_ptr_destroy_only< Json_wrapper > wrapper, unique_ptr_destroy_only< Json_object > object)
Definition: item_sum.cc:5645
Item_rank::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2275
Item_sum_int
Definition: item_sum.h:934
Item_func_group_concat::reset_field
void reset_field() override
Definition: item_sum.h:2121
Item_non_framing_wf::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2186
Item::get_date_from_string
bool get_date_from_string(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_str() to date in MYSQL_TIME.
Definition: item.cc:1189
Item_first_last_value::m_value
Item_cache * m_value
Definition: item_sum.h:2500
Item_sum::base_select
SELECT_LEX * base_select
query block where function is placed
Definition: item_sum.h:474
TREE
Definition: my_tree.h:67
Item_ntile::super
Item_non_framing_wf super
Definition: item_sum.h:2372
Item_sum_json_object::m_optimize
bool m_optimize
If window provides ordering on the key in Json_object, a key_map is not needed to handle rows leaving...
Definition: item_sum.h:1256
Item_func_grouping::val_int
longlong val_int() override
Evaluation of the GROUPING function.
Definition: item_sum.cc:5943
Item_nth_value::update_field
void update_field() override
Definition: item_sum.h:2606
Item_sum_num::val_int
longlong val_int() override
Definition: item_sum.h:919
Aggregator::Aggregator
Aggregator(Item_sum *arg)
Definition: item_sum.h:107
Item_sum::used_tables
table_map used_tables() const override
Definition: item_sum.h:596
Item_sum_min::func_name
const char * func_name() const override
Definition: item_sum.h:1672
Item_ntile::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4832
Item_sum_hybrid::super
Item_sum super
Definition: item_sum.h:1499
Item_sum_udf_str::val_int
longlong val_int() override
Definition: item_sum.h:1999
Item_func_group_concat::context
Name_resolution_context * context
Definition: item_sum.h:2073
Item_sum_num::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:925
Item_sum::FIRST_LAST_VALUE_FUNC
@ FIRST_LAST_VALUE_FUNC
Definition: item_sum.h:455
Item_row_number::func_name
const char * func_name() const override
Definition: item_sum.h:2219
my_decimal.h
Item_avg_field::f_scale
uint f_scale
Definition: item_sum.h:1135
Item_func_group_concat::tree
TREE * tree
Definition: item_sum.h:2061
Item_lead_lag::has_value
bool has_value() const
Definition: item_sum.h:2477
Item_avg_field::f_precision
uint f_precision
Definition: item_sum.h:1135
Item_cume_dist::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2308
Item_sum_xor::func_name
const char * func_name() const override
Definition: item_sum.h:1884
Item_sum_hybrid::m_saved_last_value_at
int64 m_saved_last_value_at
Execution state: keeps track of at which row we saved a non-null last value.
Definition: item_sum.h:1545
Item_sum::PERCENT_RANK_FUNC
@ PERCENT_RANK_FUNC
Definition: item_sum.h:452
Item_sum_avg::Item_sum_avg
Item_sum_avg(THD *thd, Item_sum_avg *item)
Definition: item_sum.h:1285
Item_sum_json_array::add
bool add() override
Definition: item_sum.cc:5694
Item_rank::cleanup
void cleanup() override
Cleanup after query, free up resources.
Definition: item_sum.cc:4628
Item_sum_std::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1482
Aggregator::add
virtual bool add()=0
Called when there's a new value to be aggregated.
Item_sum_or::Item_sum_or
Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1858
Item_sum::add
virtual bool add()=0
Item_nth_value::val_int
longlong val_int() override
Definition: item_sum.cc:5130
list
class udf_list * list
Item_lead_lag::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5375
Item_sum_json_array
Implements aggregation of values into an array.
Definition: item_sum.h:1218
Item::val_string_from_real
String * val_string_from_real(String *str)
Definition: item.cc:247
Item_lead_lag::use_default
bool use_default() const
Definition: item_sum.h:2480
Item_sum_bit::remove_bits
void remove_bits(const String *s1, ulonglong b1)
For windowing: perform inverse aggregation.
Definition: item_sum.cc:1414
Item_nth_value::m_hybrid_type
Item_result m_hybrid_type
Definition: item_sum.h:2565
Item_non_framing_wf::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4492
Item_sum_udf_decimal::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3762
Item_udf_sum::Item_udf_sum
Item_udf_sum(THD *thd, Item_udf_sum *item)
Definition: item_sum.h:1903
Item_sum_udf_decimal::val_int
longlong val_int() override
Definition: item_sum.cc:3760
Item_nth_value::m_n
int64 m_n
The N of the function.
Definition: item_sum.h:2563
Item_sum_or::func_name
const char * func_name() const override
Definition: item_sum.h:1862
Item_ntile::clear
void clear() override
Definition: item_sum.h:2399
Item_sum_bit::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1793
Item_sum_udf_float::Item_sum_udf_float
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
Definition: item_sum.h:1935
Item_func_group_concat::m_result_finalized
bool m_result_finalized
True if result has been written to output buffer.
Definition: item_sum.h:2087
key1
static uint16 key1[1001]
Definition: hp_test2.cc:44
Item_sum_min::Item_sum_min
Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1667
Item::set_data_type_longlong
void set_data_type_longlong()
Set the data type of the Item to be longlong.
Definition: item.h:1025
Item_sum_hybrid::uses_only_one_row
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:1644
Item_nth_value::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2594
Item_sum_udf_float::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3750
uchar
unsigned char uchar
Definition: my_inttypes.h:51
Item_sum::print
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:463
Aggregator_distinct::NOT_CONST
@ NOT_CONST
Definition: item_sum.h:825
sql_const.h
Item_lead_lag::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5350
Item_non_framing_wf::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2190
Item_sum_sum::curr_dec_buff
uint curr_dec_buff
Definition: item_sum.h:976
Item_func_group_concat::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2157
Parse_tree_node_tmpl::error
void error(Context *pc, const POS &pos) const
syntax_error() function replacement for deferred reporting of syntax errors
Definition: parse_tree_node_base.h:178
Item_sum_int::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:950
Item_sum_std::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1489
Item_sum_bit_field::val_real
double val_real() override
Definition: item_sum.cc:3579
Item_percent_rank::cleanup
void cleanup() override
Definition: item_sum.cc:4750
Item_sum_json::super
Item_sum super
Definition: item_sum.h:1173
Item_sum_avg::val_real
double val_real() override
Definition: item_sum.cc:2185
Item_sum_json_array::clear
void clear() override
Definition: item_sum.cc:5636
rules_table_service::end
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
udf_handler::not_original
bool not_original
Definition: sql_udf.h:99
Item_sum_udf_int::Item_sum_udf_int
Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1960
table_map
uint64_t table_map
Definition: my_table_map.h:30
Item_sum::DENSE_RANK_FUNC
@ DENSE_RANK_FUNC
Definition: item_sum.h:450
Item_sum_avg::m_avg
double m_avg
Definition: item_sum.h:1280
Item_first_last_value::add
bool add() override
Definition: item_sum.h:2538
Item_sum_min::Item_sum_min
Item_sum_min(Item *item_par)
Definition: item_sum.h:1666
Item_func_group_concat::change_context_processor
bool change_context_processor(uchar *cntx) override
Definition: item_sum.h:2152
Item_first_last_value::uses_only_one_row
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2545
Item_func_group_concat::add
bool add() override
Definition: item_sum.cc:4204
Item_sum_udf_float::Item_sum_udf_float
Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1933
Item_func::GROUPING_FUNC
@ GROUPING_FUNC
Definition: item_func.h:173
Item_func_group_concat::group_concat_max_len
uint group_concat_max_len
The maximum permitted result length in bytes as set for group_concat_max_len system variable.
Definition: item_sum.h:2081
Item_rank::func_name
const char * func_name() const override
Definition: item_sum.h:2267
my_time_flags_t
unsigned int my_time_flags_t
Flags to str_to_datetime and number_to_datetime.
Definition: my_time.h:82
Item_sum_bit_field
This is used in connection with an Item_sum_bit,.
Definition: item_sum.h:1150
Item_lead_lag::m_hybrid_type
Item_result m_hybrid_type
Definition: item_sum.h:2410
Item_sum_json::update_field
void update_field() override
Definition: item_sum.cc:5601
my_decimal
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:91
Item_ntile::val_str
String * val_str(String *) override
Definition: item_sum.cc:4825
Item_sum_hybrid::m_optimize
bool m_optimize
Set to true when min/max can be optimized using window's ordering.
Definition: item_sum.h:1525
Item_func_group_concat::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2144
Aggregator_distinct::clear
void clear() override
Invalidate calculated value and clear the distinct rows.
Definition: item_sum.cc:1149
Item_sum::LEAD_LAG_FUNC
@ LEAD_LAG_FUNC
Definition: item_sum.h:454
uint32
uint32_t uint32
Definition: my_inttypes.h:66
Item_percent_rank::clear
void clear() override
Definition: item_sum.cc:4744
Aggregator_distinct::tree_key_length
uint tree_key_length
Definition: item_sum.h:822
Aggregator_distinct::use_distinct_values
bool use_distinct_values
When feeding back the data in endup() from Unique/temp table back to Item_sum::add() methods we must ...
Definition: item_sum.h:853
Item_sum_variance::update_field
void update_field() override
Definition: item_sum.cc:2620
Item_sum_sum::val_str
String * val_str(String *str) override
Definition: item_sum.cc:1934
my_table_map.h
Item_avg_field::prec_increment
uint prec_increment
Definition: item_sum.h:1136
Item_sum_udf_decimal::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2039
Aggregator_simple::endup
void endup() override
Called when there are no more data and the final value is to be retrieved.
Definition: item_sum.h:891
Item_sum_count::clear
void clear() override
Definition: item_sum.cc:2076
Item_sum_and::Item_sum_and
Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1868
Item_sum_avg::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1301
Item_sum::setup
virtual bool setup(THD *)
Definition: item_sum.h:684
enum_query_type
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
Item_sum::set_aggregator
int set_aggregator(Aggregator::Aggregator_type aggregator)
Definition: item_sum.cc:758
Item_sum_num::Item_sum_num
Item_sum_num(const POS &pos, Item *item_par, PT_window *window)
Definition: item_sum.h:910
Item_sum_hybrid::min_max_update_decimal_field
void min_max_update_decimal_field()
Definition: item_sum.cc:3472
Item_sum_min
Definition: item_sum.h:1664
Item_percent_rank::val_str
String * val_str(String *) override
Definition: item_sum.cc:4735
Item_sum_xor::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3094
Item_sum::has_aggregate_ref_in_group_by
bool has_aggregate_ref_in_group_by(uchar *arg) override
Check if an aggregate is referenced from within the GROUP BY clause of the query block in which it is...
Definition: item_sum.cc:655
Item_row_number::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2220
Item_sum_count::Item_sum_count
Item_sum_count(THD *thd, Item_sum_count *item)
Definition: item_sum.h:1047
Item_nth_value::m_null_treatment
enum_null_treatment m_null_treatment
Definition: item_sum.h:2562
Item_non_framing_wf::Item_non_framing_wf
Item_non_framing_wf(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2180
Item_ntile::Item_ntile
Item_ntile(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2376
Check_function_as_value_generator_parameters
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:479
Item_sum_udf_float::val_real
double val_real() override
Definition: item_sum.cc:3738
Item_cume_dist::result_type
Item_result result_type() const override
Definition: item_sum.h:2324
MYSQL_TYPE_DOUBLE
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:62
Item_first_last_value::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, List< Item > &fields) override
Definition: item_sum.cc:4891
Item_sum::allow_group_via_temp_table
bool allow_group_via_temp_table
If incremental update of fields is supported.
Definition: item_sum.h:484
Item_sum_bit::value_buff
String value_buff
Stores the result value for the STRING_RESULT.
Definition: item_sum.h:1704
Item_sum_std::func_name
const char * func_name() const override
Definition: item_sum.h:1485
Aggregator::Aggrtype
virtual Aggregator_type Aggrtype()=0
Aggregator_simple
The pass-through aggregator.
Definition: item_sum.h:883
Item_row_number::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2222
Item_sum::walk
bool walk(Item_processor processor, enum_walk walk, uchar *arg) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item_sum.cc:500
Item_func_group_concat::order_array
Mem_root_array< ORDER > order_array
Definition: item_sum.h:2072
Item_avg_field::dec_bin_size
uint dec_bin_size
Definition: item_sum.h:1135
Item_sum_count::add
bool add() override
Definition: item_sum.cc:2078
Item_sum_sum::m_count
ulonglong m_count
Execution state: this is for counting rows entering and leaving the window frame, see m_frame_null_co...
Definition: item_sum.h:982
Item_first_last_value::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2525
Item_sum::ram_limitation
static ulonglong ram_limitation(THD *thd)
Calculate the affordable RAM limit for structures like TREE or Unique used in Item_sum_*.
Definition: item_sum.cc:119
Item_lead_lag::val_int
longlong val_int() override
Definition: item_sum.cc:5319
Item_func_group_concat::force_copy_fields
bool force_copy_fields
Definition: item_sum.h:2085
Item_first_last_value::clear
void clear() override
Definition: item_sum.cc:4910
Item_func_group_concat::dump_leaf_key
friend int dump_leaf_key(void *key_arg, element_count count, void *item_arg)
Append data from current leaf to item->result.
Definition: item_sum.cc:3927
Item_sum_bit::m_count
ulonglong m_count
Execution state (windowing): this is for counting rows entering and leaving the window frame,...
Definition: item_sum.h:1714
Item_sum::COUNT_FUNC
@ COUNT_FUNC
Definition: item_sum.h:434
Item_sum_udf_int::Item_sum_udf_int
Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
Definition: item_sum.h:1962
Item_func_group_concat::make_unique
void make_unique() override
Definition: item_sum.cc:4419
PT_item_list
Wrapper class for an Item list head, used to allocate Item lists in the parser in a context-independe...
Definition: parse_tree_helpers.h:96
Item_first_last_value::m_hybrid_type
Item_result m_hybrid_type
Definition: item_sum.h:2499
Item_sum::eq
bool eq(const Item *item, bool binary_cmp) const override
Definition: item_sum.cc:584
Item_func_group_concat::distinct
bool distinct
Definition: item_sum.h:2082
Item::FIELD_AVG_ITEM
@ FIELD_AVG_ITEM
Definition: item.h:712
Item_sum_sum::update_field
void update_field() override
calc next value and merge it with field_value.
Definition: item_sum.cc:3294
Aggregator::DISTINCT_AGGREGATOR
@ DISTINCT_AGGREGATOR
Definition: item_sum.h:110
Item::unsigned_flag
bool unsigned_flag
Definition: item.h:2722
Item::val_real
virtual double val_real()=0
Item_rank::m_duplicates
ulonglong m_duplicates
Needed to make RANK different from DENSE_RANK.
Definition: item_sum.h:2253
key2
static uchar key2[100]
Definition: mi_test2.cc:58
Item_sum_sum::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1010
Item_sum::SUM_FUNC
@ SUM_FUNC
Definition: item_sum.h:436
Item_func_group_concat::group_concat_key_cmp_with_distinct
friend int group_concat_key_cmp_with_distinct(const void *arg, const void *key1, const void *key2)
Compares the values for fields in expr list of GROUP_CONCAT.
Definition: item_sum.cc:3849
Item_sum_json_object::clear
void clear() override
Definition: item_sum.cc:5660
Item_sum_count::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1057
Item_sum_bit::initial_value_buff_storage
const char initial_value_buff_storage[1]
Buffer used to avoid String allocation in the constructor.
Definition: item_sum.h:1708
Item_sum_sum::val_int
longlong val_int() override
Definition: item_sum.cc:1866
PT_window
Parse tree node for a window; just a shallow wrapper for class Window, q.v.
Definition: parse_tree_nodes.h:1393
Item_first_last_value::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:4951
Item_sum_udf_str::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2016
Item_row_number::val_int
longlong val_int() override
Definition: item_sum.cc:4517
Item_sum_num::is_evaluated
bool is_evaluated
Definition: item_sum.h:907
Item_sum_udf_str::resolve_type
bool resolve_type(THD *) override
Default max_length is max argument length.
Definition: item_sum.cc:3797
Item_sum_json_object::m_tmp_key_value
String m_tmp_key_value
Buffer used to get the value of the key.
Definition: item_sum.h:1241
DECIMAL_RESULT
@ DECIMAL_RESULT
not valid for UDFs
Definition: udf_registration_types.h:44
Item_sum_udf_int::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3775
Item_func_group_concat::tmp_table_param
Temp_table_param * tmp_table_param
Definition: item_sum.h:2057
Item_sum_bit::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1794
Aggregator::item_sum
Item_sum * item_sum
Definition: item_sum.h:104
Item_sum_or::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3087
Item_sum_bit::clear
void clear() override
Definition: item_sum.cc:3073
Item_sum_udf_decimal::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2032
Item_sum_udf_str::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2010
Item_sum_hybrid::update_field
void update_field() override
Definition: item_sum.cc:3368
Item_sum::update_field
virtual void update_field()=0
Item_lead_lag::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5192
String::c_ptr
char * c_ptr()
Definition: sql_string.h:248
MYSQL_TIME
Definition: mysql_time.h:81
Item_non_framing_wf::Item_non_framing_wf
Item_non_framing_wf(THD *thd, Item_non_framing_wf *i)
Definition: item_sum.h:2184
Item_sum::create_tmp_field
virtual Field * create_tmp_field(bool group, TABLE *table)
Definition: item_sum.cc:663
Item_udf_sum::func_name
const char * func_name() const override
Definition: item_sum.h:1909
YYLTYPE
Bison "location" class.
Definition: parse_location.h:43
Item_sum_avg::prec_increment
uint prec_increment
Definition: item_sum.h:1276
Item_sum_json_array::Item_sum_json_array
Item_sum_json_array(THD *thd, Item_sum *item, unique_ptr_destroy_only< Json_wrapper > wrapper, unique_ptr_destroy_only< Json_array > array)
Definition: item_sum.cc:5621
Item_sum_bit_field::val_int
longlong val_int() override
Definition: item_sum.cc:3564
Item_sum_avg::reset_field
void reset_field() override
Definition: item_sum.cc:3232
Item_sum_hybrid::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *r) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:2653
my_time.h
Item_sum_udf_str::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3805
Item_cume_dist::needs_card
bool needs_card() const override
Return true if we need to make two passes over the rows in the partition - either because we need the...
Definition: item_sum.h:2318
Item_nth_value::Item_nth_value
Item_nth_value(const POS &pos, PT_item_list *a, bool from_last, enum_null_treatment null_treatment, PT_window *w)
Definition: item_sum.h:2573
Item_sum_variance::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:2494
Item_variance_field::check_function_as_value_generator
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_sum.h:1334
Item_sum_sum::add
bool add() override
Definition: item_sum.cc:1847
Aggregator_simple::arg_val_real
double arg_val_real() override
Floating point value of being-aggregated argument.
Definition: item_sum.cc:2028
Item_sum::GROUP_CONCAT_FUNC
@ GROUP_CONCAT_FUNC
Definition: item_sum.h:446
Item_func_group_concat::fix_fields
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:4249
sql_list.h
Item_nth_value::super
Item_sum super
Definition: item_sum.h:2570
Item::FIELD_STD_ITEM
@ FIELD_STD_ITEM
Definition: item.h:717
Item_sum_bit_field::Item_sum_bit_field
Item_sum_bit_field(Item_result res_type, Item_sum_bit *item, ulonglong reset_bits)
Definition: item_sum.cc:3543
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
Item_udf_sum::clear
void clear() override
Definition: item_sum.cc:3703
Item_sum_count::val_int
longlong val_int() override
Definition: item_sum.cc:2085
Item_first_last_value::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4841
Item_sum::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:620
Item_sum_int::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:964
Item_sum_variance::recurrence_m
double recurrence_m
Used in recurrence relation.
Definition: item_sum.h:1407
Item_sum_hybrid::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1638
Item_sum::args
Item ** args
Definition: item_sum.h:494
Item_variance_field::val_str
String * val_str(String *str) override
Definition: item_sum.h:1325
Item_sum_sum::sum
double sum
Definition: item_sum.h:974
Item_sum_udf_str::val_str
String * val_str(String *) override
Definition: item_sum.cc:3813
Item_sum
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:390
Item_sum_hybrid::arg_cache
Item_cache * arg_cache
Definition: item_sum.h:1514
Item_func_group_concat::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2115
Item_sum_hybrid_field::hybrid_type
Item_result hybrid_type
Stores the Item's result type.
Definition: item_sum.h:1087
Item_rank::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4547
Item_sum_hybrid::add
bool add() override
Definition: item_sum.cc:2954
Item_nth_value::m_value
Item_cache * m_value
Definition: item_sum.h:2567
Item_sum_udf_int::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1971
Item_sum_json::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1197
Item::get_time_from_real
bool get_time_from_real(MYSQL_TIME *ltime)
Convert val_real() to time in MYSQL_TIME.
Definition: item.cc:1286
Item_sum_bit::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1789
Item_sum_udf_decimal::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2038
Item_sum::aggregator_clear
void aggregator_clear()
Called to cleanup the aggregator.
Definition: item_sum.h:660
Item_sum_json::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5569
Item_sum_max
Definition: item_sum.h:1678
String::length
size_t length() const
Definition: sql_string.h:238
Item_row_number::clear
void clear() override
Definition: item_sum.cc:4545
Item_variance_field::type
enum Type type() const override
Definition: item_sum.h:1323
Item_sum_udf_decimal::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3771
Aggregator_simple::add
bool add() override
Called when there's a new value to be aggregated.
Definition: item_sum.h:890
Item_sum::keep_field_type
virtual bool keep_field_type() const
Definition: item_sum.h:593
Item_sum_count::Item_sum_count
Item_sum_count(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1030
Item_sum_hybrid::value
Item_cache * value
Definition: item_sum.h:1514
Item_std_field::Item_std_field
Item_std_field(Item_sum_std *item)
Definition: item_sum.cc:3636
Item_sum_bit::val_str
String * val_str(String *str) override
Definition: item_sum.cc:2965
Item_avg_field::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1142
Item_row_number::val_real
double val_real() override
Definition: item_sum.cc:4531
Item_udf_sum::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.h:1910
Item_sum_json::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5575
Item_sum_avg
Definition: item_sum.h:1274
Item_sum_json::fix_fields
bool fix_fields(THD *thd, Item **pItem) override
Definition: item_sum.cc:5457
Item_nth_value::reset_field
void reset_field() override
Definition: item_sum.h:2605
my_charset_bin
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:510
Item_sum_variance::cleanup
void cleanup() override
Definition: item_sum.h:1443
Item_sum::result_item
virtual Item * result_item(Field *field)
Definition: item_sum.h:595
Item_sum_sum::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1015
STRING_BUFFER_USUAL_SIZE
#define STRING_BUFFER_USUAL_SIZE
Definition: sql_const.h:126
Item::set_data_type_double
void set_data_type_double()
Set the data type of the Item to be double precision floating point.
Definition: item.h:1047
Item_sum::save_deny_window_func
nesting_map save_deny_window_func
WFs are forbidden when resolving Item_sum; this member is used to restore WF allowance status afterwa...
Definition: item_sum.h:490
Item_variance_field
Definition: item_sum.h:1317
count
ssize_t count
Definition: memcached.c:386
Aggregator_distinct::Const_distinct
Const_distinct
Definition: item_sum.h:824
Item_lead_lag::setup_lead_lag
bool setup_lead_lag()
Definition: item_sum.cc:5283
ORDER
Order clause list element.
Definition: table.h:276
Item_variance_field::sample
uint sample
Definition: item_sum.h:1319
Item_sum_bit::Item_sum_bit
Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg, PT_window *w)
Definition: item_sum.h:1757
Item_sum::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:794
Item_sum_hybrid
Abstract base class for the MIN and MAX aggregate functions.
Definition: item_sum.h:1498
Item_sum_count
Definition: item_sum.h:1020
Item_cume_dist::val_int
longlong val_int() override
Definition: item_sum.cc:4660
Item_first_last_value::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2518
Item_first_last_value::val_real
double val_real() override
Definition: item_sum.cc:4943
Item_sum_bit_field::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3629
Item_sum_hybrid::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:2857
Item_std_field::check_function_as_value_generator
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_sum.h:1464
Item_sum_variance::optimize
bool optimize
If set, uses a algorithm II mentioned in the class description to calculate the variance which helps ...
Definition: item_sum.h:1417
Parse_context
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:99
Item_nth_value::add
bool add() override
Definition: item_sum.h:2607
Item_sum::get_arg_count
uint get_arg_count() const
Definition: item_sum.h:637
Item_sum_int::val_str
String * val_str(String *str) override
Definition: item_sum.cc:1309
Aggregator_distinct::Aggrtype
Aggregator_type Aggrtype() override
Definition: item_sum.h:864
sql_base.h
MYF
#define MYF(v)
Definition: my_inttypes.h:96
Item_sum::type
Type type() const override
Definition: item_sum.h:565
items
Definition: items.h:34
Item_sum_hybrid::val_real
double val_real() override
Definition: item_sum.cc:2795
Item_sum_sum::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:1761
Item_sum_bit_field::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3622
Item_rank
RANK or DENSE_RANK window function, cf.
Definition: item_sum.h:2248
Item_sum_json_object::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5670
Item_sum_udf_int
Definition: item_sum.h:1958
Item_sum_std::Item_sum_std
Item_sum_std(THD *thd, Item_sum_std *item)
Definition: item_sum.h:1481
Item_sum_count::func_name
const char * func_name() const override
Definition: item_sum.h:1065
Item_lead_lag
LEAD/LAG window functions, cf.
Definition: item_sum.h:2406
INT_RESULT
@ INT_RESULT
double
Definition: udf_registration_types.h:42
Item_sum_and::Item_sum_and
Item_sum_and(THD *thd, Item_sum_and *item)
Definition: item_sum.h:1871
Item_cume_dist::super
Item_non_framing_wf super
Definition: item_sum.h:2302
Item_non_framing_wf
Common parent class for window functions that always work on the entire partition,...
Definition: item_sum.h:2175
Item_nth_value::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5176
Item_sum::UDF_SUM_FUNC
@ UDF_SUM_FUNC
Definition: item_sum.h:445
Item_func_group_concat::row_count
uint row_count
Definition: item_sum.h:2078
Aggregator_distinct::composite_key_cmp
static int composite_key_cmp(const void *arg, const void *a, const void *b)
Correctly compare composite keys.
Definition: item_sum.cc:876
Check_function_as_value_generator_parameters::get_unnamed_function_error_code
int get_unnamed_function_error_code() const
Return the correct error code, based on whether or not if we are checking for disallowed functions in...
Definition: item.h:498
Aggregator::~Aggregator
virtual ~Aggregator()
Definition: item_sum.h:108
Item_lead_lag::set_has_value
void set_has_value(bool value)
Definition: item_sum.h:2476
Item_sum_min::Item_sum_min
Item_sum_min(THD *thd, const Item_sum_min *item)
Definition: item_sum.h:1669
Item_sum::MIN_FUNC
@ MIN_FUNC
Definition: item_sum.h:440
udf_handler::fix_fields
bool fix_fields(THD *thd, Item_result_field *item, uint arg_count, Item **args)
Definition: item_func.cc:3932
Item_sum_udf_decimal::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2035
m_string.h
my_atof
double my_atof(const char *nptr)
Definition: dtoa.cc:530
Item_sum_json_array::~Item_sum_json_array
~Item_sum_json_array() override
Item_sum_udf_float::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1950
Item_sum_bit_field::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3596
Item_sum::tmp_args
Item * tmp_args[2]
Definition: item_sum.h:494
Aggregator_distinct::table
TABLE * table
Definition: item_sum.h:791
Aggregator_distinct::CONST_NULL
@ CONST_NULL
Set to true if the result is known to be always NULL.
Definition: item_sum.h:835
my_strntod
#define my_strntod(s, a, b, c, d)
Definition: m_ctype.h:739
parse_tree_node_base.h
Item_processor
bool(Item::* Item_processor)(uchar *arg)
Processor type for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:449
Item_func_group_concat::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:2149
Item_sum_udf_int::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1975
Item_lead_lag::m_default
Item_cache * m_default
Definition: item_sum.h:2412
Item_sum_udf_int::val_real
double val_real() override
Definition: item_sum.h:1965
Item_sum_udf_int::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1974
sql_udf.h
Item_sum_xor::Item_sum_xor
Item_sum_xor(THD *thd, Item_sum_xor *item)
Definition: item_sum.h:1883
Item::get_time_from_decimal
bool get_time_from_decimal(MYSQL_TIME *ltime)
Convert val_decimal() to time in MYSQL_TIME.
Definition: item.cc:1295
Item_lead_lag::func_name
const char * func_name() const override
Definition: item_sum.h:2440
nesting_map
uint64_t nesting_map
Definition: my_table_map.h:31
Item_sum_hybrid_field::mark_field_in_map
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item_sum.h:1091
Item_sum::is_null
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.h:601
Bounds_checked_array< Item * >
Item_sum_sum::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:1780
Item::get_date_from_decimal
bool get_date_from_decimal(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_decimal() to date in MYSQL_TIME.
Definition: item.cc:1208
Item_sum_variance
Definition: item_sum.h:1399
Item_func_group_concat::arg_count_field
uint arg_count_field
The number of selected items, aka the expr list.
Definition: item_sum.h:2077
enum_walk
enum_walk
Enumeration for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:431
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Item_lead_lag::super
Item_non_framing_wf super
Definition: item_sum.h:2424
Item_sum_num::val_str
String * val_str(String *str) override
Definition: item_sum.cc:1303
Item_sum_variance::val_real
double val_real() override
Definition: item_sum.cc:2563
Item_func_group_concat::warning_for_row
bool warning_for_row
Definition: item_sum.h:2083
Item_non_framing_wf::reset_field
void reset_field() override
Definition: item_sum.h:2194
Item_sum::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, List< Item > &fields) override
Definition: item_sum.cc:806
Item_variance_field::func_name
const char * func_name() const override
Definition: item_sum.h:1330
Item_sum::check_sum_func
bool check_sum_func(THD *thd, Item **ref)
Validate the semantic requirements of a set function.
Definition: item_sum.cc:239
Item_sum_count::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1052
List< Item >
Item_first_last_value::cnt
int64 cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2501
Item_sum_avg::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2210
Item_func_group_concat::func_name
const char * func_name() const override
Definition: item_sum.h:2116
Item_udf_sum::print
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:3723
Item_sum_json::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5483
Aggregator::arg_is_null
virtual bool arg_is_null(bool use_null_value)=0
NULLness of being-aggregated argument.
Item_nth_value::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5013
Item_sum_hybrid::create_tmp_field
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:1700
Item_sum_json::check_wf_semantics
bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5452
Item_percent_rank::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2348
Item_sum::get_arg
Item * get_arg(uint i)
Definition: item_sum.h:635
Item_sum_variance::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1428
Item_first_last_value::m_null_treatment
enum_null_treatment m_null_treatment
Definition: item_sum.h:2498
Item_func_group_concat::~Item_func_group_concat
~Item_func_group_concat() override
Definition: item_sum.cc:4488
Field
Definition: field.h:695
Item_func_group_concat::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4184
Item_percent_rank::Item_percent_rank
Item_percent_rank(const POS &pos, PT_window *w)
Definition: item_sum.h:2341
udf_registration_types.h
Aggregator_distinct::endup
void endup() override
Calculate the aggregate function value.
Definition: item_sum.cc:1239
Aggregator_distinct::setup
bool setup(THD *) override
Called before feeding the first row.
Definition: item_sum.cc:947
Item_sum_sum::val_real
double val_real() override
Definition: item_sum.cc:1890
Item_sum_json::m_value
String m_value
String used when reading JSON binary values or JSON text values.
Definition: item_sum.h:1177
Item_percent_rank::m_last_peer_visited
bool m_last_peer_visited
Set when the last peer has been visited.
Definition: item_sum.h:2338
Item_sum_bit_field::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1161
Window_evaluation_requirements
Collects evaluation requirements from a window function, used by Item_sum::check_wf_semantics and its...
Definition: window.h:1429
Item_ntile::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4752
Item_sum::clean_up_after_removal
bool clean_up_after_removal(uchar *arg) override
Remove the item from the list of inner aggregation functions in the SELECT_LEX it was moved to by Ite...
Definition: item_sum.cc:534
Item_sum_udf_decimal::val_str
String * val_str(String *) override
Definition: item_sum.cc:3754
Item_sum_and::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3101
SELECT_LEX
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:986
Item_func_group_concat::tree_base
TREE tree_base
Definition: item_sum.h:2060
Item_nth_value::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5168
Item_sum_int::Item_sum_int
Item_sum_int(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:936
Item_sum::STD_FUNC
@ STD_FUNC
Definition: item_sum.h:442
Item_sum_hybrid::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:2884
Item_sum::check_wf_semantics
virtual bool check_wf_semantics(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs)
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:383
Item_sum_udf_str::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2013
Aggregator_simple::arg_val_decimal
my_decimal * arg_val_decimal(my_decimal *value) override
Decimal value of being-aggregated argument.
Definition: item_sum.cc:2024
Item_func_grouping
Class for implementation of the GROUPING function.
Definition: item_sum.h:2634
Item_sum_json_object
Implements aggregation of values into an object.
Definition: item_sum.h:1237
Item_variance_field::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1329
Item_sum_num::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1305
final
#define final(a, b, c)
Definition: hash.c:109
Aggregator_distinct::endup_done
bool endup_done
Definition: item_sum.h:780
Item_sum_json::m_wrapper
unique_ptr_destroy_only< Json_wrapper > m_wrapper
Wrapper around the container (object/array) which accumulates the value.
Definition: item_sum.h:1181
Item_sum_num::Item_sum_num
Item_sum_num(THD *thd, Item_sum_num *item)
Definition: item_sum.h:916
Item_sum::ref_by
Item ** ref_by[2]
For a group aggregate which is aggregated into an outer query block; none, or just the first or both ...
Definition: item_sum.h:471
Item::get_time_from_string
bool get_time_from_string(MYSQL_TIME *ltime)
Convert val_str() to time in MYSQL_TIME.
Definition: item.cc:1276
Item_row_number::val_decimal
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4540
Item_nth_value::resolve_type
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:4998
Item_func_group_concat::print
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:4452
Item_rank::val_decimal
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4605
MY_CHARSET_HANDLER::strtoll10
longlong(* strtoll10)(const CHARSET_INFO *cs, const char *nptr, const char **endptr, int *error)
Definition: m_ctype.h:341
Item_sum_udf_decimal::val_real
double val_real() override
Definition: item_sum.cc:3758
Item_sum::Item_sum
Item_sum(Item *a)
Definition: item_sum.h:516
Item_sum_json::~Item_sum_json
~Item_sum_json() override
udf_handler::name
const char * name() const
Definition: sql_udf.h:108
buffer
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
Item_std_field::func_name
const char * func_name() const override
Definition: item_sum.h:1460
Item_sum::wf_common_init
bool wf_common_init()
Common initial actions for window functions.
Definition: item_sum.cc:827
Item::FIELD_BIT_ITEM
@ FIELD_BIT_ITEM
Definition: item.h:730
Item_sum_count::cleanup
void cleanup() override
Definition: item_sum.cc:2117
my_sys.h
Item_sum_bit::reset_bits
ulonglong reset_bits
Stores the neutral element for function.
Definition: item_sum.h:1700
Item_sum::set_distinct
void set_distinct(bool distinct)
Definition: item_sum.h:669
Item_sum_bit_field::func_name
const char * func_name() const override
Definition: item_sum.h:1165
Item_sum_xor
Definition: item_sum.h:1876
Item_sum_json::m_conversion_buffer
String m_conversion_buffer
String used for converting JSON text values to utf8mb4 charset.
Definition: item_sum.h:1179
Item_sum_avg::val_str
String * val_str(String *str) override
Definition: item_sum.cc:2296
Item_sum_avg::m_avg_dec
my_decimal m_avg_dec
Definition: item_sum.h:1279
Item_sum_hybrid::m_want_first
bool m_want_first
For min() - Set to true when results are ordered in ascending and false when descending.
Definition: item_sum.h:1533
Item_sum_hybrid::Item_sum_hybrid
Item_sum_hybrid(THD *thd, const Item_sum_hybrid *item)
Definition: item_sum.h:1609
Item_func_group_concat::val_str
String * val_str(String *str) override
Definition: item_sum.cc:4427
mem_root_array.h
Item_percent_rank::result_type
Item_result result_type() const override
Definition: item_sum.h:2365
Item_func_group_concat::val_int
longlong val_int() override
Definition: item_sum.h:2131
Item_rank::val_int
longlong val_int() override
Definition: item_sum.cc:4567
Item_ntile::val_decimal
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4827
Item_sum_hybrid_field::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1090
Item_sum_json_object::m_json_object
unique_ptr_destroy_only< Json_object > m_json_object
Accumulates the final value.
Definition: item_sum.h:1239
Item_sum_variance::recurrence_s2
double recurrence_s2
Definition: item_sum.h:1408
Item_non_framing_wf::super
Item_sum super
Definition: item_sum.h:2176
Item_sum_bit::is_and
bool is_and() const
Definition: item_sum.h:1819
Aggregator_distinct::~Aggregator_distinct
~Aggregator_distinct() override
Definition: item_sum.cc:2008
Item_first_last_value::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:4968
Item_sum_min::clone_hybrid
Item_sum_min * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:2931
Item_sum::get_arg_ptr
Item ** get_arg_ptr(uint i)
Definition: item_sum.h:639
Item_sum_hybrid::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2839
Item_sum_sum::m_frame_null_count
ulonglong m_frame_null_count
Execution state: this is for counting NULLs of rows entering and leaving the window frame,...
Definition: item_sum.h:989
Item_lead_lag::needs_card
bool needs_card() const override
Return true if we need to make two passes over the rows in the partition - either because we need the...
Definition: item_sum.h:2461
Item_sum_num::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:928
Item_sum::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:488
Item_func::Functype
Functype
Definition: item_func.h:121
mysql_time.h
Item_func_group_concat::result_type
Item_result result_type() const override
Definition: item_sum.h:2117
Item_sum_udf_float::val_str
String * val_str(String *str) override
Definition: item_sum.cc:3746
Item_udf_sum::super
Item_sum super
Definition: item_sum.h:1893
Aggregator_distinct::tmp_table_param
Temp_table_param * tmp_table_param
Definition: item_sum.h:805
Item_sum::NTILE_FUNC
@ NTILE_FUNC
Definition: item_sum.h:453
Item_sum::super
Item_result_field super
Definition: item_sum.h:391
Item_sum_bit::m_digit_cnt_card
uint m_digit_cnt_card
Definition: item_sum.h:1749
Item_sum::aggr_select
SELECT_LEX * aggr_select
For a group aggregate, query block where function is aggregated.
Definition: item_sum.h:480
Item_sum_sum::hybrid_type
Item_result hybrid_type
Definition: item_sum.h:973
Item_func_group_concat::unique_filter
Unique * unique_filter
If DISTINCT is used with this GROUP_CONCAT, this member is used to filter out duplicates.
Definition: item_sum.h:2070
Item_sum_variance::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2595
Aggregator_distinct::arg_val_decimal
my_decimal * arg_val_decimal(my_decimal *value) override
Decimal value of being-aggregated argument.
Definition: item_sum.cc:2047
Item::get_date_from_numeric
bool get_date_from_numeric(MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
Convert a numeric type to date.
Definition: item.cc:1236
Item_sum::in_sum_func
Item_sum * in_sum_func
the containing set function if any
Definition: item_sum.h:473
Item_sum_bit::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:1367
Item_sum_udf_int::resolve_type
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1976
Item_sum::reset_and_add
bool reset_and_add()
Resets the aggregate value to its default and aggregates the current value of its attribute(s).
Definition: item_sum.h:572
Item_sum_bit::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3003
Aggregator_simple::arg_is_null
bool arg_is_null(bool use_null_value) override
NULLness of being-aggregated argument.
Definition: item_sum.cc:2032
Item_sum_avg::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1304
Item_func_group_concat::clear
void clear() override
Definition: item_sum.cc:4192
Item_sum::Sumfunctype
Sumfunctype
Definition: item_sum.h:433
Item_sum_bit::val_int
longlong val_int() override
Definition: item_sum.cc:3050
Item_sum_bit::hybrid_type
Item_result hybrid_type
Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT.
Definition: item_sum.h:1706
Item_sum::m_window_resolved
bool m_window_resolved
True if we have already resolved this window functions window reference.
Definition: item_sum.h:411
Item_lead_lag::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2450
Item_cume_dist::Item_cume_dist
Item_cume_dist(const POS &pos, PT_window *w)
Definition: item_sum.h:2305
Item_sum_bit::super
Item_sum super
Definition: item_sum.h:1698
Item_sum_variance::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1436
false
#define false
Definition: config_static.h:43
group_concat_key_cmp_with_distinct
int group_concat_key_cmp_with_distinct(const void *arg, const void *key1, const void *key2)
Compares the values for fields in expr list of GROUP_CONCAT.
Definition: item_sum.cc:3849
Item_sum_or::Item_sum_or
Item_sum_or(THD *thd, Item_sum_or *item)
Definition: item_sum.h:1861
item.h