MySQL 8.4.3
Source Code Documentation
sql_const_folding.h
Go to the documentation of this file.
1#ifndef SQL_CONST_FOLDING_INCLUDED
2#define SQL_CONST_FOLDING_INCLUDED
3
4/* Copyright (c) 2018, 2024, 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/**
28 @file sql/sql_const_folding.h
29
30 Interface to SQL expression constant folding
31*/
32
33#include "sql/item.h" // Item, Item::cond_result
34class THD;
35
36/**
37 Fold boolean condition {=, <>, >, >=, <, <=, <=>} involving constants and
38 fields (or references to fields), possibly determining if the condition is
39 always true or false based on type range of the field, or possibly simplifying
40 >=, <= to = if constant lies on the range border.
41
42 Also fold such conditions if they are present as arguments of other functions
43 in the same way, except there we replace the arguments with manifest FALSE or
44 field <> field to exclude NULLs if the field is nullable, cf.
45 ignore_unknown().
46
47 The constants are always converted to constants of the type of the field, no
48 widening of the field type in therefore necessary after this folding for
49 comparison to occur. When converting constants to decimal (when the field is a
50 decimal), the constant will receive the same number of fractional decimals as
51 the field. If decimal constant fraction truncation occurs, the comparison
52 {GT,GE,LT,LE} logic is adjusted to preserve semantics without widening the
53 field's type.
54
55 @param thd session state
56 @param cond the condition to handle
57 @param[out] retcond condition after const removal
58 @param[out] cond_value resulting value of the condition
59 - COND_OK: condition must be evaluated (e.g int == 3)
60 - COND_TRUE: always true (e.g signed tinyint < 128)
61 - COND_FALSE: always false (e.g unsigned tinyint < 0)
62
63 @param manifest_result
64 For IS NOT NULL on a not nullable item, if true,
65 return item TRUE (1), else remove condition and return
66 COND_TRUE. For cmp items, this is determined by
67 Item_bool_func2::ignore_unknown.
68 @returns false if success, true if error
69*/
70bool fold_condition(THD *thd, Item *cond, Item **retcond,
71 Item::cond_result *cond_value,
72 bool manifest_result = false);
73
74#endif /* SQL_CONST_FOLDING_INCLUDED */
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:936
cond_result
Definition: item.h:998
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
bool fold_condition(THD *thd, Item *cond, Item **retcond, Item::cond_result *cond_value, bool manifest_result=false)
Fold boolean condition {=, <>, >, >=, <, <=, <=>} involving constants and fields (or references to fi...
Definition: sql_const_folding.cc:1256