revision-id: 1e8b79d966fca2ae541477972ac759be5ee60c4e (mariadb-10.2.16-66-g1e8b79d966f) parent(s): 4ddcb4eb46c62cf459936554d43351db740ba14d author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-08-07 15:28:58 +0200 message: MDEV-16217: Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed in Field_num::get_date Provide possibility for constant function like DEFAULT() still mark tables as being read. --- mysql-test/r/func_time.result | 28 ++++++++++++++++++++++++++++ mysql-test/t/func_time.test | 21 +++++++++++++++++++++ sql/item.h | 9 +++++++++ 3 files changed, 58 insertions(+) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 55c2c93eb56..d3e81a8f2ee 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -3260,3 +3260,31 @@ DROP TABLE t1,t2; # # End of 10.1 tests # +# +# MDEV-16217: Assertion `!table || (!table->read_set || +# bitmap_is_set(table->read_set, field_index))' +# failed in Field_num::get_date +# +CREATE TABLE t1 (pk int default 0, a1 date); +INSERT INTO t1 VALUES (1,'1900-01-01'),(2,NULL),(3,NULL),(4,NULL); +CREATE VIEW v1 AS +SELECT t1.pk AS pk, t1.a1 AS a1 FROM t1; +SELECT a1 BETWEEN (('2018-08-24')) AND (DEFAULT(pk)) FROM v1; +a1 BETWEEN (('2018-08-24')) AND (DEFAULT(pk)) +0 +NULL +NULL +NULL +SELECT a1 BETWEEN (('2018-08-24')) AND (~ DEFAULT(pk)) FROM v1; +a1 BETWEEN (('2018-08-24')) AND (~ DEFAULT(pk)) +0 +NULL +NULL +NULL +Warnings: +Warning 1292 Incorrect datetime value: '18446744073709551615' +DROP VIEW v1; +DROP TABLE t1; +# +# End of 10.2 tests +# diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 3503b6d5bc6..98b5f968fe0 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -1857,3 +1857,24 @@ DROP TABLE t1,t2; --echo # --echo # End of 10.1 tests --echo # + +--echo # +--echo # MDEV-16217: Assertion `!table || (!table->read_set || +--echo # bitmap_is_set(table->read_set, field_index))' +--echo # failed in Field_num::get_date +--echo # +CREATE TABLE t1 (pk int default 0, a1 date); +INSERT INTO t1 VALUES (1,'1900-01-01'),(2,NULL),(3,NULL),(4,NULL); + +CREATE VIEW v1 AS +SELECT t1.pk AS pk, t1.a1 AS a1 FROM t1; + +SELECT a1 BETWEEN (('2018-08-24')) AND (DEFAULT(pk)) FROM v1; +SELECT a1 BETWEEN (('2018-08-24')) AND (~ DEFAULT(pk)) FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + +--echo # +--echo # End of 10.2 tests +--echo # diff --git a/sql/item.h b/sql/item.h index 8fad8dadf22..54cd358112d 100644 --- a/sql/item.h +++ b/sql/item.h @@ -5649,6 +5649,15 @@ class Item_cache: public Item_basic_constant, example->split_sum_func2(thd, ref_pointer_array, fields, &example, flags); } Item *get_example() const { return example; } + /* + Functiuons like DEFAULT() are constant but still read from tables and + update them, so we should gave that chance to them in case of caching. + */ + virtual void update_used_tables() + { + if (example) + return example->update_used_tables(); + } virtual Item *convert_to_basic_const_item(THD *thd) { return 0; }; Item *derived_field_transformer_for_having(THD *thd, uchar *arg)