mirror of
https://github.com/MariaDB/server.git
synced 2025-11-09 11:41:36 +03:00
if a bunch of tables are prelocked, when a table is actually needed in the routine, open_tables picks one table out of the prelocked list with a smallest "distance". Distance is simply a difference between the actual table lock and the requested table lock. Say, if the prelocked set contains both t1 write-locked and t1 read-locked, than an UPDATE will prefer write-locked t1 and SELECT will prefer read-locked. if there's only write-locked table in the set, both UPDATE and SELECT will use it. this doesn't distingush between UPDATE and INSERT, but INSERT marks tables with tables->for_insert_data=1, which causes prelocking to invoke add_internal_tables() and prepare sequences for execution. in this bug there were two prelocked t1's, one for INSERT (with for_insert_data=1) and one for UPDATE. INSERT picks the second (they both are write-locked, so the distance is the same), its sequence is not prepared and crashes. Let's add for_insert_data as the lowest bit into the distance.