2009-09-23 23:32:31 +02:00
|
|
|
#ifndef ITEM_ROW_INCLUDED
|
|
|
|
#define ITEM_ROW_INCLUDED
|
|
|
|
|
2011-06-30 17:37:13 +02:00
|
|
|
/*
|
2016-03-21 11:21:44 +04:00
|
|
|
Copyright (c) 2002, 2013, Oracle and/or its affiliates.
|
2002-11-15 20:32:09 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2002-11-15 20:32:09 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 21:29:06 +03:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2002-11-15 20:32:09 +02:00
|
|
|
|
2015-04-24 12:59:21 +04:00
|
|
|
/**
|
|
|
|
Row items used for comparing rows and IN operations on rows:
|
|
|
|
|
|
|
|
@verbatim
|
|
|
|
(a, b, c) > (10, 10, 30)
|
|
|
|
(a, b, c) = (select c, d, e, from t1 where x=12)
|
|
|
|
(a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
|
|
|
|
(a, b, c) IN (select c, d, e, from t1)
|
|
|
|
@endverbatim
|
|
|
|
*/
|
|
|
|
|
2016-03-21 11:21:44 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Item which stores (x,y,...) and ROW(x,y,...).
|
|
|
|
Note that this can be recursive: ((x,y),(z,t)) is a ROW of ROWs.
|
|
|
|
*/
|
2018-06-05 11:56:19 +04:00
|
|
|
class Item_row: public Item_fixed_hybrid,
|
2015-04-24 12:59:21 +04:00
|
|
|
private Item_args,
|
2020-07-29 13:51:47 +03:00
|
|
|
private Used_tables_and_const_cache
|
2002-11-15 20:32:09 +02:00
|
|
|
{
|
2015-04-22 12:40:23 +04:00
|
|
|
table_map not_null_tables_cache;
|
2016-03-21 11:21:44 +04:00
|
|
|
/**
|
|
|
|
If elements are made only of constants, of which one or more are
|
|
|
|
NULL. For example, this item is (1,2,NULL), or ( (1,NULL), (2,3) ).
|
|
|
|
*/
|
2002-12-31 18:39:16 +02:00
|
|
|
bool with_null;
|
2002-11-15 20:32:09 +02:00
|
|
|
public:
|
2018-06-05 11:56:19 +04:00
|
|
|
Item_row(THD *thd, List<Item> &list)
|
|
|
|
:Item_fixed_hybrid(thd), Item_args(thd, list),
|
|
|
|
not_null_tables_cache(0), with_null(0)
|
2015-04-24 12:59:21 +04:00
|
|
|
{ }
|
2018-06-05 11:56:19 +04:00
|
|
|
Item_row(THD *thd, Item_row *row)
|
|
|
|
:Item_fixed_hybrid(thd), Item_args(thd, static_cast<Item_args*>(row)),
|
|
|
|
Used_tables_and_const_cache(),
|
2017-10-22 13:03:41 +02:00
|
|
|
not_null_tables_cache(0), with_null(0)
|
|
|
|
{ }
|
2002-11-15 20:32:09 +02:00
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
enum Type type() const override { return ROW_ITEM; };
|
|
|
|
const Type_handler *type_handler() const override { return &type_handler_row; }
|
2019-07-12 06:58:51 +04:00
|
|
|
Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src,
|
2020-08-19 02:53:22 +03:00
|
|
|
const Tmp_field_param *param) override
|
2018-05-28 16:57:59 +04:00
|
|
|
{
|
|
|
|
return NULL; // Check with Vicentiu why it's called for Item_row
|
|
|
|
}
|
2002-11-15 20:32:09 +02:00
|
|
|
void illegal_method_call(const char *);
|
2020-08-19 02:53:22 +03:00
|
|
|
bool is_null() override { return null_value; }
|
|
|
|
void make_send_field(THD *thd, Send_field *) override
|
2002-11-15 20:32:09 +02:00
|
|
|
{
|
2018-04-05 21:27:33 +04:00
|
|
|
illegal_method_call((const char*)"make_send_field");
|
2002-11-15 20:32:09 +02:00
|
|
|
};
|
2020-08-19 02:53:22 +03:00
|
|
|
double val_real() override
|
2002-11-15 20:32:09 +02:00
|
|
|
{
|
|
|
|
illegal_method_call((const char*)"val");
|
|
|
|
return 0;
|
|
|
|
};
|
2020-08-19 02:53:22 +03:00
|
|
|
longlong val_int() override
|
2002-11-15 20:32:09 +02:00
|
|
|
{
|
|
|
|
illegal_method_call((const char*)"val_int");
|
|
|
|
return 0;
|
|
|
|
};
|
2020-08-19 02:53:22 +03:00
|
|
|
String *val_str(String *) override
|
2002-11-15 20:32:09 +02:00
|
|
|
{
|
|
|
|
illegal_method_call((const char*)"val_str");
|
|
|
|
return 0;
|
|
|
|
};
|
2020-08-19 02:53:22 +03:00
|
|
|
my_decimal *val_decimal(my_decimal *) override
|
2005-02-09 02:50:45 +04:00
|
|
|
{
|
|
|
|
illegal_method_call((const char*)"val_decimal");
|
|
|
|
return 0;
|
|
|
|
};
|
2020-08-19 02:53:22 +03:00
|
|
|
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override
|
2018-02-13 20:37:31 +04:00
|
|
|
{
|
|
|
|
illegal_method_call((const char*)"get_date");
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
bool fix_fields(THD *thd, Item **ref) override;
|
|
|
|
void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge)
|
|
|
|
override;
|
|
|
|
void cleanup() override;
|
2016-02-09 12:35:59 -08:00
|
|
|
void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array,
|
2020-08-19 02:53:22 +03:00
|
|
|
List<Item> &fields, uint flags) override;
|
|
|
|
table_map used_tables() const override { return used_tables_cache; };
|
|
|
|
bool const_item() const override { return const_item_cache; };
|
|
|
|
void update_used_tables() override
|
2015-04-22 12:40:23 +04:00
|
|
|
{
|
|
|
|
used_tables_and_const_cache_init();
|
2015-04-24 12:59:21 +04:00
|
|
|
used_tables_and_const_cache_update_and_join(arg_count, args);
|
2015-04-22 12:40:23 +04:00
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
table_map not_null_tables() const override { return not_null_tables_cache; }
|
|
|
|
void print(String *str, enum_query_type query_type) override;
|
2002-11-15 20:32:09 +02:00
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
bool walk(Item_processor processor, bool walk_subquery, void *arg) override
|
2015-04-24 12:59:21 +04:00
|
|
|
{
|
|
|
|
if (walk_args(processor, walk_subquery, arg))
|
|
|
|
return true;
|
|
|
|
return (this->*processor)(arg);
|
|
|
|
}
|
2020-08-19 02:53:22 +03:00
|
|
|
Item *transform(THD *thd, Item_transformer transformer, uchar *arg) override;
|
|
|
|
bool eval_not_null_tables(void *opt_arg) override;
|
|
|
|
bool find_not_null_fields(table_map allowed) override;
|
2003-07-02 13:12:18 +03:00
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
uint cols() const override { return arg_count; }
|
|
|
|
Item* element_index(uint i) override { return args[i]; }
|
|
|
|
Item** addr(uint i) override { return args + i; }
|
|
|
|
bool check_cols(uint c) override;
|
|
|
|
bool null_inside() override { return with_null; };
|
|
|
|
void bring_value() override;
|
2017-04-03 15:59:38 -07:00
|
|
|
|
|
|
|
Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond)
|
2020-08-19 02:53:22 +03:00
|
|
|
override
|
2017-04-03 15:59:38 -07:00
|
|
|
{
|
|
|
|
Item_args::propagate_equal_fields(thd, Context_identity(), cond);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
bool excl_dep_on_table(table_map tab_map) override
|
2017-06-22 00:41:44 -07:00
|
|
|
{
|
|
|
|
return Item_args::excl_dep_on_table(tab_map);
|
|
|
|
}
|
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
bool excl_dep_on_grouping_fields(st_select_lex *sel) override
|
2017-06-22 00:41:44 -07:00
|
|
|
{
|
|
|
|
return Item_args::excl_dep_on_grouping_fields(sel);
|
|
|
|
}
|
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
bool excl_dep_on_in_subq_left_part(Item_in_subselect *subq_pred) override
|
2018-05-15 23:45:59 +02:00
|
|
|
{
|
|
|
|
return Item_args::excl_dep_on_in_subq_left_part(subq_pred);
|
|
|
|
}
|
|
|
|
|
2020-08-19 02:53:22 +03:00
|
|
|
bool check_vcol_func_processor(void *arg) override {return FALSE; }
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_get_copy(THD *thd) const override
|
2017-11-22 08:01:07 +02:00
|
|
|
{ return get_item_copy<Item_row>(thd, this); }
|
MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone
The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()`
face an issue where they may be defined in a descendant class
(e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`).
This can lead to scenarios where `build_clone()`, when operating on an
instance of `Item_func_child` with a pointer to the base class (`Item`),
returns an instance of `Item_func` instead of `Item_func_child`.
Since this limitation cannot be resolved at compile time, this commit
introduces runtime type checks for the copy/clone operations.
A debug assertion will now trigger in case of a type mismatch.
`get_copy()`, `build_clone()`, and `clone_item()` are no more virtual,
but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()`
are added to the protected section of the class `Item`.
Additionally, const qualifiers have been added to certain methods
to enhance code reliability.
Reviewer: Oleksandr Byelkin <sanja@mariadb.com>
2024-07-03 15:42:21 +07:00
|
|
|
Item *do_build_clone(THD *thd) const override;
|
2002-11-15 20:32:09 +02:00
|
|
|
};
|
2009-09-23 23:32:31 +02:00
|
|
|
|
|
|
|
#endif /* ITEM_ROW_INCLUDED */
|