Bug #121892 Failed INPLACE ALTER leaves InnoDB buffer pages fixed
Description:
An INPLACE ALTER that rebuilds a nullable column as NOT NULL and encounters a NULL late in the clustered-index scan returns the expected error:
ERROR 1138 (22004): Invalid use of NULL value
However, it leaves two stale buffer pages fixed. Before the ALTER, INFORMATION_SCHEMA.INNODB_BUFFER_PAGE showed:
baseline_fixed_pages baseline_total_fixes
0 0
After the failed ALTER it showed:
fixed_pages total_fixes
2 2
SPACE PAGE_NUMBER TABLE_NAME INDEX_NAME FIX_COUNT PAGE_STATE IS_STALE
8 7 NULL NULL 1 FILE_PAGE YES
8 745 NULL NULL 1 FILE_PAGE YES
A second reproduction produced the same result with SPACE values belonging to the newly created table. The table remained unchanged with 5000 rows and one NULL, and the server remained healthy. The two fixed pages remained observable after dropping the database.
This contradicts the cleanup contract in storage/innobase/include/ddl0impl-builder.h, which says that pages buffer-fixed in Page_load::release "must be unfixed (with Page_load::latch) before returning the error."
The error-return path from Row::build() during the parallel scan appears to bypass cleanup across all builders.
Related issue: #121058 also concerns Page_load buffer fixes retained after an INPLACE ALTER error and Parallel_cursor::scan cleanup, but it triggers DB_INTERRUPTED after traversal. This report triggers the late NULL-validation error ER_INVALID_USE_OF_NULL while rebuilding a column as NOT NULL.
How to repeat:
Run as root in a mysql client on a server where the initial fixed-page query returns zero. The client must continue after the intentionally generated ERROR 1138 so that the final queries run.
DROP DATABASE IF EXISTS db1;
SELECT COUNT(*) AS baseline_fixed_pages,
COALESCE(SUM(FIX_COUNT), 0) AS baseline_total_fixes
FROM information_schema.innodb_buffer_page
WHERE FIX_COUNT > 0;
CREATE DATABASE db1;
USE db1;
SET SESSION innodb_parallel_read_threads = 1;
SET SESSION innodb_ddl_threads = 1;
SET SESSION innodb_ddl_buffer_size = 65536;
CREATE TABLE t1 (
id INT NOT NULL PRIMARY KEY,
c1 INT NULL,
payload VARCHAR(2000) NOT NULL
) ENGINE=InnoDB;
INSERT INTO t1
SELECT n, IF(n = 4999, NULL, n), REPEAT('x', 2000)
FROM (
SELECT ones.n + tens.n * 10 + hundreds.n * 100 + thousands.n * 1000 AS n
FROM
(SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) ones
CROSS JOIN
(SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) tens
CROSS JOIN
(SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4
UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) hundreds
CROSS JOIN
(SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) thousands
) numbers;
SELECT COUNT(*) AS rows_before,
SUM(c1 IS NULL) AS late_nulls
FROM t1;
-- returns rows_before=5000, late_nulls=1
ALTER TABLE t1
MODIFY c1 INT NOT NULL,
ALGORITHM=INPLACE;
-- returns ERROR 1138 (22004): Invalid use of NULL value
SELECT COUNT(*) AS fixed_pages,
COALESCE(SUM(FIX_COUNT), 0) AS total_fixes
FROM information_schema.innodb_buffer_page
WHERE FIX_COUNT > 0;
-- observed fixed_pages=2, total_fixes=2; expected 0, 0
SELECT SPACE, PAGE_NUMBER, TABLE_NAME, INDEX_NAME, FIX_COUNT, PAGE_STATE,
IS_STALE
FROM information_schema.innodb_buffer_page
WHERE FIX_COUNT > 0
ORDER BY SPACE, PAGE_NUMBER;
SELECT COUNT(*) AS rows_after_failed_alter,
SUM(c1 IS NULL) AS nulls_after_failed_alter
FROM t1;
-- returns rows_after_failed_alter=5000, nulls_after_failed_alter=1
DROP DATABASE db1;
SELECT COUNT(*) AS fixed_pages_after_drop,
COALESCE(SUM(FIX_COUNT), 0) AS total_fixes_after_drop
FROM information_schema.innodb_buffer_page
WHERE FIX_COUNT > 0;
-- the two leaked fixes remain observable
Suggested fix:
When Row::build() returns an error during Parallel_cursor::scan, perform cleanup for every builder before returning so that all pages retained by Page_load::release are unfixed.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: An INPLACE ALTER that rebuilds a nullable column as NOT NULL and encounters a NULL late in the clustered-index scan returns the expected error: ERROR 1138 (22004): Invalid use of NULL value However, it leaves two stale buffer pages fixed. Before the ALTER, INFORMATION_SCHEMA.INNODB_BUFFER_PAGE showed: baseline_fixed_pages baseline_total_fixes 0 0 After the failed ALTER it showed: fixed_pages total_fixes 2 2 SPACE PAGE_NUMBER TABLE_NAME INDEX_NAME FIX_COUNT PAGE_STATE IS_STALE 8 7 NULL NULL 1 FILE_PAGE YES 8 745 NULL NULL 1 FILE_PAGE YES A second reproduction produced the same result with SPACE values belonging to the newly created table. The table remained unchanged with 5000 rows and one NULL, and the server remained healthy. The two fixed pages remained observable after dropping the database. This contradicts the cleanup contract in storage/innobase/include/ddl0impl-builder.h, which says that pages buffer-fixed in Page_load::release "must be unfixed (with Page_load::latch) before returning the error." The error-return path from Row::build() during the parallel scan appears to bypass cleanup across all builders. Related issue: #121058 also concerns Page_load buffer fixes retained after an INPLACE ALTER error and Parallel_cursor::scan cleanup, but it triggers DB_INTERRUPTED after traversal. This report triggers the late NULL-validation error ER_INVALID_USE_OF_NULL while rebuilding a column as NOT NULL. How to repeat: Run as root in a mysql client on a server where the initial fixed-page query returns zero. The client must continue after the intentionally generated ERROR 1138 so that the final queries run. DROP DATABASE IF EXISTS db1; SELECT COUNT(*) AS baseline_fixed_pages, COALESCE(SUM(FIX_COUNT), 0) AS baseline_total_fixes FROM information_schema.innodb_buffer_page WHERE FIX_COUNT > 0; CREATE DATABASE db1; USE db1; SET SESSION innodb_parallel_read_threads = 1; SET SESSION innodb_ddl_threads = 1; SET SESSION innodb_ddl_buffer_size = 65536; CREATE TABLE t1 ( id INT NOT NULL PRIMARY KEY, c1 INT NULL, payload VARCHAR(2000) NOT NULL ) ENGINE=InnoDB; INSERT INTO t1 SELECT n, IF(n = 4999, NULL, n), REPEAT('x', 2000) FROM ( SELECT ones.n + tens.n * 10 + hundreds.n * 100 + thousands.n * 1000 AS n FROM (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) ones CROSS JOIN (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) tens CROSS JOIN (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) hundreds CROSS JOIN (SELECT 0 n UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) thousands ) numbers; SELECT COUNT(*) AS rows_before, SUM(c1 IS NULL) AS late_nulls FROM t1; -- returns rows_before=5000, late_nulls=1 ALTER TABLE t1 MODIFY c1 INT NOT NULL, ALGORITHM=INPLACE; -- returns ERROR 1138 (22004): Invalid use of NULL value SELECT COUNT(*) AS fixed_pages, COALESCE(SUM(FIX_COUNT), 0) AS total_fixes FROM information_schema.innodb_buffer_page WHERE FIX_COUNT > 0; -- observed fixed_pages=2, total_fixes=2; expected 0, 0 SELECT SPACE, PAGE_NUMBER, TABLE_NAME, INDEX_NAME, FIX_COUNT, PAGE_STATE, IS_STALE FROM information_schema.innodb_buffer_page WHERE FIX_COUNT > 0 ORDER BY SPACE, PAGE_NUMBER; SELECT COUNT(*) AS rows_after_failed_alter, SUM(c1 IS NULL) AS nulls_after_failed_alter FROM t1; -- returns rows_after_failed_alter=5000, nulls_after_failed_alter=1 DROP DATABASE db1; SELECT COUNT(*) AS fixed_pages_after_drop, COALESCE(SUM(FIX_COUNT), 0) AS total_fixes_after_drop FROM information_schema.innodb_buffer_page WHERE FIX_COUNT > 0; -- the two leaked fixes remain observable Suggested fix: When Row::build() returns an error during Parallel_cursor::scan, perform cleanup for every builder before returning so that all pages retained by Page_load::release are unfixed.