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