MySQL 8.4.0
Source Code Documentation
find_contained_subqueries.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_FIND_CONTAINED_SUBQUERIES
25#define SQL_JOIN_OPTIMIZER_FIND_CONTAINED_SUBQUERIES 1
26
27#include "sql/item_subselect.h"
29#include "sql/sql_const.h"
30#include "sql/sql_lex.h"
31
32class Item;
33class THD;
34class Item;
35class Query_block;
36
37/***
38Find out which subqueries are contained in this predicate, if any.
39(This only counts IN/ALL/ANY/comparison_operator subqueries, ie.,
40those that we consider materializing and have not converted to
41semijoins.) Note that calling this repeatedly can be quite expensive,
42so many callers will want to cache this information.
43
44Func should be on the form void func(ContainedSubquery), or something
45compatible.
46
47@param condition the root of the predicate.
48@param outer_query_block the Query_block to which 'condition' belongs.
49@param func a function that is called for each contained subquery.
50*/
51template <class Func>
54 Func &&func) {
56 [outer_query_block, &func](Item *item) {
57 std::optional<ContainedSubquery> subquery =
59
60 if (subquery.has_value()) {
61 func(subquery.value());
62 }
63 return false;
64 });
65}
66
67#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:934
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:1367
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1163
Query_block * outer_query_block() const
Definition: sql_lex.h:1258
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
void FindContainedSubqueries(Item *condition, const Query_block *outer_query_block, Func &&func)
Definition: find_contained_subqueries.h:52
bool WalkItem(Item *item, enum_walk walk, T &&functor)
A helper class to give in a functor to Item::walk().
Definition: item.h:3758
File containing constants that can be used throughout the server.