MySQL 9.1.0
Source Code Documentation
replace_item.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_JOIN_OPTIMIZER_REPLACE_ITEM_H
25#define SQL_JOIN_OPTIMIZER_REPLACE_ITEM_H
26
27class Func_ptr;
28class Item;
29class Item_field;
30template <class T>
31class Mem_root_array;
32class THD;
34
35/*
36 Return a new item that is to be used after materialization (as given by
37 items_to_copy). There are three main cases:
38
39 1. The item isn't touched by materialization (e.g., because it's constant,
40 or because we're not ready to compute it yet).
41 2. The item is directly in the items_to_copy list, so it has its own field
42 in the resulting temporary table; the corresponding new Item_field
43 is returned.
44 3. A _part_ of the item is in the items_to_copy list; e.g. say that we
45 have an item (t1.x + 1), and t1.x is materialized into <temporary>.x.
46 (In particular, this happens when having expressions that contain
47 aggregate functions _and_ non-aggregates.) In this case, we go in and
48 modify the item in-place, so that the appropriate sub-expressions are
49 replaced; in this case, to (<temporary>.x + 1). This assumes that we
50 never use the same item before and after a materialization in the
51 query plan!
52 4. The item is not in items_to_copy but it is an aggregate item, so it
53 *has* to have a replacement created. In such case, 'agg_items_to_copy' is
54 non-null, and it indicates that a new items_to_copy list is to be saved
55 into this. It is made up of all such aggregate items that were not found
56 while finding replacement. These items need to be added in
57 'agg_items_to_copy' so that further items get a direct match for
58 subsequent occurences of these items, rather than generating a new
59 replacement. Without this, the replacement does not propagate from the
60 bottom to the top plan node.
61
62 */
64 THD *thd, Item *item, const Func_ptr_array &items_to_copy,
65 bool need_exact_match, Func_ptr_array *agg_items_to_copy = nullptr);
66
67/**
68 Like FindReplacementOrReplaceMaterializedItems, but only search _below_ the
69 item, ie. ignore point 2 above. This can be useful if doing self-replacement,
70 ie., we are replacing source items in items_to_copy and don't want to
71 replace an item with its own output.
72 */
73void ReplaceMaterializedItems(THD *thd, Item *item,
74 const Func_ptr_array &items_to_copy,
75 bool need_exact_match,
76 bool window_frame_buffer = false);
77
78/**
79 Replace "@var:=<expr>" with "@var:=<tmp_table_column>" rather than
80 "<tmp_table_column>".
81
82 If a join field such as "@var:=expr" points to a temp table field, the
83 var assignment won't happen because there is no re-evaluation of the
84 materialized field. . So, rather than returning the temp table field,
85 return a new Item_func_set_user_var item that points to temp table
86 field, so that "@var" gets updated.
87
88 (It's another thing that the temp table field itself is an
89 Item_func_set_user_var field, i.e. of the form "@var:=<expr>", which
90 means the var assignment redundantly happens for *each* temp table
91 record while initializing the table; but this function does not fix
92 that)
93
94 TODO: remove this function cf. deprecated setting of variable in
95 expressions when it is finally disallowed.
96 */
97Item *ReplaceSetVarItem(THD *thd, Item *item, Item *new_item);
98
99#endif // SQL_JOIN_OPTIMIZER_REPLACE_ITEM_H
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:48
Definition: item.h:4385
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Item * ReplaceSetVarItem(THD *thd, Item *item, Item *new_item)
Replace "@var:=<expr>" with "@var:=<tmp_table_column>" rather than "<tmp_table_column>".
Definition: replace_item.cc:204
void ReplaceMaterializedItems(THD *thd, Item *item, const Func_ptr_array &items_to_copy, bool need_exact_match, bool window_frame_buffer=false)
Like FindReplacementOrReplaceMaterializedItems, but only search below the item, ie.
Definition: replace_item.cc:157
Item * FindReplacementOrReplaceMaterializedItems(THD *thd, Item *item, const Func_ptr_array &items_to_copy, bool need_exact_match, Func_ptr_array *agg_items_to_copy=nullptr)
Definition: replace_item.cc:105