- Notifications
You must be signed in to change notification settings - Fork 9.4k
Replaced CREATE TEMPORARY TABLE ... LIKE
with different approach #36022
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 ... LIKE
with different approach #36022
Conversation
…at doesn't conflict with MySQL 8
Hi @michalbiarda. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
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. 🕙 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 |
@magento give me test instance |
Hi @michalbiarda. Thank you for your request. I'm working on Magento instance for you. |
Hi @michalbiarda, here is your Magento Instance: https://eb2c38a2f68947025bfccecf2d856c46.instances.magento-community.engineering |
@magento run all tests |
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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
There was a problem hiding this comment.
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 👍.
@kandy I'm converting this PR to draft. I'll apply your suggestion about |
…nflict with MySQL 8
@magento run all tests |
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. |
@magento run Static Tests, Functional Tests EE |
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. |
Hello @michalbiarda, Thanks for the contribution! According to the below comment here, it seems that you are still working on it.
Can you please confirm, if the PR is ready for review? Thanks |
Hello @engcom-Hotel, After that comment I added something to my change, and marked this PR as ready for review 10 months ago 😅. I confirm it's still ready for review 😄. |
@magento run Functional Tests EE |
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. |
Hello @michalbiarda, Thanks for the reply! Hope you had a great vacation :) After changing the Hence we are proceeding further with this PR. Thanks |
✔️ QA Passed Preconditions:
Manual testing scenario:
Actual Result: ✔️ Reindex command should run properly without any errors and frontend is accessible with categories and products. After: ✔️ Before: ✖️ Some functional tests are still failing hence moving this PR into extended testing. Thanks |
@magento run Functional Tests EE |
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. |
@magento run Functional Tests EE |
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. |
@magento create issue |
Moving back this PR to |
...sooooo..... what exactly is the solution? I currently have to remember to modify the mysql pdo adapter file (vendor/magento/framework/DB/Adapter/Pdo/Mysql.php) every time I update with any new Magento releases. This has been going on for at least four years, ever since MySQL v8. I host at MageMojo/Webscale, and at the moment the following links to their "official" fix for this at the following page whenever I forget and end up creating a new ticket because indexing fails: https://github.com/magemojo/m2-patches/wiki Is there going to be a more permanent solution? Or is something wrong with the configuration at one of the largest Magento hosting environments (or possibly just my old config is out of date) ? From this issue thread, I wasn't able to grasp what exactly is the current status of the issue (wrong config? code?). Please can we have the final word on this? |
OK - I just realized that these kinds of fixes aren't added to security releases. I see in 2.4.7 the file has been updated according to the different approach mentioned above, while it does not exist in 2.4.6-p8. I will copy the relevant function over to my file. I am happy this is finally being put to rest! |
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):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
withoutLIKE
and withoutSELECT * 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: changeCREATE TABLE
toCREATE TEMPORARY TABLE
, addIF NOT EXISTS
if necessary, removeTABLESPACE
definition if it exists, and replace source table name with temporary table name.Manual testing scenarios (*)
bin/magento index:reindex
.Contribution checklist (*)
Resolved issues:
CREATE TEMPORARY TABLE ... LIKE
with different approach #37926: ReplacedCREATE TEMPORARY TABLE ... LIKE
with different approach