Skip to content

MDEV-39647: Deleted Virtual secondary records might never get purged and cause table bloating - #6108

Open
mariadb-TafzeelShams wants to merge 1 commit into
10.11from
11.4-MDEV-39647
Open

mariadb-TafzeelShams wants to merge 1 commit into
10.11from
11.4-MDEV-39647

Conversation

@mariadb-TafzeelShams

Copy link
Copy Markdown
Contributor
  • The Jira issue number for this PR is: MDEV-39647

Description

MDEV-39647: Deleted Virtual secondary records might never get purged and cause table bloating

Virtual column values are not stored in the clustered index. To check whether a secondary index record that includes a virtual column can be purged, row_purge_vc_matches_cluster() and row_vers_build_cur_vrow_low() read those values from the undo log by invoking trx_undo_prev_version_build() with TRX_UNDO_PREV_IN_PURGE.

Since MDEV-24402, this read was skipped if purge_sys.end_view saw the transaction. That happens as soon as a purge batch has ended inside the undo log of the transaction, even though the remaining undo log records of the transaction have not been freed. With no values to compare, row_purge_vc_matches_cluster() assumed a match, row_purge_is_unsafe() returned true, and the delete-marked secondary index record was never removed. CHECK TABLE...EXTENDED reported "Clustered index record not found".

Changes:

  • trx_undo_prev_version_build(): For TRX_UNDO_PREV_IN_PURGE, always read the undo log record, using purge_sys_t::view_guard::PURGE. Only purge tasks set this flag. The callers never read past the undo log record being purged, and purge only frees undo log records before purge_sys.head.

  • innodb.purge_secondary updates an indexed virtual column several times in one transaction, with innodb_purge_batch_size=1 so that its undo log is purged across several batches. CHECK TABLE...EXTENDED must not report any leftover secondary index records.

Release Notes

How can this PR be tested?

Added testcase inside mysql-test/suite/innodb/t/purge_secondary.test to cover the changes.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the main branch.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

SET GLOBAL innodb_stats_persistent = @save_stats_persistent;

--echo # End of 10.6 tests
--echo # End of 11.4 tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of 10.11 tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dr-m dr-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @Thirunarayanan ran the test with and without the fix being present, I think that this is good to go. I only have some minor nitpicks about the test itself.

Comment on lines +171 to +174
--echo # End of 10.3 tests

--echo # End of 10.6 tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests were added in 10.4, 10.5, 10.7, 10.8, 10.9, 10.10 either. Why should 10.6 be mentioned?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment on lines +190 to +207
SET GLOBAL innodb_max_purge_lag_wait=0;

connect (stop_purge,localhost,root,,);
START TRANSACTION WITH CONSISTENT SNAPSHOT;

connection default;
BEGIN;
UPDATE t1 SET value = '1B';
UPDATE t1 SET value = '2C';
UPDATE t1 SET value = '3D';
UPDATE t1 SET value = '4E';
UPDATE t1 SET value = '5F';
UPDATE t1 SET value = '6G';
COMMIT;

disconnect stop_purge;
SET GLOBAL innodb_max_purge_lag_wait=0;
CHECK TABLE t1 EXTENDED;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the stop_purge connection here? There is only one transaction executed between the two SET GLOBAL innodb_max_purge_lag_wait=0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the stop_purge connection. And checked reproducibility without the ptch.

Virtual column values are not stored in the clustered index. To check
whether a secondary index record that includes a virtual column can be
purged, row_purge_vc_matches_cluster() and row_vers_build_cur_vrow_low()
read those values from the undo log by invoking
trx_undo_prev_version_build() with TRX_UNDO_PREV_IN_PURGE.

Since MDEV-24402, this read was skipped if purge_sys.end_view saw the
transaction. That happens as soon as a purge batch has ended inside the
undo log of the transaction, even though the remaining undo log records
of the transaction have not been freed. With no values to compare,
row_purge_vc_matches_cluster() assumed a match, row_purge_is_unsafe()
returned true, and the delete-marked secondary index record was never
removed. CHECK TABLE...EXTENDED reported "Clustered index record not
found".

Changes:

- trx_undo_prev_version_build(): For TRX_UNDO_PREV_IN_PURGE, always read
the undo log record, using purge_sys_t::view_guard::PURGE. Only purge
tasks set this flag. The callers never read past the undo log record
being purged, and purge only frees undo log records before purge_sys.head.

- innodb.purge_secondary updates an indexed virtual column several
times in one transaction, with innodb_purge_batch_size=1 so that its
undo log is purged across several batches. CHECK TABLE...EXTENDED
must not report any leftover secondary index records.

@mariadb-TafzeelShams mariadb-TafzeelShams left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed review comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants