MySQL 8.3.0
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, 2023, 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 also distributed 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 included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file sql/sql_const_folding.h
28
29 Interface to SQL expression constant folding
30*/
31
32#include "sql/item.h" // Item, Item::cond_result
33class THD;
34
35/**
36 Fold boolean condition {=, <>, >, >=, <, <=, <=>} involving constants and
37 fields (or references to fields), possibly determining if the condition is
38 always true or false based on type range of the field, or possibly simplifying
39 >=, <= to = if constant lies on the range border.
40
41 Also fold such conditions if they are present as arguments of other functions
42 in the same way, except there we replace the arguments with manifest FALSE or
43 field <> field to exclude NULLs if the field is nullable, cf.
44 ignore_unknown().
45
46 The constants are always converted to constants of the type of the field, no
47 widening of the field type in therefore necessary after this folding for
48 comparison to occur. When converting constants to decimal (when the field is a
49 decimal), the constant will receive the same number of fractional decimals as
50 the field. If decimal constant fraction truncation occurs, the comparison
51 {GT,GE,LT,LE} logic is adjusted to preserve semantics without widening the
52 field's type.
53
54 @param thd session state
55 @param cond the condition to handle
56 @param[out] retcond condition after const removal
57 @param[out] cond_value resulting value of the condition
58 - COND_OK: condition must be evaluated (e.g int == 3)
59 - COND_TRUE: always true (e.g signed tinyint < 128)
60 - COND_FALSE: always false (e.g unsigned tinyint < 0)
61
62 @param manifest_result
63 For IS NOT NULL on a not nullable item, if true,
64 return item TRUE (1), else remove condition and return
65 COND_TRUE. For cmp items, this is determined by
66 Item_bool_func2::ignore_unknown.
67 @returns false if success, true if error
68*/
69bool fold_condition(THD *thd, Item *cond, Item **retcond,
70 Item::cond_result *cond_value,
71 bool manifest_result = false);
72
73#endif /* SQL_CONST_FOLDING_INCLUDED */
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
cond_result
Definition: item.h:1001
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
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:1255