MySQL 9.3.0
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, 2025, 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 ~Item_sum() override { assert(aggr == nullptr); }
541
542 bool do_itemize(Parse_context *pc, Item **res) override;
543 Type type() const override { return SUM_FUNC_ITEM; }
544 virtual enum Sumfunctype sum_func() const = 0;
545
546 // Differs only for Item_rollup_sum_switcher.
547 virtual enum Sumfunctype real_sum_func() const { return sum_func(); }
548
549 /**
550 Resets the aggregate value to its default and aggregates the current
551 value of its attribute(s).
552 */
553 inline bool reset_and_add() {
555 return aggregator_add();
556 }
557
558 /*
559 Called when new group is started and results are being saved in
560 a temporary table. Similarly to reset_and_add() it resets the
561 value to its default and aggregates the value of its
562 attribute(s), but must also store it in result_field.
563 This set of methods (result_item(), reset_field, update_field()) of
564 Item_sum is used only if allow_group_via_temp_table is true. Otherwise
565 copy_or_same() is used to obtain a copy of this item.
566 */
567 virtual void reset_field() = 0;
568 /*
569 Called for each new value in the group, when temporary table is in use.
570 Similar to add(), but uses temporary table field to obtain current value,
571 Updated value is then saved in the field.
572 */
573 virtual void update_field() = 0;
574 virtual bool keep_field_type() const { return false; }
575 bool resolve_type(THD *) override;
576 virtual Item *result_item(Field *field) {
577 Item_field *item = new Item_field(field);
578 if (item == nullptr) return nullptr;
579 // Aggregated fields have no reference to an underlying table
580 assert(item->original_db_name() == nullptr &&
581 item->original_table_name() == nullptr);
582 // Break the connection to the original field since this is an aggregation
583 item->set_original_field_name(nullptr);
584 return item;
585 }
586 table_map used_tables() const override {
587 return forced_const ? 0 : used_tables_cache;
588 }
589 table_map not_null_tables() const override { return used_tables(); }
590 void update_used_tables() override;
591 void fix_after_pullout(Query_block *parent_query_block,
592 Query_block *removed_query_block) override;
594 bool is_null() override { return null_value; }
595
596 void make_const() {
597 // "forced_const" will make used_tables() return zero for this object
598 forced_const = true;
599 }
600 void print(const THD *thd, String *str,
601 enum_query_type query_type) const override;
602 bool eq(const Item *item) const override;
603 bool eq_specific(const Item *item) const override;
604 /**
605 Mark an aggregate as having no rows.
606
607 This function is called by the execution engine to assign 'NO ROWS
608 FOUND' value to an aggregate item, when the underlying result set
609 has no rows. Such value, in a general case, may be different from
610 the default value of the item after 'clear()': e.g. a numeric item
611 may be initialized to 0 by clear() and to NULL by
612 no_rows_in_result().
613 */
614 void no_rows_in_result() override {
618 }
619 virtual void make_unique() { force_copy_fields = true; }
620 virtual Field *create_tmp_field(bool group, TABLE *table);
621
622 /// argument used by walk method collect_grouped_aggregates ("cga")
624 /// accumulated all aggregates found
625 std::vector<Item_sum *> list;
626 std::set<Item_sum *> aggregates_that_were_hidden;
627 /**
628 The query block we walk from. All found aggregates must aggregate in
629 this; if some aggregate in outer query blocks, break off transformation.
630 */
632 /// true: break off transformation
633 bool m_break_off{false};
634 /// true: an aggregate aggregates outside m_query_block
635 bool m_outside{false};
637 : m_query_block(select) {}
638 };
639
640 bool collect_grouped_aggregates(uchar *) override;
641 Item *replace_aggregate(uchar *) override;
642 bool collect_scalar_subqueries(uchar *) override;
644
645 bool clean_up_after_removal(uchar *arg) override;
646 bool aggregate_check_group(uchar *arg) override;
647 bool aggregate_check_distinct(uchar *arg) override;
648 bool has_aggregate_ref_in_group_by(uchar *arg) override;
649 bool init_sum_func_check(THD *thd);
650 bool check_sum_func(THD *thd, Item **ref);
651
652 Item *set_arg(THD *thd, uint i, Item *new_val) override;
653 /// @todo delete this when we no longer support temporary transformations
654 Item **get_arg_ptr(uint i) { return &args[i]; }
655
656 bool fix_fields(THD *thd, Item **ref) override;
657
658 /**
659 Signal to the function that its arguments may have changed,
660 and that any internal caches etc. based on those arguments
661 must be updated accordingly.
662
663 This is used by the hypergraph optimizer when it rewrites
664 arguments to window functions to take into account that they
665 have been materialized into temporary tables, or that they
666 should read their values from the framebuffer.
667 */
669
670 /**
671 Called to initialize the aggregator.
672 */
673
674 virtual bool aggregator_setup(THD *thd) { return aggr->setup(thd); }
675
676 /**
677 Called to cleanup the aggregator.
678 */
679
680 inline void aggregator_clear() { aggr->clear(); }
681
682 /**
683 Called to add value to the aggregator.
684 */
685
686 inline bool aggregator_add() { return aggr->add(); }
687
688 /* stores the declared DISTINCT flag (from the parser) */
689 void set_distinct(bool distinct) {
690 with_distinct = distinct;
692 }
693
694 /*
695 Set the type of aggregation : DISTINCT or not.
696
697 May be called multiple times.
698 */
699
700 virtual int set_aggregator(Aggregator::Aggregator_type aggregator);
701
702 virtual void clear() = 0;
703 virtual bool add() = 0;
704 virtual bool setup(THD *) { return false; }
705
706 /**
707 Only relevant for aggregates qua window functions. Checks semantics after
708 windows have been set up and checked. Window functions have specific
709 requirements on the window specifications. Used at resolution time.
710
711 @param thd Current thread
712 @param select The current select
713 @param [out] reqs Holds collected requirements from this wf
714
715 @returns true if error
716 */
717 virtual bool check_wf_semantics1(THD *thd, Query_block *select,
719
720 /**
721 Like check_wf_semantics1.
722 For checks which cannot be done in resolution phase (mostly those for
723 input parameters which can be '?' and must be >=0: value isn't known
724 before execution phase).
725 */
727 [[maybe_unused]]) {
728 return false;
729 }
730
731 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
732 mem_root_deque<Item *> *fields) override;
733
734 void cleanup() override;
735
736 Window *window() { return m_window; }
737 const Window *window() const { return m_window; }
738 bool reset_wf_state(uchar *arg) override;
739
740 /**
741 All aggregates are framing, i.e. they work on the window's frame. If none
742 is defined, the frame is by default the entire partition, unless ORDER BY
743 is defined, in which case it is the set of rows from the start of the
744 partition to and including the peer set of the current row.
745
746 Some window functions are not framing, i.e. they always work on the entire
747 partition. For such window functions, the method is overridden to
748 return false.
749 */
750 virtual bool framing() const { return true; }
751
752 /**
753 Only for framing window functions. True if this function only needs to
754 read one row per frame.
755 */
756 virtual bool uses_only_one_row() const { return false; }
757
758 /**
759 Return true if we need to make two passes over the rows in the partition -
760 either because we need the cardinality of it (and we need to read all
761 rows to detect the next partition), or we need to have all partition rows
762 available to evaluate the window function for some other reason, e.g.
763 we may need the last row in the partition in the frame buffer to be able
764 to evaluate LEAD.
765 */
766 virtual bool needs_partition_cardinality() const { return false; }
767
768 /**
769 Common initial actions for window functions. For non-buffered processing
770 ("on-the-fly"), check partition change and possible reset partition
771 state. In this case return false.
772 For buffered processing, if windowing state m_do_copy_null is true, set
773 null_value to is_nullable() and return true.
774
775 @return true if case two above holds, else false
776 */
777 bool wf_common_init();
778
779 /// Overridden by Item_rollup_sum_switcher.
780 virtual bool is_rollup_sum_wrapper() const { return false; }
781 /**
782 * In case we are an Item_rollup_sum_switcher,
783 * return the underlying Item_sum, otherwise, return this.
784 * Overridden by Item_rollup_sum_switcher.
785 */
786 virtual const Item_sum *unwrap_sum() const { return this; }
787 /// Non-const version
788 virtual Item_sum *unwrap_sum() { return this; }
789
790 protected:
791 /*
792 Raise an error (ER_NOT_SUPPORTED_YET) with the detail that this
793 function is not yet supported as a window function.
794 */
796 char buff[STRING_BUFFER_USUAL_SIZE];
797 snprintf(buff, sizeof(buff), "%s as window function", func_name());
798 my_error(ER_NOT_SUPPORTED_YET, MYF(0), buff);
799 }
800
801 void add_json_info(Json_object *obj) override {
802 obj->add_alias("distinct", create_dom_ptr<Json_boolean>(with_distinct));
803 }
804};
805
806class Unique;
807
808/**
809 The distinct aggregator.
810 Implements AGGFN (DISTINCT ..)
811 Collects all the data into an Unique (similarly to what Item_sum_distinct
812 does currently) and then (if applicable) iterates over the list of
813 unique values and pumps them back into its object
814*/
815
817 friend class Item_sum_sum;
818
819 /*
820 flag to prevent consecutive runs of endup(). Normally in endup there are
821 expensive calculations (like walking the distinct tree for example)
822 which we must do only once if there are no data changes.
823 We can re-use the data for the second and subsequent val_xxx() calls.
824 endup_done set to true also means that the calculated values for
825 the aggregate functions are correct and don't need recalculation.
826 */
828
829 /*
830 Used depending on the type of the aggregate function and the presence of
831 blob columns in it:
832 - For COUNT(DISTINCT) and no blob fields this points to a real temporary
833 table. It's used as a hash table.
834 - For AVG/SUM(DISTINCT) or COUNT(DISTINCT) with blob fields only the
835 in-memory data structure of a temporary table is constructed.
836 It's used by the Field classes to transform data into row format.
837 */
839
840 /*
841 An array of field lengths on row allocated and used only for
842 COUNT(DISTINCT) with multiple columns and no blobs. Used in
843 Aggregator_distinct::composite_key_cmp (called from Unique to compare
844 nodes
845 */
847
848 /*
849 Used in conjunction with 'table' to support the access to Field classes
850 for COUNT(DISTINCT). Needed by copy_fields()/copy_funcs().
851 */
853
854 /*
855 If there are no blobs in the COUNT(DISTINCT) arguments, we can use a tree,
856 which is faster than heap table. In that case, we still use the table
857 to help get things set up, but we insert nothing in it.
858 For AVG/SUM(DISTINCT) we always use this tree (as it takes a single
859 argument) to get the distinct rows.
860 */
862
863 /*
864 The length of the temp table row. Must be a member of the class as it
865 gets passed down to simple_raw_key_cmp () as a compare function argument
866 to Unique. simple_raw_key_cmp () is used as a fast comparison function
867 when the entire row can be binary compared.
868 */
870
873 /**
874 Set to true if the result is known to be always NULL.
875 If set deactivates creation and usage of the temporary table (in the
876 'table' member) and the Unique instance (in the 'tree' member) as well as
877 the calculation of the final value on the first call to
878 @c Item_sum::val_xxx(),
879 @c Item_avg::val_xxx(),
880 @c Item_count::val_xxx().
881 */
883 /**
884 Set to true if count distinct is on only const items. Distinct on a const
885 value will always be the constant itself. And count distinct of the same
886 would always be 1. Similar to CONST_NULL, it avoids creation of temporary
887 table and the Unique instance.
888 */
891
892 /**
893 When feeding back the data in endup() from Unique/temp table back to
894 Item_sum::add() methods we must read the data from Unique (and not
895 recalculate the functions that are given as arguments to the aggregate
896 function.
897 This flag is to tell the arg_*() methods to take the data from the Unique
898 instead of calling the relevant val_..() method.
899 */
901
902 public:
904 : Aggregator(sum),
905 table(nullptr),
907 tree(nullptr),
909 use_distinct_values(false) {}
910 ~Aggregator_distinct() override;
912
913 bool setup(THD *) override;
914 void clear() override;
915 bool add() override;
916 void endup() override;
918 double arg_val_real() override;
919 bool arg_is_null(bool use_null_value) override;
920
921 bool unique_walk_function(void *element);
922 static int composite_key_cmp(const void *arg, const void *a, const void *b);
923};
924
925/**
926 The pass-through aggregator.
927 Implements AGGFN (DISTINCT ..) by knowing it gets distinct data on input.
928 So it just pumps them back to the Item_sum descendant class.
929*/
931 public:
934
935 bool setup(THD *thd) override { return item_sum->setup(thd); }
936 void clear() override { item_sum->clear(); }
937 bool add() override { return item_sum->add(); }
938 void endup() override {}
940 double arg_val_real() override;
941 bool arg_is_null(bool use_null_value) override;
942};
943
944class Item_sum_num : public Item_sum {
946
947 protected:
948 /*
949 val_xxx() functions may be called several times during the execution of a
950 query. Derived classes that require extensive calculation in val_xxx()
951 maintain cache of aggregate value. This variable governs the validity of
952 that cache.
953 */
955
956 public:
957 Item_sum_num(const POS &pos, Item *item_par, PT_window *window)
958 : Item_sum(pos, item_par, window), is_evaluated(false) {}
959
961 : Item_sum(pos, list, w), is_evaluated(false) {}
962
964 : Item_sum(thd, item), is_evaluated(item->is_evaluated) {}
966 return MYSQL_TYPE_DOUBLE;
967 }
968
969 Item_sum_num(Item *item_par) : Item_sum(item_par), is_evaluated(false) {}
970
971 bool fix_fields(THD *, Item **) override;
972 longlong val_int() override {
973 assert(fixed);
974 return llrint_with_overflow_check(val_real()); /* Real as default */
975 }
976 String *val_str(String *str) override;
977 my_decimal *val_decimal(my_decimal *) override;
978 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
979 return get_date_from_numeric(ltime, fuzzydate); /* Decimal or real */
980 }
981 bool get_time(MYSQL_TIME *ltime) override {
982 return get_time_from_numeric(ltime); /* Decimal or real */
983 }
984 void reset_field() override;
985};
986
988 public:
989 Item_sum_int(const POS &pos, Item *item_par, PT_window *w)
990 : Item_sum_num(pos, item_par, w) {
992 }
993
995 : Item_sum_num(pos, list, w) {
997 }
998
999 Item_sum_int(THD *thd, Item_sum_int *item) : Item_sum_num(thd, item) {
1001 }
1002
1003 Item_sum_int(Item *item_par) : Item_sum_num(item_par) {
1005 }
1006
1007 double val_real() override {
1008 assert(fixed);
1009 return static_cast<double>(val_int());
1010 }
1011 String *val_str(String *str) override;
1012 my_decimal *val_decimal(my_decimal *) override;
1013 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1014 return get_date_from_int(ltime, fuzzydate);
1015 }
1016 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
1017 enum Item_result result_type() const override { return INT_RESULT; }
1018};
1019
1021 protected:
1023 double sum;
1026 bool resolve_type(THD *thd) override;
1027 /**
1028 Execution state: this is for counting rows entering and leaving the window
1029 frame, see #m_frame_null_count.
1030 */
1032
1033 /**
1034 Execution state: this is for counting NULLs of rows entering and leaving
1035 the window frame, when we use optimized inverse-based computations. By
1036 comparison with m_count we can know how many non-NULLs are in the frame.
1037 */
1039
1040 public:
1041 Item_sum_sum(const POS &pos, Item *item_par, bool distinct, PT_window *window)
1042 : Item_sum_num(pos, item_par, window),
1044 m_count(0),
1046 set_distinct(distinct);
1047 }
1048
1050 : Item_sum_num(item_par),
1052 m_count(0),
1053 m_frame_null_count(0) {}
1054
1055 Item_sum_sum(THD *thd, Item_sum_sum *item);
1056 enum Sumfunctype sum_func() const override {
1058 }
1059 void clear() override;
1060 bool add() override;
1061 double val_real() override;
1062 longlong val_int() override;
1063 String *val_str(String *str) override;
1064 my_decimal *val_decimal(my_decimal *) override;
1065 enum Item_result result_type() const override { return hybrid_type; }
1066 bool check_wf_semantics1(THD *thd, Query_block *select,
1067 Window_evaluation_requirements *reqs) override;
1068 void no_rows_in_result() override;
1069 void reset_field() override;
1070 void update_field() override;
1071 const char *func_name() const override { return "sum"; }
1072 Item *copy_or_same(THD *thd) override;
1073};
1074
1077
1079
1080 void clear() override;
1081 bool add() override;
1082 void cleanup() override;
1083
1084 public:
1085 Item_sum_count(const POS &pos, Item *item_par, PT_window *w)
1086 : Item_sum_int(pos, item_par, w), count(0) {}
1087 Item_sum_count(Item_int *number) : Item_sum_int(number), count(0) {}
1088 Item_sum_count(Item *item, bool distinct) : Item_sum_int(item), count(0) {
1089 set_distinct(distinct);
1090 }
1091 /**
1092 Constructs an instance for COUNT(DISTINCT)
1093
1094 @param pos Position of token in the parser.
1095 @param list A list of the arguments to the aggregate function
1096 @param w A window, if COUNT is used as a windowing function
1097
1098 This constructor is called by the parser only for COUNT (DISTINCT).
1099 */
1101 : Item_sum_int(pos, list, w), count(0) {
1102 set_distinct(true);
1103 }
1105 : Item_sum_int(thd, item), count(item->count) {}
1106 enum Sumfunctype sum_func() const override {
1108 }
1109 bool resolve_type(THD *thd) override {
1110 if (param_type_is_default(thd, 0, -1)) return true;
1111 set_nullable(false);
1112 null_value = false;
1113 return false;
1114 }
1115 void no_rows_in_result() override { count = 0; }
1116 void make_const(longlong count_arg) {
1117 count = count_arg;
1119 }
1120 longlong val_int() override;
1121 void reset_field() override;
1122 void update_field() override;
1123 const char *func_name() const override { return "count"; }
1124 Item *copy_or_same(THD *thd) override;
1125};
1126
1127/* Item to get the value of a stored sum function */
1128
1129class Item_sum_avg;
1130class Item_sum_bit;
1131
1132/**
1133 This is used in connection with a parent aggregate Item:
1134 - which stores function's value into a temporary table's column (one row
1135 per group).
1136 - except when the output is a local variable in a stored procedure, in which
1137 case the variable is used as the target.
1138 - which stores in the column some internal piece of information which should
1139 not be returned to the user, so special implementations are needed.
1140 The classes that inherit from Item_aggregate_field are created during
1141 optimization and resolved upon construction, thus the fix_fields() function
1142 is not needed and thus not implemented. The resolve_type() needs a default
1143 implementation since it is a virtual function.
1144*/
1146 protected:
1147 /// The tmp table's column containing the value of the set function.
1148 Field *m_field{nullptr};
1149 /// Stores the Item's result type.
1151
1152 public:
1153 enum Item_result result_type() const override { return m_result_type; }
1154 // resolve_type is not used for these classes, but is needed bc it is virtual
1155 bool resolve_type(THD *) override { return false; }
1156 bool mark_field_in_map(uchar *arg) override {
1157 /*
1158 Filesort (find_all_keys) over a temporary table collects the columns it
1159 needs.
1160 */
1161 return Item::mark_field_in_map(pointer_cast<Mark_field *>(arg), m_field);
1162 }
1165 pointer_cast<Check_function_as_value_generator_parameters *>(args);
1166 func_arg->err_code = func_arg->get_unnamed_function_error_code();
1167 return true;
1168 }
1169};
1170
1171/**
1172 Common abstract class for aggregate field classes that return numeric values:
1173 Item_aggr_avg_field
1174 Item_aggr_variance_field
1175*/
1177 public:
1178 longlong val_int() override {
1179 /* can't be fix_fields()ed */
1181 }
1182 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1183 return get_date_from_numeric(ltime, fuzzydate); /* Decimal or real */
1184 }
1185 bool get_time(MYSQL_TIME *ltime) override {
1186 return get_time_from_numeric(ltime); /* Decimal or real */
1187 }
1188 bool is_null() override { return update_null_value() || null_value; }
1189};
1190
1192 public:
1194 enum Type type() const override { return AGGR_FIELD_ITEM; }
1195 double val_real() override;
1196 my_decimal *val_decimal(my_decimal *) override;
1197 String *val_str(String *) override;
1198
1199 private:
1204};
1205
1206/// This is used in connection with an Item_sum_bit, @see Item_aggregate_field
1208 public:
1209 Item_aggr_bit_field(Item_sum_bit *item, ulonglong reset_bits);
1210 longlong val_int() override;
1211 double val_real() override;
1212 my_decimal *val_decimal(my_decimal *) override;
1213 String *val_str(String *) override;
1214 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1215 bool get_time(MYSQL_TIME *ltime) override;
1216 enum Type type() const override { return AGGR_FIELD_ITEM; }
1217
1218 private:
1220};
1221
1222/// Common abstraction for Item_sum_json_array and Item_sum_json_object
1223class Item_sum_json : public Item_sum {
1225
1226 protected:
1227 /// String used when reading JSON binary values or JSON text values.
1229 /// String used for converting JSON text values to utf8mb4 charset.
1231 /// Wrapper around the container (object/array) which accumulates the value.
1233
1234 /**
1235 Construct an Item_sum_json instance.
1236
1237 @param wrapper a wrapper around the Json_array or Json_object that contains
1238 the aggregated result
1239 @param parent_args arguments to forward to Item_sum's constructor
1240 */
1241 template <typename... Args>
1243 Args &&...parent_args);
1244
1245 public:
1246 ~Item_sum_json() override;
1247 bool fix_fields(THD *thd, Item **pItem) override;
1248 enum Sumfunctype sum_func() const override { return JSON_AGG_FUNC; }
1249 Item_result result_type() const override { return STRING_RESULT; }
1250
1251 double val_real() override;
1252 longlong val_int() override;
1253 String *val_str(String *str) override;
1254 bool val_json(Json_wrapper *wr) override;
1255 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
1256 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1257 bool get_time(MYSQL_TIME *ltime) override;
1258
1259 void reset_field() override;
1260 void update_field() override;
1261
1264};
1265
1266/// Implements aggregation of values into an array.
1268 /// Accumulates the final value.
1270
1271 public:
1272 Item_sum_json_array(THD *thd, Item_sum *item,
1275 Item_sum_json_array(const POS &pos, Item *a, PT_window *w,
1279 const char *func_name() const override { return "json_arrayagg"; }
1280 void clear() override;
1281 bool add() override;
1282 Item *copy_or_same(THD *thd) override;
1283};
1284
1285/// Implements aggregation of values into an object.
1287 /// Accumulates the final value.
1289 /// Buffer used to get the value of the key.
1291 /**
1292 Map of keys in Json_object and the count for each key
1293 within a window frame. It is used in handling rows
1294 leaving a window frame when rows are not sorted
1295 according to the key in Json_object.
1296 */
1297 std::map<std::string, int> m_key_map;
1298 /**
1299 If window provides ordering on the key in Json_object,
1300 a key_map is not needed to handle rows leaving a window
1301 frame. In this case, process_buffered_windowing_record()
1302 will set flags when a key/value pair can be removed from
1303 the Json_object.
1304 */
1305 bool m_optimize{false};
1306
1307 public:
1308 Item_sum_json_object(THD *thd, Item_sum *item,
1311 Item_sum_json_object(const POS &pos, Item *a, Item *b, PT_window *w,
1315 const char *func_name() const override { return "json_objectagg"; }
1316 void clear() override;
1317 bool add() override;
1318 Item *copy_or_same(THD *thd) override;
1319 bool check_wf_semantics1(THD *thd, Query_block *select,
1320 Window_evaluation_requirements *reqs) override;
1321};
1322
1323class Item_sum_avg final : public Item_sum_sum {
1324 public:
1329 double m_avg;
1330
1331 Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
1332 : Item_sum_sum(pos, item_par, distinct, w) {}
1333
1335 : Item_sum_sum(thd, item), prec_increment(item->prec_increment) {}
1336
1337 bool resolve_type(THD *thd) override;
1338 enum Sumfunctype sum_func() const override {
1340 }
1341 void clear() override;
1342 bool add() override;
1343 double val_real() override;
1344 // In SPs we might force the "wrong" type with select into a declare variable
1346 my_decimal *val_decimal(my_decimal *) override;
1347 String *val_str(String *str) override;
1348 void reset_field() override;
1349 void update_field() override;
1350 Item *result_item(Field *) override { return new Item_aggr_avg_field(this); }
1351 const char *func_name() const override { return "avg"; }
1352 Item *copy_or_same(THD *thd) override;
1353 Field *create_tmp_field(bool group, TABLE *table) override;
1354 void cleanup() override {
1355 m_count = 0;
1358 }
1359};
1360
1361class Item_sum_variance;
1362
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 }
1374 pointer_cast<Check_function_as_value_generator_parameters *>(args);
1375 func_arg->err_code = func_arg->get_unnamed_function_error_code();
1376 return true;
1377 }
1378
1379 private:
1381};
1382
1383/*
1384 variance(a) =
1385
1386 = sum (ai - avg(a))^2 / count(a) )
1387 = sum (ai^2 - 2*ai*avg(a) + avg(a)^2) / count(a)
1388 = (sum(ai^2) - sum(2*ai*avg(a)) + sum(avg(a)^2))/count(a) =
1389 = (sum(ai^2) - 2*avg(a)*sum(a) + count(a)*avg(a)^2)/count(a) =
1390 = (sum(ai^2) - 2*sum(a)*sum(a)/count(a) + count(a)*sum(a)^2/count(a)^2
1391 )/count(a) = = (sum(ai^2) - 2*sum(a)^2/count(a) + sum(a)^2/count(a)
1392 )/count(a) = = (sum(ai^2) - sum(a)^2/count(a))/count(a)
1393
1394 But, this falls prey to catastrophic cancellation.
1395 Instead, we use recurrence formulas in Algorithm I mentoned below
1396 for group aggregates.
1397
1398 Algorithm I:
1399 M_{1} = x_{1}, ~ M_{k} = M_{k-1} + (x_{k} - M_{k-1}) / k newline
1400 S_{1} = 0, ~ S_{k} = S_{k-1} + (x_{k} - M_{k-1}) times (x_{k} - M_{k}) newline
1401 for 2 <= k <= n newline
1402 ital variance = S_{n} / (n-1)
1403
1404 For aggregate window functions algorithm I cannot be optimized for
1405 moving frames since M_{i} changes for every row. So we use the
1406 following algorithm.
1407
1408 Algorithm II:
1409
1410 K = 0
1411 n = 0
1412 ex = 0
1413 ex2 = 0
1414
1415 def add_sample(x):
1416 if (n == 0):
1417 K = x
1418 n = n + 1
1419 ex += x - K
1420 ex2 += (x - K) * (x - K)
1421
1422 def remove_sample(x):
1423 n = n - 1
1424 ex -= (x - K)
1425 ex2 -= (x - K) * (x - K)
1426
1427 def variance():
1428 return (ex2 - (ex*ex)/n) / (n-1)
1429
1430 This formula facilitates incremental computation enabling us to
1431 optimize in case of moving window frames. The optimized codepath is taken
1432 only when windowing_use_high_precision is set to false. By default,
1433 aggregate window functions take the non-optimized codepath.
1434 Note:
1435 Results could differ between optimized and non-optimized code path.
1436 Hence algorithm II is used only when user sets
1437 windowing_use_high_precision to false.
1438*/
1439
1441 bool resolve_type(THD *) override;
1442
1443 public:
1445 /**
1446 Used in recurrence relation.
1447 */
1448 double recurrence_m{0.0};
1449 double recurrence_s{0.0};
1450 double recurrence_s2{0.0};
1454 /**
1455 If set, uses a algorithm II mentioned in the class description
1456 to calculate the variance which helps in optimizing windowing
1457 functions in presence of frames.
1458 */
1460
1461 Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg,
1462 PT_window *w)
1463 : Item_sum_num(pos, item_par, w),
1465 count(0),
1466 sample(sample_arg),
1467 optimize(false) {}
1468
1470 enum Sumfunctype sum_func() const override { return VARIANCE_FUNC; }
1471 void clear() override;
1472 bool add() override;
1473 double val_real() override;
1474 my_decimal *val_decimal(my_decimal *) override;
1475 void reset_field() override;
1476 void update_field() override;
1477 Item *result_item(Field *) override {
1478 return new Item_aggr_variance_field(this);
1479 }
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; }
1506 pointer_cast<Check_function_as_value_generator_parameters *>(args);
1507 func_arg->err_code = func_arg->get_unnamed_function_error_code();
1508 return true;
1509 }
1510};
1511
1512/*
1513 standard_deviation(a) = sqrt(variance(a))
1514*/
1515
1517 public:
1518 Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
1519 : Item_sum_variance(pos, item_par, sample_arg, w) {}
1520
1521 Item_sum_std(THD *thd, Item_sum_std *item) : Item_sum_variance(thd, item) {}
1522 enum Sumfunctype sum_func() const override { return STD_FUNC; }
1523 double val_real() override;
1524 Item *result_item(Field *) override { return new Item_aggr_std_field(this); }
1525 const char *func_name() const override {
1526 return sample ? "stddev_samp" : "std";
1527 }
1528 Item *copy_or_same(THD *thd) override;
1529 enum Item_result result_type() const override { return REAL_RESULT; }
1530};
1531
1532// This class is a string or number function depending on num_func
1533class Arg_comparator;
1534
1535/**
1536 Abstract base class for the MIN and MAX aggregate functions.
1537*/
1540
1541 private:
1542 /**
1543 Tells if this is the MIN function (true) or the MAX function (false).
1544 */
1545 const bool m_is_min;
1546 /*
1547 For window functions MIN/MAX with optimized code path, no comparisons
1548 are needed beyond NULL detection: MIN/MAX are then roughly equivalent to
1549 FIRST/LAST_VALUE. For this case, 'value' is the value of
1550 the window function a priori taken from args[0], while arg_cache is used to
1551 remember the value from the previous row. NULLs need a bit of careful
1552 treatment.
1553 */
1557 bool m_has_values; // Set if at least one row is found (for max/min only)
1558 /**
1559 Set to true if the window is ordered ascending.
1560 */
1562 /**
1563 Set to true when min/max can be optimized using window's ordering.
1564 */
1566 /**
1567 For min() - Set to true when results are ordered in ascending and
1568 false when descending.
1569 For max() - Set to true when results are ordered in descending and
1570 false when ascending.
1571 Valid only when m_optimize is true.
1572 */
1573 bool m_want_first; ///< Want first non-null value, else last non_null value
1574 /**
1575 Execution state: keeps track if this is the first row in the frame
1576 when buffering is not needed.
1577 Valid only when m_optimize is true.
1578 */
1580
1581 /**
1582 Execution state: keeps track of at which row we saved a non-null last
1583 value.
1584 */
1586
1587 /**
1588 This function implements the optimized version of retrieving min/max
1589 value. When we have "ordered ASC" results in a window, min will always
1590 be the first value in the result set (neglecting the NULL's) and max
1591 will always be the last value (or the other way around, if ordered DESC).
1592 It is based on the implementation of FIRST_VALUE/LAST_VALUE, except for
1593 the NULL handling.
1594
1595 @return true if computation yielded a NULL or error
1596 */
1597 bool compute();
1598
1599 /**
1600 MIN/MAX function setup.
1601
1602 Setup cache/comparator of MIN/MAX functions. When called by the
1603 copy_or_same() function, the value_arg parameter contains the calculated
1604 value of the original MIN/MAX object, and it is saved in this object's
1605 cache.
1606
1607 @param item the argument of the MIN/MAX function
1608 @param value_arg the calculated value of the MIN/MAX function
1609 @return false on success, true on error
1610 */
1611 bool setup_hybrid(Item *item, Item *value_arg);
1612
1613 /** Create a clone of this object. */
1614 virtual Item_sum_hybrid *clone_hybrid(THD *thd) const = 0;
1615
1616 protected:
1617 Item_sum_hybrid(Item *item_par, bool is_min)
1618 : Item_sum(item_par),
1619 m_is_min(is_min),
1620 value(nullptr),
1622 cmp(nullptr),
1624 m_has_values(true),
1625 m_nulls_first(false),
1626 m_optimize(false),
1627 m_want_first(false),
1628 m_cnt(0),
1631 }
1632
1633 Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
1634 : Item_sum(pos, item_par, w),
1635 m_is_min(is_min),
1636 value(nullptr),
1638 cmp(nullptr),
1640 m_has_values(true),
1641 m_nulls_first(false),
1642 m_optimize(false),
1643 m_want_first(false),
1644 m_cnt(0),
1647 }
1648
1650 : Item_sum(thd, item),
1651 m_is_min(item->m_is_min),
1652 value(item->value),
1654 hybrid_type(item->hybrid_type),
1657 m_optimize(item->m_optimize),
1659 m_cnt(item->m_cnt),
1661
1662 public:
1663 bool fix_fields(THD *, Item **) override;
1664 void clear() override;
1665 void update_after_wf_arguments_changed(THD *thd) override;
1666 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
1667 mem_root_deque<Item *> *fields) override;
1668 double val_real() override;
1669 longlong val_int() override;
1670 longlong val_time_temporal() override;
1671 longlong val_date_temporal() override;
1672 my_decimal *val_decimal(my_decimal *) override;
1673 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1674 bool get_time(MYSQL_TIME *ltime) override;
1675 void reset_field() override;
1676 String *val_str(String *) override;
1677 bool val_json(Json_wrapper *wr) override;
1678 bool keep_field_type() const override { return true; }
1679 enum Item_result result_type() const override { return hybrid_type; }
1680 TYPELIB *get_typelib() const override {
1681 assert(sum_func() == MAX_FUNC || sum_func() == MIN_FUNC);
1682 return arguments()[0]->get_typelib();
1683 }
1684 void update_field() override;
1685 void cleanup() override;
1686 bool has_values() { return m_has_values; }
1687 void no_rows_in_result() override;
1688 Field *create_tmp_field(bool group, TABLE *table) override;
1689 bool uses_only_one_row() const override { return m_optimize; }
1690 bool add() override;
1691 Item *copy_or_same(THD *thd) override;
1692 bool check_wf_semantics1(THD *thd, Query_block *select,
1694
1695 private:
1696 /*
1697 These functions check if the value on the current row exceeds the maximum or
1698 minimum value seen so far, and update the current max/min stored in
1699 result_field, if needed.
1700 */
1707};
1708
1709class Item_sum_min final : public Item_sum_hybrid {
1710 public:
1711 Item_sum_min(Item *item_par) : Item_sum_hybrid(item_par, true) {}
1712 Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
1713 : Item_sum_hybrid(pos, item_par, true, w) {}
1714 Item_sum_min(THD *thd, const Item_sum_min *item)
1715 : Item_sum_hybrid(thd, item) {}
1716 enum Sumfunctype sum_func() const override { return MIN_FUNC; }
1717 const char *func_name() const override { return "min"; }
1718
1719 private:
1720 Item_sum_min *clone_hybrid(THD *thd) const override;
1721};
1722
1723class Item_sum_max final : public Item_sum_hybrid {
1724 public:
1725 Item_sum_max(Item *item_par) : Item_sum_hybrid(item_par, false) {}
1726 Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
1727 : Item_sum_hybrid(pos, item_par, false, w) {}
1728 Item_sum_max(THD *thd, const Item_sum_max *item)
1729 : Item_sum_hybrid(thd, item) {}
1730 enum Sumfunctype sum_func() const override { return MAX_FUNC; }
1731 const char *func_name() const override { return "max"; }
1732
1733 private:
1734 Item_sum_max *clone_hybrid(THD *thd) const override;
1735};
1736
1737/**
1738 Base class used to implement BIT_AND, BIT_OR and BIT_XOR.
1739
1740 Each of them is both a set function and a framing window function.
1741*/
1742class Item_sum_bit : public Item_sum {
1744 /// Stores the neutral element for function
1746 /// Stores the result value for the INT_RESULT
1748 /// Stores the result value for the STRING_RESULT
1750 /// Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT
1752 /// Buffer used to avoid String allocation in the constructor
1753 const char initial_value_buff_storage[1] = {0};
1754
1755 /**
1756 Execution state (windowing): this is for counting rows entering and leaving
1757 the window frame, see #m_frame_null_count.
1758 */
1760
1761 /**
1762 Execution state (windowing): this is for counting NULLs of rows entering
1763 and leaving the window frame, when we use optimized inverse-based
1764 computations. By comparison with m_count we can know how many non-NULLs are
1765 in the frame.
1766 */
1768
1769 /**
1770 Execution state (windowing): Used for AND, OR to be able to invert window
1771 functions in optimized mode.
1772
1773 For the optimized code path of BIT_XXX wfs, we keep track of the number of
1774 bit values (0's or 1's; see below) seen in a frame using a 64 bits counter
1775 pr bit. This lets us compute the value of OR by just inspecting:
1776
1777 - the number of 1's in the previous frame
1778 - whether any removed row(s) is a 1
1779 - whether any added row(s) is a 1
1780
1781 Similarly for AND, we keep track of the number of 0's seen for a particular
1782 bit. To do this trick we need a counter per bit position. This array holds
1783 these counters.
1784
1785 Note that for XOR, the inverse operation is identical to the operation,
1786 so we don't need the above.
1787 */
1789 /*
1790 Size of allocated array m_digit_cnt.
1791 The size is DIGIT_CNT_CARD (for integer types) or ::max_length * 8 for bit
1792 strings.
1793 */
1795
1796 static constexpr uint DIGIT_CNT_CARD = sizeof(ulonglong) * 8;
1797
1798 protected:
1799 bool m_is_xor; ///< true iff BIT_XOR
1800
1801 public:
1802 Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg,
1803 PT_window *w)
1804 : Item_sum(pos, item_par, w),
1805 reset_bits(reset_arg),
1806 bits(reset_arg),
1808 m_count(0),
1812 m_is_xor(false) {}
1813
1814 /// Copy constructor, used for executing subqueries with temporary tables
1816 : Item_sum(thd, item),
1817 reset_bits(item->reset_bits),
1818 bits(item->bits),
1820 hybrid_type(item->hybrid_type),
1821 m_count(item->m_count),
1825 m_is_xor(item->m_is_xor) {
1826 /*
1827 This constructor should only be called during the Optimize stage.
1828 Asserting that the item was not evaluated yet.
1829 */
1830 assert(item->value_buff.length() == 1);
1831 assert(item->bits == item->reset_bits);
1832 }
1833
1834 Item *result_item(Field *) override {
1835 return new Item_aggr_bit_field(this, reset_bits);
1836 }
1837
1838 enum Sumfunctype sum_func() const override { return SUM_BIT_FUNC; }
1839 enum Item_result result_type() const override { return hybrid_type; }
1840 void clear() override;
1841 longlong val_int() override;
1842 double val_real() override;
1843 String *val_str(String *str) override;
1844 my_decimal *val_decimal(my_decimal *decimal_value) override;
1845 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1846 bool get_time(MYSQL_TIME *ltime) override;
1847 void reset_field() override;
1848 void update_field() override;
1849 bool resolve_type(THD *) override;
1850 bool fix_fields(THD *thd, Item **ref) override;
1851 void cleanup() override {
1852 bits = reset_bits;
1853 // At end of one execution of statement, free buffer to reclaim memory:
1856 }
1857
1858 /**
1859 Common implementation of Item_sum_or::add, Item_sum_and:add
1860 and Item_sum_xor::add.
1861 */
1862 bool add() override;
1863 /// @returns true iff this is BIT_AND.
1864 inline bool is_and() const { return reset_bits != 0; }
1865
1866 private:
1867 /**
1868 Accumulate the value of 's1' (if in string mode) or of 'b1' (if in integer
1869 mode). Updates 'value_buff' or 'bits'.
1870
1871 @param s1 argument to accumulate
1872 @param b1 argument to accumulate
1873
1874 @returns true if error
1875 */
1876 bool add_bits(const String *s1, ulonglong b1);
1877
1878 /**
1879 For windowing: perform inverse aggregation. "De-accumulate" the value of
1880 's1' (if in string mode) or of 'b1' (if in integer mode). Updates
1881 'value_buff' or 'bits'.
1882
1883 For BIT_XOR we simply apply XOR as it's its inverse operation. For BIT_OR
1884 and BIT_AND we do the rest below.
1885
1886 For each bit in argument, decrement the corresponding bits's counter
1887 ('m_digit_cnt') for that bit as follows: for BIT_AND, decrement the
1888 counter if we see a zero in that bit; for BIT_OR decrement the counter if
1889 we see a 1 in that bit. Next, update 'value_buff' or 'bits' using the
1890 resulting counters: for each bit, for BIT_AND, set bit if we have counter
1891 == 0, i.e. we have no zero bits for that bit in the frame (yet). For
1892 BIT_OR, set bit if we have counter > 0, i.e. at least one row in the frame
1893 has that bit set.
1894
1895 @param s1 the bits to be inverted from the aggregate value
1896 @param b1 the bits to be inverted from the aggregate value
1897 */
1898 void remove_bits(const String *s1, ulonglong b1);
1899};
1900
1901class Item_sum_or final : public Item_sum_bit {
1902 public:
1903 Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
1904 : Item_sum_bit(pos, item_par, 0LL, w) {}
1905
1906 Item_sum_or(THD *thd, Item_sum_or *item) : Item_sum_bit(thd, item) {}
1907 const char *func_name() const override { return "bit_or"; }
1908 Item *copy_or_same(THD *thd) override;
1909};
1910
1911class Item_sum_and final : public Item_sum_bit {
1912 public:
1913 Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
1914 : Item_sum_bit(pos, item_par, ULLONG_MAX, w) {}
1915
1916 Item_sum_and(THD *thd, Item_sum_and *item) : Item_sum_bit(thd, item) {}
1917 const char *func_name() const override { return "bit_and"; }
1918 Item *copy_or_same(THD *thd) override;
1919};
1920
1921class Item_sum_xor final : public Item_sum_bit {
1922 public:
1923 Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
1924 : Item_sum_bit(pos, item_par, 0LL, w) {
1925 m_is_xor = true;
1926 }
1927
1928 Item_sum_xor(THD *thd, Item_sum_xor *item) : Item_sum_bit(thd, item) {}
1929 const char *func_name() const override { return "bit_xor"; }
1930 Item *copy_or_same(THD *thd) override;
1931};
1932
1933/*
1934 User defined aggregates
1935*/
1936
1937class Item_udf_sum : public Item_sum {
1939
1940 protected:
1942
1943 public:
1944 Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1945 : Item_sum(pos, opt_list, nullptr), udf(udf_arg) {
1947 }
1949 : Item_sum(thd, item), udf(item->udf) {
1950 udf.m_original = false;
1951 }
1952 ~Item_udf_sum() override {
1954 }
1955
1956 bool do_itemize(Parse_context *pc, Item **res) override;
1957 const char *func_name() const override { return udf.name(); }
1958 bool fix_fields(THD *thd, Item **ref) override {
1959 assert(!fixed);
1960
1961 if (init_sum_func_check(thd)) return true;
1962
1963 fixed = true;
1964 if (udf.fix_fields(thd, this, this->arg_count, this->args)) return true;
1965
1966 return check_sum_func(thd, ref);
1967 }
1968 enum Sumfunctype sum_func() const override { return UDF_SUM_FUNC; }
1969
1970 void clear() override;
1971 bool add() override;
1972 void reset_field() override {}
1973 void update_field() override {}
1974 void cleanup() override;
1975 void print(const THD *thd, String *str,
1976 enum_query_type query_type) const override;
1977};
1978
1979class Item_sum_udf_float final : public Item_udf_sum {
1980 public:
1981 Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
1982 : Item_udf_sum(pos, udf_arg, opt_list) {}
1984 : Item_udf_sum(thd, item) {}
1985 longlong val_int() override {
1986 assert(fixed);
1987 return (longlong)rint(Item_sum_udf_float::val_real());
1988 }
1989 double val_real() override;
1990 String *val_str(String *str) override;
1991 my_decimal *val_decimal(my_decimal *) override;
1992 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
1993 return get_date_from_real(ltime, fuzzydate);
1994 }
1995 bool get_time(MYSQL_TIME *ltime) override {
1996 return get_time_from_real(ltime);
1997 }
1998 bool resolve_type(THD *) override {
2001 return false;
2002 }
2003 Item *copy_or_same(THD *thd) override;
2004};
2005
2006class Item_sum_udf_int final : public Item_udf_sum {
2007 public:
2008 Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
2009 : Item_udf_sum(pos, udf_arg, opt_list) {}
2011 : Item_udf_sum(thd, item) {}
2012 longlong val_int() override;
2013 double val_real() override {
2014 assert(fixed);
2015 return (double)Item_sum_udf_int::val_int();
2016 }
2017 String *val_str(String *str) override;
2018 my_decimal *val_decimal(my_decimal *) override;
2019 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2020 return get_date_from_int(ltime, fuzzydate);
2021 }
2022 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
2023 enum Item_result result_type() const override { return INT_RESULT; }
2024 bool resolve_type(THD *) override {
2026 return false;
2027 }
2028 Item *copy_or_same(THD *thd) override;
2029};
2030
2031class Item_sum_udf_str final : public Item_udf_sum {
2032 public:
2033 Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
2034 : Item_udf_sum(pos, udf_arg, opt_list) {}
2036 : Item_udf_sum(thd, item) {}
2037 String *val_str(String *) override;
2038 double val_real() override {
2039 int err_not_used;
2040 const char *end_not_used;
2041 String *res;
2042 res = val_str(&str_value);
2043 return res ? my_strntod(res->charset(), res->ptr(), res->length(),
2044 &end_not_used, &err_not_used)
2045 : 0.0;
2046 }
2047 longlong val_int() override {
2048 int err_not_used;
2049 String *res;
2050 const CHARSET_INFO *cs;
2051
2052 if (!(res = val_str(&str_value))) return 0; /* Null value */
2053 cs = res->charset();
2054 const char *end = res->ptr() + res->length();
2055 return cs->cset->strtoll10(cs, res->ptr(), &end, &err_not_used);
2056 }
2058 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2059 return get_date_from_string(ltime, fuzzydate);
2060 }
2061 bool get_time(MYSQL_TIME *ltime) override {
2062 return get_time_from_string(ltime);
2063 }
2064 enum Item_result result_type() const override { return STRING_RESULT; }
2065 bool resolve_type(THD *) override;
2066 Item *copy_or_same(THD *thd) override;
2067};
2068
2070 public:
2071 Item_sum_udf_decimal(const POS &pos, udf_func *udf_arg,
2072 PT_item_list *opt_list)
2073 : Item_udf_sum(pos, udf_arg, opt_list) {}
2075 : Item_udf_sum(thd, item) {}
2076 String *val_str(String *) override;
2077 double val_real() override;
2078 longlong val_int() override;
2079 my_decimal *val_decimal(my_decimal *) override;
2080 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2081 return get_date_from_decimal(ltime, fuzzydate);
2082 }
2083 bool get_time(MYSQL_TIME *ltime) override {
2084 return get_time_from_decimal(ltime);
2085 }
2086 enum Item_result result_type() const override { return DECIMAL_RESULT; }
2087 bool resolve_type(THD *) override {
2090 return false;
2091 }
2092 Item *copy_or_same(THD *thd) override;
2093};
2094
2095int group_concat_key_cmp_with_distinct(const void *arg, const void *key1,
2096 const void *key2);
2097int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2098 const void *key2);
2099int dump_leaf_key(void *key_arg, element_count count [[maybe_unused]],
2100 void *item_arg);
2101
2102class Item_func_group_concat final : public Item_sum {
2104
2105 /// True if GROUP CONCAT has the DISTINCT attribute
2107 /// The number of ORDER BY items.
2109 /// The number of selected items, aka the concat field list
2111 /// Resolver context, points to containing query block
2113 /// String containing separator between group items
2115 /// Describes the temporary table used to perform group concat
2119 TREE *tree{nullptr};
2120
2121 /**
2122 If DISTINCT is used with this GROUP_CONCAT, this member is used to filter
2123 out duplicates.
2124 @see Item_func_group_concat::setup
2125 @see Item_func_group_concat::add
2126 @see Item_func_group_concat::clear
2127 */
2129 /// Temporary table used to perform group concat
2130 TABLE *table{nullptr};
2132 uint row_count{0};
2133 /**
2134 The maximum permitted result length in bytes as set in
2135 group_concat_max_len system variable
2136 */
2138 bool warning_for_row{false};
2140 /// True if result has been written to output buffer.
2142 /**
2143 Following is 0 normal object and pointer to original one for copy
2144 (to correctly free resources)
2145 */
2147
2148 friend int group_concat_key_cmp_with_distinct(const void *arg,
2149 const void *key1,
2150 const void *key2);
2151 friend int group_concat_key_cmp_with_order(const void *arg, const void *key1,
2152 const void *key2);
2153 friend int dump_leaf_key(void *key_arg, element_count count [[maybe_unused]],
2154 void *item_arg);
2155
2156 public:
2157 Item_func_group_concat(const POS &pos, bool is_distinct,
2158 PT_item_list *select_list,
2159 PT_order_list *opt_order_list, String *separator,
2160 PT_window *w);
2161
2164 assert(original != nullptr || unique_filter == nullptr);
2165 }
2166
2167 bool do_itemize(Parse_context *pc, Item **res) override;
2168 void cleanup() override;
2169
2170 enum Sumfunctype sum_func() const override { return GROUP_CONCAT_FUNC; }
2171 const char *func_name() const override { return "group_concat"; }
2172 Item_result result_type() const override { return STRING_RESULT; }
2173 Field *make_string_field(TABLE *table_arg) const override;
2174 void clear() override;
2175 bool add() override;
2176 void reset_field() override { assert(0); } // not used
2177 void update_field() override { assert(0); } // not used
2178 bool fix_fields(THD *, Item **) override;
2179 bool setup(THD *thd) override;
2180 void make_unique() override;
2181 double val_real() override;
2182 longlong val_int() override {
2183 String *res;
2184 int error;
2185 if (!(res = val_str(&str_value))) return (longlong)0;
2186 const char *end_ptr = res->ptr() + res->length();
2187 return my_strtoll10(res->ptr(), &end_ptr, &error);
2188 }
2189 my_decimal *val_decimal(my_decimal *decimal_value) override {
2190 return val_decimal_from_string(decimal_value);
2191 }
2192 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2193 return get_date_from_string(ltime, fuzzydate);
2194 }
2195 bool get_time(MYSQL_TIME *ltime) override {
2196 return get_time_from_string(ltime);
2197 }
2198
2199 bool has_distinct() const noexcept { return distinct; }
2200 const String *get_separator_str() const noexcept { return separator; }
2201 uint32_t get_group_concat_max_len() const noexcept {
2202 return group_concat_max_len;
2203 }
2204 const Mem_root_array<ORDER> &get_order_array() const noexcept {
2205 return order_array;
2206 }
2207
2208 String *val_str(String *str) override;
2209 Item *copy_or_same(THD *thd) override;
2210 void no_rows_in_result() override;
2211 void print(const THD *thd, String *str,
2212 enum_query_type query_type) const override;
2213 bool change_context_processor(uchar *arg) override {
2214 context = pointer_cast<Item_ident::Change_context *>(arg)->m_context;
2215 return false;
2216 }
2217
2219 Window_evaluation_requirements *) override {
2221 return true;
2222 }
2223};
2224
2225/**
2226 Common parent class for window functions that always work on the entire
2227 partition, even if a frame is defined.
2228
2229 The subclasses can be divided in two disjoint sub-categories:
2230 - one-pass
2231 - two-pass (requires partition cardinality to be evaluated)
2232 cf. method needs_partition_cardinality.
2233*/
2236
2237 public:
2238 Item_non_framing_wf(const POS &pos, PT_window *w) : Item_sum(pos, w) {}
2240 : Item_sum(pos, a, w) {}
2242 : Item_sum(pos, opt_list, w) {}
2244
2245 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
2246 return get_date_from_numeric(ltime, fuzzydate);
2247 }
2248
2249 bool get_time(MYSQL_TIME *ltime) override {
2250 return get_time_from_numeric(ltime);
2251 }
2252
2253 void reset_field() override { assert(false); }
2254 void update_field() override { assert(false); }
2255 bool add() override {
2256 assert(false);
2257 return false;
2258 }
2259
2260 bool fix_fields(THD *thd, Item **items) override;
2261
2262 bool framing() const override { return false; }
2263};
2264
2265/**
2266 ROW_NUMBER window function, cf. SQL 2003 Section 6.10 <window function>
2267*/
2269 // Execution state variables
2270 ulonglong m_ctr; ///< Increment for each row in partition
2271
2272 public:
2274 : Item_non_framing_wf(pos, w), m_ctr(0) {
2275 unsigned_flag = true;
2276 }
2277
2278 const char *func_name() const override { return "row_number"; }
2279 enum Sumfunctype sum_func() const override { return ROW_NUMBER_FUNC; }
2280
2281 bool resolve_type(THD *thd [[maybe_unused]]) override {
2283 return false;
2284 }
2285
2286 longlong val_int() override;
2287 double val_real() override;
2288 my_decimal *val_decimal(my_decimal *buff) override;
2289 String *val_str(String *) override;
2290
2291 void clear() override;
2292
2293 Item_result result_type() const override { return INT_RESULT; }
2294
2296 Window_evaluation_requirements *) override {
2297 return false;
2298 }
2299};
2300
2301/**
2302 RANK or DENSE_RANK window function, cf. SQL 2003 Section 6.10 <window
2303 function>
2304*/
2307 bool m_dense; ///< If true, the object represents DENSE_RANK
2308 // Execution state variables
2309 ulonglong m_rank_ctr; ///< Increment when window order columns change
2310 ulonglong m_duplicates; ///< Needed to make RANK different from DENSE_RANK
2312 m_previous; ///< Values of previous row's ORDER BY items
2313 public:
2314 Item_rank(const POS &pos, bool dense, PT_window *w)
2315 : Item_non_framing_wf(pos, w),
2316 m_dense(dense),
2317 m_rank_ctr(0),
2318 m_duplicates(0),
2320 unsigned_flag = true;
2321 }
2322
2323 ~Item_rank() override;
2324
2325 const char *func_name() const override {
2326 return m_dense ? "dense_rank" : "rank";
2327 }
2328
2329 enum Sumfunctype sum_func() const override {
2331 }
2332
2333 bool resolve_type(THD *thd [[maybe_unused]]) override {
2335 return false;
2336 }
2337
2338 longlong val_int() override;
2339 double val_real() override;
2340 my_decimal *val_decimal(my_decimal *buff) override;
2341 String *val_str(String *) override;
2342
2343 void update_after_wf_arguments_changed(THD *thd) override;
2344 bool check_wf_semantics1(THD *thd, Query_block *select,
2345 Window_evaluation_requirements *reqs) override;
2346 /**
2347 Clear state for a new partition
2348 */
2349 void clear() override;
2350 Item_result result_type() const override { return INT_RESULT; }
2351};
2352
2353/**
2354 CUME_DIST window function, cf. SQL 2003 Section 6.10 <window function>
2355*/
2358
2359 public:
2361
2362 const char *func_name() const override { return "cume_dist"; }
2363 enum Sumfunctype sum_func() const override { return CUME_DIST_FUNC; }
2364
2365 bool resolve_type(THD *thd [[maybe_unused]]) override {
2367 return false;
2368 }
2369
2370 bool check_wf_semantics1(THD *thd, Query_block *select,
2371 Window_evaluation_requirements *reqs) override;
2372
2373 bool needs_partition_cardinality() const override { return true; }
2374 void clear() override {}
2375 longlong val_int() override;
2376 double val_real() override;
2377 String *val_str(String *) override;
2379 Item_result result_type() const override { return REAL_RESULT; }
2380};
2381
2382/**
2383 PERCENT_RANK window function, cf. SQL 2003 Section 6.10 <window function>
2384*/
2387 // Execution state variables
2388 ulonglong m_rank_ctr; ///< Increment when window order columns change
2389 ulonglong m_peers; ///< Needed to make PERCENT_RANK same for peers
2390 /**
2391 Set when the last peer has been visited. Needed to increment m_rank_ctr.
2392 */
2394
2395 public:
2397 : Item_non_framing_wf(pos, w),
2398 m_rank_ctr(0),
2399 m_peers(0),
2400 m_last_peer_visited(false) {}
2401
2403 const char *func_name() const override { return "percent_rank"; }
2404 enum Sumfunctype sum_func() const override { return PERCENT_RANK_FUNC; }
2405
2406 bool resolve_type(THD *thd [[maybe_unused]]) override {
2408 return false;
2409 }
2410
2411 bool check_wf_semantics1(THD *thd, Query_block *select,
2412 Window_evaluation_requirements *reqs) override;
2413 bool needs_partition_cardinality() const override { return true; }
2414
2415 void clear() override;
2416 longlong val_int() override;
2417 double val_real() override;
2418 String *val_str(String *) override;
2420 Item_result result_type() const override { return REAL_RESULT; }
2421};
2422
2423/**
2424 NTILE window function, cf. SQL 2011 Section 6.10 <window function>
2425*/
2429
2430 public:
2431 Item_ntile(const POS &pos, Item *a, PT_window *w)
2432 : Item_non_framing_wf(pos, a, w), m_value(0) {
2433 unsigned_flag = true;
2434 }
2435
2436 const char *func_name() const override { return "ntile"; }
2437 enum Sumfunctype sum_func() const override { return NTILE_FUNC; }
2438
2439 bool resolve_type(THD *thd) override {
2440 if (args[0]->propagate_type(thd, MYSQL_TYPE_LONGLONG, true)) return true;
2442 return false;
2443 }
2444
2445 bool fix_fields(THD *thd, Item **items) override;
2446
2447 longlong val_int() override;
2448 double val_real() override;
2449 my_decimal *val_decimal(my_decimal *buff) override;
2450 String *val_str(String *) override;
2451
2452 bool check_wf_semantics1(THD *thd, Query_block *select,
2453 Window_evaluation_requirements *reqs) override;
2455 Item_result result_type() const override { return INT_RESULT; }
2456 void clear() override {}
2457 bool needs_partition_cardinality() const override { return true; }
2458};
2459
2460/**
2461 LEAD/LAG window functions, cf. SQL 2011 Section 6.10 <window function>
2462*/
2465 bool m_is_lead; ///< if true, the function is LEAD, else LAG
2466 int64 m_n; ///< canonicalized offset value
2470 /**
2471 Execution state: if set, we already have a value for current row.
2472 State is used to avoid interference with other LEAD/LAG functions on
2473 the same window, since they share the same eval loop and they should
2474 trigger evaluation only when they are on the "right" row relative to
2475 current row. For other offsets, return NULL if we don't know the value
2476 for this function yet, or if we do (m_has_value==true), return the
2477 found value.
2478 */
2480 bool m_use_default; ///< execution state: use default value for current row
2482
2483 public:
2484 Item_lead_lag(const POS &pos, bool lead,
2485 PT_item_list *opt_list, // [0] expr, [1] offset, [2] default
2486 enum_null_treatment null_treatment, PT_window *w)
2487 : Item_non_framing_wf(pos, opt_list, w),
2488 m_null_treatment(null_treatment),
2489 m_is_lead(lead),
2490 m_n(0),
2494 m_has_value(false),
2495 m_use_default(false) {}
2496
2497 const char *func_name() const override {
2498 return (m_is_lead ? "lead" : "lag");
2499 }
2500 enum Sumfunctype sum_func() const override { return LEAD_LAG_FUNC; }
2501
2502 bool resolve_type(THD *thd) override;
2503 bool fix_fields(THD *thd, Item **items) override;
2504 TYPELIB *get_typelib() const override;
2505 void update_after_wf_arguments_changed(THD *thd) override;
2506 void clear() override;
2507 bool check_wf_semantics1(THD *thd, Query_block *select,
2508 Window_evaluation_requirements *reqs) override;
2510 enum Item_result result_type() const override { return m_hybrid_type; }
2511
2512 longlong val_int() override;
2513 double val_real() override;
2514 String *val_str(String *str) override;
2515 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2516
2517 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2518 bool get_time(MYSQL_TIME *ltime) override;
2519 bool val_json(Json_wrapper *wr) override;
2520
2521 bool needs_partition_cardinality() const override {
2522 /*
2523 A possible optimization here: if LAG, we are only interested in rows we
2524 have already seen, so we might compute the result without reading the
2525 entire partition as soon as we have the current row. Similarly, a small
2526 LEAD value might avoid reading the entire partition also, giving shorter
2527 time to first result. For now, we read the entirely partition for these
2528 window functions - for simplicity.
2529 */
2530 return true;
2531 }
2532
2533 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2534 mem_root_deque<Item *> *fields) override;
2535
2537 bool has_value() const { return m_has_value; }
2538
2540 bool use_default() const { return m_use_default; }
2541
2542 private:
2543 bool setup_lead_lag();
2544 /**
2545 Core logic of LEAD/LAG window functions
2546
2547 @return true if computation yielded a NULL or error
2548 */
2549 bool compute();
2550};
2551
2552/**
2553 FIRST_VALUE/LAST_VALUE window functions, cf. SQL 2011 Section 6.10 <window
2554 function>
2555*/
2557 bool m_is_first; ///< if true, the function is FIRST_VALUE, else LAST_VALUE
2561 int64 cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2563
2564 public:
2565 Item_first_last_value(const POS &pos, bool first, Item *a,
2566 enum_null_treatment null_treatment, PT_window *w)
2567 : Item_sum(pos, a, w),
2568 m_is_first(first),
2569 m_null_treatment(null_treatment),
2572 cnt(0) {}
2573
2574 const char *func_name() const override {
2575 return m_is_first ? "first_value" : "last_value";
2576 }
2577
2578 enum Sumfunctype sum_func() const override { return FIRST_LAST_VALUE_FUNC; }
2579
2580 bool resolve_type(THD *thd) override;
2581 bool fix_fields(THD *thd, Item **items) override;
2582 void update_after_wf_arguments_changed(THD *thd) override;
2583 void clear() override;
2584 bool check_wf_semantics1(THD *thd, Query_block *select,
2585 Window_evaluation_requirements *reqs) override;
2586 enum Item_result result_type() const override { return m_hybrid_type; }
2587
2588 longlong val_int() override;
2589 double val_real() override;
2590 String *val_str(String *str) override;
2591 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2592
2593 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2594 bool get_time(MYSQL_TIME *ltime) override;
2595 bool val_json(Json_wrapper *wr) override;
2596
2597 void reset_field() override { assert(false); }
2598 void update_field() override { assert(false); }
2599 bool add() override {
2600 assert(false);
2601 return false;
2602 }
2603
2604 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2605 mem_root_deque<Item *> *fields) override;
2606 bool uses_only_one_row() const override { return true; }
2607
2608 private:
2609 bool setup_first_last();
2610 /**
2611 Core logic of FIRST/LAST_VALUE window functions
2612
2613 @return true if computation yielded a NULL or error
2614 */
2615 bool compute();
2616};
2617
2618/**
2619 NTH_VALUE window function, cf. SQL 2011 Section 6.10 <window
2620 function>
2621*/
2622class Item_nth_value : public Item_sum {
2624 int64 m_n; ///< The N of the function
2625 bool m_from_last; ///< true iff FROM_LAST was specified
2629 int64 m_cnt; ///< used when evaluating on-the-fly (non-buffered processing)
2630
2632
2633 public:
2634 Item_nth_value(const POS &pos, PT_item_list *a, bool from_last,
2635 enum_null_treatment null_treatment, PT_window *w)
2636 : Item_sum(pos, a, w),
2637 m_null_treatment(null_treatment),
2638 m_n(0),
2639 m_from_last(from_last),
2642 m_cnt(0) {}
2643
2644 const char *func_name() const override { return "nth_value"; }
2645 enum Sumfunctype sum_func() const override { return NTH_VALUE_FUNC; }
2646
2647 bool resolve_type(THD *thd) override;
2648 bool fix_fields(THD *thd, Item **items) override;
2649 void update_after_wf_arguments_changed(THD *thd) override;
2650 bool setup_nth();
2651 void clear() override;
2652
2653 bool check_wf_semantics1(THD *thd, Query_block *select,
2654 Window_evaluation_requirements *reqs) override;
2656
2657 enum Item_result result_type() const override { return m_hybrid_type; }
2658
2659 longlong val_int() override;
2660 double val_real() override;
2661 String *val_str(String *str) override;
2662 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2663
2664 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2665 bool get_time(MYSQL_TIME *ltime) override;
2666 bool val_json(Json_wrapper *wr) override;
2667
2668 void reset_field() override { assert(false); }
2669 void update_field() override { assert(false); }
2670 bool add() override {
2671 assert(false);
2672 return false;
2673 }
2674
2675 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2676 mem_root_deque<Item *> *fields) override;
2677 bool uses_only_one_row() const override { return true; }
2678
2679 private:
2680 /**
2681 Core logic of NTH_VALUE window functions
2682
2683 @return true if computation yielded a NULL or error
2684 */
2685 bool compute();
2686};
2687
2688/**
2689 Class for implementation of the GROUPING function. The GROUPING
2690 function distinguishes super-aggregate rows from regular grouped
2691 rows. GROUP BY extensions such as ROLLUP and CUBE produce
2692 super-aggregate rows where the set of all values is represented
2693 by null. Using the GROUPING function, you can distinguish a null
2694 representing the set of all values in a super-aggregate row from
2695 a NULL in a regular row.
2696*/
2698 public:
2701 }
2702 const char *func_name() const override { return "grouping"; }
2703 enum Functype functype() const override { return GROUPING_FUNC; }
2704 longlong val_int() override;
2705 bool aggregate_check_group(uchar *arg) override;
2706 bool fix_fields(THD *thd, Item **ref) override;
2707 void update_used_tables() override;
2708 bool aggregate_check_distinct(uchar *arg) override;
2709
2710 private:
2711 /// The query block in which this function is called.
2713};
2714
2715/**
2716 A wrapper Item that contains a number of aggregate items, one for each level
2717 of rollup (see Item_rollup_group_item for numbering conventions). When
2718 aggregating, every aggregator is either reset or updated as per the correct
2719 level, and when returning a value, the correct child item corresponding to
2720 the current rollup level is queried.
2721 */
2723 public:
2724 explicit Item_rollup_sum_switcher(List<Item> *sum_func_per_level)
2725 : Item_sum((*sum_func_per_level)[0]),
2726 m_num_levels(sum_func_per_level->size()) {
2727 args = (*THR_MALLOC)->ArrayAlloc<Item *>(sum_func_per_level->size());
2728 int i = 0;
2729 for (Item &item : *sum_func_per_level) {
2730 args[i++] = &item;
2731 }
2735 hidden = master()->hidden;
2739 }
2740 double val_real() override;
2741 longlong val_int() override;
2742 String *val_str(String *str) override;
2744 bool val_json(Json_wrapper *result) override;
2745 bool is_null() override;
2746 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
2747 bool get_time(MYSQL_TIME *ltime) override;
2748 const char *func_name() const override { return "rollup_sum_switcher"; }
2749 table_map used_tables() const override { return master()->used_tables(); }
2750 Item_result result_type() const override { return master()->result_type(); }
2751 bool resolve_type(THD *) override {
2753 return false;
2754 }
2755 void print(const THD *thd, String *str,
2756 enum_query_type query_type) const override;
2757 Field *create_tmp_field(bool group, TABLE *table) override;
2758
2759 enum Sumfunctype sum_func() const override { return master()->sum_func(); }
2760 enum Sumfunctype real_sum_func() const override {
2762 }
2763 void reset_field() override { assert(false); }
2764 void update_field() override { assert(false); }
2765 void clear() override;
2766 bool add() override {
2767 assert(false);
2768 return true;
2769 }
2770
2771 bool reset_and_add_for_rollup(int last_unchanged_group_item_idx);
2772
2773 int set_aggregator(Aggregator::Aggregator_type aggregator) override;
2774 bool aggregator_setup(THD *thd) override;
2775 inline bool aggregator_add_all() {
2776 for (int i = 0; i < m_num_levels; ++i) {
2777 if (child(i)->aggregator_add()) {
2778 return true;
2779 }
2780 }
2781 return false;
2782 }
2783
2784 // Used when create_tmp_table() needs to delay application of aggregate
2785 // functions to a later stage in the query processing.
2786 Item *get_arg(uint i) override { return master()->get_arg(i); }
2787 const Item *get_arg(uint i) const override { return master()->get_arg(i); }
2788 Item *set_arg(THD *thd, uint i, Item *new_val) override {
2789 Item *ret = nullptr;
2790 for (int j = 0; j < m_num_levels; ++j) {
2791 ret = child(j)->set_arg(thd, i, new_val);
2792 }
2793 return ret; // Return the last one, arbitrarily.
2794 }
2795 uint argument_count() const override { return master()->argument_count(); }
2796
2797 // Used by AggregateIterator.
2799 inline Item_sum *master() const { return child(0); }
2800
2801 bool is_rollup_sum_wrapper() const override { return true; }
2802 const Item_sum *unwrap_sum() const override { return master(); }
2803 Item_sum *unwrap_sum() override { return master(); }
2804
2805 private:
2806 inline Item *current_arg() const;
2807 inline Item_sum *child(size_t i) const {
2808 return down_cast<Item_sum *>(args[i]);
2809 }
2810
2811 const int m_num_levels;
2813};
2814/// Implements ST_Collect which aggregates geometries into Multipoints,
2815/// Multilinestrings, Multipolygons and Geometrycollections.
2816
2818 private:
2819 std::optional<gis::srid_t> srid;
2820 std::unique_ptr<gis::Geometrycollection> m_geometrycollection;
2821 void pop_front();
2822
2823 public:
2825 Item_sum_collect(THD *thd, Item_sum *item) : Item_sum(thd, item) {
2827 }
2828 Item_sum_collect(const POS &pos, Item *a, PT_window *w, bool distinct)
2829 : Item_sum(pos, a, w) {
2830 set_distinct(distinct);
2832 }
2833
2834 my_decimal *val_decimal(my_decimal *decimal_buffer) override;
2835 longlong val_int() override { return val_int_from_string(); }
2836 double val_real() override { return val_real_from_string(); }
2837 bool get_date(MYSQL_TIME *, my_time_flags_t) override { return true; }
2838 bool get_time(MYSQL_TIME *) override { return true; }
2839 enum Sumfunctype sum_func() const override { return GEOMETRY_AGGREGATE_FUNC; }
2840 Item_result result_type() const override { return STRING_RESULT; }
2842 /*
2843 In contrast to Item_sum, Item_sum_collect always uses Aggregator_simple,
2844 and only needs to reset its aggregator when called.
2845 */
2846 if (aggr != nullptr) {
2847 aggr->clear();
2848 return false;
2849 }
2850
2851 aggr = new (*THR_MALLOC) Aggregator_simple(this);
2852 return aggr ? false : true;
2853 }
2854
2855 bool fix_fields(THD *thd, Item **ref) override;
2856 /*
2857 We need to override check_wf_semantics1 because it reports an error when
2858 with_distinct is set.
2859 */
2860 bool check_wf_semantics1(THD *thd, Query_block *,
2862
2863 Item *copy_or_same(THD *thd) override;
2864
2865 void update_field() override;
2866 void reset_field() override;
2867
2868 String *val_str(String *str) override;
2869
2870 bool add() override;
2871
2872 void read_result_field();
2873 void store_result_field();
2874
2875 void clear() override;
2876 const char *func_name() const override { return "st_collect"; }
2877};
2878
2879#endif /* ITEM_SUM_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
The distinct aggregator.
Definition: item_sum.h:816
uint tree_key_length
Definition: item_sum.h:869
uint32 * field_lengths
Definition: item_sum.h:846
bool arg_is_null(bool use_null_value) override
NULLness of being-aggregated argument.
Definition: item_sum.cc:2225
bool endup_done
Definition: item_sum.h:827
Const_distinct
Definition: item_sum.h:871
@ CONST_NULL
Set to true if the result is known to be always NULL.
Definition: item_sum.h:882
@ CONST_NOT_NULL
Set to true if count distinct is on only const items.
Definition: item_sum.h:889
@ NOT_CONST
Definition: item_sum.h:872
static int composite_key_cmp(const void *arg, const void *a, const void *b)
Correctly compare composite keys.
Definition: item_sum.cc:1009
void endup() override
Calculate the aggregate function value.
Definition: item_sum.cc:1402
~Aggregator_distinct() override
Definition: item_sum.cc:2175
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:900
double arg_val_real() override
Floating point value of being-aggregated argument.
Definition: item_sum.cc:2220
void clear() override
Invalidate calculated value and clear the distinct rows.
Definition: item_sum.cc:1296
bool setup(THD *) override
Called before feeding the first row.
Definition: item_sum.cc:1080
bool unique_walk_function(void *element)
Aggregate a distinct row from the distinct hash table.
Definition: item_sum.cc:2168
Unique * tree
Definition: item_sum.h:861
Temp_table_param * tmp_table_param
Definition: item_sum.h:852
bool add() override
Process incoming row.
Definition: item_sum.cc:1328
TABLE * table
Definition: item_sum.h:838
Aggregator_type Aggrtype() override
Definition: item_sum.h:911
my_decimal * arg_val_decimal(my_decimal *value) override
Decimal value of being-aggregated argument.
Definition: item_sum.cc:2215
enum Aggregator_distinct::Const_distinct const_distinct
Aggregator_distinct(Item_sum *sum)
Definition: item_sum.h:903
The pass-through aggregator.
Definition: item_sum.h:930
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:936
Aggregator_simple(Item_sum *sum)
Definition: item_sum.h:932
bool setup(THD *thd) override
Called before adding the first row.
Definition: item_sum.h:935
Aggregator_type Aggrtype() override
Definition: item_sum.h:933
my_decimal * arg_val_decimal(my_decimal *value) override
Decimal value of being-aggregated argument.
Definition: item_sum.cc:2192
void endup() override
Called when there are no more data and the final value is to be retrieved.
Definition: item_sum.h:938
double arg_val_real() override
Floating point value of being-aggregated argument.
Definition: item_sum.cc:2196
bool add() override
Called when there's a new value to be aggregated.
Definition: item_sum.h:937
bool arg_is_null(bool use_null_value) override
NULLness of being-aggregated argument.
Definition: item_sum.cc:2200
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:205
Definition: field.h:573
Definition: item_sum.h:1191
Item_aggr_avg_field(Item_sum_avg *item)
Definition: item_sum.cc:3739
String * val_str(String *) override
Definition: item_sum.cc:3781
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3767
uint m_prec_increment
Definition: item_sum.h:1203
uint m_dec_bin_size
Definition: item_sum.h:1202
double val_real() override
Definition: item_sum.cc:3756
enum Type type() const override
Definition: item_sum.h:1194
uint m_scale
Definition: item_sum.h:1201
uint m_precision
Definition: item_sum.h:1200
This is used in connection with an Item_sum_bit,.
Definition: item_sum.h:1207
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3871
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3864
enum Type type() const override
Definition: item_sum.h:1216
ulonglong m_reset_bits
Definition: item_sum.h:1219
longlong val_int() override
Definition: item_sum.cc:3803
double val_real() override
Definition: item_sum.cc:3818
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3835
String * val_str(String *) override
Definition: item_sum.cc:3843
Item_aggr_bit_field(Item_sum_bit *item, ulonglong reset_bits)
Definition: item_sum.cc:3786
Common abstract class for aggregate field classes that return numeric values: Item_aggr_avg_field Ite...
Definition: item_sum.h:1176
longlong val_int() override
Definition: item_sum.h:1178
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1182
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1185
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.h:1188
Definition: item_sum.h:1497
enum Type type() const override
Definition: item_sum.h:1500
enum Item_result result_type() const override
Definition: item_sum.h:1503
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:1504
double val_real() override
Definition: item_sum.cc:3881
Item_aggr_std_field(Item_sum_std *item)
Definition: item_sum.cc:3878
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3887
Definition: item_sum.h:1363
double val_real() override
Definition: item_sum.cc:3919
Item_aggr_variance_field(Item_sum_variance *item)
Definition: item_sum.cc:3907
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_sum.h:1372
String * val_str(String *str) override
Definition: item_sum.h:1368
my_decimal * val_decimal(my_decimal *dec_buf) override
Definition: item_sum.h:1369
uint m_sample
Definition: item_sum.h:1380
enum Type type() const override
Definition: item_sum.h:1366
This is used in connection with a parent aggregate Item:
Definition: item_sum.h:1145
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item_sum.h:1156
Item_result m_result_type
Stores the Item's result type.
Definition: item_sum.h:1150
Field * m_field
The tmp table's column containing the value of the set function.
Definition: item_sum.h:1148
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:1163
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1155
enum Item_result result_type() const override
Definition: item_sum.h:1153
Definition: item.h:6804
CUME_DIST window function, cf.
Definition: item_sum.h:2356
Item_cume_dist(const POS &pos, PT_window *w)
Definition: item_sum.h:2360
Item_non_framing_wf super
Definition: item_sum.h:2357
double val_real() override
Definition: item_sum.cc:4944
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2363
void clear() override
Definition: item_sum.h:2374
const char * func_name() const override
Definition: item_sum.h:2362
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:2373
String * val_str(String *) override
Definition: item_sum.cc:4964
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:4934
longlong val_int() override
Definition: item_sum.cc:4956
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2365
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:4968
Item_result result_type() const override
Definition: item_sum.h:2379
Definition: item.h:4389
FIRST_VALUE/LAST_VALUE window functions, cf.
Definition: item_sum.h:2556
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2578
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5172
void reset_field() override
Definition: item_sum.h:2597
const char * func_name() const override
Definition: item_sum.h:2574
bool setup_first_last()
Definition: item_sum.cc:5214
double val_real() override
Definition: item_sum.cc:5263
String * val_str(String *str) override
Definition: item_sum.cc:5318
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:5231
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:5202
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:5158
bool compute()
Core logic of FIRST/LAST_VALUE window functions.
Definition: item_sum.cc:5235
int64 cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2561
Item_result m_hybrid_type
Definition: item_sum.h:2559
enum Item_result result_type() const override
Definition: item_sum.h:2586
Item_cache * m_value
Definition: item_sum.h:2560
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5294
void update_field() override
Definition: item_sum.h:2598
enum_null_treatment m_null_treatment
Definition: item_sum.h:2558
Item_sum super
Definition: item_sum.h:2562
void clear() override
Definition: item_sum.cc:5225
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2606
bool add() override
Definition: item_sum.h:2599
Item_first_last_value(const POS &pos, bool first, Item *a, enum_null_treatment null_treatment, PT_window *w)
Definition: item_sum.h:2565
bool m_is_first
if true, the function is FIRST_VALUE, else LAST_VALUE
Definition: item_sum.h:2557
longlong val_int() override
Definition: item_sum.cc:5253
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5304
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5284
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5183
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5273
Definition: item_sum.h:2102
void clear() override
Definition: item_sum.cc:4425
bool m_result_finalized
True if result has been written to output buffer.
Definition: item_sum.h:2141
String result
Definition: item_sum.h:2117
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:2146
longlong val_int() override
Definition: item_sum.h:2182
const String * get_separator_str() const noexcept
Definition: item_sum.h:2200
uint32_t get_group_concat_max_len() const noexcept
Definition: item_sum.h:2201
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.h:2189
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:4171
uint row_count
Definition: item_sum.h:2132
void make_unique() override
Definition: item_sum.cc:4698
bool change_context_processor(uchar *arg) override
Definition: item_sum.h:2213
bool setup(THD *thd) override
Definition: item_sum.cc:4581
Item_sum super
Definition: item_sum.h:2103
bool distinct
True if GROUP CONCAT has the DISTINCT attribute.
Definition: item_sum.h:2106
TABLE * table
Temporary table used to perform group concat.
Definition: item_sum.h:2130
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:4092
double val_real() override
Definition: item_sum.cc:4706
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2170
String * val_str(String *str) override
Definition: item_sum.cc:4713
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:4128
bool force_copy_fields
Definition: item_sum.h:2139
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:4488
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2192
Unique * unique_filter
If DISTINCT is used with this GROUP_CONCAT, this member is used to filter out duplicates.
Definition: item_sum.h:2128
bool check_wf_semantics1(THD *, Query_block *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2218
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:4423
Mem_root_array< ORDER > order_array
Definition: item_sum.h:2131
TREE tree_base
Definition: item_sum.h:2118
void update_field() override
Definition: item_sum.h:2177
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:4738
Temp_table_param * tmp_table_param
Describes the temporary table used to perform group concat.
Definition: item_sum.h:2116
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:4350
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4415
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_sum.cc:4298
const char * func_name() const override
Definition: item_sum.h:2171
Item_result result_type() const override
Definition: item_sum.h:2172
Field * make_string_field(TABLE *table_arg) const override
Create a field to hold a string value from an item.
Definition: item_sum.cc:4382
uint m_order_arg_count
The number of ORDER BY items.
Definition: item_sum.h:2108
TREE * tree
Definition: item_sum.h:2119
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:4260
bool has_distinct() const noexcept
Definition: item_sum.h:2199
bool add() override
Definition: item_sum.cc:4437
Name_resolution_context * context
Resolver context, points to containing query block.
Definition: item_sum.h:2112
void reset_field() override
Definition: item_sum.h:2176
uint m_field_arg_count
The number of selected items, aka the concat field list.
Definition: item_sum.h:2110
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:2137
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2195
bool warning_for_row
Definition: item_sum.h:2138
String * separator
String containing separator between group items.
Definition: item_sum.h:2114
~Item_func_group_concat() override
Definition: item_sum.h:2163
const Mem_root_array< ORDER > & get_order_array() const noexcept
Definition: item_sum.h:2204
Class for implementation of the GROUPING function.
Definition: item_sum.h:2697
const Query_block * m_query_block
The query block in which this function is called.
Definition: item_sum.h:2712
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:6384
longlong val_int() override
Evaluation of the GROUPING function.
Definition: item_sum.cc:6333
Item_func_grouping(const POS &pos, PT_item_list *a)
Definition: item_sum.h:2699
const char * func_name() const override
Definition: item_sum.h:2702
bool fix_fields(THD *thd, Item **ref) override
Resolve the fields in the GROUPING function.
Definition: item_sum.cc:6278
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:6354
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_sum.cc:6396
enum Functype functype() const override
Definition: item_sum.h:2703
Definition: item_func.h:100
Item ** args
Array of pointers to arguments.
Definition: item_func.h:107
virtual Item * get_arg(uint i)
Get the i'th argument of the function that this object represents.
Definition: item_func.h:495
Functype
Definition: item_func.h:209
@ GROUPING_FUNC
Definition: item_func.h:263
virtual uint argument_count() const
Definition: item_func.h:131
table_map used_tables_cache
Value used in calculation of result of used_tables()
Definition: item_func.h:193
virtual const char * func_name() const =0
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:528
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:504
Item ** arguments() const
Definition: item_func.h:132
virtual void fix_num_length_and_dec()
Definition: item_func.cc:861
const char * original_db_name() const
Definition: item.h:4281
void set_original_field_name(const char *name_arg)
Definition: item.h:4278
const char * original_table_name() const
Definition: item.h:4282
Definition: item_func.h:1021
Definition: item.h:5126
LEAD/LAG window functions, cf.
Definition: item_sum.h:2463
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5591
bool has_value() const
Definition: item_sum.h:2537
bool m_is_lead
if true, the function is LEAD, else LAG
Definition: item_sum.h:2465
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:2521
const char * func_name() const override
Definition: item_sum.h:2497
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5744
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:5651
void set_use_default(bool value)
Definition: item_sum.h:2539
String * val_str(String *str) override
Definition: item_sum.cc:5731
bool m_use_default
execution state: use default value for current row
Definition: item_sum.h:2480
enum Item_result result_type() const override
Definition: item_sum.h:2510
Item_cache * m_default
Definition: item_sum.h:2469
bool compute()
Core logic of LEAD/LAG window functions.
Definition: item_sum.cc:5771
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:2484
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:5678
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2500
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5753
enum_null_treatment m_null_treatment
Definition: item_sum.h:2464
void clear() override
Definition: item_sum.cc:5690
bool use_default() const
Definition: item_sum.h:2540
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_sum.cc:5600
bool m_has_value
Execution state: if set, we already have a value for current row.
Definition: item_sum.h:2479
longlong val_int() override
Definition: item_sum.cc:5702
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5718
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5623
Item_result m_hybrid_type
Definition: item_sum.h:2467
int64 m_n
canonicalized offset value
Definition: item_sum.h:2466
double val_real() override
Definition: item_sum.cc:5710
void set_has_value(bool value)
Definition: item_sum.h:2536
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5541
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5761
bool setup_lead_lag()
Definition: item_sum.cc:5662
Item_cache * m_value
Definition: item_sum.h:2468
Item_non_framing_wf super
Definition: item_sum.h:2481
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:5697
Common parent class for window functions that always work on the entire partition,...
Definition: item_sum.h:2234
Item_non_framing_wf(const POS &pos, PT_window *w)
Definition: item_sum.h:2238
bool add() override
Definition: item_sum.h:2255
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2249
Item_non_framing_wf(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2239
Item_non_framing_wf(const POS &pos, PT_item_list *opt_list, PT_window *w)
Definition: item_sum.h:2241
Item_sum super
Definition: item_sum.h:2235
Item_non_framing_wf(THD *thd, Item_non_framing_wf *i)
Definition: item_sum.h:2243
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2245
void update_field() override
Definition: item_sum.h:2254
void reset_field() override
Definition: item_sum.h:2253
bool framing() const override
All aggregates are framing, i.e.
Definition: item_sum.h:2262
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:4774
NTH_VALUE window function, cf.
Definition: item_sum.h:2622
int64 m_cnt
used when evaluating on-the-fly (non-buffered processing)
Definition: item_sum.h:2629
void update_field() override
Definition: item_sum.h:2669
bool compute()
Core logic of NTH_VALUE window functions.
Definition: item_sum.cc:5434
String * val_str(String *str) override
Definition: item_sum.cc:5501
Item_sum super
Definition: item_sum.h:2631
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5048
enum Item_result result_type() const override
Definition: item_sum.h:2657
Item_result m_hybrid_type
Definition: item_sum.h:2626
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5487
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5521
bool setup_nth()
Definition: item_sum.cc:5393
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5342
enum_field_types m_hybrid_field_type
Definition: item_sum.h:2627
int64 m_n
The N of the function.
Definition: item_sum.h:2624
double val_real() override
Definition: item_sum.cc:5477
bool m_from_last
true iff FROM_LAST was specified
Definition: item_sum.h:2625
Item_cache * m_value
Definition: item_sum.h:2628
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5531
enum_null_treatment m_null_treatment
Definition: item_sum.h:2623
void reset_field() override
Definition: item_sum.h:2668
longlong val_int() override
Definition: item_sum.cc:5467
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:2634
void clear() override
Definition: item_sum.cc:5404
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:5328
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:5382
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2645
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:5410
bool add() override
Definition: item_sum.h:2670
const char * func_name() const override
Definition: item_sum.h:2644
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5511
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:5414
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:2677
NTILE window function, cf.
Definition: item_sum.h:2426
void clear() override
Definition: item_sum.h:2456
Item_non_framing_wf super
Definition: item_sum.h:2427
String * val_str(String *) override
Definition: item_sum.cc:5127
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2439
const char * func_name() const override
Definition: item_sum.h:2436
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:2457
bool check_wf_semantics2(Window_evaluation_requirements *reqs) override
Like check_wf_semantics1.
Definition: item_sum.cc:5142
bool fix_fields(THD *thd, Item **items) override
Definition: item_sum.cc:5066
double val_real() override
Definition: item_sum.cc:5122
longlong val_int() override
Definition: item_sum.cc:5072
longlong m_value
Definition: item_sum.h:2428
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:5129
Item_ntile(const POS &pos, Item *a, PT_window *w)
Definition: item_sum.h:2431
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2437
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:5134
Item_result result_type() const override
Definition: item_sum.h:2455
PERCENT_RANK window function, cf.
Definition: item_sum.h:2385
String * val_str(String *) override
Definition: item_sum.cc:5031
Item_percent_rank(const POS &pos, PT_window *w)
Definition: item_sum.h:2396
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2388
const char * func_name() const override
Definition: item_sum.h:2403
Item_result result_type() const override
Definition: item_sum.h:2420
~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:4973
ulonglong m_peers
Needed to make PERCENT_RANK same for peers.
Definition: item_sum.h:2389
double val_real() override
Definition: item_sum.cc:4997
Item_non_framing_wf super
Definition: item_sum.h:2386
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2406
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2404
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:2413
bool m_last_peer_visited
Set when the last peer has been visited.
Definition: item_sum.h:2393
void clear() override
Definition: item_sum.cc:5040
my_decimal * val_decimal(my_decimal *buffer) override
Definition: item_sum.cc:5035
longlong val_int() override
Definition: item_sum.cc:5023
RANK or DENSE_RANK window function, cf.
Definition: item_sum.h:2305
Item_result result_type() const override
Definition: item_sum.h:2350
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:4829
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:4853
ulonglong m_duplicates
Needed to make RANK different from DENSE_RANK.
Definition: item_sum.h:2310
bool m_dense
If true, the object represents DENSE_RANK.
Definition: item_sum.h:2307
longlong val_int() override
Definition: item_sum.cc:4871
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2329
~Item_rank() override
Definition: item_sum.cc:4927
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2333
Item_rank(const POS &pos, bool dense, PT_window *w)
Definition: item_sum.h:2314
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4906
const char * func_name() const override
Definition: item_sum.h:2325
double val_real() override
Definition: item_sum.cc:4899
String * val_str(String *) override
Definition: item_sum.cc:4904
ulonglong m_rank_ctr
Increment when window order columns change.
Definition: item_sum.h:2309
void clear() override
Clear state for a new partition.
Definition: item_sum.cc:4911
Mem_root_array< Cached_item * > m_previous
Values of previous row's ORDER BY items.
Definition: item_sum.h:2312
Item_non_framing_wf super
Definition: item_sum.h:2306
Item with result field.
Definition: item.h:5833
longlong llrint_with_overflow_check(double realval)
Definition: item.h:5872
A wrapper Item that contains a number of aggregate items, one for each level of rollup (see Item_roll...
Definition: item_sum.h:2722
table_map used_tables() const override
Definition: item_sum.h:2749
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:6472
void update_field() override
Definition: item_sum.h:2764
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2751
Item * get_arg(uint i) override
Get the i'th argument of the function that this object represents.
Definition: item_sum.h:2786
Item * set_arg(THD *thd, uint i, Item *new_val) override
Definition: item_sum.h:2788
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.cc:6458
void set_current_rollup_level(int level)
Definition: item_sum.h:2798
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:6412
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:6463
bool aggregator_setup(THD *thd) override
Called to initialize the aggregator.
Definition: item_sum.cc:6505
Item_result result_type() const override
Definition: item_sum.h:2750
String * val_str(String *str) override
Definition: item_sum.cc:6437
int set_aggregator(Aggregator::Aggregator_type aggregator) override
Definition: item_sum.cc:6494
Item_sum * unwrap_sum() override
Non-const version.
Definition: item_sum.h:2803
longlong val_int() override
Definition: item_sum.cc:6430
void reset_field() override
Definition: item_sum.h:2763
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:2802
Item_rollup_sum_switcher(List< Item > *sum_func_per_level)
Definition: item_sum.h:2724
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:6418
bool aggregator_add_all()
Definition: item_sum.h:2775
Item * current_arg() const
Definition: item_sum.cc:6407
Item_sum * master() const
Definition: item_sum.h:2799
Item_sum * child(size_t i) const
Definition: item_sum.h:2807
enum Sumfunctype real_sum_func() const override
Definition: item_sum.h:2760
bool is_rollup_sum_wrapper() const override
Overridden by Item_rollup_sum_switcher.
Definition: item_sum.h:2801
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2759
const char * func_name() const override
Definition: item_sum.h:2748
int m_current_rollup_level
Definition: item_sum.h:2812
double val_real() override
Definition: item_sum.cc:6423
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_sum.cc:6451
uint argument_count() const override
Definition: item_sum.h:2795
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:6444
bool add() override
Definition: item_sum.h:2766
void clear() override
Definition: item_sum.cc:6476
bool reset_and_add_for_rollup(int last_unchanged_group_item_idx)
Definition: item_sum.cc:6482
const int m_num_levels
Definition: item_sum.h:2811
const Item * get_arg(uint i) const override
Get the i'th argument of the function that this object represents.
Definition: item_sum.h:2787
ROW_NUMBER window function, cf.
Definition: item_sum.h:2268
ulonglong m_ctr
Increment for each row in partition.
Definition: item_sum.h:2270
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2281
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2279
bool check_wf_semantics1(THD *, Query_block *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.h:2295
Item_row_number(const POS &pos, PT_window *w)
Definition: item_sum.h:2273
my_decimal * val_decimal(my_decimal *buff) override
Definition: item_sum.cc:4822
Item_result result_type() const override
Definition: item_sum.h:2293
String * val_str(String *) override
Definition: item_sum.cc:4818
longlong val_int() override
Definition: item_sum.cc:4799
void clear() override
Definition: item_sum.cc:4827
const char * func_name() const override
Definition: item_sum.h:2278
double val_real() override
Definition: item_sum.cc:4813
Definition: item_sum.h:1911
Item_sum_and(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1913
const char * func_name() const override
Definition: item_sum.h:1917
Item_sum_and(THD *thd, Item_sum_and *item)
Definition: item_sum.h:1916
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3346
Definition: item_sum.h:1323
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:2293
void clear() override
Definition: item_sum.cc:2349
String * val_str(String *str) override
Definition: item_sum.cc:2464
const char * func_name() const override
Definition: item_sum.h:1351
void update_field() override
calc next value and merge it with field_value.
Definition: item_sum.cc:3583
Item_sum_sum super
Definition: item_sum.h:1327
Item * result_item(Field *) override
Definition: item_sum.h:1350
double val_real() override
Definition: item_sum.cc:2358
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1354
Item_sum_avg(const POS &pos, Item *item_par, bool distinct, PT_window *w)
Definition: item_sum.h:1331
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:2327
my_decimal m_avg_dec
Definition: item_sum.h:1328
uint f_scale
Definition: item_sum.h:1326
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1338
double m_avg
Definition: item_sum.h:1329
longlong val_int() override
Definition: item_sum.h:1345
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2320
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2381
void reset_field() override
Definition: item_sum.cc:3481
uint prec_increment
Definition: item_sum.h:1325
uint dec_bin_size
Definition: item_sum.h:1326
bool add() override
Definition: item_sum.cc:2351
Item_sum_avg(THD *thd, Item_sum_avg *item)
Definition: item_sum.h:1334
uint f_precision
Definition: item_sum.h:1326
Base class used to implement BIT_AND, BIT_OR and BIT_XOR.
Definition: item_sum.h:1742
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3236
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:1666
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1851
void remove_bits(const String *s1, ulonglong b1)
For windowing: perform inverse aggregation.
Definition: item_sum.cc:1588
const char initial_value_buff_storage[1]
Buffer used to avoid String allocation in the constructor.
Definition: item_sum.h:1753
static constexpr uint DIGIT_CNT_CARD
Definition: item_sum.h:1796
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1838
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:1530
bool m_is_xor
true iff BIT_XOR
Definition: item_sum.h:1799
void clear() override
Definition: item_sum.cc:3318
Item * result_item(Field *) override
Definition: item_sum.h:1834
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:1505
longlong val_int() override
Definition: item_sum.cc:3294
Item_sum super
Definition: item_sum.h:1743
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:1788
Item_result hybrid_type
Stores the Item's result type. Can only be INT_RESULT or STRING_RESULT.
Definition: item_sum.h:1751
ulonglong reset_bits
Stores the neutral element for function.
Definition: item_sum.h:1745
Item_sum_bit(const POS &pos, Item *item_par, ulonglong reset_arg, PT_window *w)
Definition: item_sum.h:1802
bool is_and() const
Definition: item_sum.h:1864
void reset_field() override
Definition: item_sum.cc:3511
ulonglong m_count
Execution state (windowing): this is for counting rows entering and leaving the window frame,...
Definition: item_sum.h:1759
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3243
double val_real() override
Definition: item_sum.cc:3268
bool add() override
Common implementation of Item_sum_or::add, Item_sum_and:add and Item_sum_xor::add.
Definition: item_sum.cc:1750
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item_sum.cc:3250
enum Item_result result_type() const override
Definition: item_sum.h:1839
uint m_digit_cnt_card
Definition: item_sum.h:1794
Item_sum_bit(THD *thd, Item_sum_bit *item)
Copy constructor, used for executing subqueries with temporary tables.
Definition: item_sum.h:1815
String * val_str(String *str) override
Definition: item_sum.cc:3205
void update_field() override
Definition: item_sum.cc:3521
ulonglong bits
Stores the result value for the INT_RESULT.
Definition: item_sum.h:1747
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:1767
String value_buff
Stores the result value for the STRING_RESULT.
Definition: item_sum.h:1749
Implements ST_Collect which aggregates geometries into Multipoints, Multilinestrings,...
Definition: item_sum.h:2817
bool add() override
Definition: item_sum.cc:6580
void clear() override
Definition: item_sum.cc:6574
void read_result_field()
Definition: item_sum.cc:6635
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:6543
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item_sum.h:2837
std::optional< gis::srid_t > srid
Definition: item_sum.h:2819
Item_sum_collect(const POS &pos, Item *a, PT_window *w, bool distinct)
Definition: item_sum.h:2828
void update_field() override
Definition: item_sum.cc:6728
longlong val_int() override
Definition: item_sum.h:2835
bool get_time(MYSQL_TIME *) override
Definition: item_sum.h:2838
std::unique_ptr< gis::Geometrycollection > m_geometrycollection
Definition: item_sum.h:2820
String * val_str(String *str) override
Definition: item_sum.cc:6681
void reset_field() override
Definition: item_sum.cc:6791
Item_sum_collect(THD *thd, Item_sum *item)
Definition: item_sum.h:2825
void store_result_field()
Definition: item_sum.cc:6734
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:6786
bool check_wf_semantics1(THD *thd, Query_block *, Window_evaluation_requirements *r) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:6565
const char * func_name() const override
Definition: item_sum.h:2876
void pop_front()
Definition: item_sum.cc:6674
enum Sumfunctype sum_func() const override
Definition: item_sum.h:2839
Item_result result_type() const override
Definition: item_sum.h:2840
int set_aggregator(Aggregator::Aggregator_type) override
Definition: item_sum.h:2841
double val_real() override
Definition: item_sum.h:2836
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6630
Definition: item_sum.h:1075
longlong count
Definition: item_sum.h:1076
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1109
longlong val_int() override
Definition: item_sum.cc:2255
Item_sum_count(Item *item, bool distinct)
Definition: item_sum.h:1088
void update_field() override
Definition: item_sum.cc:3574
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2236
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1106
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:2287
void make_const(longlong count_arg)
Definition: item_sum.h:1116
void reset_field() override
Definition: item_sum.cc:3473
Item_sum_count(Item_int *number)
Definition: item_sum.h:1087
Item_sum_count(THD *thd, Item_sum_count *item)
Definition: item_sum.h:1104
Item_sum_count(const POS &pos, PT_item_list *list, PT_window *w)
Constructs an instance for COUNT(DISTINCT)
Definition: item_sum.h:1100
void clear() override
Definition: item_sum.cc:2244
const char * func_name() const override
Definition: item_sum.h:1123
Item_sum_count(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1085
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.h:1115
bool add() override
Definition: item_sum.cc:2246
Abstract base class for the MIN and MAX aggregate functions.
Definition: item_sum.h:1538
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3158
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:3153
bool setup_hybrid(Item *item, Item *value_arg)
MIN/MAX function setup.
Definition: item_sum.cc:1842
bool uses_only_one_row() const override
Only for framing window functions.
Definition: item_sum.h:1689
virtual Item_sum_hybrid * clone_hybrid(THD *thd) const =0
Create a clone of this object.
bool add() override
Definition: item_sum.cc:3188
const bool m_is_min
Tells if this is the MIN function (true) or the MAX function (false).
Definition: item_sum.h:1545
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:3087
bool compute()
This function implements the optimized version of retrieving min/max value.
Definition: item_sum.cc:2889
bool has_values()
Definition: item_sum.h:1686
void min_max_update_int_field()
Definition: item_sum.cc:3705
longlong val_int() override
Definition: item_sum.cc:3022
bool m_has_values
Definition: item_sum.h:1557
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:3077
void reset_field() override
Definition: item_sum.cc:3370
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:3124
void clear() override
Definition: item_sum.cc:2840
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:1585
Item_cache * arg_cache
Definition: item_sum.h:1554
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:3139
void min_max_update_json_field()
Definition: item_sum.cc:3658
void update_field() override
Definition: item_sum.cc:3619
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item_sum.cc:3048
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:2850
bool keep_field_type() const override
Definition: item_sum.h:1678
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3060
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:1579
void min_max_update_real_field()
Definition: item_sum.cc:3692
Item_sum_hybrid(THD *thd, const Item_sum_hybrid *item)
Definition: item_sum.h:1649
Item_result hybrid_type
Definition: item_sum.h:1556
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item_sum.cc:3036
bool m_optimize
Set to true when min/max can be optimized using window's ordering.
Definition: item_sum.h:1565
Item_sum_hybrid(const POS &pos, Item *item_par, bool is_min, PT_window *w)
Definition: item_sum.h:1633
Item_sum_hybrid(Item *item_par, bool is_min)
Definition: item_sum.h:1617
Item_sum super
Definition: item_sum.h:1539
void min_max_update_temporal_field()
Definition: item_sum.cc:3640
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:2855
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1811
String * val_str(String *) override
Definition: item_sum.cc:3097
Arg_comparator * cmp
Definition: item_sum.h:1555
void min_max_update_str_field()
Definition: item_sum.cc:3676
enum Item_result result_type() const override
Definition: item_sum.h:1679
void min_max_update_decimal_field()
Definition: item_sum.cc:3723
double val_real() override
Definition: item_sum.cc:3008
Field * create_tmp_field(bool group, TABLE *table) override
Definition: item_sum.cc:1859
bool m_want_first
For min() - Set to true when results are ordered in ascending and false when descending.
Definition: item_sum.h:1573
Item_cache * value
Definition: item_sum.h:1554
bool m_nulls_first
Set to true if the window is ordered ascending.
Definition: item_sum.h:1561
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_sum.h:1680
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:3110
Definition: item_sum.h:987
Item_sum_int(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:989
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1013
Item_sum_int(THD *thd, Item_sum_int *item)
Definition: item_sum.h:999
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1016
double val_real() override
Definition: item_sum.h:1007
Item_sum_int(Item *item_par)
Definition: item_sum.h:1003
enum Item_result result_type() const override
Definition: item_sum.h:1017
String * val_str(String *str) override
Definition: item_sum.cc:1472
Item_sum_int(const POS &pos, PT_item_list *list, PT_window *w)
Definition: item_sum.h:994
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1474
Implements aggregation of values into an array.
Definition: item_sum.h:1267
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:6014
~Item_sum_json_array() override
bool add() override
Definition: item_sum.cc:6087
unique_ptr_destroy_only< Json_array > m_json_array
Accumulates the final value.
Definition: item_sum.h:1269
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6136
const char * func_name() const override
Definition: item_sum.h:1279
void clear() override
Definition: item_sum.cc:6029
Implements aggregation of values into an object.
Definition: item_sum.h:1286
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:6038
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:6244
bool add() override
Definition: item_sum.cc:6149
unique_ptr_destroy_only< Json_object > m_json_object
Accumulates the final value.
Definition: item_sum.h:1288
~Item_sum_json_object() override
const char * func_name() const override
Definition: item_sum.h:1315
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:6063
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:1297
void clear() override
Definition: item_sum.cc:6053
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:1305
String m_tmp_key_value
Buffer used to get the value of the key.
Definition: item_sum.h:1290
Common abstraction for Item_sum_json_array and Item_sum_json_object.
Definition: item_sum.h:1223
void reset_field() override
Definition: item_sum.cc:5974
void update_field() override
Definition: item_sum.cc:5994
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_sum.cc:5888
unique_ptr_destroy_only< Json_wrapper > m_wrapper
Wrapper around the container (object/array) which accumulates the value.
Definition: item_sum.h:1232
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1248
longlong val_int() override
Definition: item_sum.cc:5926
String m_value
String used when reading JSON binary values or JSON text values.
Definition: item_sum.h:1228
String m_conversion_buffer
String used for converting JSON text values to utf8mb4 charset.
Definition: item_sum.h:1230
Item_sum super
Definition: item_sum.h:1224
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.cc:5967
Item_sum_json(unique_ptr_destroy_only< Json_wrapper > wrapper, Args &&...parent_args)
Construct an Item_sum_json instance.
Definition: item_sum.cc:5829
~Item_sum_json() override
String * val_str(String *str) override
Definition: item_sum.cc:5869
my_decimal * val_decimal(my_decimal *decimal_buffer) override
Definition: item_sum.cc:5941
Item_result result_type() const override
Definition: item_sum.h:1249
bool fix_fields(THD *thd, Item **pItem) override
Definition: item_sum.cc:5843
bool check_wf_semantics1(THD *, Query_block *, Window_evaluation_requirements *) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:5838
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.cc:5959
double val_real() override
Definition: item_sum.cc:5911
Definition: item_sum.h:1723
Item_sum_max(Item *item_par)
Definition: item_sum.h:1725
Item_sum_max(THD *thd, const Item_sum_max *item)
Definition: item_sum.h:1728
const char * func_name() const override
Definition: item_sum.h:1731
Item_sum_max * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:3169
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1730
Item_sum_max(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1726
Definition: item_sum.h:1709
Item_sum_min(THD *thd, const Item_sum_min *item)
Definition: item_sum.h:1714
Item_sum_min(Item *item_par)
Definition: item_sum.h:1711
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1716
const char * func_name() const override
Definition: item_sum.h:1717
Item_sum_min(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1712
Item_sum_min * clone_hybrid(THD *thd) const override
Create a clone of this object.
Definition: item_sum.cc:3165
Definition: item_sum.h:944
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:1468
Item_sum_num(THD *thd, Item_sum_num *item)
Definition: item_sum.h:963
bool fix_fields(THD *, Item **) override
Definition: item_sum.cc:1478
longlong val_int() override
Definition: item_sum.h:972
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_sum.h:965
String * val_str(String *str) override
Definition: item_sum.cc:1466
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:978
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:981
Item_sum super
Definition: item_sum.h:945
Item_sum_num(Item *item_par)
Definition: item_sum.h:969
bool is_evaluated
Definition: item_sum.h:954
Item_sum_num(const POS &pos, Item *item_par, PT_window *window)
Definition: item_sum.h:957
void reset_field() override
Definition: item_sum.cc:3357
Item_sum_num(const POS &pos, PT_item_list *list, PT_window *w)
Definition: item_sum.h:960
Definition: item_sum.h:1901
Item_sum_or(THD *thd, Item_sum_or *item)
Definition: item_sum.h:1906
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3332
const char * func_name() const override
Definition: item_sum.h:1907
Item_sum_or(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1903
Definition: item_sum.h:1516
double val_real() override
Definition: item_sum.cc:2474
Item_sum_std(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
Definition: item_sum.h:1518
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2483
Item_sum_std(THD *thd, Item_sum_std *item)
Definition: item_sum.h:1521
const char * func_name() const override
Definition: item_sum.h:1525
enum Item_result result_type() const override
Definition: item_sum.h:1529
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1522
Item * result_item(Field *) override
Definition: item_sum.h:1524
Definition: item_sum.h:1020
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:1031
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:1991
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:1923
enum Item_result result_type() const override
Definition: item_sum.h:1065
double sum
Definition: item_sum.h:1023
bool add() override
Definition: item_sum.cc:2013
Item_result hybrid_type
Definition: item_sum.h:1022
void no_rows_in_result() override
Mark an aggregate as having no rows.
Definition: item_sum.cc:1942
void reset_field() override
Definition: item_sum.cc:3452
String * val_str(String *str) override
Definition: item_sum.cc:2102
longlong val_int() override
Definition: item_sum.cc:2034
my_decimal dec_buffs[2]
Definition: item_sum.h:1024
void clear() override
Definition: item_sum.cc:1930
const char * func_name() const override
Definition: item_sum.h:1071
Item_sum_sum(const POS &pos, Item *item_par, bool distinct, PT_window *window)
Definition: item_sum.h:1041
void update_field() override
calc next value and merge it with field_value.
Definition: item_sum.cc:3545
Item_sum_sum(Item *item_par)
Definition: item_sum.h:1049
uint curr_dec_buff
Definition: item_sum.h:1025
ulonglong m_frame_null_count
Execution state: this is for counting NULLs of rows entering and leaving the window frame,...
Definition: item_sum.h:1038
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2108
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:1944
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1056
double val_real() override
Definition: item_sum.cc:2058
Definition: item_sum.h:2069
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2080
longlong val_int() override
Definition: item_sum.cc:4003
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2083
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:4005
Item_sum_udf_decimal(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2071
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4014
double val_real() override
Definition: item_sum.cc:4001
enum Item_result result_type() const override
Definition: item_sum.h:2086
String * val_str(String *) override
Definition: item_sum.cc:3997
Item_sum_udf_decimal(THD *thd, Item_sum_udf_decimal *item)
Definition: item_sum.h:2074
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2087
Definition: item_sum.h:1979
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:1998
longlong val_int() override
Definition: item_sum.h:1985
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:3993
String * val_str(String *str) override
Definition: item_sum.cc:3989
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3976
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:1992
double val_real() override
Definition: item_sum.cc:3981
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
Definition: item_sum.h:1983
Item_sum_udf_float(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1981
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:1995
Definition: item_sum.h:2006
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2019
Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
Definition: item_sum.h:2010
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.h:2024
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2022
enum Item_result result_type() const override
Definition: item_sum.h:2023
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4018
String * val_str(String *str) override
Definition: item_sum.cc:4030
Item_sum_udf_int(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2008
longlong val_int() override
Definition: item_sum.cc:4022
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:4034
double val_real() override
Definition: item_sum.h:2013
Definition: item_sum.h:2031
bool resolve_type(THD *) override
Default max_length is max argument length.
Definition: item_sum.cc:4040
double val_real() override
Definition: item_sum.h:2038
String * val_str(String *) override
Definition: item_sum.cc:4056
enum Item_result result_type() const override
Definition: item_sum.h:2064
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_sum.h:2058
bool get_time(MYSQL_TIME *ltime) override
Definition: item_sum.h:2061
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:4048
my_decimal * val_decimal(my_decimal *dec) override
Definition: item_sum.cc:4052
Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
Definition: item_sum.h:2035
longlong val_int() override
Definition: item_sum.h:2047
Item_sum_udf_str(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:2033
Definition: item_sum.h:1440
ulonglong count
Definition: item_sum.h:1451
void update_field() override
Definition: item_sum.cc:2814
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:2682
double val_real() override
Definition: item_sum.cc:2759
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.h:1487
void clear() override
Definition: item_sum.cc:2736
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:2702
Item * result_item(Field *) override
Definition: item_sum.h:1477
Item_sum_variance(const POS &pos, Item *item_par, uint sample_arg, PT_window *w)
Definition: item_sum.h:1461
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1470
double recurrence_s
Definition: item_sum.h:1449
bool optimize
If set, uses a algorithm II mentioned in the class description to calculate the variance which helps ...
Definition: item_sum.h:1459
const char * func_name() const override
Definition: item_sum.h:1481
bool add() override
Definition: item_sum.cc:2738
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:1450
Item_result hybrid_type
Definition: item_sum.h:1444
bool check_wf_semantics1(THD *thd, Query_block *select, Window_evaluation_requirements *reqs) override
Only relevant for aggregates qua window functions.
Definition: item_sum.cc:2666
double recurrence_m
Used in recurrence relation.
Definition: item_sum.h:1448
my_decimal * val_decimal(my_decimal *) override
Definition: item_sum.cc:2789
uint prec_increment
Definition: item_sum.h:1453
enum Item_result result_type() const override
Definition: item_sum.h:1486
void reset_field() override
Definition: item_sum.cc:2794
uint sample
Definition: item_sum.h:1452
Field * create_tmp_field(bool group, TABLE *table) override
Create a new field to match the type of value we're expected to yield.
Definition: item_sum.cc:2715
Definition: item_sum.h:1921
const char * func_name() const override
Definition: item_sum.h:1929
Item * copy_or_same(THD *thd) override
Definition: item_sum.cc:3339
Item_sum_xor(const POS &pos, Item *item_par, PT_window *w)
Definition: item_sum.h:1923
Item_sum_xor(THD *thd, Item_sum_xor *item)
Definition: item_sum.h:1928
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:668
bool collect_grouped_aggregates(uchar *) override
Definition: item_sum.cc:737
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:589
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:425
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:726
void aggregator_clear()
Called to cleanup the aggregator.
Definition: item_sum.h:680
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:786
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_sum.cc:497
bool aggregate_check_distinct(uchar *arg) override
Definition: item_sum.cc:653
~Item_sum() override
Definition: item_sum.h:540
bool init_sum_func_check(THD *thd)
Prepare an aggregate function for checking of context.
Definition: item_sum.cc:165
virtual bool aggregator_setup(THD *thd)
Called to initialize the aggregator.
Definition: item_sum.h:674
bool wf_common_init()
Common initial actions for window functions.
Definition: item_sum.cc:959
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:614
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:801
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:479
void make_const()
Definition: item_sum.h:596
Item * replace_aggregate(uchar *) override
Definition: item_sum.cc:768
Window * window()
Definition: item_sum.h:736
virtual void make_unique()
Definition: item_sum.h:619
bool eq_specific(const Item *item) const override
Provide a more specific equality check for a function.
Definition: item_sum.cc:645
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_sum.cc:104
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.cc:923
bool reset_and_add()
Resets the aggregate value to its default and aggregates the current value of its attribute(s).
Definition: item_sum.h:553
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:935
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_sum.h:594
virtual Item * result_item(Field *field)
Definition: item_sum.h:576
bool forced_const
True means that this field has been evaluated during optimization.
Definition: item_sum.h:508
virtual void update_field()=0
bool eq(const Item *item) const override
Definition: item_sum.cc:622
bool check_sum_func(THD *thd, Item **ref)
Validate the semantic requirements of a set function.
Definition: item_sum.cc:250
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:541
void unsupported_as_wf()
Definition: item_sum.h:795
Aggregator * aggr
Aggregator class instance.
Definition: item_sum.h:408
const Window * window() const
Definition: item_sum.h:737
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:766
virtual bool is_rollup_sum_wrapper() const
Overridden by Item_rollup_sum_switcher.
Definition: item_sum.h:780
bool aggregate_check_group(uchar *arg) override
Definition: item_sum.cc:677
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:547
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:776
virtual void reset_field()=0
virtual bool framing() const
All aggregates are framing, i.e.
Definition: item_sum.h:750
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:796
Item * set_arg(THD *thd, uint i, Item *new_val) override
Definition: item_sum.cc:876
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:710
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:864
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:881
bool aggregator_add()
Called to add value to the aggregator.
Definition: item_sum.h:686
Item_sum(Item *a)
Definition: item_sum.h:524
void set_distinct(bool distinct)
Definition: item_sum.h:689
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:574
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:786
bool has_force_copy_fields() const
Definition: item_sum.h:437
Type type() const override
Definition: item_sum.h:543
void mark_as_sum_func()
Definition: item_sum.cc:469
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:137
bool reset_wf_state(uchar *arg) override
Reset execution state for such window function types as determined by arg.
Definition: item_sum.cc:946
table_map used_tables() const override
Definition: item_sum.h:586
virtual Item_sum * unwrap_sum()
Non-const version.
Definition: item_sum.h:788
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:817
virtual bool setup(THD *)
Definition: item_sum.h:704
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:911
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:756
Item ** get_arg_ptr(uint i)
Definition: item_sum.h:654
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 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:702
Query_block * base_query_block
query block where function is placed
Definition: item_sum.h:484
Definition: item_sum.h:1937
udf_handler udf
Definition: item_sum.h:1941
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_sum.cc:3935
void update_field() override
Definition: item_sum.h:1973
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_sum.cc:3956
void reset_field() override
Definition: item_sum.h:1972
bool add() override
Definition: item_sum.cc:3950
bool fix_fields(THD *thd, Item **ref) override
Definition: item_sum.h:1958
Item_udf_sum(const POS &pos, udf_func *udf_arg, PT_item_list *opt_list)
Definition: item_sum.h:1944
void clear() override
Definition: item_sum.cc:3944
~Item_udf_sum() override
Definition: item_sum.h:1952
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_sum.cc:3965
Item_udf_sum(THD *thd, Item_udf_sum *item)
Definition: item_sum.h:1948
Item_sum super
Definition: item_sum.h:1938
const char * func_name() const override
Definition: item_sum.h:1957
enum Sumfunctype sum_func() const override
Definition: item_sum.h:1968
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
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:3579
void set_nullable(bool nullable)
Definition: item.h:3691
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3586
bool get_time_from_decimal(MYSQL_TIME *ltime)
Convert val_decimal() to time in MYSQL_TIME.
Definition: item.cc:1667
void set_data_type(enum_field_types data_type)
Set the data type of the current Item.
Definition: item.h:1513
my_decimal * val_decimal_from_string(my_decimal *decimal_value)
Definition: item.cc:369
bool is_nullable() const
Definition: item.h:3690
void set_data_type_geometry()
Set the data type of the Item to be GEOMETRY.
Definition: item.h:1755
bool get_time_from_string(MYSQL_TIME *ltime)
Convert val_str() to time in MYSQL_TIME.
Definition: item.cc:1648
bool get_time_from_real(MYSQL_TIME *ltime)
Convert val_real() to time in MYSQL_TIME.
Definition: item.cc:1658
bool get_date_from_decimal(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_decimal() to date in MYSQL_TIME.
Definition: item.cc:1580
void set_data_type_double()
Set the data type of the Item to be double precision floating point.
Definition: item.h:1579
Item_name_string item_name
Name from query.
Definition: item.h:3587
bool fixed
True if item has been resolved.
Definition: item.h:3679
virtual Item_result result_type() const
Definition: item.h:1451
bool null_value
True if item is null.
Definition: item.h:3716
Type
Definition: item.h:965
@ SUM_FUNC_ITEM
A grouped aggregate function, or window function.
Definition: item.h:969
@ AGGR_FIELD_ITEM
A special field for certain aggregate operations.
Definition: item.h:970
bool get_date_from_numeric(MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
Convert a numeric type to date.
Definition: item.cc:1608
virtual TYPELIB * get_typelib() const
Get the typelib information for an item of type set or enum.
Definition: item.h:1822
my_decimal * val_decimal_from_real(my_decimal *decimal_value)
Definition: item.cc:354
bool unsigned_flag
Definition: item.h:3717
longlong val_int_from_string()
Definition: item.cc:526
bool get_date_from_string(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_str() to date in MYSQL_TIME.
Definition: item.cc:1561
void set_grouping_func()
Set the property: this item is a call to GROUPING.
Definition: item.h:3496
bool get_time_from_numeric(MYSQL_TIME *ltime)
Convert a numeric type to time.
Definition: item.cc:1700
virtual bool mark_field_in_map(uchar *arg)
Mark underlying field in read or write map of a table.
Definition: item.h:2830
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:3727
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1589
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:1799
bool get_date_from_real(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_real() to date in MYSQL_TIME.
Definition: item.cc:1571
void set_data_type_longlong()
Set the data type of the Item to be longlong.
Definition: item.h:1555
double val_real_from_string()
Definition: item.cc:472
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:7539
String * val_string_from_real(String *str)
Definition: item.cc:287
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1676
Represents a JSON array container, i.e.
Definition: json_dom.h:513
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:367
bool add_alias(std::string_view key, Json_dom *value)
Insert the value into the object.
Definition: json_dom.h:409
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1150
Definition: sql_list.h:494
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
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:235
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:345
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1174
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:97
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:326
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:96
Definition: sql_udf.h:83
const char * name() const
Definition: sql_udf.h:118
bool is_initialized() const
Definition: sql_udf.h:116
bool m_original
Definition: sql_udf.h:105
bool fix_fields(THD *thd, Item_result_field *item, uint arg_count, Item **args)
Definition: item_func.cc:4624
void free_handler()
Definition: item_func.cc:4605
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:31
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:64
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:81
@ 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:4171
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:4092
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:4128
A better implementation of the UNIX ctype(3) library.
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:499
double my_strntod(const CHARSET_INFO *cs, const char *str, size_t length, const char **end, int *err)
Definition: m_ctype.h:759
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:480
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
thread_local MEM_ROOT ** THR_MALLOC
Definition: mysqld.cc:1579
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1084
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
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
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:2880
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:126
Our own string classes, used pervasively throughout the executor.
Definition: m_ctype.h:421
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:488
int err_code
the error code found during check(if any)
Definition: item.h:495
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:507
argument used by walk method collect_grouped_aggregates ("cga")
Definition: item_sum.h:623
Collect_grouped_aggregate_info(Query_block *select)
Definition: item_sum.h:636
Query_block * m_query_block
The query block we walk from.
Definition: item_sum.h:631
std::vector< Item_sum * > list
accumulated all aggregates found
Definition: item_sum.h:625
std::set< Item_sum * > aggregates_that_were_hidden
Definition: item_sum.h:626
bool m_break_off
true: break off transformation
Definition: item_sum.h:633
bool m_outside
true: an aggregate aggregates outside m_query_block
Definition: item_sum.h:635
Definition: mysql_time.h:82
Bison "location" class.
Definition: parse_location.h:43
Instances of Name_resolution_context store the information necessary for name resolution of Items and...
Definition: item.h:415
Definition: table.h:290
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:421
Definition: table.h:1425
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...