MySQL  8.0.23
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, 2020, Oracle and/or its affiliates.
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 <sys/types.h>
29 
30 #include <climits>
31 #include <cmath>
32 #include <cstdio>
33 #include <map>
34 #include <memory>
35 #include <string>
36 #include <vector>
37 
38 #include "field_types.h" // enum_field_types
39 #include "m_ctype.h"
40 #include "m_string.h"
41 #include "my_alloc.h"
42 #include "my_compiler.h"
43 #include "my_dbug.h"
44 #include "my_inttypes.h"
45 #include "my_sys.h"
46 #include "my_table_map.h"
47 #include "my_time.h"
48 #include "my_tree.h" // TREE
50 #include "mysql_time.h"
51 #include "mysqld_error.h"
52 #include "sql/enum_query_type.h"
53 #include "sql/item.h" // Item_result_field
54 #include "sql/item_func.h" // Item_int_func
55 #include "sql/mem_root_array.h"
56 #include "sql/my_decimal.h"
57 #include "sql/parse_location.h" // POS
58 #include "sql/parse_tree_window.h" // PT_window
59 #include "sql/sql_base.h"
60 #include "sql/sql_const.h"
61 #include "sql/sql_list.h"
62 #include "sql/sql_udf.h" // udf_handler
63 #include "sql/thr_malloc.h" // THR_MALLOC
64 #include "sql/window_lex.h"
65 #include "sql_string.h"
66 #include "template_utils.h"
67 
68 class Field;
69 class Item_sum;
70 class Json_array;
71 class Json_object;
72 class Json_wrapper;
73 class PT_item_list;
74 class PT_order_list;
75 class SELECT_LEX;
76 class THD;
77 class Temp_table_param;
78 class Window;
79 struct ORDER;
80 struct Parse_context;
81 struct TABLE;
83 
84 /**
85  The abstract base class for the Aggregator_* classes.
86  It implements the data collection functions (setup/add/clear)
87  as either pass-through to the real functionality or
88  as collectors into an Unique (for distinct) structure.
89 
90  Note that update_field/reset_field are not in that
91  class, because they're simply not called when
92  GROUP BY/DISTINCT can be handled with help of index on grouped
93  fields (allow_group_via_temp_table is false);
94 */
95 
96 class Aggregator {
97  friend class Item_sum;
98  friend class Item_sum_sum;
99  friend class Item_sum_count;
100  friend class Item_sum_avg;
101 
102  /*
103  All members are protected as this class is not usable outside of an
104  Item_sum descendant.
105  */
106  protected:
107  /* the aggregate function class to act on */
109 
110  public:
111  Aggregator(Item_sum *arg) : item_sum(arg) {}
112  virtual ~Aggregator() {}
113 
115  virtual Aggregator_type Aggrtype() = 0;
116 
117  /**
118  Called before adding the first row.
119  Allocates and sets up the internal aggregation structures used,
120  e.g. the Unique instance used to calculate distinct.
121  */
122  virtual bool setup(THD *) = 0;
123 
124  /**
125  Called when we need to wipe out all the data from the aggregator :
126  all the values acumulated and all the state.
127  Cleans up the internal structures and resets them to their initial state.
128  */
129  virtual void clear() = 0;
130 
131  /**
132  Called when there's a new value to be aggregated.
133  Updates the internal state of the aggregator to reflect the new value.
134  */
135  virtual bool add() = 0;
136 
137  /**
138  Called when there are no more data and the final value is to be retrieved.
139  Finalises the state of the aggregator, so the final result can be retrieved.
140  */
141  virtual void endup() = 0;
142 
143  /** Decimal value of being-aggregated argument */
145  /** Floating point value of being-aggregated argument */
146  virtual double arg_val_real() = 0;
147  /**
148  NULLness of being-aggregated argument.
149 
150  @param use_null_value Optimization: to determine if the argument is NULL
151  we must, in the general case, call is_null() on it, which itself might
152  call val_*() on it, which might be costly. If you just have called
153  arg_val*(), you can pass use_null_value=true; this way, arg_is_null()
154  might avoid is_null() and instead do a cheap read of the Item's null_value
155  (updated by arg_val*()).
156  */
157  virtual bool arg_is_null(bool use_null_value) = 0;
158 };
159 
160 /**
161  Class Item_sum is the base class used for special expressions that SQL calls
162  'set functions'. These expressions are formed with the help of aggregate
163  functions such as SUM, MAX, GROUP_CONCAT etc.
164  Class Item_sum is also the base class for Window functions; the text below
165  first documents set functions, then window functions.
166 
167  GENERAL NOTES
168 
169  A set function cannot be used in all positions where expressions are accepted.
170  There are some quite explicable restrictions for the use of set functions.
171 
172  In the query:
173 
174  SELECT AVG(b) FROM t1 WHERE SUM(b) > 20 GROUP by a
175 
176  the set function AVG(b) is valid, while the usage of SUM(b) is invalid.
177  A WHERE condition must contain expressions that can be evaluated for each row
178  of the table. Yet the expression SUM(b) can be evaluated only for each group
179  of rows with the same value of column a.
180  In the query:
181 
182  SELECT AVG(b) FROM t1 WHERE c > 30 GROUP BY a HAVING SUM(b) > 20
183 
184  both set function expressions AVG(b) and SUM(b) are valid.
185 
186  We can say that in a query without nested selects an occurrence of a
187  set function in an expression of the SELECT list or/and in the HAVING
188  clause is valid, while in the WHERE clause, FROM clause or GROUP BY clause
189  it is invalid.
190 
191  The general rule to detect whether a set function is valid in a query with
192  nested subqueries is much more complicated.
193 
194  Consider the following query:
195 
196  SELECT t1.a FROM t1 GROUP BY t1.a
197  HAVING t1.a > ALL (SELECT t2.c FROM t2 WHERE SUM(t1.b) < t2.c).
198 
199  The set function SUM(b) is used here in the WHERE clause of the subquery.
200  Nevertheless it is valid since it is contained in the HAVING clause of the
201  outer query. The expression SUM(t1.b) is evaluated for each group defined
202  in the main query, not for groups of the subquery.
203 
204  The problem of finding the query where to aggregate a particular
205  set function is not so simple as it seems to be.
206 
207  In the query:
208  SELECT t1.a FROM t1 GROUP BY t1.a
209  HAVING t1.a > ALL(SELECT t2.c FROM t2 GROUP BY t2.c
210  HAVING SUM(t1.a) < t2.c)
211 
212  the set function can be evaluated in both the outer and the inner query block.
213  If we evaluate SUM(t1.a) for the outer query then we get the value of t1.a
214  multiplied by the cardinality of a group in table t1. In this case,
215  SUM(t1.a) is used as a constant value in each correlated subquery.
216  But SUM(t1.a) can also be evaluated for the inner query.
217  In this case t1.a will be a constant value for each correlated subquery and
218  summation is performed for each group of table t2.
219  (Here it makes sense to remind that the query
220 
221  SELECT c FROM t GROUP BY a HAVING SUM(1) < a
222 
223  is quite valid in our SQL).
224 
225  So depending on what query block we assign the set function to we
226  can get different results.
227 
228  The general rule to detect the query block Q where a set function will be
229  aggregated (evaluated) can be formulated as follows.
230 
231  Reference: SQL2011 @<set function specification@> syntax rules 6 and 7.
232 
233  Consider a set function S(E) where E is an expression which contains
234  column references C1, ..., Cn. Resolve all column references Ci against
235  the query block Qi containing the set function S(E). Let Q be the innermost
236  query block of all query blocks Qi. (It should be noted here that S(E)
237  in no way can be aggregated in the query block containing the subquery Q,
238  otherwise S(E) would refer to at least one unbound column reference).
239  If S(E) is used in a construct of Q where set functions are allowed then
240  we aggregate S(E) in Q.
241  Otherwise:
242  - if ANSI SQL mode is enabled (MODE_ANSI), then report an error.
243  - otherwise, look for the innermost query block containing S(E) of those
244  where usage of S(E) is allowed. The place of aggregation depends on which
245  clause the subquery is contained within; It will be different when
246  contained in a WHERE clause versus in the select list or in HAVING clause.
247 
248  Let's demonstrate how this rule is applied to the following queries.
249 
250  1. SELECT t1.a FROM t1 GROUP BY t1.a
251  HAVING t1.a > ALL(SELECT t2.b FROM t2 GROUP BY t2.b
252  HAVING t2.b > ALL(SELECT t3.c FROM t3 GROUP BY t3.c
253  HAVING SUM(t1.a+t2.b) < t3.c))
254  For this query the set function SUM(t1.a+t2.b) contains t1.a and t2.b
255  with t1.a defined in the outermost query, and t2.b defined for its
256  subquery. The set function is contained in the HAVING clause of the subquery
257  and can be evaluated in this subquery.
258 
259  2. SELECT t1.a FROM t1 GROUP BY t1.a
260  HAVING t1.a > ALL(SELECT t2.b FROM t2
261  WHERE t2.b > ALL (SELECT t3.c FROM t3 GROUP BY t3.c
262  HAVING SUM(t1.a+t2.b) < t3.c))
263  The set function SUM(t1.a+t2.b) is contained in the WHERE clause of the second
264  query block - the outermost query block where t1.a and t2.b are defined.
265  If we evaluate the function in this subquery we violate the context rules.
266  So we evaluate the function in the third query block (over table t3) where it
267  is used under the HAVING clause; if in ANSI SQL mode, an error is thrown.
268 
269  3. SELECT t1.a FROM t1 GROUP BY t1.a
270  HAVING t1.a > ALL(SELECT t2.b FROM t2
271  WHERE t2.b > ALL (SELECT t3.c FROM t3
272  WHERE SUM(t1.a+t2.b) < t3.c))
273  In this query, evaluation of SUM(t1.a+t2.b) is not valid neither in the second
274  nor in the third query block.
275 
276  Set functions can generally not be nested. In the query
277 
278  SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20
279 
280  the expression SUM(b) is not valid, even though it is contained inside
281  a HAVING clause.
282  However, it is acceptable in the query:
283 
284  SELECT t.1 FROM t1 GROUP BY t1.a HAVING SUM(t1.b) > 20.
285 
286  An argument of a set function does not have to be a simple column reference
287  as seen in examples above. This can be a more complex expression
288 
289  SELECT t1.a FROM t1 GROUP BY t1.a HAVING SUM(t1.b+1) > 20.
290 
291  The expression SUM(t1.b+1) has clear semantics in this context:
292  we sum up the values of t1.b+1 where t1.b varies for all values within a
293  group of rows that contain the same t1.a value.
294 
295  A set function for an outer query yields a constant value within a subquery.
296  So the semantics of the query
297 
298  SELECT t1.a FROM t1 GROUP BY t1.a
299  HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
300  HAVING AVG(t2.c+SUM(t1.b)) > 20)
301 
302  is still clear. For a group of rows with the same value for t1.a, calculate
303  the value of SUM(t1.b) as 's'. This value is substituted in the subquery:
304 
305  SELECT t2.c FROM t2 GROUP BY t2.c HAVING AVG(t2.c+s)
306 
307  By the same reason the following query with a subquery
308 
309  SELECT t1.a FROM t1 GROUP BY t1.a
310  HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
311  HAVING AVG(SUM(t1.b)) > 20)
312  is also valid.
313 
314  IMPLEMENTATION NOTES
315 
316  The member base_select contains a reference to the query block that the
317  set function is contained within.
318 
319  The member aggr_select contains a reference to the query block where the
320  set function is aggregated.
321 
322  The field max_aggr_level holds the maximum of the nest levels of the
323  unbound column references contained in the set function. A column reference
324  is unbound within a set function if it is not bound by any subquery
325  used as a subexpression in this function. A column reference is bound by
326  a subquery if it is a reference to the column by which the aggregation
327  of some set function that is used in the subquery is calculated.
328  For the set function used in the query
329 
330  SELECT t1.a FROM t1 GROUP BY t1.a
331  HAVING t1.a > ALL(SELECT t2.b FROM t2 GROUP BY t2.b
332  HAVING t2.b > ALL(SELECT t3.c FROM t3 GROUP BY t3.c
333  HAVING SUM(t1.a+t2.b) < t3.c))
334 
335  the value of max_aggr_level is equal to 1 since t1.a is bound in the main
336  query, and t2.b is bound by the first subquery whose nest level is 1.
337  Obviously a set function cannot be aggregated in a subquery whose
338  nest level is less than max_aggr_level. (Yet it can be aggregated in the
339  subqueries whose nest level is greater than max_aggr_level.)
340  In the query
341  SELECT t1.a FROM t1 HAVING AVG(t1.a+(SELECT MIN(t2.c) FROM t2))
342 
343  the value of the max_aggr_level for the AVG set function is 0 since
344  the reference t2.c is bound in the subquery.
345 
346  If a set function contains no column references (like COUNT(*)),
347  max_aggr_level is -1.
348 
349  The field 'max_sum_func_level' is to contain the maximum of the
350  nest levels of the set functions that are used as subexpressions of
351  the arguments of the given set function, but not aggregated in any
352  subquery within this set function. A nested set function s1 can be
353  used within set function s0 only if s1.max_sum_func_level <
354  s0.max_sum_func_level. Set function s1 is considered as nested
355  for set function s0 if s1 is not calculated in any subquery
356  within s0.
357 
358  A set function that is used as a subexpression in an argument of another
359  set function refers to the latter via the field 'in_sum_func'.
360 
361  The condition imposed on the usage of set functions are checked when
362  we traverse query subexpressions with the help of the recursive method
363  fix_fields. When we apply this method to an object of the class
364  Item_sum, first, on the descent, we call the method init_sum_func_check
365  that initialize members used at checking. Then, on the ascent, we
366  call the method check_sum_func that validates the set function usage
367  and reports an error if it is invalid.
368  The method check_sum_func serves to link the items for the set functions
369  that are aggregated in the containing query blocks. Circular chains of such
370  functions are attached to the corresponding SELECT_LEX structures
371  through the field inner_sum_func_list.
372 
373  Exploiting the fact that the members mentioned above are used in one
374  recursive function we could have allocated them on the thread stack.
375  Yet we don't do it now.
376 
377  It is assumed that the nesting level of subqueries does not exceed 63
378  (valid nesting levels are stored in a 64-bit bitmap called nesting_map).
379  The assumption is enforced in LEX::new_query().
380 
381  WINDOW FUNCTIONS
382 
383  Most set functions (e.g. SUM, COUNT, AVG) can also be used as window
384  functions. In that case, notable differences compared to set functions are:
385  - not using any Aggregator
386  - not supporting DISTINCT
387  - val_*() does more than returning the function's current value: it
388  first accumulates the function's argument into the function's
389  state. Execution (e.g. end_write_wf()) manipulates temporary tables which
390  contain input for WFs; each input row is passed to copy_funcs() which calls
391  the WF's val_*() to accumulate it.
392 */
393 
397 
398  friend class Aggregator_distinct;
399  friend class Aggregator_simple;
400 
401  protected:
402  /**
403  Aggregator class instance. Not set initially. Allocated only after
404  it is determined if the incoming data are already distinct.
405  */
407 
408  /**
409  If sum is a window function, this field contains the window.
410  */
412  /**
413  True if we have already resolved this window functions window reference.
414  Used in execution of prepared statement to avoid re-resolve.
415  */
417 
418  private:
419  /**
420  Used in making ROLLUP. Set for the ROLLUP copies of the original
421  Item_sum and passed to create_tmp_field() to cause it to work
422  over the temp table buffer that is referenced by
423  Item_result_field::result_field.
424  */
426 
427  /**
428  Indicates how the aggregate function was specified by the parser :
429  true if it was written as AGGREGATE(DISTINCT),
430  false if it was AGGREGATE()
431  */
433 
434  public:
435  bool has_force_copy_fields() const { return force_copy_fields; }
436  bool has_with_distinct() const { return with_distinct; }
437 
438  enum Sumfunctype {
439  COUNT_FUNC, // COUNT
440  COUNT_DISTINCT_FUNC, // COUNT (DISTINCT)
441  SUM_FUNC, // SUM
442  SUM_DISTINCT_FUNC, // SUM (DISTINCT)
443  AVG_FUNC, // AVG
444  AVG_DISTINCT_FUNC, // AVG (DISTINCT)
445  MIN_FUNC, // MIN
446  MAX_FUNC, // MAX
447  STD_FUNC, // STD/STDDEV/STDDEV_POP
448  VARIANCE_FUNC, // VARIANCE/VAR_POP and VAR_SAMP
449  SUM_BIT_FUNC, // BIT_AND, BIT_OR and BIT_XOR
450  UDF_SUM_FUNC, // user defined functions
451  GROUP_CONCAT_FUNC, // GROUP_CONCAT
452  JSON_AGG_FUNC, // JSON_ARRAYAGG and JSON_OBJECTAGG
453  ROW_NUMBER_FUNC, // Window functions
463  };
464 
465  /**
466  @note most member variables below serve only for grouped aggregate
467  functions.
468  */
469 
470  /**
471  For a group aggregate which is aggregated into an outer query
472  block; none, or just the first or both cells may be non-zero. They are
473  filled with references to the group aggregate (for example if it is the
474  argument of a function; it is then a pointer to that function's args[i]
475  pointer).
476  */
478  Item_sum *next_sum; ///< next in the circular chain of registered objects
479  Item_sum *in_sum_func; ///< the containing set function if any
480  SELECT_LEX *base_select; ///< query block where function is placed
481  /**
482  For a group aggregate, query block where function is aggregated. For a
483  window function, nullptr, as such function is always aggregated in
484  base_select, as it mustn't contain any outer reference.
485  */
487  int8 max_aggr_level; ///< max level of unbound column references
488  int8
489  max_sum_func_level; ///< max level of aggregation for contained functions
490  bool allow_group_via_temp_table; ///< If incremental update of fields is
491  ///< supported.
492  /**
493  WFs are forbidden when resolving Item_sum; this member is used to restore
494  WF allowance status afterwards.
495  */
497 
498  protected:
500  /**
501  True means that this field has been evaluated during optimization.
502  When set, used_tables() returns zero and const_item() returns true.
503  The value must be reset to false after execution.
504  */
506  static ulonglong ram_limitation(THD *thd);
507 
508  public:
509  void mark_as_sum_func();
511 
512  Item_sum(const POS &pos, PT_window *w)
513  : super(pos),
514  super2(nullptr, 0),
515  m_window(w),
517  next_sum(nullptr),
521  init_aggregator();
522  }
523 
525  : super2(1),
526  m_window(nullptr),
528  next_sum(nullptr),
532  args[0] = a;
534  init_aggregator();
535  }
536 
537  Item_sum(const POS &pos, Item *a, PT_window *w)
538  : super(pos),
539  super2(1),
540  m_window(w),
542  next_sum(nullptr),
546  args[0] = a;
547  init_aggregator();
548  }
549 
550  Item_sum(const POS &pos, Item *a, Item *b, PT_window *w)
551  : super(pos),
552  super2(2),
553  m_window(w),
555  next_sum(nullptr),
559  args[0] = a;
560  args[1] = b;
561  init_aggregator();
562  }
563 
564  Item_sum(const POS &pos, PT_item_list *opt_list, PT_window *w);
565 
566  /// Copy constructor, need to perform subqueries with temporary tables
567  Item_sum(THD *thd, const Item_sum *item);
568 
569  bool itemize(Parse_context *pc, Item **res) override;
570  Type type() const override { return SUM_FUNC_ITEM; }
571  virtual enum Sumfunctype sum_func() const = 0;
572 
573  // Differs only for Item_rollup_sum_switcher.
574  virtual enum Sumfunctype real_sum_func() const { return sum_func(); }
575 
576  /**
577  Resets the aggregate value to its default and aggregates the current
578  value of its attribute(s).
579  */
580  inline bool reset_and_add() {
582  return aggregator_add();
583  }
584 
585  /*
586  Called when new group is started and results are being saved in
587  a temporary table. Similarly to reset_and_add() it resets the
588  value to its default and aggregates the value of its
589  attribute(s), but must also store it in result_field.
590  This set of methods (result_item(), reset_field, update_field()) of
591  Item_sum is used only if allow_group_via_temp_table is true. Otherwise
592  copy_or_same() is used to obtain a copy of this item.
593  */
594  virtual void reset_field() = 0;
595  /*
596  Called for each new value in the group, when temporary table is in use.
597  Similar to add(), but uses temporary table field to obtain current value,
598  Updated value is then saved in the field.
599  */
600  virtual void update_field() = 0;
601  virtual bool keep_field_type() const { return false; }
602  bool resolve_type(THD *) override;
603  virtual Item *result_item(Field *field) {
604  Item_field *item = new Item_field(field);
605  if (item == nullptr) return nullptr;
606  // Aggregated fields have no reference to an underlying table
607  DBUG_ASSERT(item->orig_db_name() == nullptr &&
608  item->orig_table_name() == nullptr);
609  // Break the connection to the original field since this is an aggregation
610  item->set_orig_field_name(nullptr);
611  return item;
612  }
613  table_map used_tables() const override {
614  return forced_const ? 0 : used_tables_cache;
615  }
616  void update_used_tables() override;
617  void fix_after_pullout(SELECT_LEX *parent_select,
618  SELECT_LEX *removed_select) override;
620  bool is_null() override { return null_value; }
621  void make_const() {
622  // "forced_const" will make used_tables() return zero for this object
623  forced_const = true;
624  }
625  void print(const THD *thd, String *str,
626  enum_query_type query_type) const override;
627  void fix_num_length_and_dec();
628  bool eq(const Item *item, bool binary_cmp) const override;
629  /**
630  Mark an aggregate as having no rows.
631 
632  This function is called by the execution engine to assign 'NO ROWS
633  FOUND' value to an aggregate item, when the underlying result set
634  has no rows. Such value, in a general case, may be different from
635  the default value of the item after 'clear()': e.g. a numeric item
636  may be initialized to 0 by clear() and to NULL by
637  no_rows_in_result().
638  */
639  void no_rows_in_result() override {
643  }
644  virtual void make_unique() { force_copy_fields = true; }
645  virtual Field *create_tmp_field(bool group, TABLE *table);
646 
647  /// argument used by walk method collect_grouped_aggregates ("cga")
649  /// accumulated all aggregates found
650  std::vector<Item_sum *> list;
651  std::set<Item_sum *> aggregates_that_were_hidden;
652  /**
653  The query block we walk from. All found aggregates must aggregate in
654  this; if some aggregate in outer query blocks, break off transformation.
655  */
656  SELECT_LEX *m_select{nullptr};
657  /// true: break off transformation
658  bool m_break_off{false};
660  };
661 
662  bool collect_grouped_aggregates(uchar *) override;
663  Item *replace_aggregate(uchar *) override;
664  bool collect_scalar_subqueries(uchar *) override;
666 
667  bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
668  Item *transform(Item_transformer transformer, uchar *arg) override;
669  bool clean_up_after_removal(uchar *arg) override;
670  bool aggregate_check_group(uchar *arg) override;
671  bool aggregate_check_distinct(uchar *arg) override;
672  bool has_aggregate_ref_in_group_by(uchar *arg) override;
673  bool init_sum_func_check(THD *thd);
674  bool check_sum_func(THD *thd, Item **ref);
675 
676  virtual Item *get_arg(uint i) { return args[i]; }
677  virtual Item *set_arg(THD *thd, uint i, Item *new_val);
678  /// @todo delete this when we no longer support temporary transformations
679  Item **get_arg_ptr(uint i) { return &args[i]; }
680 
681  bool fix_fields(THD *thd, Item **ref) override;
682 
683  /* Initialization of distinct related members */
685  aggr = nullptr;
686  with_distinct = false;
687  force_copy_fields = false;
688  }
689 
690  /**
691  Called to initialize the aggregator.
692  */
693 
694  virtual bool aggregator_setup(THD *thd) { return aggr->setup(thd); }
695 
696  /**
697  Called to cleanup the aggregator.
698  */
699 
700  inline void aggregator_clear() { aggr->clear(); }
701 
702  /**
703  Called to add value to the aggregator.
704  */
705 
706  inline bool aggregator_add() { return aggr->add(); }
707 
708  /* stores the declared DISTINCT flag (from the parser) */
709  void set_distinct(bool distinct) {
710  with_distinct = distinct;
712  }
713 
714  /*
715  Set the type of aggregation : DISTINCT or not.
716 
717  May be called multiple times.
718  */
719 
720  virtual int set_aggregator(Aggregator::Aggregator_type aggregator);
721 
722  virtual void clear() = 0;
723  virtual bool add() = 0;
724  virtual bool setup(THD *) { return false; }
725 
726  /**
727  Only relevant for aggregates qua window functions. Checks semantics after
728  windows have been set up and checked. Window functions have specific
729  requirements on the window specifications. Used at resolution time.
730 
731  @param thd Current thread
732  @param select The current select
733  @param [out] reqs Holds collected requirements from this wf
734 
735  @returns true if error
736  */
737  virtual bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
739 
740  /**
741  Like check_wf_semantics1.
742  For checks which cannot be done in resolution phase (mostly those for
743  input parameters which can be '?' and must be >=0: value isn't known
744  before execution phase).
745  */
746  virtual bool check_wf_semantics2(
747  Window_evaluation_requirements *reqs MY_ATTRIBUTE((unused))) {
748  return false;
749  }
750 
751  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
752  mem_root_deque<Item *> *fields) override;
753 
754  void cleanup() override;
755 
756  const Window *window() const { return m_window; }
757  bool reset_wf_state(uchar *arg) override;
758 
759  /**
760  All aggregates are framing, i.e. they work on the window's frame. If none
761  is defined, the frame is by default the entire partition, unless ORDER BY
762  is defined, in which case it is the set of rows from the start of the
763  partition to and including the peer set of the current row.
764 
765  Some window functions are not framing, i.e. they always work on the entire
766  partition. For such window functions, the method is overridden to
767  return false.
768  */
769  virtual bool framing() const { return true; }
770 
771  /**
772  Only for framing window functions. True if this function only needs to
773  read one row per frame.
774  */
775  virtual bool uses_only_one_row() const { return false; }
776 
777  /**
778  Return true if we need to make two passes over the rows in the partition -
779  either because we need the cardinality of it (and we need to read all
780  rows to detect the next partition), or we need to have all partition rows
781  available to evaluate the window function for some other reason, e.g.
782  we may need the last row in the partition in the frame buffer to be able
783  to evaluate LEAD.
784  */
785  virtual bool needs_card() const { return false; }
786 
787  /**
788  Common initial actions for window functions. For non-buffered processing
789  ("on-the-fly"), check partition change and possible reset partition
790  state. In this case return false.
791  For buffered processing, if windowing state m_do_copy_null is true, set
792  null_value to true and return true.
793 
794  @return true if case two above holds, else false
795  */
796  bool wf_common_init();
797 
798  protected:
799  /*
800  Raise an error (ER_NOT_SUPPORTED_YET) with the detail that this
801  function is not yet supported as a window function.
802  */
804  char buff[STRING_BUFFER_USUAL_SIZE];
805  snprintf(buff, sizeof(buff), "%s as window function", func_name());
806  my_error(ER_NOT_SUPPORTED_YET, MYF(0), buff);
807  }
808 };
809 
810 class Unique;
811 
812 /**
813  The distinct aggregator.
814  Implements AGGFN (DISTINCT ..)
815  Collects all the data into an Unique (similarly to what Item_sum_distinct
816  does currently) and then (if applicable) iterates over the list of
817  unique values and pumps them back into its object
818 */
819 
821  friend class Item_sum_sum;
822 
823  /*
824  flag to prevent consecutive runs of endup(). Normally in endup there are
825  expensive calculations (like walking the distinct tree for example)
826  which we must do only once if there are no data changes.
827  We can re-use the data for the second and subsequent val_xxx() calls.
828  endup_done set to true also means that the calculated values for
829  the aggregate functions are correct and don't need recalculation.
830  */
832 
833  /*
834  Used depending on the type of the aggregate function and the presence of
835  blob columns in it:
836  - For COUNT(DISTINCT) and no blob fields this points to a real temporary
837  table. It's used as a hash table.
838  - For AVG/SUM(DISTINCT) or COUNT(DISTINCT) with blob fields only the
839  in-memory data structure of a temporary table is constructed.
840  It's used by the Field classes to transform data into row format.
841  */
843 
844  /*
845  An array of field lengths on row allocated and used only for
846  COUNT(DISTINCT) with multiple columns and no blobs. Used in
847  Aggregator_distinct::composite_key_cmp (called from Unique to compare
848  nodes
849  */
851 
852  /*
853  Used in conjunction with 'table' to support the access to Field classes
854  for COUNT(DISTINCT). Needed by copy_fields()/copy_funcs().
855  */
857 
858  /*
859  If there are no blobs in the COUNT(DISTINCT) arguments, we can use a tree,
860  which is faster than heap table. In that case, we still use the table
861  to help get things set up, but we insert nothing in it.
862  For AVG/SUM(DISTINCT) we always use this tree (as it takes a single
863  argument) to get the distinct rows.
864  */
866 
867  /*
868  The length of the temp table row. Must be a member of the class as it
869  gets passed down to simple_raw_key_cmp () as a compare function argument
870  to Unique. simple_raw_key_cmp () is used as a fast comparison function
871  when the entire row can be binary compared.
872  */
874 
877  /**
878  Set to true if the result is known to be always NULL.
879  If set deactivates creation and usage of the temporary table (in the
880  'table' member) and the Unique instance (in the 'tree' member) as well as
881  the calculation of the final value on the first call to
882  @c Item_sum::val_xxx(),
883  @c Item_avg::val_xxx(),
884  @c Item_count::val_xxx().
885  */
887  /**
888  Set to true if count distinct is on only const items. Distinct on a const
889  value will always be the constant itself. And count distinct of the same
890  would always be 1. Similar to CONST_NULL, it avoids creation of temporary
891  table and the Unique instance.
892  */
895 
896  /**
897  When feeding back the data in endup() from Unique/temp table back to
898  Item_sum::add() methods we must read the data from Unique (and not
899  recalculate the functions that are given as arguments to the aggregate
900  function.
901  This flag is to tell the arg_*() methods to take the data from the Unique
902  instead of calling the relevant val_..() method.
903  */
905 
906  public:
908  : Aggregator(sum),
909  table(nullptr),
911  tree(nullptr),
914  ~Aggregator_distinct() override;
916 
917  bool setup(THD *) override;
918  void clear() override;
919  bool add() override;
920  void endup() override;
922  double arg_val_real() override;
923  bool arg_is_null(bool use_null_value) override;
924 
925  bool unique_walk_function(void *element);
926  static int composite_key_cmp(const void *arg, const void *a, const void *b);
927 };
928 
929 /**
930  The pass-through aggregator.
931  Implements AGGFN (DISTINCT ..) by knowing it gets distinct data on input.
932  So it just pumps them back to the Item_sum descendant class.
933 */
935  public:
938 
939  bool setup(THD *thd) override { return item_sum->setup(thd); }
940  void clear() override { item_sum->clear(); }
941  bool add() override { return item_sum->add(); }
942  void endup() override {}
944  double arg_val_real() override;
945  bool arg_is_null(bool use_null_value) override;
946 };
947 
948 class Item_sum_num : public Item_sum {
949  typedef Item_sum super;
950 
951  protected:
952  /*
953  val_xxx() functions may be called several times during the execution of a
954  query. Derived classes that require extensive calculation in val_xxx()
955  maintain cache of aggregate value. This variable governs the validity of
956  that cache.
957  */
959 
960  public:
961  Item_sum_num(const POS &pos, Item *item_par, PT_window *window)
962  : Item_sum(pos, item_par, window), is_evaluated(false) {}
963 
965  : Item_sum(pos, list, w), is_evaluated(false) {}
966 
968  : Item_sum(thd, item), is_evaluated(item->is_evaluated) {}
970  return MYSQL_TYPE_DOUBLE;
971  }
972  bool fix_fields(THD *, Item **) override;
973  longlong val_int() override {
974  DBUG_ASSERT(fixed == 1);
975  return llrint_with_overflow_check(val_real()); /* Real as default */
976  }
977  String *val_str(String *str) override;
978  my_decimal *val_decimal(my_decimal *) override;
979  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
980  return get_date_from_numeric(ltime, fuzzydate); /* Decimal or real */
981  }
982  bool get_time(MYSQL_TIME *ltime) override {
983  return get_time_from_numeric(ltime); /* Decimal or real */
984  }
985  void reset_field() override;
986 };
987 
988 class Item_sum_int : public Item_sum_num {
989  public:
990  Item_sum_int(const POS &pos, Item *item_par, PT_window *w)
991  : Item_sum_num(pos, item_par, w) {
993  }
994 
996  : Item_sum_num(pos, list, w) {
998  }
999 
1000  Item_sum_int(THD *thd, Item_sum_int *item) : Item_sum_num(thd, item) {
1002  }
1003 
1004  double val_real() override {
1005  DBUG_ASSERT(fixed);
1006  return static_cast<double>(val_int());
1007  }
1008  String *val_str(String *str) override;
1009  my_decimal *val_decimal(my_decimal *) override;
1010  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1011  return get_date_from_int(ltime, fuzzydate);
1012  }
1013  bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
1014  enum Item_result result_type() const override { return INT_RESULT; }
1015 };
1016 
1017 class Item_sum_sum : public Item_sum_num {
1018  protected:
1020  double sum;
1023  bool resolve_type(THD *thd) override;
1024  /**
1025  Execution state: this is for counting rows entering and leaving the window
1026  frame, see #m_frame_null_count.
1027  */
1029 
1030  /**
1031  Execution state: this is for counting NULLs of rows entering and leaving
1032  the window frame, when we use optimized inverse-based computations. By
1033  comparison with m_count we can know how many non-NULLs are in the frame.
1034  */
1036 
1037  public:
1038  Item_sum_sum(const POS &pos, Item *item_par, bool distinct, PT_window *window)
1039  : Item_sum_num(pos, item_par, window),
1041  m_count(0),
1042  m_frame_null_count(0) {
1043  set_distinct(distinct);
1044  }
1045 
1047  enum Sumfunctype sum_func() const override {
1049  }
1050  void clear() override;
1051  bool add() override;
1052  double val_real() override;
1053  longlong val_int() override;
1054  String *val_str(String *str) override;
1056  enum Item_result result_type() const override { return hybrid_type; }
1057  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
1058  Window_evaluation_requirements *reqs) override;
1059  void reset_field() override;
1060  void update_field() override;
1061  void no_rows_in_result() override {}
1062  const char *func_name() const override { return "sum"; }
1063  Item *copy_or_same(THD *thd) override;
1064 };
1065 
1068 
1069  friend class Aggregator_distinct;
1070 
1071  void clear() override;
1072  bool add() override;
1073  void cleanup() override;
1074 
1075  public:
1076  Item_sum_count(const POS &pos, Item *item_par, PT_window *w)
1077  : Item_sum_int(pos, item_par, w), count(0) {}
1078 
1079  /**
1080  Constructs an instance for COUNT(DISTINCT)
1081 
1082  @param pos Position of token in the parser.
1083  @param list A list of the arguments to the aggregate function
1084  @param w A window, if COUNT is used as a windowing function
1085 
1086  This constructor is called by the parser only for COUNT (DISTINCT).
1087  */
1088 
1090  : Item_sum_int(pos, list, w), count(0) {
1091  set_distinct(true);
1092  }
1094  : Item_sum_int(thd, item), count(item->count) {}
1095  enum Sumfunctype sum_func() const override {
1097  }
1098  bool resolve_type(THD *thd) override {
1099  if (param_type_is_default(thd, 0, -1)) return true;
1100  maybe_null = false;
1101  null_value = false;
1102  return false;
1103  }
1104  void no_rows_in_result() override { count = 0; }
1105  void make_const(longlong count_arg) {
1106  count = count_arg;
1108  }
1109  longlong val_int() override;
1110  void reset_field() override;
1111  void update_field() override;
1112  const char *func_name() const override { return "count"; }
1113  Item *copy_or_same(THD *thd) override;
1114 };
1115 
1116 /* Item to get the value of a stored sum function */
1117 
1118 class Item_sum_avg;
1119 class Item_sum_bit;
1120 
1121 /**
1122  This is used in connection which a parent Item_sum:
1123  - which can produce different result types (is "hybrid")
1124  - which stores function's value into a temporary table's column (one
1125  row per group).
1126  - which stores in the column some internal piece of information which should
1127  not be returned to the user, so special implementations are needed.
1128 */
1130  protected:
1131  /// The tmp table's column containing the value of the set function.
1133  /// Stores the Item's result type.
1135 
1136  public:
1137  enum Item_result result_type() const override { return hybrid_type; }
1138  bool mark_field_in_map(uchar *arg) override {
1139  /*
1140  Filesort (find_all_keys) over a temporary table collects the columns it
1141  needs.
1142  */
1143  return Item::mark_field_in_map(pointer_cast<Mark_field *>(arg), field);
1144  }
1147  pointer_cast<Check_function_as_value_generator_parameters *>(args);
1148  func_arg->banned_function_name = func_name();
1149  return true;
1150  }
1151 };
1152 
1153 /**
1154  Common abstract class for:
1155  Item_avg_field
1156  Item_variance_field
1157 */
1159  public:
1160  longlong val_int() override {
1161  /* can't be fix_fields()ed */
1163  }
1164  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1165  return get_date_from_numeric(ltime, fuzzydate); /* Decimal or real */
1166  }
1167  bool get_time(MYSQL_TIME *ltime) override {
1168  return get_time_from_numeric(ltime); /* Decimal or real */
1169  }
1170  bool is_null() override { return update_null_value() || null_value; }
1171 };
1172 
1174  public:
1178  enum Type type() const override { return FIELD_AVG_ITEM; }
1179  double val_real() override;
1180  my_decimal *val_decimal(my_decimal *) override;
1181  String *val_str(String *) override;
1182  bool resolve_type(THD *) override { return false; }
1183  const char *func_name() const override {
1184  DBUG_ASSERT(0);
1185  return "avg_field";
1186  }
1187 };
1188 
1189 /// This is used in connection with an Item_sum_bit, @see Item_sum_hybrid_field
1191  protected:
1193 
1194  public:
1197  longlong val_int() override;
1198  double val_real() override;
1199  my_decimal *val_decimal(my_decimal *) override;
1200  String *val_str(String *) override;
1201  bool resolve_type(THD *) override { return false; }
1202  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1203  bool get_time(MYSQL_TIME *ltime) override;
1204  enum Type type() const override { return FIELD_BIT_ITEM; }
1205  const char *func_name() const override {
1206  DBUG_ASSERT(0);
1207  return "sum_bit_field";
1208  }
1209 };
1210 
1211 /// Common abstraction for Item_sum_json_array and Item_sum_json_object
1212 class Item_sum_json : public Item_sum {
1213  typedef Item_sum super;
1214 
1215  protected:
1216  /// String used when reading JSON binary values or JSON text values.
1218  /// String used for converting JSON text values to utf8mb4 charset.
1220  /// Wrapper around the container (object/array) which accumulates the value.
1222 
1223  /**
1224  Construct an Item_sum_json instance.
1225 
1226  @param wrapper a wrapper around the Json_array or Json_object that contains
1227  the aggregated result
1228  @param parent_args arguments to forward to Item_sum's constructor
1229  */
1230  template <typename... Args>
1232  Args &&... parent_args);
1233 
1234  public:
1235  ~Item_sum_json() override;
1236  bool fix_fields(THD *thd, Item **pItem) override;
1237  enum Sumfunctype sum_func() const override { return JSON_AGG_FUNC; }
1238  Item_result result_type() const override { return STRING_RESULT; }
1239 
1240  double val_real() override;
1241  longlong val_int() override;
1242  String *val_str(String *str) override;
1243  bool val_json(Json_wrapper *wr) override;
1244  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
1245  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1246  bool get_time(MYSQL_TIME *ltime) override;
1247 
1248  void reset_field() override;
1249  void update_field() override;
1250 
1252  Window_evaluation_requirements *) override;
1253 };
1254 
1255 /// Implements aggregation of values into an array.
1257  /// Accumulates the final value.
1259 
1260  public:
1261  Item_sum_json_array(THD *thd, Item_sum *item,
1264  Item_sum_json_array(const POS &pos, Item *a, PT_window *w,
1268  const char *func_name() const override { return "json_arrayagg"; }
1269  void clear() override;
1270  bool add() override;
1271  Item *copy_or_same(THD *thd) override;
1272 };
1273 
1274 /// Implements aggregation of values into an object.
1276  /// Accumulates the final value.
1278  /// Buffer used to get the value of the key.
1280  /**
1281  Map of keys in Json_object and the count for each key
1282  within a window frame. It is used in handling rows
1283  leaving a window frame when rows are not sorted
1284  according to the key in Json_object.
1285  */
1286  std::map<std::string, int> m_key_map;
1287  /**
1288  If window provides ordering on the key in Json_object,
1289  a key_map is not needed to handle rows leaving a window
1290  frame. In this case, process_buffered_windowing_record()
1291  will set flags when a key/value pair can be removed from
1292  the Json_object.
1293  */
1294  bool m_optimize{false};
1295 
1296  public:
1297  Item_sum_json_object(THD *thd, Item_sum *item,
1300  Item_sum_json_object(const POS &pos, Item *a, Item *b, PT_window *w,
1304  const char *func_name() const override { return "json_objectagg"; }
1305  void clear() override;
1306  bool add() override;
1307  Item *copy_or_same(THD *thd) override;
1308  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
1309  Window_evaluation_requirements *reqs) override;
1310 };
1311 
1313  public:
1318  double m_avg;
1319 
1320  Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
1321  : Item_sum_sum(pos, item_par, distinct, w) {}
1322 
1324  : Item_sum_sum(thd, item), prec_increment(item->prec_increment) {}
1325 
1326  bool resolve_type(THD *thd) override;
1327  enum Sumfunctype sum_func() const override {
1329  }
1330  void clear() override;
1331  bool add() override;
1332  double val_real() override;
1333  // In SPs we might force the "wrong" type with select into a declare variable
1335  my_decimal *val_decimal(my_decimal *) override;
1336  String *val_str(String *str) override;
1337  void reset_field() override;
1338  void update_field() override;
1339  Item *result_item(Field *) override {
1340  return new Item_avg_field(hybrid_type, this);
1341  }
1342  void no_rows_in_result() override {}
1343  const char *func_name() const override { return "avg"; }
1344  Item *copy_or_same(THD *thd) override;
1345  Field *create_tmp_field(bool group, TABLE *table) override;
1346  void cleanup() override {
1347  m_count = 0;
1348  m_frame_null_count = 0;
1350  }
1351 };
1352 
1353 class Item_sum_variance;
1354 
1356  protected:
1358 
1359  public:
1361  enum Type type() const override { return FIELD_VARIANCE_ITEM; }
1362  double val_real() override;
1363  String *val_str(String *str) override { return val_string_from_real(str); }
1364  my_decimal *val_decimal(my_decimal *dec_buf) override {
1365  return val_decimal_from_real(dec_buf);
1366  }
1367  bool resolve_type(THD *) override { return false; }
1368  const char *func_name() const override {
1369  DBUG_ASSERT(0);
1370  return "variance_field";
1371  }
1374  pointer_cast<Check_function_as_value_generator_parameters *>(args);
1375  func_arg->err_code = func_arg->get_unnamed_function_error_code();
1376  return true;
1377  }
1378 };
1379 
1380 /*
1381  variance(a) =
1382 
1383  = sum (ai - avg(a))^2 / count(a) )
1384  = sum (ai^2 - 2*ai*avg(a) + avg(a)^2) / count(a)
1385  = (sum(ai^2) - sum(2*ai*avg(a)) + sum(avg(a)^2))/count(a) =
1386  = (sum(ai^2) - 2*avg(a)*sum(a) + count(a)*avg(a)^2)/count(a) =
1387  = (sum(ai^2) - 2*sum(a)*sum(a)/count(a) + count(a)*sum(a)^2/count(a)^2
1388  )/count(a) = = (sum(ai^2) - 2*sum(a)^2/count(a) + sum(a)^2/count(a)
1389  )/count(a) = = (sum(ai^2) - sum(a)^2/count(a))/count(a)
1390 
1391  But, this falls prey to catastrophic cancellation.
1392  Instead, we use recurrence formulas in Algorithm I mentoned below
1393  for group aggregates.
1394 
1395  Algorithm I:
1396  M_{1} = x_{1}, ~ M_{k} = M_{k-1} + (x_{k} - M_{k-1}) / k newline
1397  S_{1} = 0, ~ S_{k} = S_{k-1} + (x_{k} - M_{k-1}) times (x_{k} - M_{k}) newline
1398  for 2 <= k <= n newline
1399  ital variance = S_{n} / (n-1)
1400 
1401  For aggregate window functions algorithm I cannot be optimized for
1402  moving frames since M_{i} changes for every row. So we use the
1403  following algorithm.
1404 
1405  Algorithm II:
1406 
1407  K = 0
1408  n = 0
1409  ex = 0
1410  ex2 = 0
1411 
1412  def add_sample(x):
1413  if (n == 0):
1414  K = x
1415  n = n + 1
1416  ex += x - K
1417  ex2 += (x - K) * (x - K)
1418 
1419  def remove_sample(x):
1420  n = n - 1
1421  ex -= (x - K)
1422  ex2 -= (x - K) * (x - K)
1423 
1424  def variance():
1425  return (ex2 - (ex*ex)/n) / (n-1)
1426 
1427  This formula facilitates incremental computation enabling us to
1428  optimize in case of moving window frames. The optimized codepath is taken
1429  only when windowing_use_high_precision is set to false. By default,
1430  aggregate window functions take the non-optimized codepath.
1431  Note:
1432  Results could differ between optimized and non-optimized code path.
1433  Hence algorithm II is used only when user sets
1434  windowing_use_high_precision to false.
1435 */
1436 
1438  bool resolve_type(THD *) override;
1439 
1440  public:
1442  /**
1443  Used in recurrence relation.
1444  */
1450  /**
1451  If set, uses a algorithm II mentioned in the class description
1452  to calculate the variance which helps in optimizing windowing
1453  functions in presence of frames.
1454  */
1455  bool optimize;
1456 
1457  Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg,
1458  PT_window *w)
1459  : Item_sum_num(pos, item_par, w),
1461  count(0),
1462  sample(sample_arg),
1463  optimize(false) {}
1464 
1466  enum Sumfunctype sum_func() const override { return VARIANCE_FUNC; }
1467  void clear() override;
1468  bool add() override;
1469  double val_real() override;
1470  my_decimal *val_decimal(my_decimal *) override;
1471  void reset_field() override;
1472  void update_field() override;
1473  Item *result_item(Field *) override { return new Item_variance_field(this); }
1474  void no_rows_in_result() override {}
1475  const char *func_name() const override {
1476  return sample ? "var_samp" : "variance";
1477  }
1478  Item *copy_or_same(THD *thd) override;
1479  Field *create_tmp_field(bool group, TABLE *table) override;
1480  enum Item_result result_type() const override { return REAL_RESULT; }
1481  void cleanup() override {
1482  count = 0;
1484  }
1485  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
1486  Window_evaluation_requirements *reqs) override;
1487 };
1488 
1489 class Item_sum_std;
1490 
1492  public:
1494  enum Type type() const override { return FIELD_STD_ITEM; }
1495  double val_real() override;
1497  enum Item_result result_type() const override { return REAL_RESULT; }
1498  const char *func_name() const override {
1499  DBUG_ASSERT(0);
1500  return "std_field";
1501  }
1504  pointer_cast<Check_function_as_value_generator_parameters *>(args);
1505  func_arg->err_code = func_arg->get_unnamed_function_error_code();
1506  return true;
1507  }
1508 };
1509 
1510 /*
1511  standard_deviation(a) = sqrt(variance(a))
1512 */
1513 
1515  public:
1516  Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
1517  : Item_sum_variance(pos, item_par, sample_arg, w) {}
1518 
1519  Item_sum_std(THD *thd, Item_sum_std *item) : Item_sum_variance(thd, item) {}
1520  enum Sumfunctype sum_func() const override { return STD_FUNC; }
1521  double val_real() override;
1522  Item *result_item(Field *) override { return new Item_std_field(this); }
1523  const char *func_name() const override {
1524  return sample ? "stddev_samp" : "std";
1525  }
1526  Item *copy_or_same(THD *thd) override;
1527  enum Item_result result_type() const override { return REAL_RESULT; }
1528 };
1529 
1530 // This class is a string or number function depending on num_func
1531 class Arg_comparator;
1532 
1533 /**
1534  Abstract base class for the MIN and MAX aggregate functions.
1535 */
1536 class Item_sum_hybrid : public Item_sum {
1537  typedef Item_sum super;
1538 
1539  private:
1540  /**
1541  Tells if this is the MIN function (true) or the MAX function (false).
1542  */
1543  const bool m_is_min;
1544  /*
1545  For window functions MIN/MAX with optimized code path, no comparisons
1546  are needed beyond NULL detection: MIN/MAX are then roughly equivalent to
1547  FIRST/LAST_VALUE. For this case, 'value' is the value of
1548  the window function a priori taken from args[0], while arg_cache is used to
1549  remember the value from the previous row. NULLs need a bit of careful
1550  treatment.
1551  */
1555  bool was_values; // Set if we have found at least one row (for max/min only)
1556  /**
1557  Set to true if the window is ordered ascending.
1558  */
1560  /**
1561  Set to true when min/max can be optimized using window's ordering.
1562  */
1564  /**
1565  For min() - Set to true when results are ordered in ascending and
1566  false when descending.
1567  For max() - Set to true when results are ordered in descending and
1568  false when ascending.
1569  Valid only when m_optimize is true.
1570  */
1571  bool m_want_first; ///< Want first non-null value, else last non_null value
1572  /**
1573  Execution state: keeps track if this is the first row in the frame
1574  when buffering is not needed.
1575  Valid only when m_optimize is true.
1576  */
1578 
1579  /**
1580  Execution state: keeps track of at which row we saved a non-null last
1581  value.
1582  */
1584 
1585  /**
1586  This function implements the optimized version of retrieving min/max
1587  value. When we have "ordered ASC" results in a window, min will always
1588  be the first value in the result set (neglecting the NULL's) and max
1589  will always be the last value (or the other way around, if ordered DESC).
1590  It is based on the implementation of FIRST_VALUE/LAST_VALUE, except for
1591  the NULL handling.
1592 
1593  @return true if computation yielded a NULL or error
1594  */
1595  bool compute();
1596 
1597  /**
1598  MIN/MAX function setup.
1599 
1600  Setup cache/comparator of MIN/MAX functions. When called by the
1601  copy_or_same() function, the value_arg parameter contains the calculated
1602  value of the original MIN/MAX object, and it is saved in this object's
1603  cache.
1604 
1605  @param item the argument of the MIN/MAX function
1606  @param value_arg the calculated value of the MIN/MAX function
1607  @return false on success, true on error
1608  */
1609  bool setup_hybrid(Item *item, Item *value_arg);
1610 
1611  /** Create a clone of this object. */
1612  virtual Item_sum_hybrid *clone_hybrid(THD *thd) const = 0;
1613 
1614  protected:
1615  Item_sum_hybrid(Item *item_par, bool is_min)
1616  : Item_sum(item_par),
1617  m_is_min(is_min),
1618  value(nullptr),
1619  arg_cache(nullptr),
1620  cmp(nullptr),
1622  was_values(true),
1624  m_optimize(false),
1626  m_cnt(0),
1629  }
1630 
1631  Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
1632  : Item_sum(pos, item_par, w),
1633  m_is_min(is_min),
1634  value(nullptr),
1635  arg_cache(nullptr),
1636  cmp(nullptr),
1638  was_values(true),
1640  m_optimize(false),
1642  m_cnt(0),
1645  }
1646 
1648  : Item_sum(thd, item),
1649  m_is_min(item->m_is_min),
1650  value(item->value),
1651  arg_cache(nullptr),
1652  hybrid_type(item->hybrid_type),
1653  was_values(item->was_values),
1655  m_optimize(item->m_optimize),
1656  m_want_first(item->m_want_first),
1657  m_cnt(item->m_cnt),
1658  m_saved_last_value_at(0) {}
1659 
1660  public:
1661  bool fix_fields(THD *, Item **) override;
1662  void clear() override;
1663  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
1664  mem_root_deque<Item *> *fields) override;
1665  double val_real() override;
1666  longlong val_int() override;
1667  longlong val_time_temporal() override;
1668  longlong val_date_temporal() override;
1669  my_decimal *val_decimal(my_decimal *) override;
1670  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1671  bool get_time(MYSQL_TIME *ltime) override;
1672  void reset_field() override;
1673  String *val_str(String *) override;
1674  bool val_json(Json_wrapper *wr) override;
1675  bool keep_field_type() const override { return true; }
1676  enum Item_result result_type() const override { return hybrid_type; }
1677  void update_field() override;
1678  void cleanup() override;
1679  bool any_value() { return was_values; }
1680  void no_rows_in_result() override;
1681  Field *create_tmp_field(bool group, TABLE *table) override;
1682  bool uses_only_one_row() const override { return m_optimize; }
1683  bool add() override;
1684  Item *copy_or_same(THD *thd) override;
1685  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
1686  Window_evaluation_requirements *r) override;
1687 
1688  private:
1689  /*
1690  These functions check if the value on the current row exceeds the maximum or
1691  minimum value seen so far, and update the current max/min stored in
1692  result_field, if needed.
1693  */
1694  void min_max_update_str_field();
1698  void min_max_update_int_field();
1700 };
1701 
1703  public:
1704  Item_sum_min(Item *item_par) : Item_sum_hybrid(item_par, true) {}
1705  Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
1706  : Item_sum_hybrid(pos, item_par, true, w) {}
1707  Item_sum_min(THD *thd, const Item_sum_min *item)
1708  : Item_sum_hybrid(thd, item) {}
1709  enum Sumfunctype sum_func() const override { return MIN_FUNC; }
1710  const char *func_name() const override { return "min"; }
1711 
1712  private:
1713  Item_sum_min *clone_hybrid(THD *thd) const override;
1714 };
1715 
1717  public:
1718  Item_sum_max(Item *item_par) : Item_sum_hybrid(item_par, false) {}
1719  Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
1720  : Item_sum_hybrid(pos, item_par, false, w) {}
1721  Item_sum_max(THD *thd, const Item_sum_max *item)
1722  : Item_sum_hybrid(thd, item) {}
1723  enum Sumfunctype sum_func() const override { return MAX_FUNC; }
1724  const char *func_name() const override { return "max"; }
1725 
1726  private:
1727  Item_sum_max *clone_hybrid(THD *thd) const override;
1728 };
1729 
1730 /**
1731  Base class used to implement BIT_AND, BIT_OR and BIT_XOR.
1732 
1733  Each of them is both a set function and a framing window function.
1734 */
1735 class Item_sum_bit : public Item_sum {
1736  typedef Item_sum super;
1737  /// Stores the neutral element for function
1739  /// Stores the result value for the INT_RESULT
1741  /// Stores the result value for the STRING_RESULT
1743  /// Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT
1745  /// Buffer used to avoid String allocation in the constructor
1746  const char initial_value_buff_storage[1] = {0};
1747 
1748  /**
1749  Execution state (windowing): this is for counting rows entering and leaving
1750  the window frame, see #m_frame_null_count.
1751  */
1753 
1754  /**
1755  Execution state (windowing): this is for counting NULLs of rows entering
1756  and leaving the window frame, when we use optimized inverse-based
1757  computations. By comparison with m_count we can know how many non-NULLs are
1758  in the frame.
1759  */
1761 
1762  /**
1763  Execution state (windowing): Used for AND, OR to be able to invert window
1764  functions in optimized mode.
1765 
1766  For the optimized code path of BIT_XXX wfs, we keep track of the number of
1767  bit values (0's or 1's; see below) seen in a frame using a 64 bits counter
1768  pr bit. This lets us compute the value of OR by just inspecting:
1769 
1770  - the number of 1's in the previous frame
1771  - whether any removed row(s) is a 1
1772  - whether any added row(s) is a 1
1773 
1774  Similarly for AND, we keep track of the number of 0's seen for a particular
1775  bit. To do this trick we need a counter per bit position. This array holds
1776  these counters.
1777 
1778  Note that for XOR, the inverse operation is identical to the operation,
1779  so we don't need the above.
1780  */
1782  /*
1783  Size of allocated array m_digit_cnt.
1784  The size is DIGIT_CNT_CARD (for integer types) or ::max_length * 8 for bit
1785  strings.
1786  */
1788 
1789  static constexpr uint DIGIT_CNT_CARD = sizeof(ulonglong) * 8;
1790 
1791  protected:
1792  bool m_is_xor; ///< true iff BIT_XOR
1793 
1794  public:
1795  Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg,
1796  PT_window *w)
1797  : Item_sum(pos, item_par, w),
1798  reset_bits(reset_arg),
1799  bits(reset_arg),
1801  m_count(0),
1802  m_frame_null_count(0),
1804  m_digit_cnt_card(0),
1805  m_is_xor(false) {}
1806 
1807  /// Copy constructor, used for executing subqueries with temporary tables
1809  : Item_sum(thd, item),
1810  reset_bits(item->reset_bits),
1811  bits(item->bits),
1813  hybrid_type(item->hybrid_type),
1814  m_count(item->m_count),
1817  m_digit_cnt_card(0),
1818  m_is_xor(item->m_is_xor) {
1819  /*
1820  This constructor should only be called during the Optimize stage.
1821  Asserting that the item was not evaluated yet.
1822  */
1823  DBUG_ASSERT(item->value_buff.length() == 1);
1824  DBUG_ASSERT(item->bits == item->reset_bits);
1825  }
1826 
1827  Item *result_item(Field *) override {
1828  return new Item_sum_bit_field(hybrid_type, this, reset_bits);
1829  }
1830 
1831  enum Sumfunctype sum_func() const override { return SUM_BIT_FUNC; }
1832  enum Item_result result_type() const override { return hybrid_type; }
1833  void clear() override;
1834  longlong val_int() override;
1835  double val_real() override;
1836  String *val_str(String *str) override;
1837  my_decimal *val_decimal(my_decimal *decimal_value) override;
1838  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1839  bool get_time(MYSQL_TIME *ltime) override;
1840  void reset_field() override;
1841  void update_field() override;
1842  bool resolve_type(THD *) override;
1843  bool fix_fields(THD *thd, Item **ref) override;
1844  void cleanup() override {
1845  bits = reset_bits;
1846  // At end of one execution of statement, free buffer to reclaim memory:
1849  }
1850 
1851  /**
1852  Common implementation of Item_sum_or::add, Item_sum_and:add
1853  and Item_sum_xor::add.
1854  */
1855  bool add() override;
1856  /// @returns true iff this is BIT_AND.
1857  inline bool is_and() const { return reset_bits != 0; }
1858 
1859  private:
1860  /**
1861  Accumulate the value of 's1' (if in string mode) or of 'b1' (if in integer
1862  mode). Updates 'value_buff' or 'bits'.
1863 
1864  @param s1 argument to accumulate
1865  @param b1 argument to accumulate
1866 
1867  @returns true if error
1868  */
1869  bool add_bits(const String *s1, ulonglong b1);
1870 
1871  /**
1872  For windowing: perform inverse aggregation. "De-accumulate" the value of
1873  's1' (if in string mode) or of 'b1' (if in integer mode). Updates
1874  'value_buff' or 'bits'.
1875 
1876  For BIT_XOR we simply apply XOR as it's its inverse operation. For BIT_OR
1877  and BIT_AND we do the rest below.
1878 
1879  For each bit in argument, decrement the corresponding bits's counter
1880  ('m_digit_cnt') for that bit as follows: for BIT_AND, decrement the
1881  counter if we see a zero in that bit; for BIT_OR decrement the counter if
1882  we see a 1 in that bit. Next, update 'value_buff' or 'bits' using the
1883  resulting counters: for each bit, for BIT_AND, set bit if we have counter
1884  == 0, i.e. we have no zero bits for that bit in the frame (yet). For
1885  BIT_OR, set bit if we have counter > 0, i.e. at least one row in the frame
1886  has that bit set.
1887 
1888  @param s1 the bits to be inverted from the aggregate value
1889  @param b1 the bits to be inverted from the aggregate value
1890  */
1891  void remove_bits(const String *s1, ulonglong b1);
1892 };
1893 
1895  public:
1896  Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
1897  : Item_sum_bit(pos, item_par, 0LL, w) {}
1898 
1899  Item_sum_or(THD *thd, Item_sum_or *item) : Item_sum_bit(thd, item) {}
1900  const char *func_name() const override { return "bit_or"; }
1901  Item *copy_or_same(THD *thd) override;
1902 };
1903 
1905  public:
1906  Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
1907  : Item_sum_bit(pos, item_par, ULLONG_MAX, w) {}
1908 
1909  Item_sum_and(THD *thd, Item_sum_and *item) : Item_sum_bit(thd, item) {}
1910  const char *func_name() const override { return "bit_and"; }
1911  Item *copy_or_same(THD *thd) override;
1912 };
1913 
1915  public:
1916  Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
1917  : Item_sum_bit(pos, item_par, 0LL, w) {
1918  m_is_xor = true;
1919  }
1920 
1921  Item_sum_xor(THD *thd, Item_sum_xor *item) : Item_sum_bit(thd, item) {}
1922  const char *func_name() const override { return "bit_xor"; }
1923  Item *copy_or_same(THD *thd) override;
1924 };
1925 
1926 /*
1927  User defined aggregates
1928 */
1929 
1930 class Item_udf_sum : public Item_sum {
1931  typedef Item_sum super;
1932 
1933  protected:
1935 
1936  public:
1937  Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1938  : Item_sum(pos, opt_list, nullptr), udf(udf_arg) {
1940  }
1942  : Item_sum(thd, item), udf(item->udf) {
1943  udf.m_original = false;
1944  }
1945  ~Item_udf_sum() override {
1947  }
1948 
1949  bool itemize(Parse_context *pc, Item **res) override;
1950  const char *func_name() const override { return udf.name(); }
1951  bool fix_fields(THD *thd, Item **ref) override {
1952  DBUG_ASSERT(fixed == 0);
1953 
1954  if (init_sum_func_check(thd)) return true;
1955 
1956  fixed = true;
1957  if (udf.fix_fields(thd, this, this->arg_count, this->args)) return true;
1958 
1959  return check_sum_func(thd, ref);
1960  }
1961  enum Sumfunctype sum_func() const override { return UDF_SUM_FUNC; }
1962 
1963  void clear() override;
1964  bool add() override;
1965  void reset_field() override {}
1966  void update_field() override {}
1967  void cleanup() override;
1968  void print(const THD *thd, String *str,
1969  enum_query_type query_type) const override;
1970 };
1971 
1973  public:
1974  Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1975  : Item_udf_sum(pos, udf_arg, opt_list) {}
1977  : Item_udf_sum(thd, item) {}
1978  longlong val_int() override {
1979  DBUG_ASSERT(fixed == 1);
1980  return (longlong)rint(Item_sum_udf_float::val_real());
1981  }
1982  double val_real() override;
1983  String *val_str(String *str) override;
1984  my_decimal *val_decimal(my_decimal *) override;
1985  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1986  return get_date_from_real(ltime, fuzzydate);
1987  }
1988  bool get_time(MYSQL_TIME *ltime) override {
1989  return get_time_from_real(ltime);
1990  }
1991  bool resolve_type(THD *) override {
1994  return false;
1995  }
1996  Item *copy_or_same(THD *thd) override;
1997 };
1998 
2000  public:
2001  Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
2002  : Item_udf_sum(pos, udf_arg, opt_list) {}
2004  : Item_udf_sum(thd, item) {}
2005  longlong val_int() override;
2006  double val_real() override {
2007  DBUG_ASSERT(fixed == 1);
2008  return (double)Item_sum_udf_int::val_int();
2009  }
2010  String *val_str(String *str) override;
2011  my_decimal *val_decimal(my_decimal *) override;
2012  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2013  return get_date_from_int(ltime, fuzzydate);
2014  }
2015  bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
2016  enum Item_result result_type() const override { return INT_RESULT; }
2017  bool resolve_type(THD *) override {
2019  return false;
2020  }
2021  Item *copy_or_same(THD *thd) override;
2022 };
2023 
2025  public:
2026  Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
2027  : Item_udf_sum(pos, udf_arg, opt_list) {}
2029  : Item_udf_sum(thd, item) {}
2030  String *val_str(String *) override;
2031  double val_real() override {
2032  int err_not_used;
2033  const char *end_not_used;
2034  String *res;
2035  res = val_str(&str_value);
2036  return res ? my_strntod(res->charset(), res->ptr(), res->length(),
2037  &end_not_used, &err_not_used)
2038  : 0.0;
2039  }
2040  longlong val_int() override {
2041  int err_not_used;
2042  String *res;
2043  const CHARSET_INFO *cs;
2044 
2045  if (!(res = val_str(&str_value))) return 0; /* Null value */
2046  cs = res->charset();
2047  const char *end = res->ptr() + res->length();
2048  return cs->cset->strtoll10(cs, res->ptr(), &end, &err_not_used);
2049  }
2050  my_decimal *val_decimal(my_decimal *dec) override;
2051  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2052  return get_date_from_string(ltime, fuzzydate);
2053  }
2054  bool get_time(MYSQL_TIME *ltime) override {
2055  return get_time_from_string(ltime);
2056  }
2057  enum Item_result result_type() const override { return STRING_RESULT; }
2058  bool resolve_type(THD *) override;
2059  Item *copy_or_same(THD *thd) override;
2060 };
2061 
2063  public:
2065  PT_item_list *opt_list)
2066  : Item_udf_sum(pos, udf_arg, opt_list) {}
2068  : Item_udf_sum(thd, item) {}
2069  String *val_str(String *) override;
2070  double val_real() override;
2071  longlong val_int() override;
2072  my_decimal *val_decimal(my_decimal *) override;
2073  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2074  return get_date_from_decimal(ltime, fuzzydate);
2075  }
2076  bool get_time(MYSQL_TIME *ltime) override {
2077  return get_time_from_decimal(ltime);
2078  }
2079  enum Item_result result_type() const override { return DECIMAL_RESULT; }
2080  bool resolve_type(THD *) override {
2083  return false;
2084  }
2085  Item *copy_or_same(THD *thd) override;
2086 };
2087 
2088 int group_concat_key_cmp_with_distinct(const void *arg, const void *key1,
2089  const void *key2);
2090 int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2091  const void *key2);
2092 int dump_leaf_key(void *key_arg, element_count count MY_ATTRIBUTE((unused)),
2093  void *item_arg);
2094 
2096  typedef Item_sum super;
2097 
2103 
2104  /**
2105  If DISTINCT is used with this GROUP_CONCAT, this member is used to filter
2106  out duplicates.
2107  @see Item_func_group_concat::setup
2108  @see Item_func_group_concat::add
2109  @see Item_func_group_concat::clear
2110  */
2115  /** The number of ORDER BY items. */
2117  /** The number of selected items, aka the expr list. */
2120  /** The maximum permitted result length in bytes as set for
2121  group_concat_max_len system variable */
2123  bool distinct;
2127  /** True if result has been written to output buffer. */
2129  /*
2130  Following is 0 normal object and pointer to original one for copy
2131  (to correctly free resources)
2132  */
2134 
2135  friend int group_concat_key_cmp_with_distinct(const void *arg,
2136  const void *key1,
2137  const void *key2);
2138  friend int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2139  const void *key2);
2140  friend int dump_leaf_key(void *key_arg,
2141  element_count count MY_ATTRIBUTE((unused)),
2142  void *item_arg);
2143 
2144  public:
2145  Item_func_group_concat(const POS &pos, bool is_distinct,
2146  PT_item_list *select_list,
2147  PT_order_list *opt_order_list, String *separator,
2148  PT_window *w);
2149 
2152  DBUG_ASSERT(original != nullptr || unique_filter == nullptr);
2153  }
2154 
2155  bool itemize(Parse_context *pc, Item **res) override;
2156  void cleanup() override;
2157 
2158  enum Sumfunctype sum_func() const override { return GROUP_CONCAT_FUNC; }
2159  const char *func_name() const override { return "group_concat"; }
2160  Item_result result_type() const override { return STRING_RESULT; }
2161  Field *make_string_field(TABLE *table_arg) const override;
2162  void clear() override;
2163  bool add() override;
2164  void reset_field() override { DBUG_ASSERT(0); } // not used
2165  void update_field() override { DBUG_ASSERT(0); } // not used
2166  bool fix_fields(THD *, Item **) override;
2167  bool setup(THD *thd) override;
2168  void make_unique() override;
2169  double val_real() override {
2170  String *res;
2171  res = val_str(&str_value);
2172  return res ? my_atof(res->c_ptr()) : 0.0;
2173  }
2174  longlong val_int() override {
2175  String *res;
2176  int error;
2177  if (!(res = val_str(&str_value))) return (longlong)0;
2178  const char *end_ptr = res->ptr() + res->length();
2179  return my_strtoll10(res->ptr(), &end_ptr, &error);
2180  }
2181  my_decimal *val_decimal(my_decimal *decimal_value) override {
2182  return val_decimal_from_string(decimal_value);
2183  }
2184  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2185  return get_date_from_string(ltime, fuzzydate);
2186  }
2187  bool get_time(MYSQL_TIME *ltime) override {
2188  return get_time_from_string(ltime);
2189  }
2190  String *val_str(String *str) override;
2191  Item *copy_or_same(THD *thd) override;
2192  void no_rows_in_result() override {}
2193  void print(const THD *thd, String *str,
2194  enum_query_type query_type) const override;
2195  bool change_context_processor(uchar *arg) override {
2196  context = reinterpret_cast<Item_ident::Change_context *>(arg)->m_context;
2197  return false;
2198  }
2199 
2201  Window_evaluation_requirements *) override {
2203  return true;
2204  }
2205 };
2206 
2207 /**
2208  Common parent class for window functions that always work on the entire
2209  partition, even if a frame is defined.
2210 
2211  The subclasses can be divided in two disjoint sub-categories:
2212  - one-pass
2213  - two-pass (requires partition cardinality to be evaluated)
2214  cf. method needs_card.
2215 */
2217  typedef Item_sum super;
2218 
2219  public:
2222  : Item_sum(pos, a, w) {}
2224  : Item_sum(pos, opt_list, w) {}
2226 
2227  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2228  return get_date_from_numeric(ltime, fuzzydate);
2229  }
2230 
2231  bool get_time(MYSQL_TIME *ltime) override {
2232  return get_time_from_numeric(ltime);
2233  }
2234 
2235  void reset_field() override { DBUG_ASSERT(false); }
2236  void update_field() override { DBUG_ASSERT(false); }
2237  bool add() override {
2238  DBUG_ASSERT(false);
2239  return false;
2240  }
2241 
2242  bool fix_fields(THD *thd, Item **items) override;
2243 
2244  bool framing() const override { return false; }
2245 };
2246 
2247 /**
2248  ROW_NUMBER window function, cf. SQL 2003 Section 6.10 <window function>
2249 */
2251  // Execution state variables
2252  ulonglong m_ctr; ///< Increment for each row in partition
2253 
2254  public:
2256  : Item_non_framing_wf(pos, w), m_ctr(0) {
2257  unsigned_flag = true;
2258  }
2259 
2260  const char *func_name() const override { return "row_number"; }
2261  enum Sumfunctype sum_func() const override { return ROW_NUMBER_FUNC; }
2262 
2263  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2265  return false;
2266  }
2267 
2268  longlong val_int() override;
2269  double val_real() override;
2270  my_decimal *val_decimal(my_decimal *buff) override;
2271  String *val_str(String *) override;
2272 
2273  void clear() override;
2274 
2275  Item_result result_type() const override { return INT_RESULT; }
2276 
2278  Window_evaluation_requirements *) override {
2279  return false;
2280  }
2281 };
2282 
2283 /**
2284  RANK or DENSE_RANK window function, cf. SQL 2003 Section 6.10 <window
2285  function>
2286 */
2289  bool m_dense; ///< If true, the object represents DENSE_RANK
2290  // Execution state variables
2291  ulonglong m_rank_ctr; ///< Increment when window order columns change
2292  ulonglong m_duplicates; ///< Needed to make RANK different from DENSE_RANK
2293  List<Cached_item> m_previous; ///< Values of previous row's ORDER BY items
2294  public:
2295  Item_rank(const POS &pos, bool dense, PT_window *w)
2296  : Item_non_framing_wf(pos, w),
2297  m_dense(dense),
2298  m_rank_ctr(0),
2299  m_duplicates(0),
2300  m_previous()
2301 
2302  {
2303  unsigned_flag = true;
2304  }
2305 
2306  ~Item_rank() override;
2307 
2308  const char *func_name() const override {
2309  return m_dense ? "dense_rank" : "rank";
2310  }
2311 
2312  enum Sumfunctype sum_func() const override {
2313  return m_dense ? DENSE_RANK_FUNC : RANK_FUNC;
2314  }
2315 
2316  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2318  return false;
2319  }
2320 
2321  longlong val_int() override;
2322  double val_real() override;
2323  my_decimal *val_decimal(my_decimal *buff) override;
2324  String *val_str(String *) override;
2325 
2326  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2327  Window_evaluation_requirements *reqs) override;
2328  /**
2329  Clear state for a new partition
2330  */
2331  void clear() override;
2332  Item_result result_type() const override { return INT_RESULT; }
2333 };
2334 
2335 /**
2336  CUME_DIST window function, cf. SQL 2003 Section 6.10 <window function>
2337 */
2340 
2341  public:
2343 
2344  const char *func_name() const override { return "cume_dist"; }
2345  enum Sumfunctype sum_func() const override { return CUME_DIST_FUNC; }
2346 
2347  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2349  return false;
2350  }
2351 
2352  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2353  Window_evaluation_requirements *reqs) override;
2354 
2355  bool needs_card() const override { return true; }
2356  void clear() override {}
2357  longlong val_int() override;
2358  double val_real() override;
2359  String *val_str(String *) override;
2361  Item_result result_type() const override { return REAL_RESULT; }
2362 };
2363 
2364 /**
2365  PERCENT_RANK window function, cf. SQL 2003 Section 6.10 <window function>
2366 */
2369  // Execution state variables
2370  ulonglong m_rank_ctr; ///< Increment when window order columns change
2371  ulonglong m_peers; ///< Needed to make PERCENT_RANK same for peers
2372  /**
2373  Set when the last peer has been visited. Needed to increment m_rank_ctr.
2374  */
2376 
2377  public:
2379  : Item_non_framing_wf(pos, w),
2380  m_rank_ctr(0),
2381  m_peers(0),
2383 
2384  ~Item_percent_rank() override;
2385  const char *func_name() const override { return "percent_rank"; }
2386  enum Sumfunctype sum_func() const override { return PERCENT_RANK_FUNC; }
2387 
2388  bool resolve_type(THD *thd MY_ATTRIBUTE((unused))) override {
2390  return false;
2391  }
2392 
2393  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2394  Window_evaluation_requirements *reqs) override;
2395  bool needs_card() const override { return true; }
2396 
2397  void clear() override;
2398  longlong val_int() override;
2399  double val_real() override;
2400  String *val_str(String *) override;
2402  Item_result result_type() const override { return REAL_RESULT; }
2403 };
2404 
2405 /**
2406  NTILE window function, cf. SQL 2011 Section 6.10 <window function>
2407 */
2411 
2412  public:
2413  Item_ntile(const POS &pos, Item *a, PT_window *w)
2414  : Item_non_framing_wf(pos, a, w), m_value(0) {
2415  unsigned_flag = true;
2416  }
2417 
2418  const char *func_name() const override { return "ntile"; }
2419  enum Sumfunctype sum_func() const override { return NTILE_FUNC; }
2420 
2421  bool resolve_type(THD *thd) override {
2422  if (args[0]->propagate_type(thd, MYSQL_TYPE_LONGLONG, true)) return true;
2424  return false;
2425  }
2426 
2427  bool fix_fields(THD *thd, Item **items) override;
2428 
2429  longlong val_int() override;
2430  double val_real() override;
2431  my_decimal *val_decimal(my_decimal *buff) override;
2432  String *val_str(String *) override;
2433 
2434  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2435  Window_evaluation_requirements *reqs) override;
2437  Item_result result_type() const override { return INT_RESULT; }
2438  void clear() override {}
2439  bool needs_card() const override { return true; }
2440 };
2441 
2442 /**
2443  LEAD/LAG window functions, cf. SQL 2011 Section 6.10 <window function>
2444 */
2447  bool m_is_lead; ///< if true, the function is LEAD, else LAG
2448  int64 m_n; ///< canonicalized offset value
2452  /**
2453  Execution state: if set, we already have a value for current row.
2454  State is used to avoid interference with other LEAD/LAG functions on
2455  the same window, since they share the same eval loop and they should
2456  trigger evaluation only when they are on the "right" row relative to
2457  current row. For other offsets, return NULL if we don't know the value
2458  for this function yet, or if we do (m_has_value==true), return the
2459  found value.
2460  */
2462  bool m_use_default; ///< execution state: use default value for current row
2464 
2465  public:
2466  Item_lead_lag(const POS &pos, bool lead,
2467  PT_item_list *opt_list, // [0] expr, [1] offset, [2] default
2468  enum_null_treatment null_treatment, PT_window *w)
2469  : Item_non_framing_wf(pos, opt_list, w),
2470  m_null_treatment(null_treatment),
2471  m_is_lead(lead),
2472  m_n(0),
2474  m_value(nullptr),
2475  m_default(nullptr),
2476  m_has_value(false),
2477  m_use_default(false) {}
2478 
2479  const char *func_name() const override {
2480  return (m_is_lead ? "lead" : "lag");
2481  }
2482  enum Sumfunctype sum_func() const override { return LEAD_LAG_FUNC; }
2483 
2484  bool resolve_type(THD *thd) override;
2485  bool fix_fields(THD *thd, Item **items) override;
2486  void clear() override;
2487  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2488  Window_evaluation_requirements *reqs) override;
2490  enum Item_result result_type() const override { return m_hybrid_type; }
2491 
2492  longlong val_int() override;
2493  double val_real() override;
2494  String *val_str(String *str) override;
2495  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2496 
2497  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2498  bool get_time(MYSQL_TIME *ltime) override;
2499  bool val_json(Json_wrapper *wr) override;
2500 
2501  bool needs_card() const override {
2502  /*
2503  A possible optimization here: if LAG, we are only interested in rows we
2504  have already seen, so we might compute the result without reading the
2505  entire partition as soon as we have the current row. Similarly, a small
2506  LEAD value might avoid reading the entire partition also, giving shorter
2507  time to first result. For now, we read the entirely partition for these
2508  window functions - for simplicity.
2509  */
2510  return true;
2511  }
2512 
2513  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2514  mem_root_deque<Item *> *fields) override;
2515 
2517  bool has_value() const { return m_has_value; }
2518 
2520  bool use_default() const { return m_use_default; }
2521 
2522  private:
2523  bool setup_lead_lag();
2524  /**
2525  Core logic of LEAD/LAG window functions
2526 
2527  @return true if computation yielded a NULL or error
2528  */
2529  bool compute();
2530 };
2531 
2532 /**
2533  FIRST_VALUE/LAST_VALUE window functions, cf. SQL 2011 Section 6.10 <window
2534  function>
2535 */
2537  bool m_is_first; ///< if true, the function is FIRST_VALUE, else LAST_VALUE
2541  int64 cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2542  typedef Item_sum super;
2543 
2544  public:
2545  Item_first_last_value(const POS &pos, bool first, Item *a,
2546  enum_null_treatment null_treatment, PT_window *w)
2547  : Item_sum(pos, a, w),
2548  m_is_first(first),
2549  m_null_treatment(null_treatment),
2551  m_value(nullptr),
2552  cnt(0) {}
2553 
2554  const char *func_name() const override {
2555  return m_is_first ? "first_value" : "last_value";
2556  }
2557 
2558  enum Sumfunctype sum_func() const override { return FIRST_LAST_VALUE_FUNC; }
2559 
2560  bool resolve_type(THD *thd) override;
2561  bool fix_fields(THD *thd, Item **items) override;
2562  void clear() override;
2563  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2564  Window_evaluation_requirements *reqs) override;
2565  enum Item_result result_type() const override { return m_hybrid_type; }
2566 
2567  longlong val_int() override;
2568  double val_real() override;
2569  String *val_str(String *str) override;
2570  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2571 
2572  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2573  bool get_time(MYSQL_TIME *ltime) override;
2574  bool val_json(Json_wrapper *wr) override;
2575 
2576  void reset_field() override { DBUG_ASSERT(false); }
2577  void update_field() override { DBUG_ASSERT(false); }
2578  bool add() override {
2579  DBUG_ASSERT(false);
2580  return false;
2581  }
2582 
2583  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2584  mem_root_deque<Item *> *fields) override;
2585  bool uses_only_one_row() const override { return true; }
2586 
2587  private:
2588  bool setup_first_last();
2589  /**
2590  Core logic of FIRST/LAST_VALUE window functions
2591 
2592  @return true if computation yielded a NULL or error
2593  */
2594  bool compute();
2595 };
2596 
2597 /**
2598  NTH_VALUE window function, cf. SQL 2011 Section 6.10 <window
2599  function>
2600 */
2601 class Item_nth_value : public Item_sum {
2603  int64 m_n; ///< The N of the function
2604  bool m_from_last; ///< true iff FROM_LAST was specified
2608  int64 m_cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2609 
2610  typedef Item_sum super;
2611 
2612  public:
2613  Item_nth_value(const POS &pos, PT_item_list *a, bool from_last,
2614  enum_null_treatment null_treatment, PT_window *w)
2615  : Item_sum(pos, a, w),
2616  m_null_treatment(null_treatment),
2617  m_n(0),
2618  m_from_last(from_last),
2620  m_value(nullptr),
2621  m_cnt(0) {}
2622 
2623  const char *func_name() const override { return "nth_value"; }
2624  enum Sumfunctype sum_func() const override { return NTH_VALUE_FUNC; }
2625 
2626  bool resolve_type(THD *thd) override;
2627  bool fix_fields(THD *thd, Item **items) override;
2628  bool setup_nth();
2629  void clear() override;
2630 
2631  bool check_wf_semantics1(THD *thd, SELECT_LEX *select,
2632  Window_evaluation_requirements *reqs) override;
2634 
2635  enum Item_result result_type() const override { return m_hybrid_type; }
2636 
2637  longlong val_int() override;
2638  double val_real() override;
2639  String *val_str(String *str) override;
2640  my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2641 
2642  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2643  bool get_time(MYSQL_TIME *ltime) override;
2644  bool val_json(Json_wrapper *wr) override;
2645 
2646  void reset_field() override { DBUG_ASSERT(false); }
2647  void update_field() override { DBUG_ASSERT(false); }
2648  bool add() override {
2649  DBUG_ASSERT(false);
2650  return false;
2651  }
2652 
2653  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2654  mem_root_deque<Item *> *fields) override;
2655  bool uses_only_one_row() const override { return true; }
2656 
2657  private:
2658  /**
2659  Core logic of NTH_VALUE window functions
2660 
2661  @return true if computation yielded a NULL or error
2662  */
2663  bool compute();
2664 };
2665 
2666 /**
2667  Class for implementation of the GROUPING function. The GROUPING
2668  function distinguishes super-aggregate rows from regular grouped
2669  rows. GROUP BY extensions such as ROLLUP and CUBE produce
2670  super-aggregate rows where the set of all values is represented
2671  by null. Using the GROUPING function, you can distinguish a null
2672  representing the set of all values in a super-aggregate row from
2673  a NULL in a regular row.
2674 */
2676  public:
2679  }
2680  const char *func_name() const override { return "grouping"; }
2681  enum Functype functype() const override { return GROUPING_FUNC; }
2682  longlong val_int() override;
2683  bool aggregate_check_group(uchar *arg) override;
2684  bool fix_fields(THD *thd, Item **ref) override;
2685  void update_used_tables() override;
2686 };
2687 
2688 /**
2689  A wrapper Item that contains a number of aggregate items, one for each level
2690  of rollup (see Item_rollup_group_item for numbering conventions). When
2691  aggregating, every aggregator is either reset or updated as per the correct
2692  level, and when returning a value, the correct child item corresponding to
2693  the current rollup level is queried.
2694  */
2696  public:
2697  explicit Item_rollup_sum_switcher(List<Item> *sum_func_per_level)
2698  : Item_sum((*sum_func_per_level)[0]),
2699  m_num_levels(sum_func_per_level->size()) {
2700  args = (*THR_MALLOC)->ArrayAlloc<Item *>(sum_func_per_level->size());
2701  int i = 0;
2702  for (Item &item : *sum_func_per_level) {
2703  args[i++] = &item;
2704  }
2705  item_name = master()->item_name;
2708  hidden = master()->hidden;
2711  }
2712  double val_real() override;
2713  longlong val_int() override;
2714  String *val_str(String *str) override;
2715  my_decimal *val_decimal(my_decimal *dec) override;
2716  bool val_json(Json_wrapper *result) override;
2717  bool is_null() override;
2718  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2719  bool get_time(MYSQL_TIME *ltime) override;
2720  const char *func_name() const override { return "rollup_sum_switcher"; }
2721  table_map used_tables() const override { return master()->used_tables(); }
2722  Item_result result_type() const override { return master()->result_type(); }
2723  bool resolve_type(THD *) override {
2725  return false;
2726  }
2727  void print(const THD *thd, String *str,
2728  enum_query_type query_type) const override;
2729  Field *create_tmp_field(bool group, TABLE *table) override;
2730 
2731  enum Sumfunctype sum_func() const override { return master()->sum_func(); }
2732  enum Sumfunctype real_sum_func() const override {
2733  return ROLLUP_SUM_SWITCHER_FUNC;
2734  }
2735  void reset_field() override { DBUG_ASSERT(false); }
2736  void update_field() override { DBUG_ASSERT(false); }
2737  void clear() override;
2738  bool add() override {
2739  DBUG_ASSERT(false);
2740  return true;
2741  }
2742 
2743  bool reset_and_add_for_rollup(int last_unchanged_group_item_idx);
2744 
2745  int set_aggregator(Aggregator::Aggregator_type aggregator) override;
2746  bool aggregator_setup(THD *thd) override;
2747  inline bool aggregator_add_all() {
2748  for (int i = 0; i < m_num_levels; ++i) {
2749  if (child(i)->aggregator_add()) {
2750  return true;
2751  }
2752  }
2753  return false;
2754  }
2755 
2756  // Used when create_tmp_table() needs to delay application of aggregate
2757  // functions to a later stage in the query processing.
2758  Item *get_arg(uint i) override { return master()->get_arg(i); }
2759  Item *set_arg(THD *thd, uint i, Item *new_val) override {
2760  Item *ret = nullptr;
2761  for (int j = 0; j < m_num_levels; ++j) {
2762  ret = child(j)->set_arg(thd, i, new_val);
2763  }
2764  return ret; // Return the last one, arbitrarily.
2765  }
2766  uint argument_count() const override { return master()->argument_count(); }
2767 
2768  // Used by AggregateIterator.
2770  inline Item_sum *master() const { return child(0); }
2771 
2772  private:
2773  inline Item *current_arg() const;
2774  inline Item_sum *child(size_t i) const {
2775  return down_cast<Item_sum *>(args[i]);
2776  }
2777 
2778  const int m_num_levels;
2779  int m_current_rollup_level = INT_MAX;
2780 };
2781 
2782 #endif /* ITEM_SUM_INCLUDED */
Item_udf_sum
Definition: item_sum.h:1930
Item_nth_value::compute
bool compute()
Core logic of NTH_VALUE window functions.
Definition: item_sum.cc:5242
Item_sum_count::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2156
Item_result_field::llrint_with_overflow_check
longlong llrint_with_overflow_check(double realval)
Definition: item.h:5337
Item_rank::clear
void clear() override
Clear state for a new partition.
Definition: item_sum.cc:4745
Item_sum::SUM_BIT_FUNC
@ SUM_BIT_FUNC
Definition: item_sum.h:449
Item_sum_or
Definition: item_sum.h:1894
Item_sum_bit::val_decimal
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.cc:3131
Item_ntile::m_value
longlong m_value
Definition: item_sum.h:2410
Item_std_field
Definition: item_sum.h:1491
Item_rollup_sum_switcher::master
Item_sum * master() const
Definition: item_sum.h:2770
Item_sum_sum::Item_sum_sum
Item_sum_sum(const POS &pos, Item *item_par, bool distinct, PT_window *window)
Definition: item_sum.h:1038
Item_cume_dist::val_real
double val_real() override
Definition: item_sum.cc:4782
Item_rank::val_real
double val_real() override
Definition: item_sum.cc:4733
Item_func_group_concat::val_real
double val_real() override
Definition: item_sum.h:2169
Item_nth_value::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5291
Item_sum_avg::f_precision
uint f_precision
Definition: item_sum.h:1315
Item_sum::Collect_grouped_aggregate_info::m_break_off
bool m_break_off
true: break off transformation
Definition: item_sum.h:658
Aggregator_distinct::field_lengths
uint32 * field_lengths
Definition: item_sum.h:850
Item_udf_sum::itemize
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_sum.cc:3814
Item
Definition: item.h:775
Item_sum_bit::update_field
void update_field() override
Definition: item_sum.cc:3389
Item_sum_num::fix_fields
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1401
Item_sum_num
Definition: item_sum.h:948
Item::set_data_type
void set_data_type(enum_field_types data_type)
Set the data type of the current Item.
Definition: item.h:1285
String::ptr
const char * ptr() const
Definition: sql_string.h:246
THD
Definition: sql_class.h:807
Item_lead_lag::clear
void clear() override
Definition: item_sum.cc:5463
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:2461
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:1631
Item_sum_variance::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:2568
Item_sum_num_field
Common abstract class for: Item_avg_field Item_variance_field.
Definition: item_sum.h:1158
Item_sum_udf_str::val_decimal
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:3932
Item_sum_std
Definition: item_sum.h:1514
Item_sum_avg::val_int
longlong val_int() override
Definition: item_sum.h:1334
Mem_root_array< ORDER >
Item_sum_num::reset_field
void reset_field() override
Definition: item_sum.cc:3233
Item_func_grouping::Item_func_grouping
Item_func_grouping(const POS &pos, PT_item_list *a)
Definition: item_sum.h:2677
Item_non_framing_wf::Item_non_framing_wf
Item_non_framing_wf(const POS &pos, PT_window *w)
Definition: item_sum.h:2220
Item_sum_avg::func_name
const char * func_name() const override
Definition: item_sum.h:1343
Item_sum::NTH_VALUE_FUNC
@ NTH_VALUE_FUNC
Definition: item_sum.h:461
Item_ident::Change_context
< Argument object to change_context_processor
Definition: item.h:3822
field_types.h
This file contains the field type.
Item_percent_rank::super
Item_non_framing_wf super
Definition: item_sum.h:2368
Item_sum_and
Definition: item_sum.h:1904
Item_nth_value::check_wf_semantics2
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:4886
Aggregator::Aggregator_type
Aggregator_type
Definition: item_sum.h:114
Item_row_number::Item_row_number
Item_row_number(const POS &pos, PT_window *w)
Definition: item_sum.h:2255
template_utils.h
Item_sum_variance::count
ulonglong count
Definition: item_sum.h:1447
Item_sum_json_object::~Item_sum_json_object
~Item_sum_json_object() override
Item_sum_udf_decimal
Definition: item_sum.h:2062
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:1760
Item::maybe_null
bool maybe_null
True if this item may be null.
Definition: item.h:3226
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:146
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:2026
Item_sum_int::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1014
Item_sum::Item_sum
Item_sum(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:537
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:1577
Item_sum_int::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1013
Item_rollup_sum_switcher::get_arg
Item * get_arg(uint i) override
Definition: item_sum.h:2758
Item_sum::has_force_copy_fields
bool has_force_copy_fields() const
Definition: item_sum.h:435
Item_udf_sum::add
bool add() override
Definition: item_sum.cc:3829
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:785
Item_rank::m_rank_ctr
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2291
Item_sum::AVG_FUNC
@ AVG_FUNC
Definition: item_sum.h:443
Item_sum::make_const
void make_const()
Definition: item_sum.h:621
Func_args_handle::args
Item ** args
Array of pointers to arguments.
Definition: item_func.h:97
Item_sum::VARIANCE_FUNC
@ VARIANCE_FUNC
Definition: item_sum.h:448
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:2439
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:432
Item_sum_sum::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2027
Item_udf_sum::udf
udf_handler udf
Definition: item_sum.h:1934
Item_sum_max::func_name
const char * func_name() const override
Definition: item_sum.h:1724
Item_sum::clear
virtual void clear()=0
Item_sum_bit::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:1428
Json_wrapper
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1166
Item_std_field::val_real
double val_real() override
Definition: item_sum.cc:3758
mem_root_deque< Item * >
Item_rank::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4684
Item_func_group_concat::val_decimal
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.h:2181
Item_sum::transform
Item * transform(Item_transformer transformer, uchar *arg) override
Transform an Item_func object with a transformer callback function.
Definition: item_sum.cc:522
Item_sum_hybrid::min_max_update_real_field
void min_max_update_real_field()
Definition: item_sum.cc:3560
Item_avg_field::val_real
double val_real() override
Definition: item_sum.cc:3626
Item_sum_sum::dec_buffs
my_decimal dec_buffs[2]
Definition: item_sum.h:1021
Item::set_grouping_func
void set_grouping_func()
Set the property: this item is a call to GROUPING.
Definition: item.h:3051
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:1671
Item_sum::super2
Func_args_handle super2
Definition: item_sum.h:396
Item_rollup_sum_switcher::set_arg
Item * set_arg(THD *thd, uint i, Item *new_val) override
Definition: item_sum.h:2759
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:1808
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:1587
Item_avg_field::val_str
String * val_str(String *) override
Definition: item_sum.cc:3656
Item_sum::ROLLUP_SUM_SWITCHER_FUNC
@ ROLLUP_SUM_SWITCHER_FUNC
Definition: item_sum.h:462
Unique
Unique – class for unique (removing of duplicates).
Definition: uniques.h:52
Item_sum_sum
Definition: item_sum.h:1017
Item_sum_udf_float::val_int
longlong val_int() override
Definition: item_sum.h:1978
Item_sum::max_aggr_level
int8 max_aggr_level
max level of unbound column references
Definition: item_sum.h:487
Item_sum::window
const Window * window() const
Definition: item_sum.h:756
Item_sum_bit::m_is_xor
bool m_is_xor
true iff BIT_XOR
Definition: item_sum.h:1792
Item_sum::CUME_DIST_FUNC
@ CUME_DIST_FUNC
Definition: item_sum.h:456
Aggregator_distinct::tree
Unique * tree
Definition: item_sum.h:865
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:6123
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:2211
Item_sum::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields) override
Definition: item_sum.cc:892
Item_sum_udf_str::val_real
double val_real() override
Definition: item_sum.h:2031
Item_lead_lag::m_null_treatment
enum_null_treatment m_null_treatment
Definition: item_sum.h:2446
Item_sum_json_array::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:5894
udf_handler
Definition: sql_udf.h:82
Item_sum_max::Item_sum_max
Item_sum_max(Item *item_par)
Definition: item_sum.h:1718
Temp_table_param
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:73
Item_sum_json
Common abstraction for Item_sum_json_array and Item_sum_json_object.
Definition: item_sum.h:1212
Item_rollup_sum_switcher::current_arg
Item * current_arg() const
Definition: item_sum.cc:6146
Item_cume_dist::val_decimal
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:4806
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:4188
Item_ntile::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4969
Item_udf_sum::update_field
void update_field() override
Definition: item_sum.h:1966
Aggregator_simple::Aggregator_simple
Aggregator_simple(Item_sum *sum)
Definition: item_sum.h:936
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:2408
Item::SUM_FUNC_ITEM
@ SUM_FUNC_ITEM
Definition: item.h:815
my_compiler.h
Item_sum_json_object::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6005
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:2617
Item_rank::m_previous
List< Cached_item > m_previous
Values of previous row's ORDER BY items.
Definition: item_sum.h:2293
Item_sum_avg::dec_bin_size
uint dec_bin_size
Definition: item_sum.h:1315
Item_rollup_sum_switcher::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:6158
Item_sum_udf_int::val_int
longlong val_int() override
Definition: item_sum.cc:3902
Item_percent_rank::m_peers
ulonglong m_peers
Needed to make PERCENT_RANK same for peers.
Definition: item_sum.h:2371
CHARSET_INFO
Definition: m_ctype.h:354
Item_rank::result_type
Item_result result_type() const override
Definition: item_sum.h:2332
nullptr
Dialog Client Authentication nullptr
Definition: dialog.cc:353
Item_sum::aggregate_check_group
bool aggregate_check_group(uchar *arg) override
Definition: item_sum.cc:652
Item_func_group_concat::result
String result
Definition: item_sum.h:2099
Item_non_framing_wf::framing
bool framing() const override
All aggregates are framing, i.e.
Definition: item_sum.h:2244
Item_sum::Collect_grouped_aggregate_info::m_select
SELECT_LEX * m_select
The query block we walk from.
Definition: item_sum.h:656
Item_sum::update_used_tables
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_sum.cc:770
Item_func_grouping::func_name
const char * func_name() const override
Definition: item_sum.h:2680
Item_rank::val_str
String * val_str(String *) override
Definition: item_sum.cc:4738
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:2421
Item_rollup_sum_switcher::aggregator_add_all
bool aggregator_add_all()
Definition: item_sum.h:2747
Item_nth_value::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2624
Item_cume_dist::clear
void clear() override
Definition: item_sum.h:2356
Item_rollup_sum_switcher::val_real
double val_real() override
Definition: item_sum.cc:6163
Item_sum_hybrid::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:3020
Item_sum_bit::DIGIT_CNT_CARD
static constexpr uint DIGIT_CNT_CARD
Definition: item_sum.h:1789
Item_nth_value::m_from_last
bool m_from_last
true iff FROM_LAST was specified
Definition: item_sum.h:2604
Item_row_number
ROW_NUMBER window function, cf.
Definition: item_sum.h:2250
Item_sum_variance::reset_field
void reset_field() override
Definition: item_sum.cc:2694
Item_rank::m_dense
bool m_dense
If true, the object represents DENSE_RANK.
Definition: item_sum.h:2289
Item_sum_udf_float::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1985
Item::propagate_type
virtual bool propagate_type(THD *thd, const Type_properties &type)
Propagate data type specifications into parameters and user variables.
Definition: item.h:1124
Item_sum_xor::Item_sum_xor
Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1916
Item_nth_value
NTH_VALUE window function, cf.
Definition: item_sum.h:2601
Item_sum::next_sum
Item_sum * next_sum
next in the circular chain of registered objects
Definition: item_sum.h:478
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:1238
Item_rollup_sum_switcher::update_field
void update_field() override
Definition: item_sum.h:2736
Aggregator_distinct::const_distinct
enum Aggregator_distinct::Const_distinct const_distinct
Item_nth_value::clear
void clear() override
Definition: item_sum.cc:5216
Item_avg_field::Item_avg_field
Item_avg_field(Item_result res_type, Item_sum_avg *item)
Definition: item_sum.cc:3607
Item_first_last_value::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5017
Item_lead_lag::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2482
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:2395
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:406
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:2223
Item_cume_dist::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4772
Item_first_last_value
FIRST_VALUE/LAST_VALUE window functions, cf.
Definition: item_sum.h:2536
Item_percent_rank::val_int
longlong val_int() override
Definition: item_sum.cc:4861
Item_sum::unsupported_as_wf
void unsupported_as_wf()
Definition: item_sum.h:803
pos
char * pos
Definition: do_ctype.cc:76
Item_sum::MAX_FUNC
@ MAX_FUNC
Definition: item_sum.h:446
sql_string.h
Item_sum_avg::super
Item_sum_sum super
Definition: item_sum.h:1316
Item_sum_variance::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1480
Item_sum_udf_float::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1988
Item_sum_num_field::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1164
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:101
my_dbug.h
Item_udf_sum::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1961
thr_malloc.h
Item_sum_bit_field::type
enum Type type() const override
Definition: item_sum.h:1204
Item_sum_json::reset_field
void reset_field() override
Definition: item_sum.cc:5732
Item_rollup_sum_switcher::aggregator_setup
bool aggregator_setup(THD *thd) override
Called to initialize the aggregator.
Definition: item_sum.cc:6245
Item_sum_udf_str::Item_sum_udf_str
Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
Definition: item_sum.h:2028
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:498
Item_sum::AVG_DISTINCT_FUNC
@ AVG_DISTINCT_FUNC
Definition: item_sum.h:444
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:2918
Item_sum_avg::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1327
TABLE
Definition: table.h:1364
Item_variance_field::val_decimal
my_decimal * val_decimal(my_decimal *dec_buf) override
Definition: item_sum.h:1364
Item_func_group_concat::always_null
bool always_null
Definition: item_sum.h:2125
Item_percent_rank::func_name
const char * func_name() const override
Definition: item_sum.h:2385
Item::FIELD_VARIANCE_ITEM
@ FIELD_VARIANCE_ITEM
Definition: item.h:828
Item_sum_hybrid::setup_hybrid
bool setup_hybrid(Item *item, Item *value_arg)
MIN/MAX function setup.
Definition: item_sum.cc:1763
Item_sum_num_field::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1167
Item::Type
Type
Definition: item.h:811
Item_sum_num_field::val_int
longlong val_int() override
Definition: item_sum.h:1160
Item_sum_variance::func_name
const char * func_name() const override
Definition: item_sum.h:1475
Item_percent_rank::val_decimal
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:4873
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:2388
Aggregator_simple::setup
bool setup(THD *thd) override
Called before adding the first row.
Definition: item_sum.h:939
Item_ntile::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2419
window_lex.h
Item::null_value
bool null_value
True if item is null.
Definition: item.h:3227
Item_sum_hybrid::min_max_update_temporal_field
void min_max_update_temporal_field()
Definition: item_sum.cc:3508
Item_sum_and::func_name
const char * func_name() const override
Definition: item_sum.h:1910
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:684
longlong
long long int longlong
Definition: my_inttypes.h:54
Item_sum_bit::reset_field
void reset_field() override
Definition: item_sum.cc:3379
udf_handler::free_handler
void free_handler()
Definition: item_func.cc:4190
Item_avg_field::type
enum Type type() const override
Definition: item_sum.h:1178
Item_ntile::result_type
Item_result result_type() const override
Definition: item_sum.h:2437
udf_handler::is_initialized
bool is_initialized() const
Definition: sql_udf.h:112
Item_first_last_value::setup_first_last
bool setup_first_last()
Definition: item_sum.cc:5046
result
Definition: result.h:29
Item_first_last_value::compute
bool compute()
Core logic of FIRST/LAST_VALUE window functions.
Definition: item_sum.cc:5063
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:2064
Item_rollup_sum_switcher::is_null
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.cc:6198
Item_nth_value::func_name
const char * func_name() const override
Definition: item_sum.h:2623
Item_lead_lag::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5486
Item_lead_lag::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5518
Item_sum_json_array::m_json_array
unique_ptr_destroy_only< Json_array > m_json_array
Accumulates the final value.
Definition: item_sum.h:1258
Item_sum_avg::f_scale
uint f_scale
Definition: item_sum.h:1315
Item_sum_count::update_field
void update_field() override
Definition: item_sum.cc:3442
Item_sum_hybrid::min_max_update_json_field
void min_max_update_json_field()
Definition: item_sum.cc:3526
Item_sum::make_unique
virtual void make_unique()
Definition: item_sum.h:644
Item_rollup_sum_switcher::m_num_levels
const int m_num_levels
Definition: item_sum.h:2778
Item_rollup_sum_switcher::clear
void clear() override
Definition: item_sum.cc:6216
Item_sum::mark_as_sum_func
void mark_as_sum_func()
Definition: item_sum.cc:451
Item_sum_variance::add
bool add() override
Definition: item_sum.cc:2640
Item_first_last_value::super
Item_sum super
Definition: item_sum.h:2542
Item_first_last_value::func_name
const char * func_name() const override
Definition: item_sum.h:2554
Item_result_field
Item with result field.
Definition: item.h:5286
Item_sum_bit::bits
ulonglong bits
Stores the result value for the INT_RESULT.
Definition: item_sum.h:1740
Item_sum::JSON_AGG_FUNC
@ JSON_AGG_FUNC
Definition: item_sum.h:452
Item_percent_rank
PERCENT_RANK window function, cf.
Definition: item_sum.h:2367
Item_sum_hybrid::compute
bool compute()
This function implements the optimized version of retrieving min/max value.
Definition: item_sum.cc:2782
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:4007
Item_sum::replace_aggregate
Item * replace_aggregate(uchar *) override
Definition: item_sum.cc:742
Item_sum_variance::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2604
Item_sum::fix_num_length_and_dec
void fix_num_length_and_dec()
Definition: item_sum.cc:479
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:1735
Aggregator_distinct::arg_is_null
bool arg_is_null(bool use_null_value) override
NULLness of being-aggregated argument.
Definition: item_sum.cc:2145
Item_sum_sum::reset_field
void reset_field() override
Definition: item_sum.cc:3325
Item_sum::force_copy_fields
bool force_copy_fields
Used in making ROLLUP.
Definition: item_sum.h:425
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:1145
Item_first_last_value::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4993
value
const string value("\"Value\"")
Item_func_group_concat::separator
String * separator
Definition: item_sum.h:2100
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:2537
Item_func_group_concat
Definition: item_sum.h:2095
Item::get_time_from_numeric
bool get_time_from_numeric(MYSQL_TIME *ltime)
Convert a numeric type to time.
Definition: item.cc:1497
Item_lead_lag::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5390
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:465
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:900
Item::str_value
String str_value
str_values's main purpose is to cache the value in save_in_field
Definition: item.h:3126
Item_sum_json::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5702
Item::collation
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3133
Item_sum::check_wf_semantics1
virtual bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs)
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:382
Item_sum_avg::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1346
Item_sum::Collect_grouped_aggregate_info::list
std::vector< Item_sum * > list
accumulated all aggregates found
Definition: item_sum.h:650
Item_variance_field::Item_variance_field
Item_variance_field(Item_sum_variance *item)
Definition: item_sum.cc:3785
Item_sum_avg::add
bool add() override
Definition: item_sum.cc:2268
Item_sum_int::Item_sum_int
Item_sum_int(THD *thd, Item_sum_int *item)
Definition: item_sum.h:1000
Aggregator
The abstract base class for the Aggregator_* classes.
Definition: item_sum.h:96
Item_sum_variance::clear
void clear() override
Definition: item_sum.cc:2638
udf_func
Definition: sql_udf.h:43
Item_udf_sum::~Item_udf_sum
~Item_udf_sum() override
Definition: item_sum.h:1945
Item_sum_bit::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3117
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:4140
Item_sum_int::val_real
double val_real() override
Definition: item_sum.h:1004
Item_sum_std::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1522
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:940
Item_sum::framing
virtual bool framing() const
All aggregates are framing, i.e.
Definition: item_sum.h:769
Item_sum_hybrid::hybrid_type
Item_result hybrid_type
Definition: item_sum.h:1554
Item_rank::Item_rank
Item_rank(const POS &pos, bool dense, PT_window *w)
Definition: item_sum.h:2295
Item_sum_variance::prec_increment
uint prec_increment
Definition: item_sum.h:1449
Item_nth_value::m_cnt
int64 m_cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2608
Item_sum_hybrid::min_max_update_str_field
void min_max_update_str_field()
Definition: item_sum.cc:3544
Item_sum::max_sum_func_level
int8 max_sum_func_level
max level of aggregation for contained functions
Definition: item_sum.h:489
Item_lead_lag::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5451
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:4007
Item_func_group_concat::update_field
void update_field() override
Definition: item_sum.h:2165
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:2405
udf_handler::m_original
bool m_original
Definition: sql_udf.h:101
Item_transformer
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:717
Item_sum_udf_float
Definition: item_sum.h:1972
Item_sum_int::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1397
Item_sum_hybrid::Item_sum_hybrid
Item_sum_hybrid(Item *item_par, bool is_min)
Definition: item_sum.h:1615
Item_sum::Collect_grouped_aggregate_info::Collect_grouped_aggregate_info
Collect_grouped_aggregate_info(SELECT_LEX *select)
Definition: item_sum.h:659
Item_row_number::result_type
Item_result result_type() const override
Definition: item_sum.h:2275
DTCollation::set
void set(const DTCollation &dt)
Definition: item.h:191
Item_cache
Definition: item.h:6258
Item_field
Definition: item.h:3900
PT_order_list
Definition: parse_tree_nodes.h:211
Item_udf_sum::reset_field
void reset_field() override
Definition: item_sum.h:1965
Item_sum_json_object::func_name
const char * func_name() const override
Definition: item_sum.h:1304
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:1105
Item_sum_avg::create_tmp_field
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:2244
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:2312
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:2545
Item_sum_udf_decimal::Item_sum_udf_decimal
Item_sum_udf_decimal(THD *thd, Item_sum_udf_decimal *item)
Definition: item_sum.h:2067
Aggregator_distinct
The distinct aggregator.
Definition: item_sum.h:820
Item_non_framing_wf::add
bool add() override
Definition: item_sum.h:2237
Item_sum::aggregate_check_distinct
bool aggregate_check_distinct(uchar *arg) override
Definition: item_sum.cc:628
Item_rollup_sum_switcher::reset_and_add_for_rollup
bool reset_and_add_for_rollup(int last_unchanged_group_item_idx)
Definition: item_sum.cc:6222
Item_sum::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:870
Item_sum::reset_field
virtual void reset_field()=0
Item_first_last_value::update_field
void update_field() override
Definition: item_sum.h:2577
Item_sum_hybrid::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:2970
Item_first_last_value::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5137
Item_lead_lag::set_use_default
void set_use_default(bool value)
Definition: item_sum.h:2519
Item_func_grouping::functype
enum Functype functype() const override
Definition: item_sum.h:2681
Item_sum_count::count
longlong count
Definition: item_sum.h:1067
Item_sum_count::reset_field
void reset_field() override
Definition: item_sum.cc:3343
Item_sum::Item_sum
Item_sum(const POS &pos, PT_window *w)
Definition: item_sum.h:512
Item_nth_value::uses_only_one_row
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2655
Item_int_func
Definition: item_func.h:888
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:2904
Item_sum_hybrid::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields) override
Definition: item_sum.cc:3009
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:2448
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:791
Item_sum_max::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1723
Arg_comparator
Definition: item_cmpfunc.h:131
Item_std_field::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3766
Item_sum_hybrid::keep_field_type
bool keep_field_type() const override
Definition: item_sum.h:1675
Item_sum_bit_field::reset_bits
ulonglong reset_bits
Definition: item_sum.h:1192
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:5594
Item_sum_sum::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1047
Item_ntile::val_int
longlong val_int() override
Definition: item_sum.cc:4911
Item_nth_value::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5329
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:1543
Item_first_last_value::reset_field
void reset_field() override
Definition: item_sum.h:2576
Item::val_decimal_from_real
my_decimal * val_decimal_from_real(my_decimal *decimal_value)
Definition: item.cc:306
Item_sum_hybrid::m_nulls_first
bool m_nulls_first
Set to true if the window is ordered ascending.
Definition: item_sum.h:1559
Item_non_framing_wf::update_field
void update_field() override
Definition: item_sum.h:2236
Item_cume_dist::func_name
const char * func_name() const override
Definition: item_sum.h:2344
Item::val_decimal_from_string
my_decimal * val_decimal_from_string(my_decimal *decimal_value)
Definition: item.cc:321
Item::result_type
virtual Item_result result_type() const
Definition: item.h:1223
Item_lead_lag::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields) override
Definition: item_sum.cc:5427
Item_std_field::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1497
Item_func_group_concat::original
Item_func_group_concat * original
Definition: item_sum.h:2133
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:5007
Item_sum::Item_sum
Item_sum(const POS &pos, Item *a, Item *b, PT_window *w)
Definition: item_sum.h:550
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:964
Item_sum::ROW_NUMBER_FUNC
@ ROW_NUMBER_FUNC
Definition: item_sum.h:453
Item_sum_variance::recurrence_s
double recurrence_s
Definition: item_sum.h:1445
Item_sum_json::val_real
double val_real() override
Definition: item_sum.cc:5672
Item_first_last_value::val_decimal
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5123
Item_ntile::func_name
const char * func_name() const override
Definition: item_sum.h:2418
Item_percent_rank::val_real
double val_real() override
Definition: item_sum.cc:4835
Item_sum_hybrid::fix_fields
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1732
Item_sum_hybrid::any_value
bool any_value()
Definition: item_sum.h:1679
Item_sum_hybrid::was_values
bool was_values
Definition: item_sum.h:1555
Item_sum_hybrid::reset_field
void reset_field() override
Definition: item_sum.cc:3246
Item_func_group_concat::super
Item_sum super
Definition: item_sum.h:2096
Aggregator_distinct::unique_walk_function
bool unique_walk_function(void *element)
Aggregate a distinct row from the distinct hash table.
Definition: item_sum.cc:2088
Item_sum_sum::clear
void clear() override
Definition: item_sum.cc:1851
Aggregator_distinct::Aggregator_distinct
Aggregator_distinct(Item_sum *sum)
Definition: item_sum.h:907
Item_sum_max::clone_hybrid
Item_sum_max * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:3050
Item_nth_value::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5305
enum_query_type.h
Item_sum_bit::val_real
double val_real() override
Definition: item_sum.cc:3147
Item_sum_num::super
Item_sum super
Definition: item_sum.h:949
Item_sum::uses_only_one_row
virtual bool uses_only_one_row() const
Only for framing window functions.
Definition: item_sum.h:775
Item_sum::SUM_DISTINCT_FUNC
@ SUM_DISTINCT_FUNC
Definition: item_sum.h:442
Item_sum_udf_float::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3856
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:3451
Item_sum_hybrid::clear
void clear() override
Definition: item_sum.cc:2738
Item_rollup_sum_switcher::real_sum_func
enum Sumfunctype real_sum_func() const override
Definition: item_sum.h:2732
Item_variance_field::val_real
double val_real() override
Definition: item_sum.cc:3799
Name_resolution_context
Definition: item.h:394
Item_sum_int::Item_sum_int
Item_sum_int(const POS &pos, PT_item_list *list, PT_window *w)
Definition: item_sum.h:995
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:2112
Item_sum::RANK_FUNC
@ RANK_FUNC
Definition: item_sum.h:454
MYSQL_TYPE_NEWDECIMAL
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:81
Item_sum_avg::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2237
Item::get_time_from_int
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1473
Item::update_null_value
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:6826
Func_args_handle::param_type_is_default
bool param_type_is_default(THD *thd, uint start, uint end, uint step, enum_field_types def)
For arguments of this Func_args_handle ("args" array), in range [start, start+step,...
Definition: item_func.cc:393
Item_sum_json::val_int
longlong val_int() override
Definition: item_sum.cc:5687
Item_sum_hybrid::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:3034
Item_sum_variance::sample
uint sample
Definition: item_sum.h:1448
Item_func_grouping::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Resolve the fields in the GROUPING function.
Definition: item_sum.cc:6039
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:1268
Aggregator_distinct::CONST_NOT_NULL
@ CONST_NOT_NULL
Set to true if count distinct is on only const items.
Definition: item_sum.h:893
Item_lead_lag::compute
bool compute()
Core logic of LEAD/LAG window functions.
Definition: item_sum.cc:5536
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:2347
Item_sum_sum::func_name
const char * func_name() const override
Definition: item_sum.h:1062
Item_lead_lag::m_n
int64 m_n
canonicalized offset value
Definition: item_sum.h:2448
Item_cume_dist
CUME_DIST window function, cf.
Definition: item_sum.h:2338
Item_sum::collect_item_field_or_view_ref_processor
bool collect_item_field_or_view_ref_processor(uchar *) override
Definition: item_sum.cc:760
my_inttypes.h
Item_sum_count::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1095
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:1516
Item_nth_value::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5222
Item_sum_bit::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1844
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:4050
Aggregator::SIMPLE_AGGREGATOR
@ SIMPLE_AGGREGATOR
Definition: item_sum.h:114
Item_sum_hybrid::val_str
String * val_str(String *) override
Definition: item_sum.cc:2980
Item_cume_dist::val_str
String * val_str(String *) override
Definition: item_sum.cc:4802
Item_func_group_concat::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:4241
Item_sum::forced_const
bool forced_const
True means that this field has been evaluated during optimization.
Definition: item_sum.h:505
Item_func_grouping::update_used_tables
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_sum.cc:6135
Item_lead_lag::val_real
double val_real() override
Definition: item_sum.cc:5478
Item_first_last_value::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5107
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:1286
Item_sum_variance::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1473
Item_sum_udf_int::val_str
String * val_str(String *str) override
Definition: item_sum.cc:3910
Item_nth_value::m_hybrid_field_type
enum_field_types m_hybrid_field_type
Definition: item_sum.h:2606
Item_row_number::val_str
String * val_str(String *) override
Definition: item_sum.cc:4673
Item_func_group_concat::setup
bool setup(THD *thd) override
Definition: item_sum.cc:4440
Item_lead_lag::m_use_default
bool m_use_default
execution state: use default value for current row
Definition: item_sum.h:2462
Item_nth_value::setup_nth
bool setup_nth()
Definition: item_sum.cc:5205
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:1132
Item_lead_lag::m_is_lead
bool m_is_lead
if true, the function is LEAD, else LAG
Definition: item_sum.h:2447
Item_sum::real_sum_func
virtual enum Sumfunctype real_sum_func() const
Definition: item_sum.h:574
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:2252
Item_avg_field::func_name
const char * func_name() const override
Definition: item_sum.h:1183
Item_sum_sum::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:1910
Item::fixed
bool fixed
True if item has been resolved.
Definition: item.h:3197
Item_sum_udf_str
Definition: item_sum.h:2024
Item_sum_hybrid_field
This is used in connection which a parent Item_sum:
Definition: item_sum.h:1129
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:2116
Item_sum_min::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1709
Item_func_group_concat::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2184
Item_sum_hybrid::cmp
Arg_comparator * cmp
Definition: item_sum.h:1553
Item_lead_lag::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5509
Item_sum_json_object::add
bool add() override
Definition: item_sum.cc:5907
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:1368
Item_sum::aggregator_add
bool aggregator_add()
Called to add value to the aggregator.
Definition: item_sum.h:706
Item_sum::COUNT_DISTINCT_FUNC
@ COUNT_DISTINCT_FUNC
Definition: item_sum.h:440
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:1457
Item_sum_std::val_real
double val_real() override
Definition: item_sum.cc:2396
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:3723
Item_sum::m_window
PT_window * m_window
If sum is a window function, this field contains the window.
Definition: item_sum.h:411
Item_rank::super
Item_non_framing_wf super
Definition: item_sum.h:2288
Item_rollup_sum_switcher::val_str
String * val_str(String *str) override
Definition: item_sum.cc:6177
parse_location.h
Item_sum_hybrid::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3039
Aggregator_simple::Aggrtype
Aggregator_type Aggrtype() override
Definition: item_sum.h:937
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:2930
Item_nth_value::val_real
double val_real() override
Definition: item_sum.cc:5283
Item_sum_json::check_wf_semantics1
bool check_wf_semantics1(THD *, SELECT_LEX *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5603
Item_lead_lag::m_value
Item_cache * m_value
Definition: item_sum.h:2450
Json_array
Represents a JSON array container, i.e.
Definition: json_dom.h:519
Item_percent_rank::m_rank_ctr
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2370
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:1170
Item_row_number::check_wf_semantics1
bool check_wf_semantics1(THD *, SELECT_LEX *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2277
Item_sum_avg::Item_sum_avg
Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
Definition: item_sum.h:1320
Item_sum_variance::hybrid_type
Item_result hybrid_type
Definition: item_sum.h:1441
Item_sum_avg::clear
void clear() override
Definition: item_sum.cc:2266
Item_sum::itemize
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_sum.cc:86
Item_first_last_value::val_int
longlong val_int() override
Definition: item_sum.cc:5082
cs
Definition: commit_order_queue.h:33
Item::item_name
Item_name_string item_name
Name from query.
Definition: item.h:3134
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:1386
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:2466
Item_rollup_sum_switcher::create_tmp_field
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:6212
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:1089
Item_sum_max::Item_sum_max
Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1719
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:1781
net::buffer
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:388
Aggregator_distinct::add
bool add() override
Process incoming row.
Definition: item_sum.cc:1264
Item_udf_sum::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:3836
Item_avg_field::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3641
Item_avg_field
Definition: item_sum.h:1173
Item_sum_hybrid::min_max_update_int_field
void min_max_update_int_field()
Definition: item_sum.cc:3573
Item_sum::used_tables_cache
table_map used_tables_cache
Definition: item_sum.h:499
enum_field_types
enum_field_types
Column types for MySQL.
Definition: field_types.h:57
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:827
Aggregator_distinct::arg_val_real
double arg_val_real() override
Floating point value of being-aggregated argument.
Definition: item_sum.cc:2140
Item_sum_num::default_data_type
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_sum.h:969
Json_object
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:368
Item_ntile::val_real
double val_real() override
Definition: item_sum.cc:4957
Item_sum_udf_int::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3914
Item_sum::has_with_distinct
bool has_with_distinct() const
Definition: item_sum.h:436
Check_function_as_value_generator_parameters::err_code
int err_code
the error code found during check(if any)
Definition: item.h:491
Item_std_field::type
enum Type type() const override
Definition: item_sum.h:1494
Item_rollup_sum_switcher::m_current_rollup_level
int m_current_rollup_level
Definition: item_sum.h:2779
Item_sum_json::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5652
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:1937
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:5796
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:2316
Item_rollup_sum_switcher::set_aggregator
int set_aggregator(Aggregator::Aggregator_type aggregator) override
Definition: item_sum.cc:6234
Item_sum_int
Definition: item_sum.h:988
Item_func_group_concat::reset_field
void reset_field() override
Definition: item_sum.h:2164
Item_non_framing_wf::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2227
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:1358
Item_first_last_value::m_value
Item_cache * m_value
Definition: item_sum.h:2540
Item_sum::base_select
SELECT_LEX * base_select
query block where function is placed
Definition: item_sum.h:480
TREE
Definition: my_tree.h:67
Item_ntile::super
Item_non_framing_wf super
Definition: item_sum.h:2409
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:1294
Item_func_grouping::val_int
longlong val_int() override
Evaluation of the GROUPING function.
Definition: item_sum.cc:6094
Item_nth_value::update_field
void update_field() override
Definition: item_sum.h:2647
Item_sum_num::val_int
longlong val_int() override
Definition: item_sum.h:973
Aggregator::Aggregator
Aggregator(Item_sum *arg)
Definition: item_sum.h:111
Item_sum::used_tables
table_map used_tables() const override
Definition: item_sum.h:613
Item_sum_min::func_name
const char * func_name() const override
Definition: item_sum.h:1710
Item_sum_hybrid::super
Item_sum super
Definition: item_sum.h:1537
Item_sum_udf_str::val_int
longlong val_int() override
Definition: item_sum.h:2040
Item_func_group_concat::context
Name_resolution_context * context
Definition: item_sum.h:2114
Item_sum_num::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:979
Item_sum::FIRST_LAST_VALUE_FUNC
@ FIRST_LAST_VALUE_FUNC
Definition: item_sum.h:460
Item_row_number::func_name
const char * func_name() const override
Definition: item_sum.h:2260
Item_rollup_sum_switcher::func_name
const char * func_name() const override
Definition: item_sum.h:2720
my_decimal.h
Item_avg_field::f_scale
uint f_scale
Definition: item_sum.h:1175
Item_func_group_concat::tree
TREE * tree
Definition: item_sum.h:2102
Item_lead_lag::has_value
bool has_value() const
Definition: item_sum.h:2517
Item_avg_field::f_precision
uint f_precision
Definition: item_sum.h:1175
Item_cume_dist::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2345
Item_sum_xor::func_name
const char * func_name() const override
Definition: item_sum.h:1922
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:1583
Item_sum_hybrid::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *r) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:2748
Item_sum::PERCENT_RANK_FUNC
@ PERCENT_RANK_FUNC
Definition: item_sum.h:457
Item_sum_avg::Item_sum_avg
Item_sum_avg(THD *thd, Item_sum_avg *item)
Definition: item_sum.h:1323
dec
static const std::string dec("DECRYPTION")
Item_sum_json_array::add
bool add() override
Definition: item_sum.cc:5845
Item_sum_std::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1520
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:1896
Item_sum::add
virtual bool add()=0
Item_nth_value::val_int
longlong val_int() override
Definition: item_sum.cc:5275
Item_lead_lag::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5526
Item_sum_json_array
Implements aggregation of values into an array.
Definition: item_sum.h:1256
Item::val_string_from_real
String * val_string_from_real(String *str)
Definition: item.cc:255
Item_lead_lag::use_default
bool use_default() const
Definition: item_sum.h:2520
Item_sum_bit::remove_bits
void remove_bits(const String *s1, ulonglong b1)
For windowing: perform inverse aggregation.
Definition: item_sum.cc:1509
Item_nth_value::m_hybrid_type
Item_result m_hybrid_type
Definition: item_sum.h:2605
Item_non_framing_wf::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4629
Item_sum_udf_decimal::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3885
Item_udf_sum::Item_udf_sum
Item_udf_sum(THD *thd, Item_udf_sum *item)
Definition: item_sum.h:1941
Item_sum_udf_decimal::val_int
longlong val_int() override
Definition: item_sum.cc:3883
Item_nth_value::m_n
int64 m_n
The N of the function.
Definition: item_sum.h:2603
Item_sum_or::func_name
const char * func_name() const override
Definition: item_sum.h:1900
parse_tree_window.h
Item_ntile::clear
void clear() override
Definition: item_sum.h:2438
Item_sum_bit::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1831
Item_sum_udf_float::Item_sum_udf_float
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
Definition: item_sum.h:1976
Item_func_group_concat::m_result_finalized
bool m_result_finalized
True if result has been written to output buffer.
Definition: item_sum.h:2128
key1
static uint16 key1[1001]
Definition: hp_test2.cc:46
Item_sum_min::Item_sum_min
Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1705
Item::set_data_type_longlong
void set_data_type_longlong()
Set the data type of the Item to be longlong.
Definition: item.h:1300
Item_sum_hybrid::uses_only_one_row
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:1682
Item_rollup_sum_switcher::argument_count
uint argument_count() const override
Definition: item_sum.h:2766
Item_nth_value::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2635
Item_ident::orig_table_name
const char * orig_table_name() const
Definition: item.h:3769
Item_sum_udf_float::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3873
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:461
Aggregator_distinct::NOT_CONST
@ NOT_CONST
Definition: item_sum.h:876
sql_const.h
Item_lead_lag::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5501
Item_non_framing_wf::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2231
Item_sum_sum::curr_dec_buff
uint curr_dec_buff
Definition: item_sum.h:1022
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:168
Item_sum_std::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1527
Item_sum_bit_field::val_real
double val_real() override
Definition: item_sum.cc:3698
Item_sum_json::super
Item_sum super
Definition: item_sum.h:1213
Item_sum_avg::val_real
double val_real() override
Definition: item_sum.cc:2275
Item_sum_json_array::clear
void clear() override
Definition: item_sum.cc:5787
rules_table_service::end
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
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:2001
table_map
uint64_t table_map
Definition: my_table_map.h:29
Item_sum::DENSE_RANK_FUNC
@ DENSE_RANK_FUNC
Definition: item_sum.h:455
Item_sum_avg::m_avg
double m_avg
Definition: item_sum.h:1318
Item_first_last_value::add
bool add() override
Definition: item_sum.h:2578
Item_sum_min::Item_sum_min
Item_sum_min(Item *item_par)
Definition: item_sum.h:1704
Item_sum::Collect_grouped_aggregate_info
argument used by walk method collect_grouped_aggregates ("cga")
Definition: item_sum.h:648
Item_first_last_value::uses_only_one_row
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2585
Item_func_group_concat::add
bool add() override
Definition: item_sum.cc:4330
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:1974
Item_func::GROUPING_FUNC
@ GROUPING_FUNC
Definition: item_func.h:220
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:2122
Item_rank::func_name
const char * func_name() const override
Definition: item_sum.h:2308
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:1190
Item_lead_lag::m_hybrid_type
Item_result m_hybrid_type
Definition: item_sum.h:2449
Item::hidden
bool hidden
If the item is in a SELECT list (SELECT_LEX::fields) and hidden is true, the item wasn't actually in ...
Definition: item.h:3238
Item_rollup_sum_switcher::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:6152
Item_sum_json::update_field
void update_field() override
Definition: item_sum.cc:5752
my_decimal
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:91
Item_percent_rank::~Item_percent_rank
~Item_percent_rank() override
Definition: item_sum.cc:4884
Item_ntile::val_str
String * val_str(String *) override
Definition: item_sum.cc:4962
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:1563
Item_func_group_concat::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2187
Aggregator_distinct::clear
void clear() override
Invalidate calculated value and clear the distinct rows.
Definition: item_sum.cc:1232
Item_sum::LEAD_LAG_FUNC
@ LEAD_LAG_FUNC
Definition: item_sum.h:459
uint32
uint32_t uint32
Definition: my_inttypes.h:66
Item_percent_rank::clear
void clear() override
Definition: item_sum.cc:4878
Aggregator_distinct::tree_key_length
uint tree_key_length
Definition: item_sum.h:873
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:904
Item_sum_variance::update_field
void update_field() override
Definition: item_sum.cc:2714
Item_sum_sum::val_str
String * val_str(String *str) override
Definition: item_sum.cc:2021
my_table_map.h
Item_avg_field::prec_increment
uint prec_increment
Definition: item_sum.h:1176
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:2080
Item_sum::get_arg
virtual Item * get_arg(uint i)
Definition: item_sum.h:676
Item_rollup_sum_switcher::reset_field
void reset_field() override
Definition: item_sum.h:2735
Func_args_handle
Mixin class for classes which have an array of arguments ('args') and a count of them ('arg_count').
Definition: item_func.h:90
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:942
Item_sum_count::clear
void clear() override
Definition: item_sum.cc:2164
Item_sum_and::Item_sum_and
Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1906
Item_sum_avg::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1339
Item_sum::aggregator_setup
virtual bool aggregator_setup(THD *thd)
Called to initialize the aggregator.
Definition: item_sum.h:694
Item_sum::setup
virtual bool setup(THD *)
Definition: item_sum.h:724
enum_query_type
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
Item_sum::set_aggregator
virtual int set_aggregator(Aggregator::Aggregator_type aggregator)
Definition: item_sum.cc:843
Item_sum_num::Item_sum_num
Item_sum_num(const POS &pos, Item *item_par, PT_window *window)
Definition: item_sum.h:961
Item_sum_hybrid::min_max_update_decimal_field
void min_max_update_decimal_field()
Definition: item_sum.cc:3591
Item_sum_min
Definition: item_sum.h:1702
Item_percent_rank::val_str
String * val_str(String *) override
Definition: item_sum.cc:4869
Item_sum_xor::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3215
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:677
Item_row_number::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2261
Item_rollup_sum_switcher::result_type
Item_result result_type() const override
Definition: item_sum.h:2722
Item_nth_value::m_null_treatment
enum_null_treatment m_null_treatment
Definition: item_sum.h:2602
Item_non_framing_wf::Item_non_framing_wf
Item_non_framing_wf(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2221
Item_ntile::Item_ntile
Item_ntile(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2413
Item_rollup_sum_switcher::val_decimal
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:6184
Item_lead_lag::check_wf_semantics2
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5399
Check_function_as_value_generator_parameters
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:484
Item_sum_udf_float::val_real
double val_real() override
Definition: item_sum.cc:3861
Item_cume_dist::result_type
Item_result result_type() const override
Definition: item_sum.h:2361
Item_ident::orig_db_name
const char * orig_db_name() const
Definition: item.h:3768
MYSQL_TYPE_DOUBLE
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:62
Item_sum::allow_group_via_temp_table
bool allow_group_via_temp_table
If incremental update of fields is supported.
Definition: item_sum.h:490
Item_sum_bit::value_buff
String value_buff
Stores the result value for the STRING_RESULT.
Definition: item_sum.h:1742
Item_sum_std::func_name
const char * func_name() const override
Definition: item_sum.h:1523
Aggregator::Aggrtype
virtual Aggregator_type Aggrtype()=0
Aggregator_simple
The pass-through aggregator.
Definition: item_sum.h:934
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:2263
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:2113
Item_avg_field::dec_bin_size
uint dec_bin_size
Definition: item_sum.h:1175
Item_sum_count::add
bool add() override
Definition: item_sum.cc:2166
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:1028
Item_first_last_value::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2565
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:118
Item_lead_lag::val_int
longlong val_int() override
Definition: item_sum.cc:5470
Item_func_group_concat::force_copy_fields
bool force_copy_fields
Definition: item_sum.h:2126
Item_first_last_value::clear
void clear() override
Definition: item_sum.cc:5057
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:4050
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:1752
Item_sum::COUNT_FUNC
@ COUNT_FUNC
Definition: item_sum.h:439
Item_rank::~Item_rank
~Item_rank() override
Definition: item_sum.cc:4763
Item_sum_udf_int::Item_sum_udf_int
Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
Definition: item_sum.h:2003
Item_func_group_concat::make_unique
void make_unique() override
Definition: item_sum.cc:4560
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:100
Item_first_last_value::m_hybrid_type
Item_result m_hybrid_type
Definition: item_sum.h:2539
Item_sum::eq
bool eq(const Item *item, bool binary_cmp) const override
Definition: item_sum.cc:606
Item_func_group_concat::distinct
bool distinct
Definition: item_sum.h:2123
Item::FIELD_AVG_ITEM
@ FIELD_AVG_ITEM
Definition: item.h:822
Item_sum_sum::update_field
void update_field() override
calc next value and merge it with field_value.
Definition: item_sum.cc:3413
Item_rollup_sum_switcher::used_tables
table_map used_tables() const override
Definition: item_sum.h:2721
Item_ident::set_orig_field_name
void set_orig_field_name(const char *name_arg)
Definition: item.h:3765
Aggregator::DISTINCT_AGGREGATOR
@ DISTINCT_AGGREGATOR
Definition: item_sum.h:114
Item::unsigned_flag
bool unsigned_flag
Definition: item.h:3228
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:2292
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:1056
Item_sum::SUM_FUNC
@ SUM_FUNC
Definition: item_sum.h:441
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:3972
Item_sum_json_object::clear
void clear() override
Definition: item_sum.cc:5811
Item_sum_count::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1104
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:1746
Item_sum_sum::val_int
longlong val_int() override
Definition: item_sum.cc:1953
PT_window
Parse tree node for a window; just a shallow wrapper for class Window, q.v.
Definition: parse_tree_window.h:38
Item_first_last_value::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5098
Item_sum_udf_str::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2057
Item_row_number::val_int
longlong val_int() override
Definition: item_sum.cc:4654
Item_sum_num::is_evaluated
bool is_evaluated
Definition: item_sum.h:958
Item_sum_udf_str::resolve_type
bool resolve_type(THD *) override
Default max_length is max argument length.
Definition: item_sum.cc:3920
Item_rollup_sum_switcher::set_current_rollup_level
void set_current_rollup_level(int level)
Definition: item_sum.h:2769
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:1279
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:3898
Item_func_group_concat::tmp_table_param
Temp_table_param * tmp_table_param
Definition: item_sum.h:2098
Item_sum_bit::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1832
Item_func_group_concat::check_wf_semantics1
bool check_wf_semantics1(THD *, SELECT_LEX *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2200
Aggregator::item_sum
Item_sum * item_sum
Definition: item_sum.h:108
Item_sum_or::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3208
Item_sum_bit::clear
void clear() override
Definition: item_sum.cc:3194
Item_sum_udf_decimal::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2073
Item_sum_udf_str::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2051
Item_sum_hybrid::update_field
void update_field() override
Definition: item_sum.cc:3487
Item_sum::update_field
virtual void update_field()=0
Item_rollup_sum_switcher::val_int
longlong val_int() override
Definition: item_sum.cc:6170
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:5337
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:2225
Item_sum::create_tmp_field
virtual Field * create_tmp_field(bool group, TABLE *table)
Definition: item_sum.cc:685
Item_rollup_sum_switcher::Item_rollup_sum_switcher
Item_rollup_sum_switcher(List< Item > *sum_func_per_level)
Definition: item_sum.h:2697
Item_udf_sum::func_name
const char * func_name() const override
Definition: item_sum.h:1950
YYLTYPE
Bison "location" class.
Definition: parse_location.h:42
Item_sum_avg::prec_increment
uint prec_increment
Definition: item_sum.h:1314
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:5772
Item_sum_bit_field::val_int
longlong val_int() override
Definition: item_sum.cc:3683
Item_sum_avg::reset_field
void reset_field() override
Definition: item_sum.cc:3351
my_time.h
Item_sum_udf_str::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3928
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:2355
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:2613
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:2584
Item_rollup_sum_switcher::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:2723
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:1372
Item_sum_sum::add
bool add() override
Definition: item_sum.cc:1932
Aggregator_simple::arg_val_real
double arg_val_real() override
Floating point value of being-aggregated argument.
Definition: item_sum.cc:2116
Item_sum::GROUP_CONCAT_FUNC
@ GROUP_CONCAT_FUNC
Definition: item_sum.h:451
Item_func_group_concat::fix_fields
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:4379
sql_list.h
Item_nth_value::super
Item_sum super
Definition: item_sum.h:2610
Item::FIELD_STD_ITEM
@ FIELD_STD_ITEM
Definition: item.h:827
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:3662
DBUG_ASSERT
#define DBUG_ASSERT(A)
Definition: my_dbug.h:199
Item_udf_sum::clear
void clear() override
Definition: item_sum.cc:3823
Item_sum_count::val_int
longlong val_int() override
Definition: item_sum.cc:2173
Item_sum::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:639
Item_sum_int::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1010
Item_sum_variance::recurrence_m
double recurrence_m
Used in recurrence relation.
Definition: item_sum.h:1445
Item_sum_hybrid::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1676
Item_variance_field::val_str
String * val_str(String *str) override
Definition: item_sum.h:1363
Item_sum_sum::sum
double sum
Definition: item_sum.h:1020
Item_sum_udf_str::val_str
String * val_str(String *) override
Definition: item_sum.cc:3936
Item_sum
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:394
Item_sum_hybrid::arg_cache
Item_cache * arg_cache
Definition: item_sum.h:1552
Item_func_group_concat::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2158
Item_sum_hybrid_field::hybrid_type
Item_result hybrid_type
Stores the Item's result type.
Definition: item_sum.h:1134
Item_sum_hybrid::add
bool add() override
Definition: item_sum.cc:3069
Item_nth_value::m_value
Item_cache * m_value
Definition: item_sum.h:2607
Item_sum_udf_int::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2012
Item_sum_json::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1237
Item::get_time_from_real
bool get_time_from_real(MYSQL_TIME *ltime)
Convert val_real() to time in MYSQL_TIME.
Definition: item.cc:1455
Item_sum_bit::result_item
Item * result_item(Field *) override
Definition: item_sum.h:1827
Item_sum_udf_decimal::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2079
Item_sum::aggregator_clear
void aggregator_clear()
Called to cleanup the aggregator.
Definition: item_sum.h:700
Item_sum_json::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5720
Item_sum_max
Definition: item_sum.h:1716
String::length
size_t length() const
Definition: sql_string.h:238
Item_row_number::clear
void clear() override
Definition: item_sum.cc:4682
Item_variance_field::type
enum Type type() const override
Definition: item_sum.h:1361
Item_sum_udf_decimal::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3894
Aggregator_simple::add
bool add() override
Called when there's a new value to be aggregated.
Definition: item_sum.h:941
Item_sum::keep_field_type
virtual bool keep_field_type() const
Definition: item_sum.h:601
Item_sum_count::Item_sum_count
Item_sum_count(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1076
Item_sum_hybrid::value
Item_cache * value
Definition: item_sum.h:1552
Item_std_field::Item_std_field
Item_std_field(Item_sum_std *item)
Definition: item_sum.cc:3755
Item_sum_bit::val_str
String * val_str(String *str) override
Definition: item_sum.cc:3086
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:1182
Item_row_number::val_real
double val_real() override
Definition: item_sum.cc:4668
Item_udf_sum::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.h:1951
Item_sum_json::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5726
Item_sum_avg
Definition: item_sum.h:1312
Item_sum_json::fix_fields
bool fix_fields(THD *thd, Item **pItem) override
Definition: item_sum.cc:5608
Item_nth_value::reset_field
void reset_field() override
Definition: item_sum.h:2646
MYSQL_TYPE_LONGLONG
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:65
my_charset_bin
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:510
Item_sum_variance::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1481
Item_sum::result_item
virtual Item * result_item(Field *field)
Definition: item_sum.h:603
Item_sum::set_arg
virtual Item * set_arg(THD *thd, uint i, Item *new_val)
Definition: item_sum.cc:838
Item_sum_sum::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1061
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:1322
Item_sum::referenced_by
Item ** referenced_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:477
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:496
Item_variance_field
Definition: item_sum.h:1355
count
ssize_t count
Definition: memcached.c:386
Aggregator_distinct::Const_distinct
Const_distinct
Definition: item_sum.h:875
Item_lead_lag::setup_lead_lag
bool setup_lead_lag()
Definition: item_sum.cc:5435
ORDER
Definition: table.h:272
Item_variance_field::sample
uint sample
Definition: item_sum.h:1357
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:1795
Item_sum::fix_fields
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:880
Item_sum_hybrid
Abstract base class for the MIN and MAX aggregate functions.
Definition: item_sum.h:1536
Item_sum_count
Definition: item_sum.h:1066
Item_cume_dist::val_int
longlong val_int() override
Definition: item_sum.cc:4794
Func_args_handle::argument_count
virtual uint argument_count() const
Definition: item_func.h:110
Item_first_last_value::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2558
Item_first_last_value::val_real
double val_real() override
Definition: item_sum.cc:5090
Item_sum_bit_field::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3748
Item_sum_hybrid::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:2960
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:1502
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:1455
Parse_context
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:89
Item_rollup_sum_switcher::child
Item_sum * child(size_t i) const
Definition: item_sum.h:2774
Item_nth_value::add
bool add() override
Definition: item_sum.h:2648
Item_sum_int::val_str
String * val_str(String *str) override
Definition: item_sum.cc:1395
Aggregator_distinct::Aggrtype
Aggregator_type Aggrtype() override
Definition: item_sum.h:915
sql_base.h
MYF
#define MYF(v)
Definition: my_inttypes.h:96
Item_sum::type
Type type() const override
Definition: item_sum.h:570
Item_rollup_sum_switcher::val_json
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_sum.cc:6191
items
Definition: items.h:34
Item_sum_hybrid::val_real
double val_real() override
Definition: item_sum.cc:2890
Item_sum_sum::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:1844
Item_sum_bit_field::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3741
Item_rank
RANK or DENSE_RANK window function, cf.
Definition: item_sum.h:2287
Item_sum_udf_int
Definition: item_sum.h:1999
Item_sum_count::func_name
const char * func_name() const override
Definition: item_sum.h:1112
Item_lead_lag
LEAD/LAG window functions, cf.
Definition: item_sum.h:2445
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:1909
Item_cume_dist::super
Item_non_framing_wf super
Definition: item_sum.h:2339
Item_non_framing_wf
Common parent class for window functions that always work on the entire partition,...
Definition: item_sum.h:2216
Item_nth_value::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5321
Item_rollup_sum_switcher::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:6203
Item_sum::UDF_SUM_FUNC
@ UDF_SUM_FUNC
Definition: item_sum.h:450
Item_func_group_concat::row_count
uint row_count
Definition: item_sum.h:2119
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:962
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:503
Aggregator::~Aggregator
virtual ~Aggregator()
Definition: item_sum.h:112
Item_lead_lag::set_has_value
void set_has_value(bool value)
Definition: item_sum.h:2516
Item_sum::MIN_FUNC
@ MIN_FUNC
Definition: item_sum.h:445
udf_handler::fix_fields
bool fix_fields(THD *thd, Item_result_field *item, uint arg_count, Item **args)
Definition: item_func.cc:4208
Item_sum_udf_decimal::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2076
m_string.h
my_atof
double my_atof(const char *nptr)
Definition: dtoa.cc:528
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:1991
Item_sum_bit_field::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3715
Item_rollup_sum_switcher::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2731
Aggregator_distinct::table
TABLE * table
Definition: item_sum.h:842
Aggregator_distinct::CONST_NULL
@ CONST_NULL
Set to true if the result is known to be always NULL.
Definition: item_sum.h:886
my_strntod
#define my_strntod(s, a, b, c, d)
Definition: m_ctype.h:739
Item_processor
bool(Item::* Item_processor)(uchar *arg)
Processor type for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:456
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:2192
Item_sum_udf_int::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2016
Item_lead_lag::m_default
Item_cache * m_default
Definition: item_sum.h:2451
Item_sum_udf_int::val_real
double val_real() override
Definition: item_sum.h:2006
Item_sum_udf_int::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2015
sql_udf.h
Item_sum_xor::Item_sum_xor
Item_sum_xor(THD *thd, Item_sum_xor *item)
Definition: item_sum.h:1921
Item::get_time_from_decimal
bool get_time_from_decimal(MYSQL_TIME *ltime)
Convert val_decimal() to time in MYSQL_TIME.
Definition: item.cc:1464
Item_lead_lag::func_name
const char * func_name() const override
Definition: item_sum.h:2479
nesting_map
uint64_t nesting_map
Definition: my_table_map.h:30
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:1138
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:620
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:1863
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:1377
Item_sum_variance
Definition: item_sum.h:1437
Item_func_group_concat::arg_count_field
uint arg_count_field
The number of selected items, aka the expr list.
Definition: item_sum.h:2118
enum_walk
enum_walk
Enumeration for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:438
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Item_lead_lag::super
Item_non_framing_wf super
Definition: item_sum.h:2463
Item_sum_num::val_str
String * val_str(String *str) override
Definition: item_sum.cc:1389
Item_sum_variance::val_real
double val_real() override
Definition: item_sum.cc:2657
Item::set_data_type_from_item
void set_data_type_from_item(const Item *item)
Set data type properties of the item from the properties of another item.
Definition: item.h:1518
Item_sum_count::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:1098
Item_func_group_concat::warning_for_row
bool warning_for_row
Definition: item_sum.h:2124
Item_non_framing_wf::reset_field
void reset_field() override
Definition: item_sum.h:2235
Item_variance_field::func_name
const char * func_name() const override
Definition: item_sum.h:1368
Item_nth_value::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields) override
Definition: item_sum.cc:5198
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:238
Item_percent_rank::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:4811
List< Cached_item >
Item_first_last_value::cnt
int64 cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2541
Item_sum_avg::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2300
Item_func_group_concat::func_name
const char * func_name() const override
Definition: item_sum.h:2159
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:3845
Item_sum_json_object::check_wf_semantics1
bool check_wf_semantics1(THD *thd, SELECT_LEX *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5821
Item_sum_json::val_str
String * val_str(String *str) override
Definition: item_sum.cc:5634
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:5158
Item_sum_hybrid::create_tmp_field
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:1780
Item_percent_rank::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2386
Item_sum_variance::sum_func
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1466
Item_first_last_value::m_null_treatment
enum_null_treatment m_null_treatment
Definition: item_sum.h:2538
Item_func_group_concat::~Item_func_group_concat
~Item_func_group_concat() override
Definition: item_sum.h:2151
Item_sum::Collect_grouped_aggregate_info::aggregates_that_were_hidden
std::set< Item_sum * > aggregates_that_were_hidden
Definition: item_sum.h:651
Field
Definition: field.h:568
Item_func_group_concat::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4310
Item_percent_rank::Item_percent_rank
Item_percent_rank(const POS &pos, PT_window *w)
Definition: item_sum.h:2378
udf_registration_types.h
Aggregator_distinct::endup
void endup() override
Calculate the aggregate function value.
Definition: item_sum.cc:1325
Aggregator_distinct::setup
bool setup(THD *) override
Called before feeding the first row.
Definition: item_sum.cc:1033
Item_sum::check_wf_semantics2
virtual bool check_wf_semantics2(Window_evaluation_requirements *reqs)
Like check_wf_semantics1.
Definition: item_sum.h:746
Item_first_last_value::split_sum_func
void split_sum_func(THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields) override
Definition: item_sum.cc:5038
Item_sum_sum::val_real
double val_real() override
Definition: item_sum.cc:1977
Item_sum_json::m_value
String m_value
String used when reading JSON binary values or JSON text values.
Definition: item_sum.h:1217
Item_percent_rank::m_last_peer_visited
bool m_last_peer_visited
Set when the last peer has been visited.
Definition: item_sum.h:2375
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:1201
Window_evaluation_requirements
Collects evaluation requirements from a window function, used by Item_sum::check_wf_semantics and its...
Definition: window.h:1444
Item_ntile::fix_fields
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4904
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:556
Item_sum_udf_decimal::val_str
String * val_str(String *) override
Definition: item_sum.cc:3877
Item_sum_and::copy_or_same
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3222
SELECT_LEX
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1098
Item_func_group_concat::make_string_field
Field * make_string_field(TABLE *table_arg) const override
Create a field to hold a string value from an item.
Definition: item_sum.cc:4283
Item_func_group_concat::tree_base
TREE tree_base
Definition: item_sum.h:2101
Item_nth_value::get_date
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5313
Item_sum_int::Item_sum_int
Item_sum_int(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:990
Item_sum::STD_FUNC
@ STD_FUNC
Definition: item_sum.h:447
Item_sum_hybrid::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:2995
Item_sum_udf_str::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2054
Aggregator_simple::arg_val_decimal
my_decimal * arg_val_decimal(my_decimal *value) override
Decimal value of being-aggregated argument.
Definition: item_sum.cc:2112
Item_func_grouping
Class for implementation of the GROUPING function.
Definition: item_sum.h:2675
Item_sum::collect_scalar_subqueries
bool collect_scalar_subqueries(uchar *) override
Definition: item_sum.cc:750
Item_sum_json_object
Implements aggregation of values into an object.
Definition: item_sum.h:1275
Item_ntile::check_wf_semantics2
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:4977
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:1367
Item_sum_num::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1391
Item_rollup_sum_switcher::add
bool add() override
Definition: item_sum.h:2738
final
#define final(a, b, c)
Definition: hash.c:109
Aggregator_distinct::endup_done
bool endup_done
Definition: item_sum.h:831
Item_sum::collect_grouped_aggregates
bool collect_grouped_aggregates(uchar *) override
Definition: item_sum.cc:712
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:1221
Item_sum_num::Item_sum_num
Item_sum_num(THD *thd, Item_sum_num *item)
Definition: item_sum.h:967
Item::get_time_from_string
bool get_time_from_string(MYSQL_TIME *ltime)
Convert val_str() to time in MYSQL_TIME.
Definition: item.cc:1445
Item_row_number::val_decimal
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4677
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:5145
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:4593
Item_rank::val_decimal
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4740
Item_sum_udf_decimal::val_real
double val_real() override
Definition: item_sum.cc:3881
Item_sum::Item_sum
Item_sum(Item *a)
Definition: item_sum.h:524
Item_sum_json::~Item_sum_json
~Item_sum_json() override
udf_handler::name
const char * name() const
Definition: sql_udf.h:114
Item_std_field::func_name
const char * func_name() const override
Definition: item_sum.h:1498
Item_sum::wf_common_init
bool wf_common_init()
Common initial actions for window functions.
Definition: item_sum.cc:913
Item::FIELD_BIT_ITEM
@ FIELD_BIT_ITEM
Definition: item.h:840
Item_sum_count::cleanup
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:2205
my_sys.h
Item_sum_bit::reset_bits
ulonglong reset_bits
Stores the neutral element for function.
Definition: item_sum.h:1738
Item_sum::set_distinct
void set_distinct(bool distinct)
Definition: item_sum.h:709
Item_sum_bit_field::func_name
const char * func_name() const override
Definition: item_sum.h:1205
Item_sum_xor
Definition: item_sum.h:1914
Item_sum_json::m_conversion_buffer
String m_conversion_buffer
String used for converting JSON text values to utf8mb4 charset.
Definition: item_sum.h:1219
Item_sum_avg::val_str
String * val_str(String *str) override
Definition: item_sum.cc:2386
Item_sum_avg::m_avg_dec
my_decimal m_avg_dec
Definition: item_sum.h:1317
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:1571
Item_sum_hybrid::Item_sum_hybrid
Item_sum_hybrid(THD *thd, const Item_sum_hybrid *item)
Definition: item_sum.h:1647
Item_func_group_concat::val_str
String * val_str(String *str) override
Definition: item_sum.cc:4568
Item_rollup_sum_switcher
A wrapper Item that contains a number of aggregate items, one for each level of rollup (see Item_roll...
Definition: item_sum.h:2695
mem_root_array.h
Item_percent_rank::result_type
Item_result result_type() const override
Definition: item_sum.h:2402
Item_func_group_concat::val_int
longlong val_int() override
Definition: item_sum.h:2174
Item_rank::val_int
longlong val_int() override
Definition: item_sum.cc:4702
Item_ntile::val_decimal
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4964
Item_sum_hybrid_field::result_type
enum Item_result result_type() const override
Definition: item_sum.h:1137
Item_sum_json_object::m_json_object
unique_ptr_destroy_only< Json_object > m_json_object
Accumulates the final value.
Definition: item_sum.h:1277
Item_sum_variance::recurrence_s2
double recurrence_s2
Definition: item_sum.h:1446
Item_non_framing_wf::super
Item_sum super
Definition: item_sum.h:2217
Item_sum_bit::is_and
bool is_and() const
Definition: item_sum.h:1857
Aggregator_distinct::~Aggregator_distinct
~Aggregator_distinct() override
Definition: item_sum.cc:2095
Item_first_last_value::val_json
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5115
Item_sum_min::clone_hybrid
Item_sum_min * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:3046
Item_sum::get_arg_ptr
Item ** get_arg_ptr(uint i)
Definition: item_sum.h:679
Item_sum_hybrid::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2942
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:1035
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:2501
Item_sum_num::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:982
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:486
Item_func::Functype
Functype
Definition: item_func.h:168
mysql_time.h
Item_func_group_concat::result_type
Item_result result_type() const override
Definition: item_sum.h:2160
Item_sum_udf_float::val_str
String * val_str(String *str) override
Definition: item_sum.cc:3869
Item_udf_sum::super
Item_sum super
Definition: item_sum.h:1931
Aggregator_distinct::tmp_table_param
Temp_table_param * tmp_table_param
Definition: item_sum.h:856
Item_sum::NTILE_FUNC
@ NTILE_FUNC
Definition: item_sum.h:458
Item_sum::super
Item_result_field super
Definition: item_sum.h:395
Item_sum_bit::m_digit_cnt_card
uint m_digit_cnt_card
Definition: item_sum.h:1787
Item_sum::aggr_select
SELECT_LEX * aggr_select
For a group aggregate, query block where function is aggregated.
Definition: item_sum.h:486
Item_sum_sum::hybrid_type
Item_result hybrid_type
Definition: item_sum.h:1019
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:2111
Item_sum_variance::val_decimal
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2689
Aggregator_distinct::arg_val_decimal
my_decimal * arg_val_decimal(my_decimal *value) override
Decimal value of being-aggregated argument.
Definition: item_sum.cc:2135
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:1405
Item_sum::in_sum_func
Item_sum * in_sum_func
the containing set function if any
Definition: item_sum.h:479
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:1453
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:2017
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:580
Item_sum_bit::get_time
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3124
Aggregator_simple::arg_is_null
bool arg_is_null(bool use_null_value) override
NULLness of being-aggregated argument.
Definition: item_sum.cc:2120
Item_sum_avg::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1342
Item_func_group_concat::clear
void clear() override
Definition: item_sum.cc:4318
Item_sum::Sumfunctype
Sumfunctype
Definition: item_sum.h:438
Item_sum_bit::val_int
longlong val_int() override
Definition: item_sum.cc:3171
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:1744
Item_sum::m_window_resolved
bool m_window_resolved
True if we have already resolved this window functions window reference.
Definition: item_sum.h:416
Item_lead_lag::result_type
enum Item_result result_type() const override
Definition: item_sum.h:2490
Item_cume_dist::Item_cume_dist
Item_cume_dist(const POS &pos, PT_window *w)
Definition: item_sum.h:2342
Item_func_group_concat::change_context_processor
bool change_context_processor(uchar *arg) override
Definition: item_sum.h:2195
Item_sum_bit::super
Item_sum super
Definition: item_sum.h:1736
Item_sum_variance::no_rows_in_result
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1474
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:3972
Item_sum_or::Item_sum_or
Item_sum_or(THD *thd, Item_sum_or *item)
Definition: item_sum.h:1899
item.h