You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug#36658450 Crash when drop and add primary key with desc
Description:
============
Dropping a primary key and adding a new auto-increment column as a
primary key in descending order using the "inplace" algorithm fails.
Analysis:
=========
Dropping an existing primary key and adding a new auto-increment key in
descending order requires arranging the records in reverse order,
which necessitates a file sort. However, this scenario was not detected
in the method innobase_pk_order_preserved(), causing it to return false.
As a result, the ALTER INPLACE operation, which calls this method,
skips the file sort. Instead, it processes the primary key as usual
in batches, a method known as bulk mode. In bulk mode, records are
inserted into a sort buffer (in descending order in this case).
When the sort buffer becomes full, records are directly inserted into
the B-tree.
Consider a case where we have 2000 records, and the sort buffer can
hold 1000 records in a batch:
Batch #1 inserted: Records 1000 to 1 (in descending order)
Batch #2 inserted: Records 2000 to 1001 (in descending order)
If the records from both batches happen to be in the same page,
the record order is violated.
It's important to note that this record order violation would still
exist even if the sort buffer were skipped when file sort was skipped.
Therefore, enabling file sort is essential to ensure correct record
order across batches.
Fix:
====
Enable file sort when add autoinc descending.
This patch is based on the contribution from Shaohua Wang at Alibaba
Group. We thank you for contributing to MySQL.
Change-Id: I398173bbd27db7f5e29218d217bf11c30297c242
0 commit comments