mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-3928: Assertion `example' failed in Item_cache::is_expensive_processor with a 2-level IN subquery
Analysis: The following call stack shows that it is possible to set Item_cache::value_cached, and the relevant value without setting Item_cache::example. #0 Item_cache_temporal::store_packed at item.cc:8395 #1 get_datetime_value at item_cmpfunc.cc:915 #2 resolve_const_item at item.cc:7987 #3 propagate_cond_constants at sql_select.cc:12264 #4 propagate_cond_constants at sql_select.cc:12227 #5 optimize_cond at sql_select.cc:13026 #6 JOIN::optimize at sql_select.cc:1016 #7 st_select_lex::optimize_unflattened_subqueries at sql_lex.cc:3161 #8 JOIN::optimize_unflattened_subqueries at opt_subselect.cc:4880 #9 JOIN::optimize at sql_select.cc:1554 The fix is to set Item_cache_temporal::example even when the value is set directly by Item_cache_temporal::store_packed. This makes the Item_cache_temporal object consistent.
This commit is contained in:
@@ -2279,5 +2279,31 @@ MAX(a) bb
|
|||||||
NULL NULL
|
NULL NULL
|
||||||
drop table t1, t2;
|
drop table t1, t2;
|
||||||
set optimizer_switch=@subselect4_tmp;
|
set optimizer_switch=@subselect4_tmp;
|
||||||
|
#
|
||||||
|
# MDEV-3928 Assertion `example' failed in Item_cache::is_expensive_processor with a 2-level IN subquery
|
||||||
|
#
|
||||||
|
CREATE TABLE t1 (a1 INT, b1 TIME) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t1 VALUES (4,'21:22:34'),(6,'10:50:38');
|
||||||
|
CREATE TABLE t2 (a2 INT, b2 TIME) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t2 VALUES (8, '06:17:39');
|
||||||
|
CREATE TABLE t3 (a3 INT, b3 TIME) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t3 VALUES (1,'00:00:01'),(7,'00:00:02');
|
||||||
|
EXPLAIN
|
||||||
|
SELECT * FROM t1 WHERE a1 IN (
|
||||||
|
SELECT a2 FROM t2 WHERE a2 IN (
|
||||||
|
SELECT a3 FROM t3 WHERE b2 = b1 AND b2 <= b1 ORDER BY b3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
id select_type table type possible_keys key key_len ref rows Extra
|
||||||
|
1 PRIMARY t2 system NULL NULL NULL NULL 1
|
||||||
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
|
||||||
|
3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where
|
||||||
|
SELECT * FROM t1 WHERE a1 IN (
|
||||||
|
SELECT a2 FROM t2 WHERE a2 IN (
|
||||||
|
SELECT a3 FROM t3 WHERE b2 = b1 AND b2 <= b1 ORDER BY b3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
a1 b1
|
||||||
|
drop table t1, t2, t3;
|
||||||
SET optimizer_switch= @@global.optimizer_switch;
|
SET optimizer_switch= @@global.optimizer_switch;
|
||||||
set @@tmp_table_size= @@global.tmp_table_size;
|
set @@tmp_table_size= @@global.tmp_table_size;
|
||||||
|
@@ -1858,5 +1858,33 @@ drop table t1, t2;
|
|||||||
|
|
||||||
set optimizer_switch=@subselect4_tmp;
|
set optimizer_switch=@subselect4_tmp;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-3928 Assertion `example' failed in Item_cache::is_expensive_processor with a 2-level IN subquery
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
CREATE TABLE t1 (a1 INT, b1 TIME) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t1 VALUES (4,'21:22:34'),(6,'10:50:38');
|
||||||
|
|
||||||
|
CREATE TABLE t2 (a2 INT, b2 TIME) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t2 VALUES (8, '06:17:39');
|
||||||
|
|
||||||
|
CREATE TABLE t3 (a3 INT, b3 TIME) ENGINE=MyISAM;
|
||||||
|
INSERT INTO t3 VALUES (1,'00:00:01'),(7,'00:00:02');
|
||||||
|
|
||||||
|
EXPLAIN
|
||||||
|
SELECT * FROM t1 WHERE a1 IN (
|
||||||
|
SELECT a2 FROM t2 WHERE a2 IN (
|
||||||
|
SELECT a3 FROM t3 WHERE b2 = b1 AND b2 <= b1 ORDER BY b3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT * FROM t1 WHERE a1 IN (
|
||||||
|
SELECT a2 FROM t2 WHERE a2 IN (
|
||||||
|
SELECT a3 FROM t3 WHERE b2 = b1 AND b2 <= b1 ORDER BY b3
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
drop table t1, t2, t3;
|
||||||
|
|
||||||
SET optimizer_switch= @@global.optimizer_switch;
|
SET optimizer_switch= @@global.optimizer_switch;
|
||||||
set @@tmp_table_size= @@global.tmp_table_size;
|
set @@tmp_table_size= @@global.tmp_table_size;
|
||||||
|
@@ -8388,9 +8388,10 @@ int Item_cache_temporal::save_in_field(Field *field, bool no_conversions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Item_cache_temporal::store_packed(longlong val_arg)
|
void Item_cache_temporal::store_packed(longlong val_arg, Item *example)
|
||||||
{
|
{
|
||||||
/* An explicit values is given, save it. */
|
/* An explicit values is given, save it. */
|
||||||
|
store(example);
|
||||||
value_cached= true;
|
value_cached= true;
|
||||||
value= val_arg;
|
value= val_arg;
|
||||||
null_value= false;
|
null_value= false;
|
||||||
|
@@ -3799,7 +3799,7 @@ public:
|
|||||||
bool cache_value();
|
bool cache_value();
|
||||||
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
|
bool get_date(MYSQL_TIME *ltime, uint fuzzydate);
|
||||||
int save_in_field(Field *field, bool no_conversions);
|
int save_in_field(Field *field, bool no_conversions);
|
||||||
void store_packed(longlong val_arg);
|
void store_packed(longlong val_arg, Item *example);
|
||||||
/*
|
/*
|
||||||
Having a clone_item method tells optimizer that this object
|
Having a clone_item method tells optimizer that this object
|
||||||
is a constant and need not be optimized further.
|
is a constant and need not be optimized further.
|
||||||
@@ -3808,7 +3808,7 @@ public:
|
|||||||
Item *clone_item()
|
Item *clone_item()
|
||||||
{
|
{
|
||||||
Item_cache_temporal *item= new Item_cache_temporal(cached_field_type);
|
Item_cache_temporal *item= new Item_cache_temporal(cached_field_type);
|
||||||
item->store_packed(value);
|
item->store_packed(value, example);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -912,7 +912,7 @@ get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
|
|||||||
if (save_arena)
|
if (save_arena)
|
||||||
thd->set_query_arena(save_arena);
|
thd->set_query_arena(save_arena);
|
||||||
|
|
||||||
cache->store_packed(value);
|
cache->store_packed(value, item);
|
||||||
*cache_arg= cache;
|
*cache_arg= cache;
|
||||||
*item_arg= cache_arg;
|
*item_arg= cache_arg;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user