[MDEV-18408] Assertion `0' failed in Item::val_native_result / Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null upon mysqld_list_fields after crash recovery Created: 2019-01-29  Updated: 2019-03-05  Resolved: 2019-03-05

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.4
Fix Version/s: 10.4.4

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Relates
relates to MDEV-18685 mysql_list_fields() returns DEFAULT 0... Open

 Description   

Note: the failure was observed as an aftermath of MDEV-18402 and MDEV-18401, so it's possible that it's a garbage-in-garbage-out situation. However, I don't have test cases for these two bugs yet, while this after-recovery failure is reproducible on their datasets, so it might be worth checking independently anyway.

10.4 4007eab

mysqld: /data/src/10.4/sql/item.h:1330: virtual bool Item::val_native(THD*, Native*): Assertion `0' failed.
190129  3:47:32 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f58f5cc7ee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000559e90b7c604 in Item::val_native (this=0x7f588817b850, thd=0x7f5888000b00, to=0x7f58e04eda60) at /data/src/10.4/sql/item.h:1330
#9  0x0000559e90e93958 in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null (this=0x7f58e04eda60, thd=0x7f5888000b00, item=0x7f588817b850, conv=false) at /data/src/10.4/sql/sql_type.cc:8155
#10 0x0000559e90e976c1 in Timestamp_or_zero_datetime_native_null::Timestamp_or_zero_datetime_native_null (this=0x7f58e04eda60, thd=0x7f5888000b00, item=0x7f588817b850) at /data/src/10.4/sql/sql_type.h:2457
#11 0x0000559e90e8e403 in Type_handler::Item_send_timestamp (this=0x559e923053f0 <type_handler_timestamp2>, item=0x7f588817b850, protocol=0x7f58e04edbe0, buf=0x7f58e04edc80) at /data/src/10.4/sql/sql_type.cc:6704
#12 0x0000559e90e9a920 in Type_handler_timestamp_common::Item_send (this=0x559e923053f0 <type_handler_timestamp2>, item=0x7f588817b850, protocol=0x7f58e04edbe0, buf=0x7f58e04edc80) at /data/src/10.4/sql/sql_type.h:5465
#13 0x0000559e90b7c3e0 in Item::send (this=0x7f588817b850, protocol=0x7f58e04edbe0, buffer=0x7f58e04edc80) at /data/src/10.4/sql/item.h:1032
#14 0x0000559e90b769f0 in Protocol::send_result_set_metadata (this=0x7f58880010c8, list=0x7f58e04ee080, flags=2) at /data/src/10.4/sql/protocol.cc:937
#15 0x0000559e90d2a98b in mysqld_list_fields (thd=0x7f5888000b00, table_list=0x7f58e04ee3b0, wild=0x7f5888013da8 "") at /data/src/10.4/sql/sql_show.cc:1553
#16 0x0000559e90c8adc7 in dispatch_command (command=COM_FIELD_LIST, thd=0x7f5888000b00, packet=0x7f588801bfb9 "test\aview_BB\aview_BB\002pk\002pk\f?", packet_length=8, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:2050
#17 0x0000559e90c88bd5 in do_command (thd=0x7f5888000b00) at /data/src/10.4/sql/sql_parse.cc:1395
#18 0x0000559e90df7b67 in do_handle_one_connection (connect=0x559e951c5880) at /data/src/10.4/sql/sql_connect.cc:1398
#19 0x0000559e90df78e2 in handle_one_connection (arg=0x559e951c5880) at /data/src/10.4/sql/sql_connect.cc:1301
#20 0x00007f58f799e494 in start_thread (arg=0x7f58e04ef700) at pthread_create.c:333
#21 0x00007f58f5d8493f in clone () from /lib/x86_64-linux-gnu/libc.so.6

To reproduce, download the datadir from here:
ftp://ftp.askmonty.org/public/mdev18408-data.tar.gz

Unpack it and start the server on it, all default options will do.
It starts seemingly normally, apart from numerous InnoDB notes "Ignoring data file...".
Then, connect by the command-line client to the database test without -A, or somehow else invoke the corresponding command.



 Comments   
Comment by Alexander Barkov [ 2019-02-19 ]

To reproduce the crash, run this SQL script in any client:

CREATE OR REPLACE TABLE t1 (a TIMESTAMP);
CREATE OR REPLACE VIEW v1 AS SELECT a FROM t1;

then start the command line client as follows:

mysql --auto-rehash test

Comment by Alexander Barkov [ 2019-02-21 ]

The crash is also repeatable by this new client test:

diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 2d238d8..cb8a499 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -8467,6 +8467,39 @@ static void test_list_fields_default()
 }
 
 
+static void test_mdev18408()
+{
+  MYSQL_RES *result;
+  int rc;
+  myheader("test_mdev18408s");
+
+  rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "DROP VIEW IF EXISTS v1");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "CREATE TABLE t1 (c1 TIMESTAMP NULL DEFAULT NULL)");
+  myquery(rc);
+
+  rc= mysql_query(mysql, "CREATE VIEW v1 AS SELECT c1 FROM t1");
+  myquery(rc);
+
+  result= mysql_list_fields(mysql, "v1", NULL);
+  mytest(result);
+
+  rc= my_process_result_set(result);
+  DIE_UNLESS(rc == 0);
+
+  verify_prepare_field(result, 0, "c1", "c1", MYSQL_TYPE_TIMESTAMP,
+                       "v1", "v1",  current_db, 19, 0);
+
+  mysql_free_result(result);
+  myquery(mysql_query(mysql, "DROP VIEW v1"));
+  myquery(mysql_query(mysql, "DROP TABLE t1"));
+}
+
+
 static void test_bug19671()
 {
   MYSQL_RES *result;
@@ -20977,6 +21010,7 @@ static struct my_tests_st my_tests[]= {
   { "test_bulk_delete", test_bulk_delete },
 #endif
   { "test_explain_meta", test_explain_meta },
+  { "test_mdev18408", test_mdev18408 },
   { 0, 0 }
 };
 

Generated at Thu Feb 08 08:43:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.