MySQL 8.4.13
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, 2026, 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;
1249 bool no_conversions) override;
1250 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
1251 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1252 bool get_time(MYSQL_TIME *ltime) override;
1253
1254 void reset_field() override;
1255 void update_field() override;
1256
1259};
1260
1261/// Implements aggregation of values into an array.
1263 /// Accumulates the final value.
1265
1266 public:
1267 Item_sum_json_array(THD *thd, Item_sum *item,
1270 Item_sum_json_array(const POS &pos, Item *a, PT_window *w,
1274 const char *func_name() const override { return "json_arrayagg"; }
1275 void clear() override;
1276 bool add() override;
1277 Item *copy_or_same(THD *thd) override;
1278};
1279
1280/// Implements aggregation of values into an object.
1282 /// Accumulates the final value.
1284 /// Buffer used to get the value of the key.
1286 /**
1287 Map of keys in Json_object and the count for each key
1288 within a window frame. It is used in handling rows
1289 leaving a window frame when rows are not sorted
1290 according to the key in Json_object.
1291 */
1292 std::map<std::string, int> m_key_map;
1293 /**
1294 If window provides ordering on the key in Json_object,
1295 a key_map is not needed to handle rows leaving a window
1296 frame. In this case, process_buffered_windowing_record()
1297 will set flags when a key/value pair can be removed from
1298 the Json_object.
1299 */
1300 bool m_optimize{false};
1301
1302 public:
1303 Item_sum_json_object(THD *thd, Item_sum *item,
1306 Item_sum_json_object(const POS &pos, Item *a, Item *b, PT_window *w,
1310 const char *func_name() const override { return "json_objectagg"; }
1311 void clear() override;
1312 bool add() override;
1313 Item *copy_or_same(THD *thd) override;
1314 bool check_wf_semantics1(THD *thd, Query_block *select,
1315 Window_evaluation_requirements *reqs) override;
1316};
1317
1318class Item_sum_avg final : public Item_sum_sum {
1319 public:
1324 double m_avg;
1325
1326 Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
1327 : Item_sum_sum(pos, item_par, distinct, w) {}
1328
1330 : Item_sum_sum(thd, item), prec_increment(item->prec_increment) {}
1331
1332 bool resolve_type(THD *thd) override;
1333 enum Sumfunctype sum_func() const override {
1335 }
1336 void clear() override;
1337 bool add() override;
1338 double val_real() override;
1339 // In SPs we might force the "wrong" type with select into a declare variable
1341 my_decimal *val_decimal(my_decimal *) override;
1342 String *val_str(String *str) override;
1343 void reset_field() override;
1344 void update_field() override;
1345 Item *result_item(Field *) override {
1346 return new Item_avg_field(hybrid_type, this);
1347 }
1348 const char *func_name() const override { return "avg"; }
1349 Item *copy_or_same(THD *thd) override;
1350 Field *create_tmp_field(bool group, TABLE *table) override;
1351 void cleanup() override {
1352 m_count = 0;
1355 }
1356};
1357
1358class Item_sum_variance;
1359
1361 protected:
1363
1364 public:
1366 enum Type type() const override { return AGGR_FIELD_ITEM; }
1367 double val_real() override;
1369 my_decimal *val_decimal(my_decimal *dec_buf) override {
1370 return val_decimal_from_real(dec_buf);
1371 }
1372 bool resolve_type(THD *) override { return false; }
1373 const char *func_name() const override {
1374 assert(0);
1375 return "variance_field";
1376 }
1379 pointer_cast<Check_function_as_value_generator_parameters *>(args);
1380 func_arg->err_code = func_arg->get_unnamed_function_error_code();
1381 return true;
1382 }
1383};
1384
1385/*
1386 variance(a) =
1387
1388 = sum (ai - avg(a))^2 / count(a) )
1389 = sum (ai^2 - 2*ai*avg(a) + avg(a)^2) / count(a)
1390 = (sum(ai^2) - sum(2*ai*avg(a)) + sum(avg(a)^2))/count(a) =
1391 = (sum(ai^2) - 2*avg(a)*sum(a) + count(a)*avg(a)^2)/count(a) =
1392 = (sum(ai^2) - 2*sum(a)*sum(a)/count(a) + count(a)*sum(a)^2/count(a)^2
1393 )/count(a) = = (sum(ai^2) - 2*sum(a)^2/count(a) + sum(a)^2/count(a)
1394 )/count(a) = = (sum(ai^2) - sum(a)^2/count(a))/count(a)
1395
1396 But, this falls prey to catastrophic cancellation.
1397 Instead, we use recurrence formulas in Algorithm I mentoned below
1398 for group aggregates.
1399
1400 Algorithm I:
1401 M_{1} = x_{1}, ~ M_{k} = M_{k-1} + (x_{k} - M_{k-1}) / k newline
1402 S_{1} = 0, ~ S_{k} = S_{k-1} + (x_{k} - M_{k-1}) times (x_{k} - M_{k}) newline
1403 for 2 <= k <= n newline
1404 ital variance = S_{n} / (n-1)
1405
1406 For aggregate window functions algorithm I cannot be optimized for
1407 moving frames since M_{i} changes for every row. So we use the
1408 following algorithm.
1409
1410 Algorithm II:
1411
1412 K = 0
1413 n = 0
1414 ex = 0
1415 ex2 = 0
1416
1417 def add_sample(x):
1418 if (n == 0):
1419 K = x
1420 n = n + 1
1421 ex += x - K
1422 ex2 += (x - K) * (x - K)
1423
1424 def remove_sample(x):
1425 n = n - 1
1426 ex -= (x - K)
1427 ex2 -= (x - K) * (x - K)
1428
1429 def variance():
1430 return (ex2 - (ex*ex)/n) / (n-1)
1431
1432 This formula facilitates incremental computation enabling us to
1433 optimize in case of moving window frames. The optimized codepath is taken
1434 only when windowing_use_high_precision is set to false. By default,
1435 aggregate window functions take the non-optimized codepath.
1436 Note:
1437 Results could differ between optimized and non-optimized code path.
1438 Hence algorithm II is used only when user sets
1439 windowing_use_high_precision to false.
1440*/
1441
1443 bool resolve_type(THD *) override;
1444
1445 public:
1447 /**
1448 Used in recurrence relation.
1449 */
1450 double recurrence_m{0.0};
1451 double recurrence_s{0.0};
1452 double recurrence_s2{0.0};
1456 /**
1457 If set, uses a algorithm II mentioned in the class description
1458 to calculate the variance which helps in optimizing windowing
1459 functions in presence of frames.
1460 */
1462
1463 Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg,
1464 PT_window *w)
1465 : Item_sum_num(pos, item_par, w),
1467 count(0),
1468 sample(sample_arg),
1469 optimize(false) {}
1470
1472 enum Sumfunctype sum_func() const override { return VARIANCE_FUNC; }
1473 void clear() override;
1474 bool add() override;
1475 double val_real() override;
1476 my_decimal *val_decimal(my_decimal *) override;
1477 void reset_field() override;
1478 void update_field() override;
1479 Item *result_item(Field *) override { return new Item_variance_field(this); }
1480 void no_rows_in_result() override {}
1481 const char *func_name() const override {
1482 return sample ? "var_samp" : "variance";
1483 }
1484 Item *copy_or_same(THD *thd) override;
1485 Field *create_tmp_field(bool group, TABLE *table) override;
1486 enum Item_result result_type() const override { return REAL_RESULT; }
1487 void cleanup() override {
1488 count = 0;
1490 }
1491 bool check_wf_semantics1(THD *thd, Query_block *select,
1492 Window_evaluation_requirements *reqs) override;
1493};
1494
1495class Item_sum_std;
1496
1498 public:
1500 enum Type type() const override { return AGGR_FIELD_ITEM; }
1501 double val_real() override;
1502 my_decimal *val_decimal(my_decimal *) override;
1503 enum Item_result result_type() const override { return REAL_RESULT; }
1504 const char *func_name() const override {
1505 assert(0);
1506 return "std_field";
1507 }
1510 pointer_cast<Check_function_as_value_generator_parameters *>(args);
1511 func_arg->err_code = func_arg->get_unnamed_function_error_code();
1512 return true;
1513 }
1514};
1515
1516/*
1517 standard_deviation(a) = sqrt(variance(a))
1518*/
1519
1521 public:
1522 Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
1523 : Item_sum_variance(pos, item_par, sample_arg, w) {}
1524
1525 Item_sum_std(THD *thd, Item_sum_std *item) : Item_sum_variance(thd, item) {}
1526 enum Sumfunctype sum_func() const override { return STD_FUNC; }
1527 double val_real() override;
1528 Item *result_item(Field *) override { return new Item_std_field(this); }
1529 const char *func_name() const override {
1530 return sample ? "stddev_samp" : "std";
1531 }
1532 Item *copy_or_same(THD *thd) override;
1533 enum Item_result result_type() const override { return REAL_RESULT; }
1534};
1535
1536// This class is a string or number function depending on num_func
1537class Arg_comparator;
1538
1539/**
1540 Abstract base class for the MIN and MAX aggregate functions.
1541*/
1544
1545 private:
1546 /**
1547 Tells if this is the MIN function (true) or the MAX function (false).
1548 */
1549 const bool m_is_min;
1550 /*
1551 For window functions MIN/MAX with optimized code path, no comparisons
1552 are needed beyond NULL detection: MIN/MAX are then roughly equivalent to
1553 FIRST/LAST_VALUE. For this case, 'value' is the value of
1554 the window function a priori taken from args[0], while arg_cache is used to
1555 remember the value from the previous row. NULLs need a bit of careful
1556 treatment.
1557 */
1561 bool m_has_values; // Set if at least one row is found (for max/min only)
1562 /**
1563 Set to true if the window is ordered ascending.
1564 */
1566 /**
1567 Set to true when min/max can be optimized using window's ordering.
1568 */
1570 /**
1571 For min() - Set to true when results are ordered in ascending and
1572 false when descending.
1573 For max() - Set to true when results are ordered in descending and
1574 false when ascending.
1575 Valid only when m_optimize is true.
1576 */
1577 bool m_want_first; ///< Want first non-null value, else last non_null value
1578 /**
1579 Execution state: keeps track if this is the first row in the frame
1580 when buffering is not needed.
1581 Valid only when m_optimize is true.
1582 */
1584
1585 /**
1586 Execution state: keeps track of at which row we saved a non-null last
1587 value.
1588 */
1590
1591 /**
1592 This function implements the optimized version of retrieving min/max
1593 value. When we have "ordered ASC" results in a window, min will always
1594 be the first value in the result set (neglecting the NULL's) and max
1595 will always be the last value (or the other way around, if ordered DESC).
1596 It is based on the implementation of FIRST_VALUE/LAST_VALUE, except for
1597 the NULL handling.
1598
1599 @return true if computation yielded a NULL or error
1600 */
1601 bool compute();
1602
1603 /**
1604 MIN/MAX function setup.
1605
1606 Setup cache/comparator of MIN/MAX functions. When called by the
1607 copy_or_same() function, the value_arg parameter contains the calculated
1608 value of the original MIN/MAX object, and it is saved in this object's
1609 cache.
1610
1611 @param item the argument of the MIN/MAX function
1612 @param value_arg the calculated value of the MIN/MAX function
1613 @return false on success, true on error
1614 */
1615 bool setup_hybrid(Item *item, Item *value_arg);
1616
1617 /** Create a clone of this object. */
1618 virtual Item_sum_hybrid *clone_hybrid(THD *thd) const = 0;
1619
1620 protected:
1621 Item_sum_hybrid(Item *item_par, bool is_min)
1622 : Item_sum(item_par),
1623 m_is_min(is_min),
1624 value(nullptr),
1626 cmp(nullptr),
1628 m_has_values(true),
1629 m_nulls_first(false),
1630 m_optimize(false),
1631 m_want_first(false),
1632 m_cnt(0),
1635 }
1636
1637 Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
1638 : Item_sum(pos, item_par, w),
1639 m_is_min(is_min),
1640 value(nullptr),
1642 cmp(nullptr),
1644 m_has_values(true),
1645 m_nulls_first(false),
1646 m_optimize(false),
1647 m_want_first(false),
1648 m_cnt(0),
1651 }
1652
1654 : Item_sum(thd, item),
1655 m_is_min(item->m_is_min),
1656 value(item->value),
1658 hybrid_type(item->hybrid_type),
1661 m_optimize(item->m_optimize),
1663 m_cnt(item->m_cnt),
1665
1666 public:
1667 bool fix_fields(THD *, Item **) override;
1668 void clear() override;
1669 void update_after_wf_arguments_changed(THD *thd) override;
1670 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
1671 mem_root_deque<Item *> *fields) override;
1672 double val_real() override;
1673 longlong val_int() override;
1674 longlong val_time_temporal() override;
1675 longlong val_date_temporal() override;
1676 my_decimal *val_decimal(my_decimal *) override;
1677 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1678 bool get_time(MYSQL_TIME *ltime) override;
1679 void reset_field() override;
1680 String *val_str(String *) override;
1681 bool val_json(Json_wrapper *wr) override;
1682 bool keep_field_type() const override { return true; }
1683 enum Item_result result_type() const override { return hybrid_type; }
1684 TYPELIB *get_typelib() const override {
1685 assert(sum_func() == MAX_FUNC || sum_func() == MIN_FUNC);
1686 return arguments()[0]->get_typelib();
1687 }
1688 void update_field() override;
1689 void cleanup() override;
1690 bool has_values() { return m_has_values; }
1691 void no_rows_in_result() override;
1692 Field *create_tmp_field(bool group, TABLE *table) override;
1693 bool uses_only_one_row() const override { return m_optimize; }
1694 bool add() override;
1695 Item *copy_or_same(THD *thd) override;
1696 bool check_wf_semantics1(THD *thd, Query_block *select,
1698
1699 private:
1700 /*
1701 These functions check if the value on the current row exceeds the maximum or
1702 minimum value seen so far, and update the current max/min stored in
1703 result_field, if needed.
1704 */
1711};
1712
1713class Item_sum_min final : public Item_sum_hybrid {
1714 public:
1715 Item_sum_min(Item *item_par) : Item_sum_hybrid(item_par, true) {}
1716 Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
1717 : Item_sum_hybrid(pos, item_par, true, w) {}
1718 Item_sum_min(THD *thd, const Item_sum_min *item)
1719 : Item_sum_hybrid(thd, item) {}
1720 enum Sumfunctype sum_func() const override { return MIN_FUNC; }
1721 const char *func_name() const override { return "min"; }
1722
1723 private:
1724 Item_sum_min *clone_hybrid(THD *thd) const override;
1725};
1726
1727class Item_sum_max final : public Item_sum_hybrid {
1728 public:
1729 Item_sum_max(Item *item_par) : Item_sum_hybrid(item_par, false) {}
1730 Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
1731 : Item_sum_hybrid(pos, item_par, false, w) {}
1732 Item_sum_max(THD *thd, const Item_sum_max *item)
1733 : Item_sum_hybrid(thd, item) {}
1734 enum Sumfunctype sum_func() const override { return MAX_FUNC; }
1735 const char *func_name() const override { return "max"; }
1736
1737 private:
1738 Item_sum_max *clone_hybrid(THD *thd) const override;
1739};
1740
1741/**
1742 Base class used to implement BIT_AND, BIT_OR and BIT_XOR.
1743
1744 Each of them is both a set function and a framing window function.
1745*/
1746class Item_sum_bit : public Item_sum {
1748 /// Stores the neutral element for function
1750 /// Stores the result value for the INT_RESULT
1752 /// Stores the result value for the STRING_RESULT
1754 /// Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT
1756 /// Buffer used to avoid String allocation in the constructor
1757 const char initial_value_buff_storage[1] = {0};
1758
1759 /**
1760 Execution state (windowing): this is for counting rows entering and leaving
1761 the window frame, see #m_frame_null_count.
1762 */
1764
1765 /**
1766 Execution state (windowing): this is for counting NULLs of rows entering
1767 and leaving the window frame, when we use optimized inverse-based
1768 computations. By comparison with m_count we can know how many non-NULLs are
1769 in the frame.
1770 */
1772
1773 /**
1774 Execution state (windowing): Used for AND, OR to be able to invert window
1775 functions in optimized mode.
1776
1777 For the optimized code path of BIT_XXX wfs, we keep track of the number of
1778 bit values (0's or 1's; see below) seen in a frame using a 64 bits counter
1779 pr bit. This lets us compute the value of OR by just inspecting:
1780
1781 - the number of 1's in the previous frame
1782 - whether any removed row(s) is a 1
1783 - whether any added row(s) is a 1
1784
1785 Similarly for AND, we keep track of the number of 0's seen for a particular
1786 bit. To do this trick we need a counter per bit position. This array holds
1787 these counters.
1788
1789 Note that for XOR, the inverse operation is identical to the operation,
1790 so we don't need the above.
1791 */
1793 /*
1794 Size of allocated array m_digit_cnt.
1795 The size is DIGIT_CNT_CARD (for integer types) or ::max_length * 8 for bit
1796 strings.
1797 */
1799
1800 static constexpr uint DIGIT_CNT_CARD = sizeof(ulonglong) * 8;
1801
1802 protected:
1803 bool m_is_xor; ///< true iff BIT_XOR
1804
1805 public:
1806 Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg,
1807 PT_window *w)
1808 : Item_sum(pos, item_par, w),
1809 reset_bits(reset_arg),
1810 bits(reset_arg),
1812 m_count(0),
1816 m_is_xor(false) {}
1817
1818 /// Copy constructor, used for executing subqueries with temporary tables
1820 : Item_sum(thd, item),
1821 reset_bits(item->reset_bits),
1822 bits(item->bits),
1824 hybrid_type(item->hybrid_type),
1825 m_count(item->m_count),
1829 m_is_xor(item->m_is_xor) {
1830 /*
1831 This constructor should only be called during the Optimize stage.
1832 Asserting that the item was not evaluated yet.
1833 */
1834 assert(item->value_buff.length() == 1);
1835 assert(item->bits == item->reset_bits);
1836 }
1837
1838 Item *result_item(Field *) override {
1839 return new Item_sum_bit_field(hybrid_type, this, reset_bits);
1840 }
1841
1842 enum Sumfunctype sum_func() const override { return SUM_BIT_FUNC; }
1843 enum Item_result result_type() const override { return hybrid_type; }
1844 void clear() override;
1845 longlong val_int() override;
1846 double val_real() override;
1847 String *val_str(String *str) override;
1848 my_decimal *val_decimal(my_decimal *decimal_value) override;
1849 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1850 bool get_time(MYSQL_TIME *ltime) override;
1851 void reset_field() override;
1852 void update_field() override;
1853 bool resolve_type(THD *) override;
1854 bool fix_fields(THD *thd, Item **ref) override;
1855 void cleanup() override {
1856 bits = reset_bits;
1857 // At end of one execution of statement, free buffer to reclaim memory:
1860 }
1861
1862 /**
1863 Common implementation of Item_sum_or::add, Item_sum_and:add
1864 and Item_sum_xor::add.
1865 */
1866 bool add() override;
1867 /// @returns true iff this is BIT_AND.
1868 inline bool is_and() const { return reset_bits != 0; }
1869
1870 private:
1871 /**
1872 Accumulate the value of 's1' (if in string mode) or of 'b1' (if in integer
1873 mode). Updates 'value_buff' or 'bits'.
1874
1875 @param s1 argument to accumulate
1876 @param b1 argument to accumulate
1877
1878 @returns true if error
1879 */
1880 bool add_bits(const String *s1, ulonglong b1);
1881
1882 /**
1883 For windowing: perform inverse aggregation. "De-accumulate" the value of
1884 's1' (if in string mode) or of 'b1' (if in integer mode). Updates
1885 'value_buff' or 'bits'.
1886
1887 For BIT_XOR we simply apply XOR as it's its inverse operation. For BIT_OR
1888 and BIT_AND we do the rest below.
1889
1890 For each bit in argument, decrement the corresponding bits's counter
1891 ('m_digit_cnt') for that bit as follows: for BIT_AND, decrement the
1892 counter if we see a zero in that bit; for BIT_OR decrement the counter if
1893 we see a 1 in that bit. Next, update 'value_buff' or 'bits' using the
1894 resulting counters: for each bit, for BIT_AND, set bit if we have counter
1895 == 0, i.e. we have no zero bits for that bit in the frame (yet). For
1896 BIT_OR, set bit if we have counter > 0, i.e. at least one row in the frame
1897 has that bit set.
1898
1899 @param s1 the bits to be inverted from the aggregate value
1900 @param b1 the bits to be inverted from the aggregate value
1901 */
1902 void remove_bits(const String *s1, ulonglong b1);
1903};
1904
1905class Item_sum_or final : public Item_sum_bit {
1906 public:
1907 Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
1908 : Item_sum_bit(pos, item_par, 0LL, w) {}
1909
1910 Item_sum_or(THD *thd, Item_sum_or *item) : Item_sum_bit(thd, item) {}
1911 const char *func_name() const override { return "bit_or"; }
1912 Item *copy_or_same(THD *thd) override;
1913};
1914
1915class Item_sum_and final : public Item_sum_bit {
1916 public:
1917 Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
1918 : Item_sum_bit(pos, item_par, ULLONG_MAX, w) {}
1919
1920 Item_sum_and(THD *thd, Item_sum_and *item) : Item_sum_bit(thd, item) {}
1921 const char *func_name() const override { return "bit_and"; }
1922 Item *copy_or_same(THD *thd) override;
1923};
1924
1925class Item_sum_xor final : public Item_sum_bit {
1926 public:
1927 Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
1928 : Item_sum_bit(pos, item_par, 0LL, w) {
1929 m_is_xor = true;
1930 }
1931
1932 Item_sum_xor(THD *thd, Item_sum_xor *item) : Item_sum_bit(thd, item) {}
1933 const char *func_name() const override { return "bit_xor"; }
1934 Item *copy_or_same(THD *thd) override;
1935};
1936
1937/*
1938 User defined aggregates
1939*/
1940
1941class Item_udf_sum : public Item_sum {
1943
1944 protected:
1946
1947 public:
1948 Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1949 : Item_sum(pos, opt_list, nullptr), udf(udf_arg) {
1951 }
1953 : Item_sum(thd, item), udf(item->udf) {
1954 udf.m_original = false;
1955 }
1956 ~Item_udf_sum() override {
1958 }
1959
1960 bool do_itemize(Parse_context *pc, Item **res) override;
1961 const char *func_name() const override { return udf.name(); }
1962 bool fix_fields(THD *thd, Item **ref) override {
1963 assert(!fixed);
1964
1965 if (init_sum_func_check(thd)) return true;
1966
1967 fixed = true;
1968 if (udf.fix_fields(thd, this, this->arg_count, this->args)) return true;
1969
1970 return check_sum_func(thd, ref);
1971 }
1972 enum Sumfunctype sum_func() const override { return UDF_SUM_FUNC; }
1973
1974 void clear() override;
1975 bool add() override;
1976 void reset_field() override {}
1977 void update_field() override {}
1978 void cleanup() override;
1979 void print(const THD *thd, String *str,
1980 enum_query_type query_type) const override;
1981};
1982
1983class Item_sum_udf_float final : public Item_udf_sum {
1984 public:
1985 Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1986 : Item_udf_sum(pos, udf_arg, opt_list) {}
1988 : Item_udf_sum(thd, item) {}
1989 longlong val_int() override {
1990 assert(fixed);
1991 return (longlong)rint(Item_sum_udf_float::val_real());
1992 }
1993 double val_real() override;
1994 String *val_str(String *str) override;
1995 my_decimal *val_decimal(my_decimal *) override;
1996 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1997 return get_date_from_real(ltime, fuzzydate);
1998 }
1999 bool get_time(MYSQL_TIME *ltime) override {
2000 return get_time_from_real(ltime);
2001 }
2002 bool resolve_type(THD *) override {
2005 return false;
2006 }
2007 Item *copy_or_same(THD *thd) override;
2008};
2009
2010class Item_sum_udf_int final : public Item_udf_sum {
2011 public:
2012 Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
2013 : Item_udf_sum(pos, udf_arg, opt_list) {}
2015 : Item_udf_sum(thd, item) {}
2016 longlong val_int() override;
2017 double val_real() override {
2018 assert(fixed);
2019 return (double)Item_sum_udf_int::val_int();
2020 }
2021 String *val_str(String *str) override;
2022 my_decimal *val_decimal(my_decimal *) override;
2023 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2024 return get_date_from_int(ltime, fuzzydate);
2025 }
2026 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
2027 enum Item_result result_type() const override { return INT_RESULT; }
2028 bool resolve_type(THD *) override {
2030 return false;
2031 }
2032 Item *copy_or_same(THD *thd) override;
2033};
2034
2035class Item_sum_udf_str final : public Item_udf_sum {
2036 public:
2037 Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
2038 : Item_udf_sum(pos, udf_arg, opt_list) {}
2040 : Item_udf_sum(thd, item) {}
2041 String *val_str(String *) override;
2042 double val_real() override {
2043 int err_not_used;
2044 const char *end_not_used;
2045 String *res;
2046 res = val_str(&str_value);
2047 return res ? my_strntod(res->charset(), res->ptr(), res->length(),
2048 &end_not_used, &err_not_used)
2049 : 0.0;
2050 }
2051 longlong val_int() override {
2052 int err_not_used;
2053 String *res;
2054 const CHARSET_INFO *cs;
2055
2056 if (!(res = val_str(&str_value))) return 0; /* Null value */
2057 cs = res->charset();
2058 const char *end = res->ptr() + res->length();
2059 return cs->cset->strtoll10(cs, res->ptr(), &end, &err_not_used);
2060 }
2062 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2063 return get_date_from_string(ltime, fuzzydate);
2064 }
2065 bool get_time(MYSQL_TIME *ltime) override {
2066 return get_time_from_string(ltime);
2067 }
2068 enum Item_result result_type() const override { return STRING_RESULT; }
2069 bool resolve_type(THD *) override;
2070 Item *copy_or_same(THD *thd) override;
2071};
2072
2074 public:
2075 Item_sum_udf_decimal(const POS &pos, udf_func *udf_arg,
2076 PT_item_list *opt_list)
2077 : Item_udf_sum(pos, udf_arg, opt_list) {}
2079 : Item_udf_sum(thd, item) {}
2080 String *val_str(String *) override;
2081 double val_real() override;
2082 longlong val_int() override;
2083 my_decimal *val_decimal(my_decimal *) override;
2084 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2085 return get_date_from_decimal(ltime, fuzzydate);
2086 }
2087 bool get_time(MYSQL_TIME *ltime) override {
2088 return get_time_from_decimal(ltime);
2089 }
2090 enum Item_result result_type() const override { return DECIMAL_RESULT; }
2091 bool resolve_type(THD *) override {
2094 return false;
2095 }
2096 Item *copy_or_same(THD *thd) override;
2097};
2098
2099int group_concat_key_cmp_with_distinct(const void *arg, const void *key1,
2100 const void *key2);
2101int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2102 const void *key2);
2103int dump_leaf_key(void *key_arg, element_count count [[maybe_unused]],
2104 void *item_arg);
2105
2106class Item_func_group_concat final : public Item_sum {
2108
2109 /// True if GROUP CONCAT has the DISTINCT attribute
2111 /// The number of ORDER BY items.
2113 /// The number of selected items, aka the concat field list
2115 /// Resolver context, points to containing query block
2117 /// String containing separator between group items
2119 /// Describes the temporary table used to perform group concat
2123 TREE *tree{nullptr};
2124
2125 /**
2126 If DISTINCT is used with this GROUP_CONCAT, this member is used to filter
2127 out duplicates.
2128 @see Item_func_group_concat::setup
2129 @see Item_func_group_concat::add
2130 @see Item_func_group_concat::clear
2131 */
2133 /// Temporary table used to perform group concat
2134 TABLE *table{nullptr};
2136 uint row_count{0};
2137 /**
2138 The maximum permitted result length in bytes as set in
2139 group_concat_max_len system variable
2140 */
2142 bool warning_for_row{false};
2144 /// True if result has been written to output buffer.
2146 /**
2147 Following is 0 normal object and pointer to original one for copy
2148 (to correctly free resources)
2149 */
2151
2152 friend int group_concat_key_cmp_with_distinct(const void *arg,
2153 const void *key1,
2154 const void *key2);
2155 friend int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2156 const void *key2);
2157 friend int dump_leaf_key(void *key_arg, element_count count [[maybe_unused]],
2158 void *item_arg);
2159
2160 public:
2161 Item_func_group_concat(const POS &pos, bool is_distinct,
2162 PT_item_list *select_list,
2163 PT_order_list *opt_order_list, String *separator,
2164 PT_window *w);
2165
2168 assert(original != nullptr || unique_filter == nullptr);
2169 }
2170
2171 bool do_itemize(Parse_context *pc, Item **res) override;
2172 void cleanup() override;
2173
2174 enum Sumfunctype sum_func() const override { return GROUP_CONCAT_FUNC; }
2175 const char *func_name() const override { return "group_concat"; }
2176 Item_result result_type() const override { return STRING_RESULT; }
2177 Field *make_string_field(TABLE *table_arg) const override;
2178 void clear() override;
2179 bool add() override;
2180 void reset_field() override { assert(0); } // not used
2181 void update_field() override { assert(0); } // not used
2182 bool fix_fields(THD *, Item **) override;
2183 bool setup(THD *thd) override;
2184 void make_unique() override;
2185 double val_real() override;
2186 longlong val_int() override {
2187 String *res;
2188 int error;
2189 if (!(res = val_str(&str_value))) return (longlong)0;
2190 const char *end_ptr = res->ptr() + res->length();
2191 return my_strtoll10(res->ptr(), &end_ptr, &error);
2192 }
2193 my_decimal *val_decimal(my_decimal *decimal_value) override {
2194 return val_decimal_from_string(decimal_value);
2195 }
2196 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2197 return get_date_from_string(ltime, fuzzydate);
2198 }
2199 bool get_time(MYSQL_TIME *ltime) override {
2200 return get_time_from_string(ltime);
2201 }
2202
2203 bool has_distinct() const noexcept { return distinct; }
2204 const String *get_separator_str() const noexcept { return separator; }
2205 uint32_t get_group_concat_max_len() const noexcept {
2206 return group_concat_max_len;
2207 }
2208 const Mem_root_array<ORDER> &get_order_array() const noexcept {
2209 return order_array;
2210 }
2211
2212 String *val_str(String *str) override;
2213 Item *copy_or_same(THD *thd) override;
2214 void no_rows_in_result() override;
2215 void print(const THD *thd, String *str,
2216 enum_query_type query_type) const override;
2217 bool change_context_processor(uchar *arg) override {
2218 context = pointer_cast<Item_ident::Change_context *>(arg)->m_context;
2219 return false;
2220 }
2221
2223 Window_evaluation_requirements *) override {
2225 return true;
2226 }
2227};
2228
2229/**
2230 Common parent class for window functions that always work on the entire
2231 partition, even if a frame is defined.
2232
2233 The subclasses can be divided in two disjoint sub-categories:
2234 - one-pass
2235 - two-pass (requires partition cardinality to be evaluated)
2236 cf. method needs_partition_cardinality.
2237*/
2240
2241 public:
2242 Item_non_framing_wf(const POS &pos, PT_window *w) : Item_sum(pos, w) {}
2244 : Item_sum(pos, a, w) {}
2246 : Item_sum(pos, opt_list, w) {}
2248
2249 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2250 return get_date_from_numeric(ltime, fuzzydate);
2251 }
2252
2253 bool get_time(MYSQL_TIME *ltime) override {
2254 return get_time_from_numeric(ltime);
2255 }
2256
2257 void reset_field() override { assert(false); }
2258 void update_field() override { assert(false); }
2259 bool add() override {
2260 assert(false);
2261 return false;
2262 }
2263
2264 bool fix_fields(THD *thd, Item **items) override;
2265
2266 bool framing() const override { return false; }
2267};
2268
2269/**
2270 ROW_NUMBER window function, cf. SQL 2003 Section 6.10 <window function>
2271*/
2273 // Execution state variables
2274 ulonglong m_ctr; ///< Increment for each row in partition
2275
2276 public:
2278 : Item_non_framing_wf(pos, w), m_ctr(0) {
2279 unsigned_flag = true;
2280 }
2281
2282 const char *func_name() const override { return "row_number"; }
2283 enum Sumfunctype sum_func() const override { return ROW_NUMBER_FUNC; }
2284
2285 bool resolve_type(THD *thd [[maybe_unused]]) override {
2287 return false;
2288 }
2289
2290 longlong val_int() override;
2291 double val_real() override;
2292 my_decimal *val_decimal(my_decimal *buff) override;
2293 String *val_str(String *) override;
2294
2295 void clear() override;
2296
2297 Item_result result_type() const override { return INT_RESULT; }
2298
2300 Window_evaluation_requirements *) override {
2301 return false;
2302 }
2303};
2304
2305/**
2306 RANK or DENSE_RANK window function, cf. SQL 2003 Section 6.10 <window
2307 function>
2308*/
2311 bool m_dense; ///< If true, the object represents DENSE_RANK
2312 // Execution state variables
2313 ulonglong m_rank_ctr; ///< Increment when window order columns change
2314 ulonglong m_duplicates; ///< Needed to make RANK different from DENSE_RANK
2316 m_previous; ///< Values of previous row's ORDER BY items
2317 public:
2318 Item_rank(const POS &pos, bool dense, PT_window *w)
2319 : Item_non_framing_wf(pos, w),
2320 m_dense(dense),
2321 m_rank_ctr(0),
2322 m_duplicates(0),
2324 unsigned_flag = true;
2325 }
2326
2327 ~Item_rank() override;
2328
2329 const char *func_name() const override {
2330 return m_dense ? "dense_rank" : "rank";
2331 }
2332
2333 enum Sumfunctype sum_func() const override {
2335 }
2336
2337 bool resolve_type(THD *thd [[maybe_unused]]) override {
2339 return false;
2340 }
2341
2342 longlong val_int() override;
2343 double val_real() override;
2344 my_decimal *val_decimal(my_decimal *buff) override;
2345 String *val_str(String *) override;
2346
2347 void update_after_wf_arguments_changed(THD *thd) override;
2348 bool check_wf_semantics1(THD *thd, Query_block *select,
2349 Window_evaluation_requirements *reqs) override;
2350 /**
2351 Clear state for a new partition
2352 */
2353 void clear() override;
2354 Item_result result_type() const override { return INT_RESULT; }
2355};
2356
2357/**
2358 CUME_DIST window function, cf. SQL 2003 Section 6.10 <window function>
2359*/
2362
2363 public:
2365
2366 const char *func_name() const override { return "cume_dist"; }
2367 enum Sumfunctype sum_func() const override { return CUME_DIST_FUNC; }
2368
2369 bool resolve_type(THD *thd [[maybe_unused]]) override {
2371 return false;
2372 }
2373
2374 bool check_wf_semantics1(THD *thd, Query_block *select,
2375 Window_evaluation_requirements *reqs) override;
2376
2377 bool needs_partition_cardinality() const override { return true; }
2378 void clear() override {}
2379 longlong val_int() override;
2380 double val_real() override;
2381 String *val_str(String *) override;
2383 Item_result result_type() const override { return REAL_RESULT; }
2384};
2385
2386/**
2387 PERCENT_RANK window function, cf. SQL 2003 Section 6.10 <window function>
2388*/
2391 // Execution state variables
2392 ulonglong m_rank_ctr; ///< Increment when window order columns change
2393 ulonglong m_peers; ///< Needed to make PERCENT_RANK same for peers
2394 /**
2395 Set when the last peer has been visited. Needed to increment m_rank_ctr.
2396 */
2398
2399 public:
2401 : Item_non_framing_wf(pos, w),
2402 m_rank_ctr(0),
2403 m_peers(0),
2404 m_last_peer_visited(false) {}
2405
2407 const char *func_name() const override { return "percent_rank"; }
2408 enum Sumfunctype sum_func() const override { return PERCENT_RANK_FUNC; }
2409
2410 bool resolve_type(THD *thd [[maybe_unused]]) override {
2412 return false;
2413 }
2414
2415 bool check_wf_semantics1(THD *thd, Query_block *select,
2416 Window_evaluation_requirements *reqs) override;
2417 bool needs_partition_cardinality() const override { return true; }
2418
2419 void clear() override;
2420 longlong val_int() override;
2421 double val_real() override;
2422 String *val_str(String *) override;
2424 Item_result result_type() const override { return REAL_RESULT; }
2425};
2426
2427/**
2428 NTILE window function, cf. SQL 2011 Section 6.10 <window function>
2429*/
2433
2434 public:
2435 Item_ntile(const POS &pos, Item *a, PT_window *w)
2436 : Item_non_framing_wf(pos, a, w), m_value(0) {
2437 unsigned_flag = true;
2438 }
2439
2440 const char *func_name() const override { return "ntile"; }
2441 enum Sumfunctype sum_func() const override { return NTILE_FUNC; }
2442
2443 bool resolve_type(THD *thd) override {
2444 if (args[0]->propagate_type(thd, MYSQL_TYPE_LONGLONG, true)) return true;
2446 return false;
2447 }
2448
2449 bool fix_fields(THD *thd, Item **items) override;
2450
2451 longlong val_int() override;
2452 double val_real() override;
2453 my_decimal *val_decimal(my_decimal *buff) override;
2454 String *val_str(String *) override;
2455
2456 bool check_wf_semantics1(THD *thd, Query_block *select,
2457 Window_evaluation_requirements *reqs) override;
2459 Item_result result_type() const override { return INT_RESULT; }
2460 void clear() override {}
2461 bool needs_partition_cardinality() const override { return true; }
2462};
2463
2464/**
2465 LEAD/LAG window functions, cf. SQL 2011 Section 6.10 <window function>
2466*/
2469 bool m_is_lead; ///< if true, the function is LEAD, else LAG
2470 int64 m_n; ///< canonicalized offset value
2474 /**
2475 Execution state: if set, we already have a value for current row.
2476 State is used to avoid interference with other LEAD/LAG functions on
2477 the same window, since they share the same eval loop and they should
2478 trigger evaluation only when they are on the "right" row relative to
2479 current row. For other offsets, return NULL if we don't know the value
2480 for this function yet, or if we do (m_has_value==true), return the
2481 found value.
2482 */
2484 bool m_use_default; ///< execution state: use default value for current row
2486
2487 public:
2488 Item_lead_lag(const POS &pos, bool lead,
2489 PT_item_list *opt_list, // [0] expr, [1] offset, [2] default
2490 enum_null_treatment null_treatment, PT_window *w)
2491 : Item_non_framing_wf(pos, opt_list, w),
2492 m_null_treatment(null_treatment),
2493 m_is_lead(lead),
2494 m_n(0),
2498 m_has_value(false),
2499 m_use_default(false) {}
2500
2501 const char *func_name() const override {
2502 return (m_is_lead ? "lead" : "lag");
2503 }
2504 enum Sumfunctype sum_func() const override { return LEAD_LAG_FUNC; }
2505
2506 bool resolve_type(THD *thd) override;
2507 bool fix_fields(THD *thd, Item **items) override;
2508 TYPELIB *get_typelib() const override;
2509 void update_after_wf_arguments_changed(THD *thd) override;
2510 void clear() override;
2511 bool check_wf_semantics1(THD *thd, Query_block *select,
2512 Window_evaluation_requirements *reqs) override;
2514 enum Item_result result_type() const override { return m_hybrid_type; }
2515
2516 longlong val_int() override;
2517 double val_real() override;
2518 String *val_str(String *str) override;
2519 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2520
2521 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2522 bool get_time(MYSQL_TIME *ltime) override;
2523 bool val_json(Json_wrapper *wr) override;
2524
2525 bool needs_partition_cardinality() const override {
2526 /*
2527 A possible optimization here: if LAG, we are only interested in rows we
2528 have already seen, so we might compute the result without reading the
2529 entire partition as soon as we have the current row. Similarly, a small
2530 LEAD value might avoid reading the entire partition also, giving shorter
2531 time to first result. For now, we read the entirely partition for these
2532 window functions - for simplicity.
2533 */
2534 return true;
2535 }
2536
2537 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2538 mem_root_deque<Item *> *fields) override;
2539
2540 void set_has_value(bool value) { m_has_value = value; }
2541 bool has_value() const { return m_has_value; }
2542
2543 void set_use_default(bool value) { m_use_default = value; }
2544 bool use_default() const { return m_use_default; }
2545
2546 private:
2547 bool setup_lead_lag();
2548 /**
2549 Core logic of LEAD/LAG window functions
2550
2551 @return true if computation yielded a NULL or error
2552 */
2553 bool compute();
2554};
2555
2556/**
2557 FIRST_VALUE/LAST_VALUE window functions, cf. SQL 2011 Section 6.10 <window
2558 function>
2559*/
2561 bool m_is_first; ///< if true, the function is FIRST_VALUE, else LAST_VALUE
2565 int64 cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2567
2568 public:
2569 Item_first_last_value(const POS &pos, bool first, Item *a,
2570 enum_null_treatment null_treatment, PT_window *w)
2571 : Item_sum(pos, a, w),
2572 m_is_first(first),
2573 m_null_treatment(null_treatment),
2576 cnt(0) {}
2577
2578 const char *func_name() const override {
2579 return m_is_first ? "first_value" : "last_value";
2580 }
2581
2582 enum Sumfunctype sum_func() const override { return FIRST_LAST_VALUE_FUNC; }
2583
2584 bool resolve_type(THD *thd) override;
2585 bool fix_fields(THD *thd, Item **items) override;
2586 void update_after_wf_arguments_changed(THD *thd) override;
2587 void clear() override;
2588 bool check_wf_semantics1(THD *thd, Query_block *select,
2589 Window_evaluation_requirements *reqs) override;
2590 enum Item_result result_type() const override { return m_hybrid_type; }
2591
2592 longlong val_int() override;
2593 double val_real() override;
2594 String *val_str(String *str) override;
2595 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2596
2597 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2598 bool get_time(MYSQL_TIME *ltime) override;
2599 bool val_json(Json_wrapper *wr) override;
2600
2601 void reset_field() override { assert(false); }
2602 void update_field() override { assert(false); }
2603 bool add() override {
2604 assert(false);
2605 return false;
2606 }
2607
2608 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2609 mem_root_deque<Item *> *fields) override;
2610 bool uses_only_one_row() const override { return true; }
2611
2612 private:
2613 bool setup_first_last();
2614 /**
2615 Core logic of FIRST/LAST_VALUE window functions
2616
2617 @return true if computation yielded a NULL or error
2618 */
2619 bool compute();
2620};
2621
2622/**
2623 NTH_VALUE window function, cf. SQL 2011 Section 6.10 <window
2624 function>
2625*/
2626class Item_nth_value : public Item_sum {
2628 int64 m_n; ///< The N of the function
2629 bool m_from_last; ///< true iff FROM_LAST was specified
2633 int64 m_cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2634
2636
2637 public:
2638 Item_nth_value(const POS &pos, PT_item_list *a, bool from_last,
2639 enum_null_treatment null_treatment, PT_window *w)
2640 : Item_sum(pos, a, w),
2641 m_null_treatment(null_treatment),
2642 m_n(0),
2643 m_from_last(from_last),
2646 m_cnt(0) {}
2647
2648 const char *func_name() const override { return "nth_value"; }
2649 enum Sumfunctype sum_func() const override { return NTH_VALUE_FUNC; }
2650
2651 bool resolve_type(THD *thd) override;
2652 bool fix_fields(THD *thd, Item **items) override;
2653 void update_after_wf_arguments_changed(THD *thd) override;
2654 bool setup_nth();
2655 void clear() override;
2656
2657 bool check_wf_semantics1(THD *thd, Query_block *select,
2658 Window_evaluation_requirements *reqs) override;
2660
2661 enum Item_result result_type() const override { return m_hybrid_type; }
2662
2663 longlong val_int() override;
2664 double val_real() override;
2665 String *val_str(String *str) override;
2666 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2667
2668 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2669 bool get_time(MYSQL_TIME *ltime) override;
2670 bool val_json(Json_wrapper *wr) override;
2671
2672 void reset_field() override { assert(false); }
2673 void update_field() override { assert(false); }
2674 bool add() override {
2675 assert(false);
2676 return false;
2677 }
2678
2679 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2680 mem_root_deque<Item *> *fields) override;
2681 bool uses_only_one_row() const override { return true; }
2682
2683 private:
2684 /**
2685 Core logic of NTH_VALUE window functions
2686
2687 @return true if computation yielded a NULL or error
2688 */
2689 bool compute();
2690};
2691
2692/**
2693 Class for implementation of the GROUPING function. The GROUPING
2694 function distinguishes super-aggregate rows from regular grouped
2695 rows. GROUP BY extensions such as ROLLUP and CUBE produce
2696 super-aggregate rows where the set of all values is represented
2697 by null. Using the GROUPING function, you can distinguish a null
2698 representing the set of all values in a super-aggregate row from
2699 a NULL in a regular row.
2700*/
2702 public:
2705 }
2706 const char *func_name() const override { return "grouping"; }
2707 enum Functype functype() const override { return GROUPING_FUNC; }
2708 longlong val_int() override;
2709 bool aggregate_check_group(uchar *arg) override;
2710 bool fix_fields(THD *thd, Item **ref) override;
2711 void update_used_tables() override;
2712 bool aggregate_check_distinct(uchar *arg) override;
2713
2714 private:
2715 /// The query block in which this function is called.
2717};
2718
2719/**
2720 A wrapper Item that contains a number of aggregate items, one for each level
2721 of rollup (see Item_rollup_group_item for numbering conventions). When
2722 aggregating, every aggregator is either reset or updated as per the correct
2723 level, and when returning a value, the correct child item corresponding to
2724 the current rollup level is queried.
2725 */
2727 public:
2728 explicit Item_rollup_sum_switcher(List<Item> *sum_func_per_level)
2729 : Item_sum((*sum_func_per_level)[0]),
2730 m_num_levels(sum_func_per_level->size()) {
2731 args = (*THR_MALLOC)->ArrayAlloc<Item *>(sum_func_per_level->size());
2732 int i = 0;
2733 for (Item &item : *sum_func_per_level) {
2734 args[i++] = &item;
2735 }
2739 hidden = master()->hidden;
2743 }
2744 double val_real() override;
2745 longlong val_int() override;
2746 String *val_str(String *str) override;
2748 bool val_json(Json_wrapper *result) override;
2749 bool is_null() override;
2750 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2751 bool get_time(MYSQL_TIME *ltime) override;
2752 const char *func_name() const override { return "rollup_sum_switcher"; }
2753 table_map used_tables() const override { return master()->used_tables(); }
2754 Item_result result_type() const override { return master()->result_type(); }
2755 bool resolve_type(THD *) override {
2757 return false;
2758 }
2759 void print(const THD *thd, String *str,
2760 enum_query_type query_type) const override;
2761 Field *create_tmp_field(bool group, TABLE *table) override;
2762
2763 enum Sumfunctype sum_func() const override { return master()->sum_func(); }
2764 enum Sumfunctype real_sum_func() const override {
2766 }
2767 void reset_field() override { assert(false); }
2768 void update_field() override { assert(false); }
2769 void clear() override;
2770 bool add() override {
2771 assert(false);
2772 return true;
2773 }
2774
2775 bool reset_and_add_for_rollup(int last_unchanged_group_item_idx);
2776
2777 int set_aggregator(Aggregator::Aggregator_type aggregator) override;
2778 bool aggregator_setup(THD *thd) override;
2779 inline bool aggregator_add_all() {
2780 for (int i = 0; i < m_num_levels; ++i) {
2781 if (child(i)->aggregator_add()) {
2782 return true;
2783 }
2784 }
2785 return false;
2786 }
2787
2788 // Used when create_tmp_table() needs to delay application of aggregate
2789 // functions to a later stage in the query processing.
2790 Item *get_arg(uint i) override { return master()->get_arg(i); }
2791 const Item *get_arg(uint i) const override { return master()->get_arg(i); }
2792 Item *set_arg(THD *thd, uint i, Item *new_val) override {
2793 Item *ret = nullptr;
2794 for (int j = 0; j < m_num_levels; ++j) {
2795 ret = child(j)->set_arg(thd, i, new_val);
2796 }
2797 return ret; // Return the last one, arbitrarily.
2798 }
2799 uint argument_count() const override { return master()->argument_count(); }
2800
2801 // Used by AggregateIterator.
2803 inline Item_sum *master() const { return child(0); }
2804
2805 bool is_rollup_sum_wrapper() const override { return true; }
2806 const Item_sum *unwrap_sum() const override { return master(); }
2807 Item_sum *unwrap_sum() override { return master(); }
2808
2809 private:
2810 inline Item *current_arg() const;
2811 inline Item_sum *child(size_t i) const {
2812 return down_cast<Item_sum *>(args[i]);
2813 }
2814
2815 const int m_num_levels;
2817};
2818/// Implements ST_Collect which aggregates geometries into Multipoints,
2819/// Multilinestrings, Multipolygons and Geometrycollections.
2820
2822 private:
2823 std::optional<gis::srid_t> srid;
2824 std::unique_ptr<gis::Geometrycollection> m_geometrycollection;
2825 void pop_front();
2826
2827 public:
2829 Item_sum_collect(THD *thd, Item_sum *item) : Item_sum(thd, item) {
2831 }
2832 Item_sum_collect(const POS &pos, Item *a, PT_window *w, bool distinct)
2833 : Item_sum(pos, a, w) {
2834 set_distinct(distinct);
2836 }
2837
2838 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2839 longlong val_int() override { return val_int_from_string(); }
2840 double val_real() override { return val_real_from_string(); }
2841 bool get_date(MYSQL_TIME *, my_time_flags_t) override { return true; }
2842 bool get_time(MYSQL_TIME *) override { return true; }
2843 enum Sumfunctype sum_func() const override { return GEOMETRY_AGGREGATE_FUNC; }
2844 Item_result result_type() const override { return STRING_RESULT; }
2846 /*
2847 In contrast to Item_sum, Item_sum_collect always uses Aggregator_simple,
2848 and only needs to reset its aggregator when called.
2849 */
2850 if (aggr != nullptr) {
2851 aggr->clear();
2852 return false;
2853 }
2854
2855 aggr = new (*THR_MALLOC) Aggregator_simple(this);
2856 return aggr ? false : true;
2857 }
2858
2859 bool fix_fields(THD *thd, Item **ref) override;
2860 /*
2861 We need to override check_wf_semantics1 because it reports an error when
2862 with_distinct is set.
2863 */
2864 bool check_wf_semantics1(THD *thd, Query_block *,
2866
2867 Item *copy_or_same(THD *thd) override;
2868
2869 void update_field() override;
2870 void reset_field() override;
2871
2872 String *val_str(String *str) override;
2873
2874 bool add() override;
2875
2876 void read_result_field();
2877 void store_result_field();
2878
2879 void clear() override;
2880 const char *func_name() const override { return "st_collect"; }
2881};
2882
2883#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:2207
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:995
void endup() override
Calculate the aggregate function value.
Definition: item_sum.cc:1376
~Aggregator_distinct() override
Definition: item_sum.cc:2157
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:2202
void clear() override
Invalidate calculated value and clear the distinct rows.
Definition: item_sum.cc:1275
bool setup(THD *) override
Called before feeding the first row.
Definition: item_sum.cc:1066
bool unique_walk_function(void *element)
Aggregate a distinct row from the distinct hash table.
Definition: item_sum.cc:2150
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:1307
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:2197
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:2174
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:2178
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:2182
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:3747
String * val_str(String *) override
Definition: item_sum.cc:3762
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:3732
Item_avg_field(Item_result res_type, Item_sum_avg *item)
Definition: item_sum.cc:3713
Definition: item.h:6812
CUME_DIST window function, cf.
Definition: item_sum.h:2360
Item_cume_dist(const POS &pos, PT_window *w)
Definition: item_sum.h:2364
Item_non_framing_wf super
Definition: item_sum.h:2361
double val_real() override
Definition: item_sum.cc:4943
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2367
void clear() override
Definition: item_sum.h:2378
const char * func_name() const override
Definition: item_sum.h:2366
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:2377
String * val_str(String *) override
Definition: item_sum.cc:4963
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:4933
longlong val_int() override
Definition: item_sum.cc:4955
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2369
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:4967
Item_result result_type() const override
Definition: item_sum.h:2383
Definition: item.h:4348
FIRST_VALUE/LAST_VALUE window functions, cf.
Definition: item_sum.h:2560
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2582
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5171
void reset_field() override
Definition: item_sum.h:2601
const char * func_name() const override
Definition: item_sum.h:2578
bool setup_first_last()
Definition: item_sum.cc:5212
double val_real() override
Definition: item_sum.cc:5261
String * val_str(String *str) override
Definition: item_sum.cc:5316
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:5229
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:5200
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:5157
bool compute()
Core logic of FIRST/LAST_VALUE window functions.
Definition: item_sum.cc:5233
int64 cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2565
Item_result m_hybrid_type
Definition: item_sum.h:2563
enum Item_result result_type() const override
Definition: item_sum.h:2590
Item_cache * m_value
Definition: item_sum.h:2564
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5292
void update_field() override
Definition: item_sum.h:2602
enum_null_treatment m_null_treatment
Definition: item_sum.h:2562
Item_sum super
Definition: item_sum.h:2566
void clear() override
Definition: item_sum.cc:5223
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2610
bool add() override
Definition: item_sum.h:2603
Item_first_last_value(const POS &pos, bool first, Item *a, enum_null_treatment null_treatment, PT_window *w)
Definition: item_sum.h:2569
bool m_is_first
if true, the function is FIRST_VALUE, else LAST_VALUE
Definition: item_sum.h:2561
longlong val_int() override
Definition: item_sum.cc:5251
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5302
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5282
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5181
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5271
Definition: item_sum.h:2106
void clear() override
Definition: item_sum.cc:4410
bool m_result_finalized
True if result has been written to output buffer.
Definition: item_sum.h:2145
String result
Definition: item_sum.h:2121
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:2150
longlong val_int() override
Definition: item_sum.h:2186
const String * get_separator_str() const noexcept
Definition: item_sum.h:2204
uint32_t get_group_concat_max_len() const noexcept
Definition: item_sum.h:2205
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.h:2193
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:4156
uint row_count
Definition: item_sum.h:2136
void make_unique() override
Definition: item_sum.cc:4697
bool change_context_processor(uchar *arg) override
Definition: item_sum.h:2217
bool setup(THD *thd) override
Definition: item_sum.cc:4566
Item_sum super
Definition: item_sum.h:2107
bool distinct
True if GROUP CONCAT has the DISTINCT attribute.
Definition: item_sum.h:2110
TABLE * table
Temporary table used to perform group concat.
Definition: item_sum.h:2134
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:4077
double val_real() override
Definition: item_sum.cc:4705
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2174
String * val_str(String *str) override
Definition: item_sum.cc:4712
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:4113
bool force_copy_fields
Definition: item_sum.h:2143
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:4473
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2196
Unique * unique_filter
If DISTINCT is used with this GROUP_CONCAT, this member is used to filter out duplicates.
Definition: item_sum.h:2132
bool check_wf_semantics1(THD *, Query_block *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2222
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:4408
Mem_root_array< ORDER > order_array
Definition: item_sum.h:2135
TREE tree_base
Definition: item_sum.h:2122
void update_field() override
Definition: item_sum.h:2181
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:4737
Temp_table_param * tmp_table_param
Describes the temporary table used to perform group concat.
Definition: item_sum.h:2120
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:4335
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4400
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_sum.cc:4283
const char * func_name() const override
Definition: item_sum.h:2175
Item_result result_type() const override
Definition: item_sum.h:2176
Field * make_string_field(TABLE *table_arg) const override
Create a field to hold a string value from an item.
Definition: item_sum.cc:4367
uint m_order_arg_count
The number of ORDER BY items.
Definition: item_sum.h:2112
TREE * tree
Definition: item_sum.h:2123
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:4245
bool has_distinct() const noexcept
Definition: item_sum.h:2203
bool add() override
Definition: item_sum.cc:4422
Name_resolution_context * context
Resolver context, points to containing query block.
Definition: item_sum.h:2116
void reset_field() override
Definition: item_sum.h:2180
uint m_field_arg_count
The number of selected items, aka the concat field list.
Definition: item_sum.h:2114
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:2141
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2199
bool warning_for_row
Definition: item_sum.h:2142
String * separator
String containing separator between group items.
Definition: item_sum.h:2118
~Item_func_group_concat() override
Definition: item_sum.h:2167
const Mem_root_array< ORDER > & get_order_array() const noexcept
Definition: item_sum.h:2208
Class for implementation of the GROUPING function.
Definition: item_sum.h:2701
const Query_block * m_query_block
The query block in which this function is called.
Definition: item_sum.h:2716
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:6398
longlong val_int() override
Evaluation of the GROUPING function.
Definition: item_sum.cc:6347
Item_func_grouping(const POS &pos, PT_item_list *a)
Definition: item_sum.h:2703
const char * func_name() const override
Definition: item_sum.h:2706
bool fix_fields(THD *thd, Item **ref) override
Resolve the fields in the GROUPING function.
Definition: item_sum.cc:6292
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:6368
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_sum.cc:6410
enum Functype functype() const override
Definition: item_sum.h:2707
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:4237
void set_original_field_name(const char *name_arg)
Definition: item.h:4234
const char * original_table_name() const
Definition: item.h:4238
Definition: item_func.h:983
Definition: item.h:5107
LEAD/LAG window functions, cf.
Definition: item_sum.h:2467
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5587
bool has_value() const
Definition: item_sum.h:2541
bool m_is_lead
if true, the function is LEAD, else LAG
Definition: item_sum.h:2469
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:2525
const char * func_name() const override
Definition: item_sum.h:2501
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5735
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:5647
void set_use_default(bool value)
Definition: item_sum.h:2543
String * val_str(String *str) override
Definition: item_sum.cc:5727
bool m_use_default
execution state: use default value for current row
Definition: item_sum.h:2484
enum Item_result result_type() const override
Definition: item_sum.h:2514
Item_cache * m_default
Definition: item_sum.h:2473
bool compute()
Core logic of LEAD/LAG window functions.
Definition: item_sum.cc:5762
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:2488
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:5674
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2504
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5744
enum_null_treatment m_null_treatment
Definition: item_sum.h:2468
void clear() override
Definition: item_sum.cc:5686
bool use_default() const
Definition: item_sum.h:2544
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_sum.cc:5596
bool m_has_value
Execution state: if set, we already have a value for current row.
Definition: item_sum.h:2483
longlong val_int() override
Definition: item_sum.cc:5698
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5714
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5619
Item_result m_hybrid_type
Definition: item_sum.h:2471
int64 m_n
canonicalized offset value
Definition: item_sum.h:2470
double val_real() override
Definition: item_sum.cc:5706
void set_has_value(bool value)
Definition: item_sum.h:2540
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5538
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5752
bool setup_lead_lag()
Definition: item_sum.cc:5658
Item_cache * m_value
Definition: item_sum.h:2472
Item_non_framing_wf super
Definition: item_sum.h:2485
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:5693
Common parent class for window functions that always work on the entire partition,...
Definition: item_sum.h:2238
Item_non_framing_wf(const POS &pos, PT_window *w)
Definition: item_sum.h:2242
bool add() override
Definition: item_sum.h:2259
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2253
Item_non_framing_wf(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2243
Item_non_framing_wf(const POS &pos, PT_item_list *opt_list, PT_window *w)
Definition: item_sum.h:2245
Item_sum super
Definition: item_sum.h:2239
Item_non_framing_wf(THD *thd, Item_non_framing_wf *i)
Definition: item_sum.h:2247
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2249
void update_field() override
Definition: item_sum.h:2258
void reset_field() override
Definition: item_sum.h:2257
bool framing() const override
All aggregates are framing, i.e.
Definition: item_sum.h:2266
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4773
NTH_VALUE window function, cf.
Definition: item_sum.h:2626
int64 m_cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2633
void update_field() override
Definition: item_sum.h:2673
bool compute()
Core logic of NTH_VALUE window functions.
Definition: item_sum.cc:5431
String * val_str(String *str) override
Definition: item_sum.cc:5498
Item_sum super
Definition: item_sum.h:2635
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5047
enum Item_result result_type() const override
Definition: item_sum.h:2661
Item_result m_hybrid_type
Definition: item_sum.h:2630
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5484
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5518
bool setup_nth()
Definition: item_sum.cc:5390
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5339
enum_field_types m_hybrid_field_type
Definition: item_sum.h:2631
int64 m_n
The N of the function.
Definition: item_sum.h:2628
double val_real() override
Definition: item_sum.cc:5474
bool m_from_last
true iff FROM_LAST was specified
Definition: item_sum.h:2629
Item_cache * m_value
Definition: item_sum.h:2632
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5528
enum_null_treatment m_null_treatment
Definition: item_sum.h:2627
void reset_field() override
Definition: item_sum.h:2672
longlong val_int() override
Definition: item_sum.cc:5464
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:2638
void clear() override
Definition: item_sum.cc:5401
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5326
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:5379
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2649
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:5407
bool add() override
Definition: item_sum.h:2674
const char * func_name() const override
Definition: item_sum.h:2648
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5508
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:5411
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2681
NTILE window function, cf.
Definition: item_sum.h:2430
void clear() override
Definition: item_sum.h:2460
Item_non_framing_wf super
Definition: item_sum.h:2431
String * val_str(String *) override
Definition: item_sum.cc:5126
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2443
const char * func_name() const override
Definition: item_sum.h:2440
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:2461
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5141
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5065
double val_real() override
Definition: item_sum.cc:5121
longlong val_int() override
Definition: item_sum.cc:5071
longlong m_value
Definition: item_sum.h:2432
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:5128
Item_ntile(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2435
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2441
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:5133
Item_result result_type() const override
Definition: item_sum.h:2459
PERCENT_RANK window function, cf.
Definition: item_sum.h:2389
String * val_str(String *) override
Definition: item_sum.cc:5030
Item_percent_rank(const POS &pos, PT_window *w)
Definition: item_sum.h:2400
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2392
const char * func_name() const override
Definition: item_sum.h:2407
Item_result result_type() const override
Definition: item_sum.h:2424
~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:4972
ulonglong m_peers
Needed to make PERCENT_RANK same for peers.
Definition: item_sum.h:2393
double val_real() override
Definition: item_sum.cc:4996
Item_non_framing_wf super
Definition: item_sum.h:2390
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2410
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2408
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:2417
bool m_last_peer_visited
Set when the last peer has been visited.
Definition: item_sum.h:2397
void clear() override
Definition: item_sum.cc:5039
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:5034
longlong val_int() override
Definition: item_sum.cc:5022
RANK or DENSE_RANK window function, cf.
Definition: item_sum.h:2309
Item_result result_type() const override
Definition: item_sum.h:2354
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:4828
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:4852
ulonglong m_duplicates
Needed to make RANK different from DENSE_RANK.
Definition: item_sum.h:2314
bool m_dense
If true, the object represents DENSE_RANK.
Definition: item_sum.h:2311
longlong val_int() override
Definition: item_sum.cc:4870
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2333
~Item_rank() override
Definition: item_sum.cc:4926
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2337
Item_rank(const POS &pos, bool dense, PT_window *w)
Definition: item_sum.h:2318
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4905
const char * func_name() const override
Definition: item_sum.h:2329
double val_real() override
Definition: item_sum.cc:4898
String * val_str(String *) override
Definition: item_sum.cc:4903
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2313
void clear() override
Clear state for a new partition.
Definition: item_sum.cc:4910
Mem_root_array< Cached_item * > m_previous
Values of previous row's ORDER BY items.
Definition: item_sum.h:2316
Item_non_framing_wf super
Definition: item_sum.h:2310
Item with result field.
Definition: item.h:5815
longlong llrint_with_overflow_check(double realval)
Definition: item.h:5866
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:11030
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:2726
table_map used_tables() const override
Definition: item_sum.h:2753
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:6486
void update_field() override
Definition: item_sum.h:2768
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2755
Item * get_arg(uint i) override
Get the i'th argument of the function that this object represents.
Definition: item_sum.h:2790
Item * set_arg(THD *thd, uint i, Item *new_val) override
Definition: item_sum.h:2792
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.cc:6472
void set_current_rollup_level(int level)
Definition: item_sum.h:2802
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:6426
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:6477
bool aggregator_setup(THD *thd) override
Called to initialize the aggregator.
Definition: item_sum.cc:6533
Item_result result_type() const override
Definition: item_sum.h:2754
String * val_str(String *str) override
Definition: item_sum.cc:6451
int set_aggregator(Aggregator::Aggregator_type aggregator) override
Definition: item_sum.cc:6522
Item_sum * unwrap_sum() override
Non-const version.
Definition: item_sum.h:2807
longlong val_int() override
Definition: item_sum.cc:6444
void reset_field() override
Definition: item_sum.h:2767
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:2806
Item_rollup_sum_switcher(List< Item > *sum_func_per_level)
Definition: item_sum.h:2728
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:6432
bool aggregator_add_all()
Definition: item_sum.h:2779
Item * current_arg() const
Definition: item_sum.cc:6421
Item_sum * master() const
Definition: item_sum.h:2803
Item_sum * child(size_t i) const
Definition: item_sum.h:2811
enum Sumfunctype real_sum_func() const override
Definition: item_sum.h:2764
bool is_rollup_sum_wrapper() const override
Overridden by Item_rollup_sum_switcher.
Definition: item_sum.h:2805
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2763
const char * func_name() const override
Definition: item_sum.h:2752
int m_current_rollup_level
Definition: item_sum.h:2816
double val_real() override
Definition: item_sum.cc:6437
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_sum.cc:6465
uint argument_count() const override
Definition: item_sum.h:2799
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:6458
bool add() override
Definition: item_sum.h:2770
void clear() override
Definition: item_sum.cc:6504
bool reset_and_add_for_rollup(int last_unchanged_group_item_idx)
Definition: item_sum.cc:6510
const int m_num_levels
Definition: item_sum.h:2815
const Item * get_arg(uint i) const override
Get the i'th argument of the function that this object represents.
Definition: item_sum.h:2791
ROW_NUMBER window function, cf.
Definition: item_sum.h:2272
ulonglong m_ctr
Increment for each row in partition.
Definition: item_sum.h:2274
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2285
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2283
bool check_wf_semantics1(THD *, Query_block *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2299
Item_row_number(const POS &pos, PT_window *w)
Definition: item_sum.h:2277
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4821
Item_result result_type() const override
Definition: item_sum.h:2297
String * val_str(String *) override
Definition: item_sum.cc:4817
longlong val_int() override
Definition: item_sum.cc:4798
void clear() override
Definition: item_sum.cc:4826
const char * func_name() const override
Definition: item_sum.h:2282
double val_real() override
Definition: item_sum.cc:4812
Definition: item_sum.h:1497
enum Type type() const override
Definition: item_sum.h:1500
Item_std_field(Item_sum_std *item)
Definition: item_sum.cc:3860
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:1508
enum Item_result result_type() const override
Definition: item_sum.h:1503
double val_real() override
Definition: item_sum.cc:3863
const char * func_name() const override
Definition: item_sum.h:1504
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3871
Definition: item_sum.h:1915
Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1917
const char * func_name() const override
Definition: item_sum.h:1921
Item_sum_and(THD *thd, Item_sum_and *item)
Definition: item_sum.h:1920
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3328
Definition: item_sum.h:1318
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:2275
void clear() override
Definition: item_sum.cc:2330
String * val_str(String *str) override
Definition: item_sum.cc:2445
const char * func_name() const override
Definition: item_sum.h:1348
void update_field() override
calc next value and merge it with field_value.
Definition: item_sum.cc:3557
Item_sum_sum super
Definition: item_sum.h:1322
Item * result_item(Field *) override
Definition: item_sum.h:1345
double val_real() override
Definition: item_sum.cc:2339
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1351
Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
Definition: item_sum.h:1326
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:2308
my_decimal m_avg_dec
Definition: item_sum.h:1323
uint f_scale
Definition: item_sum.h:1321
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1333
double m_avg
Definition: item_sum.h:1324
longlong val_int() override
Definition: item_sum.h:1340
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2301
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2362
void reset_field() override
Definition: item_sum.cc:3457
uint prec_increment
Definition: item_sum.h:1320
uint dec_bin_size
Definition: item_sum.h:1321
bool add() override
Definition: item_sum.cc:2332
Item_sum_avg(THD *thd, Item_sum_avg *item)
Definition: item_sum.h:1329
uint f_precision
Definition: item_sum.h:1321
This is used in connection with an Item_sum_bit,.
Definition: item_sum.h:1194
double val_real() override
Definition: item_sum.cc:3803
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:3768
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:3820
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3846
longlong val_int() override
Definition: item_sum.cc:3788
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3853
String * val_str(String *) override
Definition: item_sum.cc:3828
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:1746
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3217
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:1638
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1855
void remove_bits(const String *s1, ulonglong b1)
For windowing: perform inverse aggregation.
Definition: item_sum.cc:1560
const char initial_value_buff_storage[1]
Buffer used to avoid String allocation in the constructor.
Definition: item_sum.h:1757
static constexpr uint DIGIT_CNT_CARD
Definition: item_sum.h:1800
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1842
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:1504
bool m_is_xor
true iff BIT_XOR
Definition: item_sum.h:1803
void clear() override
Definition: item_sum.cc:3300
Item * result_item(Field *) override
Definition: item_sum.h:1838
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:1479
longlong val_int() override
Definition: item_sum.cc:3275
Item_sum super
Definition: item_sum.h:1747
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:1792
Item_result hybrid_type
Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT.
Definition: item_sum.h:1755
ulonglong reset_bits
Stores the neutral element for function.
Definition: item_sum.h:1749
Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg, PT_window *w)
Definition: item_sum.h:1806
bool is_and() const
Definition: item_sum.h:1868
void reset_field() override
Definition: item_sum.cc:3485
ulonglong m_count
Execution state (windowing): this is for counting rows entering and leaving the window frame,...
Definition: item_sum.h:1763
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3224
double val_real() override
Definition: item_sum.cc:3249
bool add() override
Common implementation of Item_sum_or::add, Item_sum_and:add and Item_sum_xor::add.
Definition: item_sum.cc:1734
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.cc:3231
enum Item_result result_type() const override
Definition: item_sum.h:1843
uint m_digit_cnt_card
Definition: item_sum.h:1798
Item_sum_bit(THD *thd, Item_sum_bit *item)
Copy constructor, used for executing subqueries with temporary tables.
Definition: item_sum.h:1819
String * val_str(String *str) override
Definition: item_sum.cc:3186
void update_field() override
Definition: item_sum.cc:3495
ulonglong bits
Stores the result value for the INT_RESULT.
Definition: item_sum.h:1751
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:1771
String value_buff
Stores the result value for the STRING_RESULT.
Definition: item_sum.h:1753
Implements ST_Collect which aggregates geometries into Multipoints, Multilinestrings,...
Definition: item_sum.h:2821
bool add() override
Definition: item_sum.cc:6608
void clear() override
Definition: item_sum.cc:6602
void read_result_field()
Definition: item_sum.cc:6663
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:6571
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item_sum.h:2841
std::optional< gis::srid_t > srid
Definition: item_sum.h:2823
Item_sum_collect(const POS &pos, Item *a, PT_window *w, bool distinct)
Definition: item_sum.h:2832
void update_field() override
Definition: item_sum.cc:6756
longlong val_int() override
Definition: item_sum.h:2839
bool get_time(MYSQL_TIME *) override
Definition: item_sum.h:2842
std::unique_ptr< gis::Geometrycollection > m_geometrycollection
Definition: item_sum.h:2824
String * val_str(String *str) override
Definition: item_sum.cc:6709
void reset_field() override
Definition: item_sum.cc:6819
Item_sum_collect(THD *thd, Item_sum *item)
Definition: item_sum.h:2829
void store_result_field()
Definition: item_sum.cc:6762
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:6814
bool check_wf_semantics1(THD *thd, Query_block *, Window_evaluation_requirements *r) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:6593
const char * func_name() const override
Definition: item_sum.h:2880
void pop_front()
Definition: item_sum.cc:6702
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2843
Item_result result_type() const override
Definition: item_sum.h:2844
int set_aggregator(Aggregator::Aggregator_type) override
Definition: item_sum.h:2845
double val_real() override
Definition: item_sum.h:2840
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6658
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:2237
void update_field() override
Definition: item_sum.cc:3548
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2218
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:2269
void make_const(longlong count_arg)
Definition: item_sum.h:1105
void reset_field() override
Definition: item_sum.cc:3449
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:2226
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:2228
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:1542
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3139
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:3134
bool setup_hybrid(Item *item, Item *value_arg)
MIN/MAX function setup.
Definition: item_sum.cc:1826
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:1693
virtual Item_sum_hybrid * clone_hybrid(THD *thd) const =0
Create a clone of this object.
bool add() override
Definition: item_sum.cc:3169
const bool m_is_min
Tells if this is the MIN function (true) or the MAX function (false).
Definition: item_sum.h:1549
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3068
bool compute()
This function implements the optimized version of retrieving min/max value.
Definition: item_sum.cc:2870
bool has_values()
Definition: item_sum.h:1690
void min_max_update_int_field()
Definition: item_sum.cc:3679
longlong val_int() override
Definition: item_sum.cc:3003
bool m_has_values
Definition: item_sum.h:1561
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3058
void reset_field() override
Definition: item_sum.cc:3352
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:3105
void clear() override
Definition: item_sum.cc:2821
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:1589
Item_cache * arg_cache
Definition: item_sum.h:1558
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:3120
void min_max_update_json_field()
Definition: item_sum.cc:3632
void update_field() override
Definition: item_sum.cc:3593
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item_sum.cc:3029
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:2831
bool keep_field_type() const override
Definition: item_sum.h:1682
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3041
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:1583
void min_max_update_real_field()
Definition: item_sum.cc:3666
Item_sum_hybrid(THD *thd, const Item_sum_hybrid *item)
Definition: item_sum.h:1653
Item_result hybrid_type
Definition: item_sum.h:1560
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item_sum.cc:3017
bool m_optimize
Set to true when min/max can be optimized using window's ordering.
Definition: item_sum.h:1569
Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
Definition: item_sum.h:1637
Item_sum_hybrid(Item *item_par, bool is_min)
Definition: item_sum.h:1621
Item_sum super
Definition: item_sum.h:1543
void min_max_update_temporal_field()
Definition: item_sum.cc:3614
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:2836
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1795
String * val_str(String *) override
Definition: item_sum.cc:3078
Arg_comparator * cmp
Definition: item_sum.h:1559
void min_max_update_str_field()
Definition: item_sum.cc:3650
enum Item_result result_type() const override
Definition: item_sum.h:1683
void min_max_update_decimal_field()
Definition: item_sum.cc:3697
double val_real() override
Definition: item_sum.cc:2989
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:1843
bool m_want_first
For min() - Set to true when results are ordered in ascending and false when descending.
Definition: item_sum.h:1577
Item_cache * value
Definition: item_sum.h:1558
bool m_nulls_first
Set to true if the window is ordered ascending.
Definition: item_sum.h:1565
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_sum.h:1684
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:3091
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:1446
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:1448
Implements aggregation of values into an array.
Definition: item_sum.h:1262
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:6028
~Item_sum_json_array() override
bool add() override
Definition: item_sum.cc:6101
unique_ptr_destroy_only< Json_array > m_json_array
Accumulates the final value.
Definition: item_sum.h:1264
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6150
const char * func_name() const override
Definition: item_sum.h:1274
void clear() override
Definition: item_sum.cc:6043
Implements aggregation of values into an object.
Definition: item_sum.h:1281
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:6052
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6258
bool add() override
Definition: item_sum.cc:6163
unique_ptr_destroy_only< Json_object > m_json_object
Accumulates the final value.
Definition: item_sum.h:1283
~Item_sum_json_object() override
const char * func_name() const override
Definition: item_sum.h:1310
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:6077
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:1292
void clear() override
Definition: item_sum.cc:6067
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:1300
String m_tmp_key_value
Buffer used to get the value of the key.
Definition: item_sum.h:1285
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:5988
void update_field() override
Definition: item_sum.cc:6008
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5879
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item_sum.cc:5902
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:5940
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:5981
Item_sum_json(unique_ptr_destroy_only< Json_wrapper > wrapper, Args &&...parent_args)
Construct an Item_sum_json instance.
Definition: item_sum.cc:5820
~Item_sum_json() override
String * val_str(String *str) override
Definition: item_sum.cc:5860
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5955
Item_result result_type() const override
Definition: item_sum.h:1242
bool fix_fields(THD *thd, Item **pItem) override
Definition: item_sum.cc:5834
bool check_wf_semantics1(THD *, Query_block *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5829
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5973
double val_real() override
Definition: item_sum.cc:5925
Definition: item_sum.h:1727
Item_sum_max(Item *item_par)
Definition: item_sum.h:1729
Item_sum_max(THD *thd, const Item_sum_max *item)
Definition: item_sum.h:1732
const char * func_name() const override
Definition: item_sum.h:1735
Item_sum_max * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:3150
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1734
Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1730
Definition: item_sum.h:1713
Item_sum_min(THD *thd, const Item_sum_min *item)
Definition: item_sum.h:1718
Item_sum_min(Item *item_par)
Definition: item_sum.h:1715
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1720
const char * func_name() const override
Definition: item_sum.h:1721
Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1716
Item_sum_min * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:3146
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:1442
Item_sum_num(THD *thd, Item_sum_num *item)
Definition: item_sum.h:960
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1452
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:1440
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:3339
Item_sum_num(const POS &pos, PT_item_list *list, PT_window *w)
Definition: item_sum.h:957
Definition: item_sum.h:1905
Item_sum_or(THD *thd, Item_sum_or *item)
Definition: item_sum.h:1910
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3314
const char * func_name() const override
Definition: item_sum.h:1911
Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1907
Definition: item_sum.h:1520
double val_real() override
Definition: item_sum.cc:2455
Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
Definition: item_sum.h:1522
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2464
Item_sum_std(THD *thd, Item_sum_std *item)
Definition: item_sum.h:1525
const char * func_name() const override
Definition: item_sum.h:1529
enum Item_result result_type() const override
Definition: item_sum.h:1533
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1526
Item * result_item(Field *) override
Definition: item_sum.h:1528
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:1973
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:1907
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:1995
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:1926
void reset_field() override
Definition: item_sum.cc:3431
String * val_str(String *str) override
Definition: item_sum.cc:2084
longlong val_int() override
Definition: item_sum.cc:2016
my_decimal dec_buffs[2]
Definition: item_sum.h:1021
void clear() override
Definition: item_sum.cc:1914
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:3519
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:2090
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:1928
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1047
double val_real() override
Definition: item_sum.cc:2040
Definition: item_sum.h:2073
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2084
longlong val_int() override
Definition: item_sum.cc:3988
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2087
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3990
Item_sum_udf_decimal(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2075
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3999
double val_real() override
Definition: item_sum.cc:3986
enum Item_result result_type() const override
Definition: item_sum.h:2090
String * val_str(String *) override
Definition: item_sum.cc:3982
Item_sum_udf_decimal(THD *thd, Item_sum_udf_decimal *item)
Definition: item_sum.h:2078
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2091
Definition: item_sum.h:1983
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2002
longlong val_int() override
Definition: item_sum.h:1989
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3978
String * val_str(String *str) override
Definition: item_sum.cc:3974
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3961
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1996
double val_real() override
Definition: item_sum.cc:3966
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
Definition: item_sum.h:1987
Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1985
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1999
Definition: item_sum.h:2010
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2023
Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
Definition: item_sum.h:2014
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2028
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2026
enum Item_result result_type() const override
Definition: item_sum.h:2027
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4003
String * val_str(String *str) override
Definition: item_sum.cc:4015
Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2012
longlong val_int() override
Definition: item_sum.cc:4007
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:4019
double val_real() override
Definition: item_sum.h:2017
Definition: item_sum.h:2035
bool resolve_type(THD *) override
Default max_length is max argument length.
Definition: item_sum.cc:4025
double val_real() override
Definition: item_sum.h:2042
String * val_str(String *) override
Definition: item_sum.cc:4041
enum Item_result result_type() const override
Definition: item_sum.h:2068
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2062
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2065
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4033
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:4037
Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
Definition: item_sum.h:2039
longlong val_int() override
Definition: item_sum.h:2051
Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2037
Definition: item_sum.h:1442
ulonglong count
Definition: item_sum.h:1453
void update_field() override
Definition: item_sum.cc:2795
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:2663
double val_real() override
Definition: item_sum.cc:2740
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1487
void clear() override
Definition: item_sum.cc:2717
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2683
Item * result_item(Field *) override
Definition: item_sum.h:1479
Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
Definition: item_sum.h:1463
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1472
double recurrence_s
Definition: item_sum.h:1451
bool optimize
If set, uses a algorithm II mentioned in the class description to calculate the variance which helps ...
Definition: item_sum.h:1461
const char * func_name() const override
Definition: item_sum.h:1481
bool add() override
Definition: item_sum.cc:2719
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1480
double recurrence_s2
Definition: item_sum.h:1452
Item_result hybrid_type
Definition: item_sum.h:1446
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:2647
double recurrence_m
Used in recurrence relation.
Definition: item_sum.h:1450
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2770
uint prec_increment
Definition: item_sum.h:1455
enum Item_result result_type() const override
Definition: item_sum.h:1486
void reset_field() override
Definition: item_sum.cc:2775
uint sample
Definition: item_sum.h:1454
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:2696
Definition: item_sum.h:1925
const char * func_name() const override
Definition: item_sum.h:1933
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3321
Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1927
Item_sum_xor(THD *thd, Item_sum_xor *item)
Definition: item_sum.h:1932
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:723
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:424
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:496
bool aggregate_check_distinct(uchar *arg) override
Definition: item_sum.cc:639
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:945
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:478
void make_const()
Definition: item_sum.h:594
Item * replace_aggregate(uchar *) override
Definition: item_sum.cc:754
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:909
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:921
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:534
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:663
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:762
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:782
Item * set_arg(THD *thd, uint i, Item *new_val) override
Definition: item_sum.cc:862
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:696
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:850
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:867
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:772
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:468
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:932
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:803
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:897
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:612
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:688
Query_block * base_query_block
query block where function is placed
Definition: item_sum.h:484
Definition: item_sum.h:1941
udf_handler udf
Definition: item_sum.h:1945
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_sum.cc:3919
void update_field() override
Definition: item_sum.h:1977
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:3941
void reset_field() override
Definition: item_sum.h:1976
bool add() override
Definition: item_sum.cc:3934
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.h:1962
Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1948
void clear() override
Definition: item_sum.cc:3928
~Item_udf_sum() override
Definition: item_sum.h:1956
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:3950
Item_udf_sum(THD *thd, Item_udf_sum *item)
Definition: item_sum.h:1952
Item_sum super
Definition: item_sum.h:1942
const char * func_name() const override
Definition: item_sum.h:1961
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1972
Definition: item_sum.h:1360
my_decimal * val_decimal(my_decimal *dec_buf) override
Definition: item_sum.h:1369
const char * func_name() const override
Definition: item_sum.h:1373
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1372
enum Type type() const override
Definition: item_sum.h:1366
Item_variance_field(Item_sum_variance *item)
Definition: item_sum.cc:3890
uint sample
Definition: item_sum.h:1362
String * val_str(String *str) override
Definition: item_sum.h:1368
double val_real() override
Definition: item_sum.cc:3904
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:1377
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:3535
void set_nullable(bool nullable)
Definition: item.h:3646
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3542
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:3645
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:3543
bool fixed
True if item has been resolved.
Definition: item.h:3634
virtual Item_result result_type() const
Definition: item.h:1439
bool null_value
True if item is null.
Definition: item.h:3671
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:3672
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:3451
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:3682
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:7645
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:234
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:1167
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:172
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:4554
void free_handler()
Definition: item_func.cc:4535
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:31
type_conversion_status
Status when storing a value in a field or converting from one datatype to another.
Definition: field.h:202
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:4156
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:4077
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:4113
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:1564
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1087
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:2883
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:124
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:287
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:420
Definition: table.h:1407
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...