[MDEV-18293] row_sel_sec_rec_is_for_clust_rec() is being invoked for READ UNCOMMITTED Created: 2019-01-18  Updated: 2023-04-27

Status: Confirmed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB, Storage Engine - XtraDB
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Thirunarayanan Balathandayuthapani
Resolution: Unresolved Votes: 0
Labels: performance

Issue Links:
Relates
relates to MDEV-17823 Assertion `!rec_offs_nth_default(clus... Closed

 Description   

The function row_sel_get_clust_rec_for_mysql() is invoking row_sel_sec_rec_is_for_clust_rec() even at the READ UNCOMMITTED isolation level, where we should just assume that a non-delete-marked secondary index record does exist.

One of the two calls is preceded by a condition that refers to the isolation level, but that condition seems wrong:

		if (clust_rec
		    && (old_vers
			|| trx->isolation_level <= TRX_ISO_READ_UNCOMMITTED
			|| rec_get_deleted_flag(rec, dict_table_is_comp(
							sec_index->table)))
		    && !row_sel_sec_rec_is_for_clust_rec(
			    rec, sec_index, clust_rec, clust_index)) {
			clust_rec = NULL;

Because the lowest value for trx->isolation_level is

#define TRX_ISO_READ_UNCOMMITTED	0

the condition <= actually is equivalent to ==.

I think that for READ UNCOMMITTED, we should only filter secondary index records by the delete-mark flag. If a record is delete-marked, pretend that it does not exist. This is exactly what we should already be doing for clustered index records.



 Comments   
Comment by Marko Mäkelä [ 2019-01-18 ]

I hope that you can figure out how to cover the code paths. I tried and failed to create a simple test for MDEV-17823; even FORCE INDEX did not help.

Comment by Elena Stepanova [ 2019-03-11 ]

--source include/have_innodb.inc
 
CREATE TABLE t1 ( 
  pk INT AUTO_INCREMENT,
  c VARCHAR(1024),
  b BIT(15),
  vb BIT(10) AS (b) VIRTUAL,
  d DATETIME,
  vd DATETIME AS (d),
  PRIMARY KEY(pk),
  UNIQUE(vd,vb,c(64))
) ENGINE=InnoDB;
INSERT IGNORE INTO t1 (c,b,d) VALUES
  ('foo',b'11100111011','2003-06-20 12:47:46'),
  ('bar',NULL,'1981-06-28 00:00:00') ;
 
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
CREATE TABLE t2 ENGINE=InnoDB SELECT vd FROM t1;
 
# Cleanup
DROP TABLE t1, t2;

10.2 ab7e2b04

#3  <signal handler called>
#4  0x00005565749f6bc6 in row_sel_sec_rec_is_for_clust_rec (sec_rec=0x7f85470d007f "\231oh\313\356\003\377foo\200", sec_index=0x7f84fc0749a8, clust_rec=0x7f85470cc07f "\200", clust_index=0x7f84fc075148, thr=0x7f84fc08cb60) at /data/src/10.2/storage/innobase/row/row0sel.cc:254
#5  0x00005565749fd532 in row_sel_get_clust_rec_for_mysql (prebuilt=0x7f84fc08bbe8, sec_index=0x7f84fc0749a8, rec=0x7f85470d007f "\231oh\313\356\003\377foo\200", thr=0x7f84fc08cb60, out_rec=0x7f8544343100, offsets=0x7f8544343120, offset_heap=0x7f8544343118, vrow=0x7f85443430f8, mtr=0x7f8544343bf0) at /data/src/10.2/storage/innobase/row/row0sel.cc:3548
#6  0x0000556574a015d6 in row_search_mvcc (buf=0x7f84fc009158 "\356\002", mode=PAGE_CUR_G, prebuilt=0x7f84fc08bbe8, match_mode=0, direction=1) at /data/src/10.2/storage/innobase/row/row0sel.cc:5342
#7  0x000055657489182a in ha_innobase::general_fetch (this=0x7f84fc073848, buf=0x7f84fc009158 "\356\002", direction=1, match_mode=0) at /data/src/10.2/storage/innobase/handler/ha_innodb.cc:9760
#8  0x0000556574891aa8 in ha_innobase::index_next (this=0x7f84fc073848, buf=0x7f84fc009158 "\356\002") at /data/src/10.2/storage/innobase/handler/ha_innodb.cc:9827
#9  0x000055657457bdfb in handler::ha_index_next (this=0x7f84fc073848, buf=0x7f84fc009158 "\356\002") at /data/src/10.2/sql/handler.cc:2727
#10 0x000055657436c0f7 in join_read_next (info=0x7f84fc0151b8) at /data/src/10.2/sql/sql_select.cc:19761
#11 0x0000556574369bc7 in sub_select (join=0x7f84fc0135e0, join_tab=0x7f84fc0150f0, end_of_records=false) at /data/src/10.2/sql/sql_select.cc:18777
#12 0x00005565743690ad in do_select (join=0x7f84fc0135e0, procedure=0x0) at /data/src/10.2/sql/sql_select.cc:18302
#13 0x0000556574343695 in JOIN::exec_inner (this=0x7f84fc0135e0) at /data/src/10.2/sql/sql_select.cc:3623
#14 0x0000556574342b42 in JOIN::exec (this=0x7f84fc0135e0) at /data/src/10.2/sql/sql_select.cc:3418
#15 0x0000556574343d0d in mysql_select (thd=0x7f84fc000b00, tables=0x7f84fc012ce0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2416184064, result=0x7f84fc0134e8, unit=0x7f84fc0046f8, select_lex=0x7f84fc004e30) at /data/src/10.2/sql/sql_select.cc:3818
#16 0x0000556574337f17 in handle_select (thd=0x7f84fc000b00, lex=0x7f84fc004630, result=0x7f84fc0134e8, setup_tables_done_option=0) at /data/src/10.2/sql/sql_select.cc:376
#17 0x00005565742fa5ac in mysql_execute_command (thd=0x7f84fc000b00) at /data/src/10.2/sql/sql_parse.cc:4006
#18 0x000055657430723b in mysql_parse (thd=0x7f84fc000b00, rawbuf=0x7f84fc012468 "CREATE TABLE t2 ENGINE=InnoDB SELECT vd FROM t1", length=47, parser_state=0x7f8544345200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:8059
#19 0x00005565742f4ad1 in dispatch_command (command=COM_QUERY, thd=0x7f84fc000b00, packet=0x7f84fc096191 "CREATE TABLE t2 ENGINE=InnoDB SELECT vd FROM t1", packet_length=47, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1829
#20 0x00005565742f33ee in do_command (thd=0x7f84fc000b00) at /data/src/10.2/sql/sql_parse.cc:1379
#21 0x0000556574446a16 in do_handle_one_connection (connect=0x556576c22a20) at /data/src/10.2/sql/sql_connect.cc:1336
#22 0x00005565744467a3 in handle_one_connection (arg=0x556576c22a20) at /data/src/10.2/sql/sql_connect.cc:1242
#23 0x000055657486e8b4 in pfs_spawn_thread (arg=0x556576c45c30) at /data/src/10.2/storage/perfschema/pfs.cc:1862
#24 0x00007f85533fb494 in start_thread (arg=0x7f8544346700) at pthread_create.c:333
#25 0x00007f85517e193f in clone () from /lib/x86_64-linux-gnu/libc.so.6

Fails on 10.2-10.4, debug and non-debug builds. ASAN also SEGVs.

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