[MDEV-27206] [ERROR] Duplicated key: cause, Assertion `is_uniq_key' failed with optimizer trace Created: 2021-12-09  Updated: 2021-12-21  Resolved: 2021-12-14

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.8
Fix Version/s: 10.8.0

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

Issue Links:
Problem/Incident
is caused by MDEV-27036 Json_writer allows one to create dupl... Closed
Relates
relates to MDEV-27204 [ERROR] Json_writer: a member name wa... Closed
Epic Link: Tracer JSON consistency

 Description   

CREATE TABLE t1 (a INT) ENGINE=MyISAM;
 
CREATE TABLE t2 (pk TIME, b INT, primary key (pk), key (b)) ENGINE=MyISAM;
 
INSERT INTO t2 VALUES
  ('00:13:33',0),('00:13:34',1),('00:13:35',2),('00:13:36',3),
  ('00:13:37',4),('00:13:38',5),('00:13:39',6),('00:13:40',7),
  ('00:13:41',8),('00:13:42',9);
 
SET optimizer_trace = 'enabled=on';
 
SELECT * FROM t1 WHERE a IN ( SELECT b FROM t2 INNER JOIN t1 ON (a = pk) );
 
# Cleanup
DROP TABLE t1, t2;

10.8 1e8bcbd0

2021-12-09  3:36:46 4 [ERROR] Duplicated key: cause
 
mariadbd: /data/src/10.8/sql/my_json_writer.cc:166: Json_writer& Json_writer::add_member(const char*, size_t): Assertion `is_uniq_key' failed.
211209  3:36:46 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f224efc1f36 in __GI___assert_fail (assertion=0x5620c4f2cbb2 "is_uniq_key", file=0x5620c4f2ca50 "/data/src/10.8/sql/my_json_writer.cc", line=166, function=0x5620c4f2cb60 "Json_writer& Json_writer::add_member(const char*, size_t)") at assert.c:101
#8  0x00005620c4373ffc in Json_writer::add_member (this=0x7f223805c330, name=0x5620c4ec2af8 "cause", len=5) at /data/src/10.8/sql/my_json_writer.cc:166
#9  0x00005620c4373cfb in Json_writer::add_member (this=0x7f223805c330, name=0x5620c4ec2af8 "cause") at /data/src/10.8/sql/my_json_writer.cc:139
#10 0x00005620c3fc0f89 in Json_writer_object::add_member (this=0x7f22497e9c60, name=0x5620c4ec2af8 "cause") at /data/src/10.8/sql/my_json_writer.h:432
#11 0x00005620c3fc13ee in Json_writer_object::add (this=0x7f22497e9c60, name=0x5620c4ec2af8 "cause", value=0x5620c4ec2499 "cost") at /data/src/10.8/sql/my_json_writer.h:513
#12 0x00005620c418913e in best_access_path (join=0x7f2238058b38, s=0x7f223805ac58, remaining_tables=2, join_positions=0x7f223805b5f0, idx=2, disable_jbuf=true, record_count=1, pos=0x7f223805b850, loose_scan_pos=0x7f22497e9e20) at /data/src/10.8/sql/sql_select.cc:8168
#13 0x00005620c418dc35 in best_extension_by_limited_search (join=0x7f2238058b38, remaining_tables=2, idx=2, record_count=1, read_time=0, search_depth=62, prune_level=1, use_cond_selectivity=4) at /data/src/10.8/sql/sql_select.cc:9897
#14 0x00005620c418baaa in greedy_search (join=0x7f2238058b38, remaining_tables=2, search_depth=62, prune_level=1, use_cond_selectivity=4) at /data/src/10.8/sql/sql_select.cc:9073
#15 0x00005620c418acdc in choose_plan (join=0x7f2238058b38, join_tables=2) at /data/src/10.8/sql/sql_select.cc:8638
#16 0x00005620c4349643 in optimize_semijoin_nests (join=0x7f2238058b38, all_table_map=7) at /data/src/10.8/sql/opt_subselect.cc:2467
#17 0x00005620c4182552 in make_join_statistics (join=0x7f2238058b38, tables_list=..., keyuse_array=0x7f2238058e58) at /data/src/10.8/sql/sql_select.cc:5870
#18 0x00005620c4175d7c in JOIN::optimize_inner (this=0x7f2238058b38) at /data/src/10.8/sql/sql_select.cc:2453
#19 0x00005620c417366f in JOIN::optimize (this=0x7f2238058b38) at /data/src/10.8/sql/sql_select.cc:1809
#20 0x00005620c417f094 in mysql_select (thd=0x7f2238000db8, tables=0x7f2238015ad0, fields=..., conds=0x7f2238018b58, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f2238018f58, unit=0x7f22380051c0, select_lex=0x7f22380154f8) at /data/src/10.8/sql/sql_select.cc:4979
#21 0x00005620c416e2c1 in handle_select (thd=0x7f2238000db8, lex=0x7f22380050e8, result=0x7f2238018f58, setup_tables_done_option=0) at /data/src/10.8/sql/sql_select.cc:545
#22 0x00005620c4115ed9 in execute_sqlcom_select (thd=0x7f2238000db8, all_tables=0x7f2238015ad0) at /data/src/10.8/sql/sql_parse.cc:6253
#23 0x00005620c410d168 in mysql_execute_command (thd=0x7f2238000db8, is_called_from_prepared_stmt=false) at /data/src/10.8/sql/sql_parse.cc:3944
#24 0x00005620c411ad2a in mysql_parse (thd=0x7f2238000db8, rawbuf=0x7f2238015400 "SELECT * FROM t1 WHERE a IN ( SELECT b FROM t2 INNER JOIN t1 ON (a = pk) )", length=74, parser_state=0x7f22497eb480) at /data/src/10.8/sql/sql_parse.cc:8028
#25 0x00005620c410717e in dispatch_command (command=COM_QUERY, thd=0x7f2238000db8, packet=0x7f223800b989 "SELECT * FROM t1 WHERE a IN ( SELECT b FROM t2 INNER JOIN t1 ON (a = pk) )", packet_length=74, blocking=true) at /data/src/10.8/sql/sql_parse.cc:1894
#26 0x00005620c4105b1a in do_command (thd=0x7f2238000db8, blocking=true) at /data/src/10.8/sql/sql_parse.cc:1402
#27 0x00005620c42db559 in do_handle_one_connection (connect=0x5620c808fb18, put_in_cache=true) at /data/src/10.8/sql/sql_connect.cc:1418
#28 0x00005620c42db1e9 in handle_one_connection (arg=0x5620c8092178) at /data/src/10.8/sql/sql_connect.cc:1312
#29 0x00005620c47de6a7 in pfs_spawn_thread (arg=0x5620c808f668) at /data/src/10.8/storage/perfschema/pfs.cc:2201
#30 0x00007f224f4da609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#31 0x00007f224f0ad293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

The failure started happening on 10.8 tree after this commit:

commit 3a96a61eaec6679c6c5b3872383c7fd45e668647 (HEAD)
Author: Sergei Krivonos
Date:   Fri Nov 12 03:36:10 2021 +0200
 
    MDEV-27036: add assert to detect duplicated JSON keys

However, this revision added the assertion itself, so I can't tell whether an actual new problem was introduced by it, or it's a wrong assertion, or it's a good assertion which revealed a previously hidden issue. In the latter case please feel free to remove the label "regression".



 Comments   
Comment by Sergei Krivonos (Inactive) [ 2021-12-09 ]

https://buildbot.mariadb.org/#/grid?branch=bb-10.8-MDEV-27206

Comment by Sergei Krivonos (Inactive) [ 2021-12-10 ]

https://github.com/MariaDB/server/pull/1965

Comment by Sergei Petrunia [ 2021-12-14 ]

The patch was OK to push.

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