Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-35169 ALTER TABLE...IMPORT TABLESPACE does not work with INDEX DESC #3784

Open
wants to merge 1 commit into
base: 10.11
Choose a base branch
from

Conversation

Thirunarayanan
Copy link
Member

  • The Jira issue number for this PR is: MDEV-35169

Description

Problem:

  • Import tablespace fails to check the index fields descending property while matching the schema given in cfg file with the table schema.

Fix:

  • Introduce the new version format for the cfg file which has the descending bool information for all index fields

row_import_cfg_read_index_fields(): Read the field descending property from cfg file depends on the config version

row_quiesce_write_index_fields(): Write the descending property of the index fields into cfg file

How can this PR be tested?

./mtr innodb.import_cfg --mem
Basically which does create old version cfg file and import tablespace with old cfg file

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.

@Thirunarayanan Thirunarayanan requested a review from dr-m January 23, 2025 10:49
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@dr-m dr-m left a comment

Choose a reason for hiding this comment

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

Can we try to change the file format as little as possible?
I would modify row_quiesce_write_indexes() so that when descending index fields are present, we would set the most significant bit in the 32 bits that we use for encoding one of type, n_uniq, n_nullable, n_fields. The last one would seem to be an obvious choice, due to the following in row_import_read_indexes():

	} else if (cfg->m_n_indexes > 1024) {
		// FIXME: What is the upper limit? */
		ib_errf(thd, IB_LOG_LEVEL_ERROR, ER_IO_READ_ERROR,
			"Number of indexes in meta-data file is too high: "
			ULINTPF, cfg->m_n_indexes);
		cfg->m_n_indexes = 0;

		return(DB_CORRUPTION);
	}

This would give an easy to recognize error message and still allow the file to be slightly edited so that it can be imported.

We do not even seem to need the above; we could simply store the "descending field" flag in the 32 bits that store the length of the field name:

		/* The NUL byte is included in the name length. */
		ulint	len = mach_read_from_4(ptr);

		if (len > OS_FILE_MAX_PATH) {
			ib_errf(thd, IB_LOG_LEVEL_ERROR,
				ER_INNODB_INDEX_CORRUPT,
				"Index name length (" ULINTPF ") is too long, "
				"the meta-data is corrupt", len);

			return(DB_CORRUPTION);
		}

storage/innobase/include/row0quiesce.h Outdated Show resolved Hide resolved
storage/innobase/row/row0import.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0import.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0import.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0import.cc Outdated Show resolved Hide resolved
@Thirunarayanan Thirunarayanan force-pushed the 10.11-MDEV-35169 branch 2 times, most recently from 7ada05c to 2b8d361 Compare January 24, 2025 06:35
storage/innobase/row/row0import.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0quiesce.cc Outdated Show resolved Hide resolved
Problem:
=======
- Import tablespace fails to check the index fields descending
property while matching the schema given in cfg file with the
table schema.

Fix:
===
row_quiesce_write_index_fields(): Write the descending
property of the field into field fixed length field.
Since the field fixed length uses only 10 bits,
InnoDB can use 0th bit of the field fixed length
to store the descending field property.

row_import_cfg_read_index_fields(): Read the field
descending information from field fixed length.
Copy link
Contributor

@dr-m dr-m left a comment

Choose a reason for hiding this comment

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

Please update the "Testing done" section with a test that involves an attempt to import .cfg files from an export after this fix, to both MariaDB Server 10.11 and 10.6. I’d like to see three cases:

  1. No indexes declared with DESC
  2. At least one secondary indexes declared with at least one DESC column
  3. PRIMARY KEY includes a DESC column

For 10.6, please include the SQL statements that need to be executed to make the imported tables pass CHECK TABLE.

storage/innobase/row/row0import.cc Show resolved Hide resolved
storage/innobase/row/row0quiesce.cc Show resolved Hide resolved
storage/innobase/row/row0quiesce.cc Show resolved Hide resolved
storage/innobase/row/row0quiesce.cc Show resolved Hide resolved
storage/innobase/row/row0import.cc Show resolved Hide resolved
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.

4 participants