MySQL 9.1.0
Source Code Documentation
|
#include "sql/item.h"
#include "integer_digits.h"
#include "my_compiler.h"
#include "my_config.h"
#include <stdio.h>
#include <sys/time.h>
#include <stddef.h>
#include <algorithm>
#include <optional>
#include <utility>
#include "decimal.h"
#include "dig_vec.h"
#include "float.h"
#include "limits.h"
#include "m_string.h"
#include "my_alloc.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_macros.h"
#include "myisampack.h"
#include "mysql.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/strings/my_strtoll10.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "nulls.h"
#include "sql-common/json_dom.h"
#include "sql/aggregate_check.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/current_thd.h"
#include "sql/derror.h"
#include "sql/error_handler.h"
#include "sql/gis/srid.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_create.h"
#include "sql/item_func.h"
#include "sql/item_json_func.h"
#include "sql/item_row.h"
#include "sql/item_strfunc.h"
#include "sql/item_subselect.h"
#include "sql/item_sum.h"
#include "sql/key.h"
#include "sql/log_event.h"
#include "sql/mysqld.h"
#include "sql/opt_explain_format.h"
#include "sql/protocol.h"
#include "sql/query_options.h"
#include "sql/select_lex_visitor.h"
#include "sql/sp.h"
#include "sql/sp_rcontext.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_derived.h"
#include "sql/sql_error.h"
#include "sql/sql_executor.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_show.h"
#include "sql/sql_time.h"
#include "sql/sql_view.h"
#include "sql/system_variables.h"
#include "sql/thd_raii.h"
#include "sql/tztime.h"
#include "string_with_len.h"
#include "strmake.h"
#include "strxmov.h"
#include "template_utils.h"
#include "typelib.h"
#include "unsafe_string_append.h"
Classes | |
class | Item_aggregate_ref |
Functions | |
static bool | select_alias_referencable (enum_parsing_context place) |
Alias from select list can be referenced only from ORDER BY (SQL Standard) or from HAVING, GROUP BY, QUALIFY and a subquery in the select list (MySQL extension). More... | |
static uint32 | aggregate_char_width (DTCollation *const coll, Item **items, uint nitems) |
Calculate the maximum number of characters required by any of the items. More... | |
static enum_field_types | real_data_type (Item *item) |
Find real data type of item. More... | |
void | item_init (void) |
Init all special items. More... | |
const char * | fieldtype2str (enum enum_field_types type) |
Returns a string for a mysql field type. More... | |
static bool | subquery_split (THD *thd, Item *item, bool *outer_refs_wf) |
static bool | left_is_superset (DTCollation *left, DTCollation *right) |
static void | my_coll_agg_error (DTCollation &c1, DTCollation &c2, const char *fname) |
static void | my_coll_agg_error (DTCollation &c1, DTCollation &c2, DTCollation &c3, const char *fname) |
static void | my_coll_agg_error (Item **args, uint count, const char *fname, int item_sep) |
static bool | agg_item_collations (DTCollation &c, const char *fname, Item **av, uint count, uint flags, int item_sep) |
bool | agg_item_collations_for_comparison (DTCollation &c, const char *fname, Item **av, uint count, uint flags) |
bool | convert_const_strings (DTCollation &coll, Item **args, uint nargs, int item_sep) |
bool | agg_item_charsets (DTCollation &coll, const char *fname, Item **args, uint nargs, uint flags, int item_sep) |
static uint32 | adjust_max_effective_column_length (Field *field_par, uint32 max_length) |
Calculate the max column length not taking into account the limitations over integer types. More... | |
double | double_from_string_with_check (const CHARSET_INFO *cs, const char *cptr, const char *end) |
longlong | longlong_from_string_with_check (const CHARSET_INFO *cs, const char *cptr, const char *end, int unsigned_target) |
Converts a string to a longlong integer, with warnings. More... | |
static void | mark_as_dependent (THD *thd, Query_block *last, Query_block *current, Item_ident *resolved_item, Item_ident *mark_item) |
Mark item and Query_blocks as dependent if item was resolved in outer SELECT. More... | |
static Item ** | find_field_in_group_list (Item *find_item, ORDER *group_list) |
Search a GROUP BY clause for a field with a certain name. More... | |
static bool | resolve_ref_in_select_and_group (THD *thd, Item_ident *ref, Query_block *select, Item ***found) |
Resolve a column reference in a query block. More... | |
bool | is_null_on_empty_table (THD *thd, Item_field *i) |
Check if the column reference that is currently being resolved, will be set to NULL if its qualifying query returns zero rows. More... | |
static void | convert_zerofill_number_to_string (Item **item, const Field_num *field) |
Convert a numeric value to a zero-filled string. More... | |
static type_conversion_status | field_conv_with_cache (Field *to, Field *from, Field **last_to, uint32_t *to_is_memcpyable) |
Copies/converts data from “from” to “to”, but is faster on repeated execution with the same “to” field, as it caches the fields_are_memcpyable() and pack_length() calls. More... | |
static type_conversion_status | save_int_value_in_field (Field *field, longlong nr, bool null_value, bool unsigned_flag) |
Store an int in a field. More... | |
static uint | nr_of_decimals (const char *str, const char *end) |
static uint | char_val (char X) |
Item_result | item_cmp_type (Item_result a, Item_result b) |
bool | resolve_const_item (THD *thd, Item **ref, Item *comp_item) |
Substitute a const item with a simpler const item, if possible. More... | |
int | stored_field_cmp_to_item (THD *thd, Field *field, Item *item) |
Compare the value stored in field with the expression from the query. More... | |
static const char * | whence (const Item_field *cached_field) |
Get the name of the cached field of an Item_cache_json instance. More... | |
void | convert_and_print (const String *from_str, String *to_str, const CHARSET_INFO *to_cs) |
Helper method: Convert string to the given charset, then print. More... | |
string | ItemToString (const Item *item, enum_query_type q_type) |
string | ItemToString (const Item *item) |
std::string | ItemToQuerySubstrNoCharLimit (const Item *item, const LEX *lex) |
std::string | ItemToQuerySubstr (const Item *item, const LEX *lex, uint32 char_limit) |
Item_field * | FindEqualField (Item_field *item_field, table_map reachable_tables, bool replace, bool *found) |
bool | ItemsAreEqual (const Item *a, const Item *b) |
Returns true iff the two items are equal, as in a->eq(b), after unwrapping refs and Item_cache objects. More... | |
bool | AllItemsAreEqual (const Item *const *a, const Item *const *b, int num_items) |
Returns true iff all items in the two arrays (which must be of the same size) are equal, as in a->eq(b), after unwrapping refs and Item_cache objects. More... | |
Variables | |
const String | my_null_string ("NULL", 4, default_charset_info) |
const Name_string | null_name_string (nullptr, 0) |
|
inlinestatic |
Calculate the max column length not taking into account the limitations over integer types.
When storing data into fields the server currently just ignores the limits specified on integer types, e.g. 1234 can safely be stored in an int(2) and will not cause an error. Thus when creating temporary tables and doing transformations we must adjust the maximum field length to reflect this fact. We take the un-restricted maximum length and adjust it similarly to how the declared length is adjusted wrt unsignedness etc. TODO: this all needs to go when we disable storing 1234 in int(2).
field_par | Original field the use to calculate the lengths |
max_length | Item's calculated explicit max length |
bool agg_item_charsets | ( | DTCollation & | coll, |
const char * | fname, | ||
Item ** | args, | ||
uint | nargs, | ||
uint | flags, | ||
int | item_sep | ||
) |
|
static |
bool agg_item_collations_for_comparison | ( | DTCollation & | c, |
const char * | fname, | ||
Item ** | av, | ||
uint | count, | ||
uint | flags | ||
) |
|
static |
Calculate the maximum number of characters required by any of the items.
coll | Collation for the unified type of all items |
items | arguments to calculate max width for |
nitems | number of arguments |
Returns true iff all items in the two arrays (which must be of the same size) are equal, as in a->eq(b), after unwrapping refs and Item_cache objects.
|
inlinestatic |
void convert_and_print | ( | const String * | from_str, |
String * | to_str, | ||
const CHARSET_INFO * | to_cs | ||
) |
Helper method: Convert string to the given charset, then print.
from_str | String to be converted. |
to_str | Query string. |
to_cs | Character set to which the string is to be converted. |
bool convert_const_strings | ( | DTCollation & | coll, |
Item ** | args, | ||
uint | nargs, | ||
int | item_sep | ||
) |
Convert a numeric value to a zero-filled string.
[in,out] | item | the item to operate on |
field | The field that this value is equated to |
This function converts a numeric value to a string. In this conversion the zero-fill flag of the field is taken into account. This is required so the resulting string value can be used instead of the field reference when propagating equalities.
double double_from_string_with_check | ( | const CHARSET_INFO * | cs, |
const char * | cptr, | ||
const char * | end | ||
) |
|
inlinestatic |
Copies/converts data from “from” to “to”, but is faster on repeated execution with the same “to” field, as it caches the fields_are_memcpyable() and pack_length() calls.
These are not terribly expensive in themselves, but it adds up to 5–10% in DBT-3 Q1 due to the repeated calls.
The “from” field must correspond to the same last_to / to_is_memcpyable pair as earlier calls, unless last_to is cleared to nullptr.
const char * fieldtype2str | ( | enum enum_field_types | type | ) |
Returns a string for a mysql field type.
type | the type of the field. |
Search a GROUP BY clause for a field with a certain name.
Search the GROUP BY list for a column named as find_item. When searching preference is given to columns that are qualified with the same table (and database) name as the one being searched for.
find_item | the item being searched for |
group_list | GROUP BY clause |
Item_field * FindEqualField | ( | Item_field * | item_field, |
table_map | reachable_tables, | ||
bool | replace, | ||
bool * | found | ||
) |
bool is_null_on_empty_table | ( | THD * | thd, |
Item_field * | i | ||
) |
Check if the column reference that is currently being resolved, will be set to NULL if its qualifying query returns zero rows.
This is true for non-aggregated column references in the SELECT list, if the query block uses aggregation without grouping. For example:
SELECT COUNT(*), col FROM t WHERE some_condition
Here, if the table t
is empty, or some_condition
doesn't match any rows in t
, the query returns one row where col
is NULL, even if col
is a not-nullable column.
Such column references are rejected if the ONLY_FULL_GROUP_BY SQL mode is enabled, in a later resolution phase.
Item_result item_cmp_type | ( | Item_result | a, |
Item_result | b | ||
) |
void item_init | ( | void | ) |
Init all special items.
Returns true iff the two items are equal, as in a->eq(b), after unwrapping refs and Item_cache objects.
string ItemToString | ( | const Item * | item | ) |
string ItemToString | ( | const Item * | item, |
enum_query_type | q_type | ||
) |
|
static |
longlong longlong_from_string_with_check | ( | const CHARSET_INFO * | cs, |
const char * | cptr, | ||
const char * | end, | ||
int | unsigned_target | ||
) |
Converts a string to a longlong integer, with warnings.
cs | charset of string |
cptr | beginning of string |
end | end of string |
unsigned_target | If 0, caller will use result as a signed integer; if 1: an unsigned integer; if -1: caller doesn't tell. This influences warnings. |
|
static |
Mark item and Query_blocks as dependent if item was resolved in outer SELECT.
thd | Current session. |
last | select from which current item depend |
current | current select |
resolved_item | item which was resolved in outer SELECT |
mark_item | item which should be marked; resolved_item will be marked anyway. |
|
static |
|
static |
|
static |
|
static |
|
static |
Find real data type of item.
Substitute a const item with a simpler const item, if possible.
thd | Current session. | |
[in,out] | ref | Const item to be processed, contains simplest possible item on return. |
comp_item | Item that provides result type for generated const item |
|
static |
Resolve a column reference in a query block.
Resolve a column reference (usually inside a HAVING clause) against the SELECT and GROUP BY clauses of the query described by 'select'. The name resolution algorithm searches both the SELECT and GROUP BY clauses, and in case of a name conflict prefers GROUP BY column names over SELECT names. If both clauses contain different fields with the same names, a warning is issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no GROUP BY column is found, then a HAVING name is resolved as a possibly derived SELECT column.
thd | current thread | |
ref | column reference being resolved | |
select | the select that ref is resolved against | |
[out] | found | pointer to the found item = nullptr: item was not found |
|
static |
Store an int in a field.
field | The field where the int value is to be stored |
nr | The value to store in field |
null_value | True if the value to store is NULL, false otherwise |
unsigned_flag | Whether or not the int value is signed or unsigned |
TYPE_OK | Storing of value went fine without warnings or errors |
!TYPE_OK | Warning/error as indicated by type_conversion_status enum value |
|
inlinestatic |
Alias from select list can be referenced only from ORDER BY (SQL Standard) or from HAVING, GROUP BY, QUALIFY and a subquery in the select list (MySQL extension).
We don't allow it be referenced from the SELECT list, with one exception: it's accepted if nested in a subquery, which is inconsistent but necessary as our users have shown to rely on this workaround.
Compare the value stored in field with the expression from the query.
thd | Current session. |
field | Field which the Item is stored in after conversion |
item | Original expression from query |
We similarly use it to verify that expressions like BIGINT_FIELD <cmp> <literal value> is done correctly (as int/decimal/float according to literal type).
|
inlinestatic |
Get the name of the cached field of an Item_cache_json instance.
const String my_null_string("NULL", 4, default_charset_info) | ( | "NULL" | , |
4 | , | ||
default_charset_info | |||
) |
const Name_string null_name_string(nullptr, 0) | ( | nullptr | , |
0 | |||
) |