|
USE test;
|
CREATE TABLE t (a TIMESTAMP,b TIMESTAMP); # (ENGINE=InnoDB)
|
INSERT INTO t VALUES (0,0);
|
SET SQL_MODE='TRADITIONAL';
|
SELECT TRUNCATE(a,b) AS c FROM t;
|
Leads to:
|
10.5.3 cfe5ee90c8e4b9dfa98a41fcd299197a59261be7
|
mysqld: /test/10.5_dbg/sql/item_func.cc:2564: virtual bool Item_func_round::date_op(THD*, MYSQL_TIME*, date_mode_t): Assertion `maybe_null || !null_value' failed.
|
|
10.5.3 cfe5ee90c8e4b9dfa98a41fcd299197a59261be7
|
Core was generated by `/test/MD110520-mariadb-10.5.3-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
|
Program terminated with signal SIGABRT, Aborted.
|
#0 __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
|
at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
|
[Current thread is 1 (Thread 0x1550414eb700 (LWP 5986))]
|
(gdb) bt
|
#0 __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
|
#1 0x000055bf8974ec11 in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:518
|
#2 0x000055bf88ef3f8d in handle_fatal_signal (sig=6) at /test/10.5_dbg/sql/signal_handler.cc:329
|
#3 <signal handler called>
|
#4 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
|
#5 0x000015503fc2f801 in __GI_abort () at abort.c:79
|
#6 0x000015503fc1f39a in __assert_fail_base (fmt=0x15503fda67d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x55bf89a6d9d4 "maybe_null || !null_value", file=file@entry=0x55bf89a6dc30 "/test/10.5_dbg/sql/item_func.cc", line=line@entry=2564, function=function@entry=0x55bf89a6c520 <Item_func_round::date_op(THD*, st_mysql_time*, date_mode_t)::__PRETTY_FUNCTION__> "virtual bool Item_func_round::date_op(THD*, MYSQL_TIME*, date_mode_t)") at assert.c:92
|
#7 0x000015503fc1f412 in __GI___assert_fail (assertion=assertion@entry=0x55bf89a6d9d4 "maybe_null || !null_value", file=file@entry=0x55bf89a6dc30 "/test/10.5_dbg/sql/item_func.cc", line=line@entry=2564, function=function@entry=0x55bf89a6c520 <Item_func_round::date_op(THD*, st_mysql_time*, date_mode_t)::__PRETTY_FUNCTION__> "virtual bool Item_func_round::date_op(THD*, MYSQL_TIME*, date_mode_t)") at assert.c:101
|
#8 0x000055bf88f7bd0f in Item_func_round::date_op (this=0x15501e474848, thd=0x15501e415088, to=0x1550414e8fd8, fuzzydate=...) at /test/10.5_dbg/sql/item_func.cc:2564
|
#9 0x000055bf88e1ad08 in Type_handler_temporal_result::Item_func_hybrid_field_type_get_date (this=<optimized out>, thd=<optimized out>, item=<optimized out>, warn=<optimized out>, ltime=0x1550414e8fd8, fuzzydate=...) at /test/10.5_dbg/sql/sql_type.cc:5366
|
#10 0x000055bf88e2f133 in Type_handler::Item_func_hybrid_field_type_get_date_with_warn (this=0x55bf8a4c2d80 <type_handler_datetime2>, thd=thd@entry=0x15501e415088, item=item@entry=0x15501e474848, ltime=ltime@entry=0x1550414e8fd8, mode=mode@entry=...) at /test/10.5_dbg/sql/sql_type.cc:4950
|
#11 0x000055bf88f543f4 in Item_func_hybrid_field_type::get_date (this=this@entry=0x15501e474848, thd=0x15501e415088, to=to@entry=0x1550414e8fd8, mode=...) at /test/10.5_dbg/sql/item_func.h:820
|
#12 0x000055bf88e30224 in Type_handler::Item_send_datetime (this=<optimized out>, item=0x15501e474848, protocol=0x15501e415650, buf=0x1550414e8fd0) at /test/10.5_dbg/sql/sql_type.cc:7221
|
#13 0x000055bf88d84c59 in Type_handler_datetime_common::Item_send (this=<optimized out>, item=<optimized out>, protocol=<optimized out>, buf=<optimized out>) at /test/10.5_dbg/sql/sql_type.h:6186
|
#14 0x000055bf88b5d4b9 in Item::send (this=0x15501e474848, protocol=0x15501e415650, buffer=0x1550414e8fd0) at /test/10.5_dbg/sql/item.h:1054
|
#15 0x000055bf88b5b229 in Protocol::send_result_set_row (this=this@entry=0x15501e415650, row_items=row_items@entry=0x15501e474298) at /test/10.5_dbg/sql/protocol.cc:1082
|
#16 0x000055bf88becce8 in select_send::send_data (this=0x15501e475948, items=...) at /test/10.5_dbg/sql/sql_class.cc:2998
|
#17 0x000055bf88ca0e07 in select_result_sink::send_data_with_check (sent=<optimized out>, u=<optimized out>, items=..., this=<optimized out>) at /test/10.5_dbg/sql/sql_class.h:5237
|
#18 end_send (join=0x15501e475970, join_tab=0x15501e476fb0, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:21809
|
#19 0x000055bf88c890c8 in evaluate_join_record (join=join@entry=0x15501e475970, join_tab=join_tab@entry=0x15501e476c08, error=error@entry=0) at /test/10.5_dbg/sql/sql_select.cc:20838
|
#20 0x000055bf88c90447 in sub_select (join=0x15501e475970, join_tab=0x15501e476c08, end_of_records=<optimized out>) at /test/10.5_dbg/sql/sql_select.cc:20615
|
#21 0x000055bf88cc81ec in do_select (procedure=0x0, join=0x15501e475970) at /test/10.5_dbg/sql/sql_select.cc:20149
|
#22 JOIN::exec_inner (this=this@entry=0x15501e475970) at /test/10.5_dbg/sql/sql_select.cc:4464
|
#23 0x000055bf88cc8807 in JOIN::exec (this=this@entry=0x15501e475970) at /test/10.5_dbg/sql/sql_select.cc:4245
|
#24 0x000055bf88cc6b1c in mysql_select (thd=thd@entry=0x15501e415088, tables=<optimized out>, fields=..., conds=0x0, og_num=0, order=<optimized out>, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x15501e475948, unit=0x15501e419098, select_lex=0x15501e474148) at /test/10.5_dbg/sql/sql_select.cc:4669
|
#25 0x000055bf88cc6e4b in handle_select (thd=thd@entry=0x15501e415088, lex=lex@entry=0x15501e418fd0, result=result@entry=0x15501e475948, setup_tables_done_option=setup_tables_done_option@entry=0) at /test/10.5_dbg/sql/sql_select.cc:417
|
#26 0x000055bf88c51867 in execute_sqlcom_select (thd=thd@entry=0x15501e415088, all_tables=0x15501e474978) at /test/10.5_dbg/sql/sql_parse.cc:6172
|
#27 0x000055bf88c4a993 in mysql_execute_command (thd=thd@entry=0x15501e415088) at /test/10.5_dbg/sql/sql_parse.cc:3901
|
#28 0x000055bf88c57804 in mysql_parse (thd=thd@entry=0x15501e415088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x1550414ea3e0, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:7957
|
#29 0x000055bf88c43ffd in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x15501e415088, packet=packet@entry=0x15501e467089 "", packet_length=packet_length@entry=32, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:1839
|
#30 0x000055bf88c428cc in do_command (thd=0x15501e415088) at /test/10.5_dbg/sql/sql_parse.cc:1358
|
#31 0x000055bf88d9c99d in do_handle_one_connection (connect=<optimized out>, connect@entry=0x1550200433a8, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1411
|
#32 0x000055bf88d9d0b9 in handle_one_connection (arg=arg@entry=0x1550200433a8) at /test/10.5_dbg/sql/sql_connect.cc:1313
|
#33 0x000055bf891fb10a in pfs_spawn_thread (arg=0x15503f045888) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
|
#34 0x00001550409126db in start_thread (arg=0x1550414eb700) at pthread_create.c:463
|
#35 0x000015503fd1088f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
|
Bug confirmed present in:
MariaDB: 10.4.13 (dbg), 10.5.2 (dbg), 10.5.3 (dbg)
Bug confirmed not present in:
MariaDB: 10.1.45 (dbg), 10.1.45 (opt), 10.2.32 (dbg), 10.2.32 (opt), 10.3.23 (dbg), 10.3.23 (opt), 10.4.13 (opt), 10.5.2 (opt), 10.5.3 (opt), 10.5.4 (dbg), 10.5.4 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)
Oddly, alike to similar situation earlier in the comments, not reproducible on 10.5.4
|
10.5.4 69077dea25f6e7cab4ff8927e4429ad62af9de49
|
10.5.4>USE test;
|
Database changed
|
10.5.4>CREATE TABLE t (a TIMESTAMP,b TIMESTAMP); # (ENGINE=InnoDB)
|
Query OK, 0 rows affected (0.008 sec)
|
10.5.4>INSERT INTO t VALUES (0,0);
|
Query OK, 1 row affected (0.001 sec)
|
10.5.4>SET SQL_MODE='TRADITIONAL';
|
Query OK, 0 rows affected (0.000 sec)
|
10.5.4>SELECT TRUNCATE(a,b) AS c FROM t;
|
+---+
|
| c |
|
+---+
|
| NULL |
|
+---+
|
1 row in set (0.000 sec)
|
|
|
(CC: serg)
On last sql processor call, there was a question about what exactly different const-row messages mean in EXPLAIN.
When the table should have a single row and that row is not found, it can be:
- "Const row not found"
- "Unique row not found"
- "Impossible WHERE noticed after reading const tables"
- "no matching row in const table".
Internally, when the table is a system table (has 0 or 1 rows, MyISAM) and we cant find the row, it is marked with "Const row not found".
If the SELECT has no WHERE condition at all, the "Const row not found" makes it to the EXPLAIN output:
explain select * from t_empty;
|
+------+-------------+---------+--------+---------------+------+---------+------+------+---------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+---------+--------+---------------+------+---------+------+------+---------------------+
|
| 1 | SIMPLE | t_empty | system | NULL | NULL | NULL | NULL | 0 | Const row not found |
|
+------+-------------+---------+--------+---------------+------+---------+------+------+---------------------+
|
explain select * from t_empty, ten;
|
+------+-------------+---------+--------+---------------+------+---------+------+------+---------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+---------+--------+---------------+------+---------+------+------+---------------------+
|
| 1 | SIMPLE | t_empty | system | NULL | NULL | NULL | NULL | 0 | Const row not found |
|
| 1 | SIMPLE | ten | ALL | NULL | NULL | NULL | NULL | 10 | |
|
+------+-------------+---------+--------+---------------+------+---------+------+------+---------------------+
|
A more typical case is when the query has a WHERE clause. The optimizer will attempt to compute it for NULL-complemented row and
the user will see "Impossible WHERE noticed ...":
explain select * from t_empty, ten where ten.a<10;
|
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables |
|
+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+
|
When table $TBL is a "const" table (because there is table.primary_key=const restriction), but it is not a system table, it is marked with "Unique row not found". However, a restriction "table.primary_key=const" can only be inferred from the WHERE clause. That is, the WHERE clause is present, and EXPLAIN will show "Impossible WHERE noticed ...". It seems it's not possible to construct a query such that "Unique row not found" is shown to the user.
In some cases, EXPLAIN will also show "no matching row in const table". Note that the message is per-select, it won't specify which table it was.
The message is shown by ANALYZE commands where EXPLAIN would show "Impossible WHERE ...":
analyze select * from t_empty, ten where ten.a<10;
|
+------+-------------+-------+------+---------------+------+---------+------+------+--------+----------+------------+--------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | r_rows | filtered | r_filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+--------+----------+------------+--------------------------------+
|
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | no matching row in const table |
|
+------+-------------+-------+------+---------------+------+---------+------+------+--------+----------+------------+--------------------------------+
|
It is also frequently (always?) shown for subqueries:
explain select (select count(*) from t_empty, ten where ten.a<10) as SUBQ from ten;
|
+------+-------------+-------+------+---------------+------+---------+------+------+--------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+--------------------------------+
|
| 1 | PRIMARY | ten | ALL | NULL | NULL | NULL | NULL | 10 | |
|
| 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | no matching row in const table |
|
+------+-------------+-------+------+---------------+------+---------+------+------+--------------------------------+
|
The reason is SELECT_DESCRIBE check in JOIN::optimize_stage2:
{
|
if (const_table_map != found_const_table_map &&
|
!(select_options & SELECT_DESCRIBE))
|
{
|
// There is at least one empty const table
|
zero_result_cause= "no matching row in const table";
|
SELECT_DESCRIBE is not set for ANALYZE. Also it is not set when this code is executed for subqueries.
|