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

Replaced CREATE TEMPORARY TABLE ... LIKEwith different approach #36022

Conversation

michalbiarda
Copy link
Contributor

@michalbiarda michalbiarda commented Aug 25, 2022

Description (*)

Magento's MySQL adapter uses CREATE TEMPORARY TABLE ... LIKE command in \Magento\Framework\DB\Adapter\Pdo\Mysql::createTemporaryTableLike.

Newer versions of MySQL (8+) have problems with CREATE TEMPORARY TABLE ... LIKE, as you can read in the official documentation (https://dev.mysql.com/doc/refman/8.0/en/create-temporary-table.html):

You cannot use CREATE TEMPORARY TABLE ... LIKE to create an empty table based on the definition of a table that resides in the mysql tablespace, InnoDB system tablespace (innodb_system), or a general tablespace.

The documentation suggests to use CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0 instead, but such command IS NOT an exact equivalent. It will create temporary table with the same fields, but will not create indexes. Without indexes performance of reindexing big amount of data is absurdly slow.

I suggest to build CREATE TEMPORARY TABLE without LIKE and without SELECT * FROM. Here's my idea:

Firstly use SHOW CREATE TABLE to get query for creation of source table (including indexes creation), and then modify it with PHP: change CREATE TABLE to CREATE TEMPORARY TABLE, add IF NOT EXISTS if necessary, remove TABLESPACE definition if it exists, and replace source table name with temporary table name.

Manual testing scenarios (*)

  1. Install Magento 2.4 on a server with MySQL 8.
  2. Apply sample data.
  3. Run bin/magento index:reindex.
  4. Check data on frontend.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Replaced CREATE TEMPORARY TABLE ... LIKEwith different approach #37926: Replaced CREATE TEMPORARY TABLE ... LIKEwith different approach

@m2-assistant
Copy link

m2-assistant bot commented Aug 25, 2022

Hi @michalbiarda. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@michalbiarda
Copy link
Contributor Author

@magento give me test instance

@magento-deployment-service
Copy link

Hi @michalbiarda. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@michalbiarda
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

$temporaryTable = $this->quoteIdentifier($this->_getTableName($temporaryTableName));
$originTable = $this->quoteIdentifier($this->_getTableName($originTableName));
$sql = sprintf('CREATE TEMPORARY TABLE %s %s LIKE %s', $ifNotExistsSql, $temporaryTable, $originTable);
$originCreate = $this->fetchPairs(sprintf('SHOW CREATE TABLE %s', $originTable));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$originCreate = $this->fetchPairs(sprintf('SHOW CREATE TABLE %s', $originTable));
$originCreate = $this->fetchOne("SHOW CREATE TABLE {$originTable}");

You can use fetchOne to get result
Also sprintf is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kandy Unfortunately I can't use fetchOne because SHOW CREATE TABLE returns two fields. First is table name, the second is SQL query.

I like you suggestion about sprintf, though 👍.

@michalbiarda
Copy link
Contributor Author

@kandy I'm converting this PR to draft. I'll apply your suggestion about sprintf, but I will also fix one more thing reported by someone else in the meantime.

@michalbiarda michalbiarda marked this pull request as ready for review August 26, 2022 13:55
@michalbiarda
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Hotel engcom-Hotel added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Aug 26, 2022
@m2-community-project m2-community-project bot removed this from Review in Progress in Pull Requests Dashboard Aug 26, 2022
@ishakhsuvarov ishakhsuvarov removed this from Review in Progress in High Priority Pull Requests Dashboard Dec 8, 2022
@ishakhsuvarov ishakhsuvarov added this to Pending Review in Pull Requests Dashboard Dec 8, 2022
@m2-community-project m2-community-project bot moved this from Pending Review to Review in Progress in Pull Requests Dashboard May 28, 2023
@engcom-Hotel
Copy link
Contributor

@magento run Static Tests, Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Hotel
Copy link
Contributor

✔️ QA Passed

Preconditions:

  1. SET innodb_file_per_table to OFF.

Manual testing scenario:

  • Install Magento 2.4 on a server with MySQL 8.
  • Generate data using the performance toolkit provided by Magento. Please refer to this link for this same.
  • Run bin/magento index:reindex.
  • Check data on front end.

Actual Result: ✔️

Reindex command should run properly without any errors and frontend is accessible with categories and products.

After: ✔️

image

Before: ✖️

image

Some functional tests are still failing hence moving this PR into extended testing.

Thanks

@engcom-Hotel engcom-Hotel moved this from Testing in Progress to Extended testing (optional) in Community Dashboard Jul 14, 2023
@engcom-Echo
Copy link
Contributor

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Echo
Copy link
Contributor

Functional Tests EE failures are different on last two run on same commit.
Run1
image

Run2
image

Hence moving to Merge In progress

@engcom-Echo engcom-Echo moved this from Extended testing (optional) to Merge in Progress in Community Dashboard Jul 17, 2023
@engcom-Charlie
Copy link
Contributor

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please message the #magento-devops slack channel if they don't show in a reasonable amount of time and a representative will look into any issues.

@engcom-Hotel
Copy link
Contributor

@magento create issue

@m2-community-project m2-community-project bot moved this from Merge in Progress to Ready for Testing in Community Dashboard Aug 28, 2023
@m2-community-project m2-community-project bot moved this from Merge in Progress to Ready for Testing in Community Dashboard Aug 28, 2023
@engcom-Hotel
Copy link
Contributor

Moving back this PR to Merge in progress

@engcom-Hotel engcom-Hotel moved this from Ready for Testing to Merge in Progress in Community Dashboard Aug 28, 2023
@magento-devops-reposync-svc magento-devops-reposync-svc merged commit e947b85 into magento:2.4-develop Aug 31, 2023
14 checks passed
@engcom-Echo engcom-Echo moved this from Merge in Progress to Recently Merged in Community Dashboard Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: accept Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Community Dashboard
Recently Merged
Development

Successfully merging this pull request may close these issues.

[Issue] Replaced CREATE TEMPORARY TABLE ... LIKEwith different approach
9 participants