[MDEV-26589] Assertion failure upon DECODE_HISTOGRAM with NULLs in first column Created: 2021-09-11  Updated: 2022-01-19  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: Blocker
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, b INT);
INSERT INTO t1 VALUES (NULL,1), (NULL,2);
SET histogram_type = JSON_HB;
ANALYZE TABLE t1 PERSISTENT FOR ALL;
SELECT DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats;
 
# Cleanup
DROP TABLE t1;

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

mariadbd: /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_type.cc:7457: bool Type_handler::Item_send_str(Item*, Protocol*, st_value*) const: Assertion `!it
em->null_value' failed.
210911 12:44:49 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fcbe9582f36 in __GI___assert_fail (assertion=0x5595b90af58f "!item->null_value", file=0x5595b90ac490 "/data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_type.cc", line=7457, function=0x5595b90af5a8 "bool Type_handler::Item_send_str(Item*, Protocol*, st_value*) const") at assert.c:101
#8  0x00005595b7c7dcc9 in Type_handler::Item_send_str (this=0x5595ba6f9ac0 <type_handler_long_blob>, item=0x7fcbc8015a90, protocol=0x7fcbc80013a0, buf=0x7fcbe45ddc60) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_type.cc:7457
#9  0x00005595b7ad0358 in Type_handler_string_result::Item_send (this=0x5595ba6f9ac0 <type_handler_long_blob>, item=0x7fcbc8015a90, protocol=0x7fcbc80013a0, buf=0x7fcbe45ddc60) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_type.h:5440
#10 0x00005595b74ca666 in Item::send (this=0x7fcbc8015a90, protocol=0x7fcbc80013a0, buffer=0x7fcbe45ddc60) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/item.h:1227
#11 0x00005595b754fe9e in Protocol::send_result_set_row (this=0x7fcbc80013a0, row_items=0x7fcbc8015618) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/protocol.cc:1327
#12 0x00005595b76b6e27 in select_send::send_data (this=0x7fcbc8016bd0, items=...) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_class.cc:3072
#13 0x00005595b7914c19 in select_result_sink::send_data_with_check (this=0x7fcbc8016bd0, items=..., u=0x7fcbc8005120, sent=1) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_class.h:5634
#14 0x00005595b78e34fa in end_send (join=0x7fcbc8016bf8, join_tab=0x7fcbc8018278, end_of_records=false) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:22285
#15 0x00005595b78de5b1 in evaluate_join_record (join=0x7fcbc8016bf8, join_tab=0x7fcbc8017ec8, error=0) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:21278
#16 0x00005595b78dda54 in sub_select (join=0x7fcbc8016bf8, join_tab=0x7fcbc8017ec8, end_of_records=false) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:21094
#17 0x00005595b78dbe49 in do_select (join=0x7fcbc8016bf8, procedure=0x0) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:20602
#18 0x00005595b788b47c in JOIN::exec_inner (this=0x7fcbc8016bf8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:4735
#19 0x00005595b78897a5 in JOIN::exec (this=0x7fcbc8016bf8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:4513
#20 0x00005595b788c97b in mysql_select (thd=0x7fcbc8000db8, tables=0x7fcbc8015c10, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fcbc8016bd0, unit=0x7fcbc8005120, select_lex=0x7fcbc8015378) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:4991
#21 0x00005595b786cbb8 in handle_select (thd=0x7fcbc8000db8, lex=0x7fcbc8005058, result=0x7fcbc8016bd0, setup_tables_done_option=0) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_select.cc:545
#22 0x00005595b77c7176 in execute_sqlcom_select (thd=0x7fcbc8000db8, all_tables=0x7fcbc8015c10) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:6256
#23 0x00005595b77b342a in mysql_execute_command (thd=0x7fcbc8000db8, is_called_from_prepared_stmt=false) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:3946
#24 0x00005595b77d086c in mysql_parse (thd=0x7fcbc8000db8, rawbuf=0x7fcbc8015290 "SELECT DECODE_HISTOGRAM(hist_type, histogram) from mysql.column_stats", length=69, parser_state=0x7fcbe45df480) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:8030
#25 0x00005595b77a6b0c in dispatch_command (command=COM_QUERY, thd=0x7fcbc8000db8, packet=0x7fcbc800b849 "", packet_length=69, blocking=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:1896
#26 0x00005595b77a3ba2 in do_command (thd=0x7fcbc8000db8, blocking=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_parse.cc:1404
#27 0x00005595b7b0d493 in do_handle_one_connection (connect=0x5595bc8dd8c8, put_in_cache=true) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_connect.cc:1418
#28 0x00005595b7b0cc5b in handle_one_connection (arg=0x5595bc8dc1f8) at /data/src/preview-10.7-MDEV-21130-json-histograms/sql/sql_connect.cc:1312
#29 0x00005595b83eea83 in pfs_spawn_thread (arg=0x5595bc8dd418) at /data/src/preview-10.7-MDEV-21130-json-histograms/storage/perfschema/pfs.cc:2201
#30 0x00007fcbe9a9b609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#31 0x00007fcbe966e293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Reproducible with at least MyISAM and InnoDB.

As far as I could tell, the important part here is that the first column of the table has only NULLs. If one of the values in the first column isn't NULL, the failure doesn't happen.
If this generalization is incorrect, please modify the ticket summary to avoid confusion.



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

Not reproducible in bb-10.7-mdev26519 branch, revision 0fe2cfd45e616e93d47aa9e224db468f32dd391a

Comment by Sergei Petrunia [ 2021-09-20 ]

Wait, it was repeatable. Now fixed.

Comment by Sergei Petrunia [ 2021-09-20 ]

Fixed in preview-10.7-MDEV-26519-improved-json-histograms tree.

Comment by Elena Stepanova [ 2021-09-29 ]

It is not fixed in preview-10.7-MDEV-26519-json-histograms. Same test case still fails same way.
Maybe the fix got lost somewhere between the trees (the previous comment mentions a different branch).

Comment by Sergei Petrunia [ 2021-10-04 ]

Indeed, the fix was pushed into the wrong branch.

I've now cherry-picked it into the right branch:

commit 7b49fb5803e4589d4bab2123813784d9ff29018d
Author: Sergei Petrunia <psergey@askmonty.org>
Date:   Fri Oct 1 14:24:41 2021 +0300
 
    MDEV-26589: Assertion failure upon DECODE_HISTOGRAM with NULLs
    
    Item_func_decode_histogram::val_str should correctly set null_value
    when "decoding" JSON histogram.

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