MySQL 8.0.32
Source Code Documentation
find_contained_subqueries.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_JOIN_OPTIMIZER_FIND_CONTAINED_SUBQUERIES
24#define SQL_JOIN_OPTIMIZER_FIND_CONTAINED_SUBQUERIES 1
25
26#include "sql/item_subselect.h"
28#include "sql/sql_const.h"
29#include "sql/sql_lex.h"
30
31class Item;
32class THD;
33class Item;
34class Query_block;
35
36/***
37Find out which subqueries are contained in this predicate, if any.
38(This only counts IN/ALL/ANY/comparison_operator subqueries, ie.,
39those that we consider materializing and have not converted to
40semijoins.) Note that calling this repeatedly can be quite expensive,
41so many callers will want to cache this information.
42
43Func should be on the form void func(ContainedSubquery), or something
44compatible.
45
46@param condition the root of the predicate.
47@param outer_query_block the Query_block to which 'condition' belongs.
48@param func a function that is called for each contained subquery.
49*/
50template <class Func>
53 Func &&func) {
55 [outer_query_block, &func](Item *item) {
56 std::optional<ContainedSubquery> subquery =
58
59 if (subquery.has_value()) {
60 func(subquery.value());
61 }
62 return false;
63 });
64}
65
66#endif // SQL_JOIN_OPTIMIZER_FIND_CONTAINED_SUBQUERIES
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:850
virtual std::optional< ContainedSubquery > get_contained_subquery(const Query_block *outer_query_block)
If this item represents a IN/ALL/ANY/comparison_operator subquery, return that (along with data on ho...
Definition: item.h:1259
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1153
Query_block * outer_query_block() const
Definition: sql_lex.h:1245
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
void FindContainedSubqueries(Item *condition, const Query_block *outer_query_block, Func &&func)
Definition: find_contained_subqueries.h:51
bool WalkItem(Item *item, enum_walk walk, T &&functor)
A helper class to give in a functor to Item::walk().
Definition: item.h:3520
File containing constants that can be used throughout the server.