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