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-33087 ALTER TABLE...ALGORITHM=COPY should build indexes more efficiently #3145

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-33087

Description

  • During copy algorithm, InnoDB should use bulk insert operation for row by row insert operation. By doing this, copy algorithm can effectively build indexes.

How can this PR be tested?

Tested with large data set:

Existing alter copy algorithm:

MariaDB [test]> alter table t1 force, algorithm=copy;
Query OK, 6291456 rows affected (12 min 18.519 sec)
Records: 6291456 Duplicates: 0 Warnings: 0

With bulk insert (copy algorithm)

MariaDB [test]> alter table t1 force, algorithm=copy;
Query OK, 6291456 rows affected (7 min 30.760 sec)
Records: 6291456 Duplicates: 0 Warnings: 0

create..select copy algorithm:

MariaDB [test]> create table t2 select * from t1;
Query OK, 6619136 rows affected (7 min 5.126 sec)
Records: 6619136 Duplicates: 0 Warnings: 0

create..select (with bulk insert):

MariaDB [test]> create table t2 select * from t1;
Query OK, 6619136 rows affected (4 min 54.647 sec)
Records: 6619136 Duplicates: 0 Warnings: 0

Basing the PR against the correct MariaDB version

  • This is a new feature and the PR is based against the latest MariaDB development 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.

@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.

This looks mostly OK. I think that we must keep using the old code path if FOREIGN KEY constraints need to be enforced.

storage/innobase/row/row0ins.cc Show resolved Hide resolved
storage/innobase/row/row0merge.cc Outdated Show resolved Hide resolved
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.

Here are some initial comments. I think that MDEV-33809 needs to be fixed before this can be merged.

sql/sql_insert.cc Show resolved Hide resolved
sql/sql_table.cc Outdated Show resolved Hide resolved
storage/innobase/handler/ha_innodb.cc Show resolved Hide resolved
storage/innobase/handler/ha_innodb.cc Show resolved Hide resolved
storage/innobase/include/row0merge.h Outdated Show resolved Hide resolved
Comment on lines 3401 to 3414
/* MDEV-25036 FIXME: check also foreign key
constraints */
ut_ad(!trx->check_foreigns);
ut_ad(index->table->skip_alter_undo
|| !trx->check_foreigns);
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to have a comment that explains where the FOREIGN KEY constraints will be enforced during ALTER TABLE…ALGORITHM=COPY.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that a source code comment here about the FOREIGN KEY constraint enforcement would be useful. In which function is that check executed?

storage/innobase/row/row0merge.cc Outdated Show resolved Hide resolved
@Thirunarayanan Thirunarayanan force-pushed the 10.11-MDEV-33087 branch 2 times, most recently from f5dabc8 to c4b52b0 Compare April 11, 2024 12:03
sql/sql_table.cc Show resolved Hide resolved
sql/sql_table.cc Outdated Show resolved Hide resolved
sql/sql_table.cc Outdated Show resolved Hide resolved
storage/innobase/handler/handler0alter.cc Outdated Show resolved Hide resolved
storage/innobase/trx/trx0rec.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0ins.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0ins.cc Outdated Show resolved Hide resolved
@Thirunarayanan Thirunarayanan force-pushed the 10.11-MDEV-33087 branch 2 times, most recently from 0baa8f6 to a6bb0ca Compare April 22, 2024 05:45
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.

Thank you, I think that we are almost there.

storage/innobase/row/row0ins.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0ins.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0merge.cc Outdated Show resolved Hide resolved
sql/sql_table.cc Show resolved Hide resolved
mysql-test/suite/innodb/t/foreign_key.test Show resolved Hide resolved
mysql-test/suite/innodb/t/foreign_key.test Outdated Show resolved Hide resolved
sql/sql_table.cc Outdated Show resolved Hide resolved
storage/innobase/row/row0ins.cc Outdated Show resolved Hide resolved
Comment on lines 3401 to 3414
/* MDEV-25036 FIXME: check also foreign key
constraints */
ut_ad(!trx->check_foreigns);
ut_ad(index->table->skip_alter_undo
|| !trx->check_foreigns);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that a source code comment here about the FOREIGN KEY constraint enforcement would be useful. In which function is that check executed?

storage/innobase/row/row0merge.cc Outdated Show resolved Hide resolved
@Thirunarayanan Thirunarayanan force-pushed the 10.11-MDEV-33087 branch 2 times, most recently from cbaffd3 to 06ef346 Compare May 2, 2024 11:40
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.

Thank you, the code changes look fine to me, but I think that we need to add some test coverage.

storage/innobase/handler/ha_innodb.cc Show resolved Hide resolved
@Thirunarayanan Thirunarayanan force-pushed the 10.11-MDEV-33087 branch 2 times, most recently from dd1e145 to 1f66c6c Compare May 6, 2024 07:28
…iciently

- During copy algorithm, InnoDB should use bulk insert operation
for row by row insert operation. By doing this, copy algorithm
can effectively build indexes. This optimization is disabled
for temporary table, versioning table and table which has
foreign key relation.

Introduced the variable innodb_alter_copy_bulk to allow
the bulk insert operation for copy alter operation
inside InnoDB. This is enabled by default

ha_innobase::extra(): HA_EXTRA_END_ALTER_COPY mode tries to apply
the buffered bulk insert operation, updates the non-persistent
table stats.

row_merge_bulk_t::write_to_index(): Update stat_n_rows after
applying the bulk insert operation

row_ins_clust_index_entry_low(): In case of copy algorithm,
switch to bulk insert operation.

copy_data_error_ignore(): Handles the error while copying
the data from source to target file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants