summaryrefslogtreecommitdiff
path: root/sql/item.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item.h')
-rw-r--r--sql/item.h91
1 files changed, 62 insertions, 29 deletions
diff --git a/sql/item.h b/sql/item.h
index 486ca098dda..07a3d476699 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -772,8 +772,8 @@ enum class item_base_t : item_flags_t
FIXED= (1<<2), // Was fixed with fix_fields().
IS_EXPLICIT_NAME= (1<<3), // The name of this Item was set by the user
// (or was auto generated otherwise)
- IS_IN_WITH_CYCLE= (1<<4) // This item is in CYCLE clause
- // of WITH.
+ IS_IN_WITH_CYCLE= (1<<4), // This item is in CYCLE clause of WITH.
+ AT_TOP_LEVEL= (1<<5) // At top (AND) level of item tree
};
@@ -1327,6 +1327,25 @@ public:
{
set_maybe_null(maybe_null_arg);
}
+ /*
+ Mark the item that it is a top level item, or part of a top level AND item,
+ for WHERE and ON clauses:
+ Example: ... WHERE a=5 AND b=6; Both a=5 and b=6 are top level items
+
+ This is used to indicate that there is no distinction between if the
+ value of the item is FALSE or NULL..
+ This enables Item_cond_and and subquery related items to do special
+ "top level" optimizations.
+ */
+ virtual void top_level_item()
+ {
+ base_flags|= item_base_t::AT_TOP_LEVEL;
+ }
+ /*
+ Return TRUE if this item of top WHERE level (AND/OR)
+ */
+ bool is_top_level_item() const
+ { return (bool) (base_flags & item_base_t::AT_TOP_LEVEL); }
void set_typelib(const TYPELIB *typelib) override
{
@@ -1833,6 +1852,16 @@ public:
*/
virtual bool is_evaluable_expression() const { return true; }
+ virtual bool check_assignability_to(const Field *to, bool ignore) const
+ {
+ /*
+ "this" must be neither DEFAULT/IGNORE,
+ nor Item_param bound to DEFAULT/IGNORE.
+ */
+ DBUG_ASSERT(is_evaluable_expression());
+ return to->check_assignability_from(type_handler(), ignore);
+ }
+
/**
* Check whether the item is a parameter ('?') of stored routine.
* Default implementation returns false. Method is overridden in the class
@@ -2049,25 +2078,6 @@ public:
{
return type_handler()->Item_update_null_value(this);
}
-
- /*
- Inform the item that there will be no distinction between its result
- being FALSE or NULL.
-
- NOTE
- This function will be called for eg. Items that are top-level AND-parts
- of the WHERE clause. Items implementing this function (currently
- Item_cond_and and subquery-related item) enable special optimizations
- when they are "top level".
- */
- virtual void top_level_item() {}
- /*
- Return TRUE if it is item of top WHERE level (AND/OR) and it is
- important, return FALSE if it not important (we can not use to simplify
- calculations) or not top level
- */
- virtual bool is_top_level_item() const
- { return FALSE; /* not important */}
/*
return IN/ALL/ANY subquery or NULL
*/
@@ -2677,18 +2687,27 @@ public:
void register_in(THD *thd);
bool depends_only_on(table_map view_map)
- { return marker & MARKER_FULL_EXTRACTION; }
- int get_extraction_flag()
- { return marker & MARKER_EXTRACTION_MASK; }
+ { return get_extraction_flag() & MARKER_FULL_EXTRACTION; }
+ int get_extraction_flag() const
+ {
+ if (basic_const_item())
+ return MARKER_FULL_EXTRACTION;
+ else
+ return marker & MARKER_EXTRACTION_MASK;
+ }
void set_extraction_flag(int16 flags)
{
- marker &= ~MARKER_EXTRACTION_MASK;
- marker|= flags;
+ if (!basic_const_item())
+ {
+ marker= marker & ~MARKER_EXTRACTION_MASK;
+ marker|= flags;
+ }
}
void clear_extraction_flag()
{
- marker &= ~MARKER_EXTRACTION_MASK;
- }
+ if (!basic_const_item())
+ marker= marker & ~MARKER_EXTRACTION_MASK;
+ }
void check_pushable_cond(Pushdown_checker excl_dep_func, uchar *arg);
bool pushable_cond_checker_for_derived(uchar *arg)
{
@@ -4124,6 +4143,7 @@ class Item_param :public Item_basic_value,
const String *value_query_val_str(THD *thd, String* str) const;
Item *value_clone_item(THD *thd);
bool is_evaluable_expression() const override;
+ bool check_assignability_to(const Field *field, bool ignore) const override;
bool can_return_value() const;
public:
@@ -4470,11 +4490,16 @@ public:
Item_bool_static(const char *str_arg, longlong i):
Item_bool(str_arg, i) {};
+ /* Don't mark static items as top level item */
+ virtual void top_level_item() override {}
void set_join_tab_idx(uint8 join_tab_idx_arg) override
{ DBUG_ASSERT(0); }
+
+ void cleanup() override {}
};
-extern const Item_bool_static Item_false, Item_true;
+/* The following variablese are stored in a read only segment */
+extern Item_bool_static *Item_false, *Item_true;
class Item_uint :public Item_int
{
@@ -6808,6 +6833,10 @@ public:
{
str->append(STRING_WITH_LEN("default"));
}
+ bool check_assignability_to(const Field *to, bool ignore) const override
+ {
+ return false;
+ }
int save_in_field(Field *field_arg, bool) override
{
return field_arg->save_in_field_default_value(false);
@@ -6841,6 +6870,10 @@ public:
{
str->append(STRING_WITH_LEN("ignore"));
}
+ bool check_assignability_to(const Field *to, bool ignore) const override
+ {
+ return false;
+ }
int save_in_field(Field *field_arg, bool) override
{
return field_arg->save_in_field_ignore_value(false);