[MDEV-27030] vcol.vcol_keys_myisam fails on Windows x64, with Visual Studio 2022 Created: 2021-11-11  Updated: 2023-11-10  Resolved: 2021-11-12

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - MyISAM
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8
Fix Version/s: 10.2.42, 10.3.33, 10.4.23, 10.5.14, 10.6.6, 10.7.2

Type: Bug Priority: Major
Reporter: Vladislav Vaintroub Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File remove_key_vs2019.asm     Text File remove_key_vs2022.asm    

 Description   

Fails reproducibly, on x64 only . Seems to be a compiler bug, time-wise correlates with compiler upgrade.

vcol.vcol_keys_myisam                    w1 [ fail ]
        Test ended at 2021-11-10 23:19:21
 
CURRENT_TEST: vcol.vcol_keys_myisam
myisamchk: error: 138 when opening MyISAM-table 'D:/winx64-packages/build/mysql-test/var/1/mysqld.1/data//test/t1'
myisamchk: error: 138 when opening MyISAM-table 'D:/winx64-packages/build/mysql-test/var/1/mysqld.1/data//test/t1'
--- D:/winx64-packages/build/src/mysql-test/suite/vcol/r/vcol_keys_myisam.result	2021-11-10 22:57:27.000000000 +0000
+++ D:\winx64-packages\build\src\mysql-test\suite\vcol\r\vcol_keys_myisam.reject	2021-11-10 23:19:21.521194600 +0000
@@ -277,12 +277,15 @@
 delete from t1 where b=12;
 analyze table t1;
 Table	Op	Msg_type	Msg_text
+test.t1	analyze	error	Key in wrong position at page 13312
 test.t1	analyze	status	Engine-independent statistics collected
-test.t1	analyze	status	OK
+test.t1	analyze	error	Corrupt
 show keys from t1;
 Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment
 t1	1	b	1	b	A	998	NULL	NULL	YES	BTREE		
 t1	1	i	1	d	A	998	NULL	NULL	YES	BTREE		
+Warnings:
+Note	1296	Making backup of data file ./test/t1.MYD with extension '-211110231921.BAK'
 select * from t1 where b=11;
 a	b	c	d
 10	11	-5440	10-5440



 Comments   
Comment by Vladislav Vaintroub [ 2021-11-11 ]

Localized a function in myisam, which , when deoptimized, lets the test pass. it is remove_key() in storage/myisam/mi_delete.c . I'm attaching annotated disassembly, in case anyone would like to analyze what the bug was or is. It is not entirely obvious to me, especially since register allocation is done slightly differently, and I'm not good enough to map r8d to eax or similar in my mind.

Comment by Alexander Miloslavskiy [ 2023-11-10 ]

We also ran into this problem and analyzed it further.

In your disassembly, the problem can be seen here:

	; 824  : 	if ((keyinfo->seg->flag & HA_PACK_KEY) && *keypos & 128)
		<...>
		movzx	eax, BYTE PTR [rcx]
		<...>
	
	; 839  : 	    if (!(prev_length= *start & 127))
		and	eax, 127				; 0000007fH
		<...>

It first loads *keypos into EAX and then assumes that *start is in EAX.
In other words, it thinks that (keypos == start), overlooking that it was changed by calling get_key().

See also https://stackoverflow.com/questions/77455281

I had a contact in Microsoft and he confirmed that this is a compiler bug and they will fix it now that I reported.

Comment by Vladislav Vaintroub [ 2023-11-10 ]

Thanks alexandr.miloslavskiy for investigating! Interesting! If there is a link to the compiler bug report, it would be great if we had it, to track when it is fixed.

Comment by Alexander Miloslavskiy [ 2023-11-10 ]

Here's the link:
https://developercommunity.visualstudio.com/t/Compiler-optimization-bug-in-VS-2022/10512534

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