[MDEV-26592] Assertion failure in set_warning_truncated_wrong_value / Column_stat::load_histogram after failed constraint creation Created: 2021-09-11  Updated: 2021-10-05  Resolved: 2021-10-04

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: N/A
Fix Version/s: 10.7.1

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-21130 Histograms: use JSON as on-disk format Closed

 Description   

CREATE TABLE t1 (a INT) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(1);
 
CREATE TABLE t2 (b VARCHAR(255)) CHARACTER SET utf8mb4;
INSERT INTO t2 VALUES (_ASCII 0x06),('foo');
 
--error ER_DUP_ENTRY
ALTER TABLE t1 ADD UNIQUE (a);
 
SET histogram_type = JSON_HB;
ANALYZE TABLE t2 PERSISTENT FOR ALL;
 
SELECT * FROM t2;
 
# Cleanup
DROP TABLE t1, t2;

preview-10.7-MDEV-21130-json-histograms 8fc778f3e9

mariadbd: /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.cc:11173: void Field::set_warning_truncated_wrong_value(const char*, const char*): Assertion `table' failed.
210911 19:34:59 [ERROR] mysqld got signal 6 ;
 
#7  0x00007ff76e818f36 in __GI___assert_fail (assertion=0x55a1fb7be87e "table", file=0x55a1fb7ba498 "/data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.cc", line=11173, function=0x55a1fb7be888 "void Field::set_warning_truncated_wrong_value(const char*, const char*)") at assert.c:101
#8  0x000055a1fa42b1d4 in Field::set_warning_truncated_wrong_value (this=0x7ff758055be8, type_arg=0x55a1fb7bcd7e "string", value=0x7ff76906fbb0 "\\xA5\\xA5\\xA5\\xA5\\xA5\\xA5...") at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.cc:11173
#9  0x000055a1fa411355 in Field_longstr::check_string_copy_error (this=0x7ff758055be8, copier=0x7ff76906fc80, end=0x7ff7581f657d "U", cs=0x55a1fc86ec60 <my_charset_bin>) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.cc:7204
#10 0x000055a1fa4314e5 in Field_longstr::check_conversion_status (this=0x7ff758055be8, copier=0x7ff76906fc80, end=0x7ff7581f657d "U", cs=0x55a1fc86ec60 <my_charset_bin>, count_spaces=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.h:2168
#11 0x000055a1fa431634 in Field_longstr::well_formed_copy_with_check (this=0x7ff758055be8, to=0x7ff758064bd3 "\004test\002t2\001b", to_length=1020, from_cs=0x55a1fc86ec60 <my_charset_bin>, from=0x7ff7581ee586 "\004test\002t2\001b", from_length=32759, nchars=255, count_spaces=true, copy_length=0x7ff76906fcf8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.h:2185
#12 0x000055a1fa4158df in Field_varstring::store (this=0x7ff758055be8, from=0x7ff7581ee586 "\004test\002t2\001b", length=32759, cs=0x55a1fc86ec60 <my_charset_bin>) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.cc:7828
#13 0x000055a1fa08ef8a in Field::store_text (this=0x7ff758055be8, to=0x7ff7581ee586 "\004test\002t2\001b", length=32759, cs=0x55a1fc86ec60 <my_charset_bin>) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/field.h:936
#14 0x000055a1fa186e17 in Histogram_json_hb::parse (this=0x7ff75805e760, mem_root=0x7ff758060ad8, field=0x7ff758055be8, type_arg=JSON_HB, hist_data=0x7ff758068318 "{\n  \"histogram_hb_v1\": [\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    \"\006\",\n    "..., hist_data_len=2580) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/opt_histogram_json.cc:200
#15 0x000055a1f9f452f8 in Column_stat::load_histogram (this=0x7ff769070f90, mem_root=0x7ff758060ad8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_statistics.cc:1235
#16 0x000055a1f9f3b42b in read_histograms_for_table (thd=0x7ff758000db8, table=0x7ff758065068, stat_tables=0x7ff769071090) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_statistics.cc:3168
#17 0x000055a1f9f3bfa2 in read_statistics_for_tables (thd=0x7ff758000db8, tables=0x7ff7580158e8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_statistics.cc:3305
#18 0x000055a1f9f3b63c in read_statistics_for_tables_if_needed (thd=0x7ff758000db8, tables=0x7ff7580158e8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_statistics.cc:3214
#19 0x000055a1f9c2137e in open_and_lock_tables (thd=0x7ff758000db8, options=..., tables=0x7ff7580158e8, derived=true, flags=0, prelocking_strategy=0x7ff769073878) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_base.cc:5266
#20 0x000055a1f9b95521 in open_and_lock_tables (thd=0x7ff758000db8, tables=0x7ff7580158e8, derived=true, flags=0) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_base.h:509
#21 0x000055a1f9d8287d in execute_sqlcom_select (thd=0x7ff758000db8, all_tables=0x7ff7580158e8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:6177
#22 0x000055a1f9d6f42a in mysql_execute_command (thd=0x7ff758000db8, is_called_from_prepared_stmt=false) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:3946
#23 0x000055a1f9d8c86c in mysql_parse (thd=0x7ff758000db8, rawbuf=0x7ff758015290 "SELECT * FROM t2", length=16, parser_state=0x7ff769074480) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:8030
#24 0x000055a1f9d62b0c in dispatch_command (command=COM_QUERY, thd=0x7ff758000db8, packet=0x7ff75800b849 "SELECT * FROM t2", packet_length=16, blocking=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:1896
#25 0x000055a1f9d5fba2 in do_command (thd=0x7ff758000db8, blocking=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:1404
#26 0x000055a1fa0c9493 in do_handle_one_connection (connect=0x55a1ff2ee8c8, put_in_cache=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_connect.cc:1418
#27 0x000055a1fa0c8c5b in handle_one_connection (arg=0x55a1ff2ed1f8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_connect.cc:1312
#28 0x000055a1fa9aaa83 in pfs_spawn_thread (arg=0x55a1ff2ee418) at /data/src/preview-10.7-MDEV-21130-json-histograms/storage/perfschema/pfs.cc:2201
#29 0x00007ff76ed31609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#30 0x00007ff76e904293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95



 Comments   
Comment by Sergei Petrunia [ 2021-09-28 ]

Ok, the issue is caused by the "0x06". As far as I understand, it is a valid UTF-8 character, but it is a "control character". According to the JSON spec, control characters are not allowed.

Comment by Sergei Petrunia [ 2021-10-04 ]

Fixed by these two fixes:

commit efa79c9082062c3f032f7f3ec12dc0a7a0ed3939
Author: Sergei Petrunia <psergey@askmonty.org>
Date:   Fri Oct 1 14:15:17 2021 +0300
 
    MDEV-26724 Endless loop in json_escape_to_string upon ... empty string
    
    Correctly handle empty string when [un]escaping JSON
 
commit 656dff97582cca416ecf5030ed114a610f8698df
Author: Sergei Petrunia <psergey@askmonty.org>
Date:   Wed Sep 29 20:11:48 2021 +0300
 
    MDEV-26711: Values in JSON histograms are not properly quoted
    
    Escape values when serializing to JSON. Un-escape when reading back.

Comment by Sergei Petrunia [ 2021-10-04 ]

Closing this, but we're not fully over with histograms-and-odd-chars. See MDEV-26764 for the final piece.

Generated at Thu Feb 08 09:46:28 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.