Improve the performance of the SQL query generated for updating stock…#3457
Open
igorwulff wants to merge 1 commit into
Open
Improve the performance of the SQL query generated for updating stock…#3457igorwulff wants to merge 1 commit into
igorwulff wants to merge 1 commit into
Conversation
… status after an order is placed The input parameter `$dataForUpdate` uses SKU as the array key. Since SKUs can be numeric, PHP will automatically cast such keys to integers when used in an array. Reference: https://www.php.net/manual/en/language.types.array.php "Specifically, strings that represent valid decimal integers will be converted to integers" As a result, the generated SQL query may contain `sku=3938599` instead of `sku='3938599'`. This leads MySQL to perform implicit type conversion, causing a full table scan where every row is loaded into memory and compared by converting string values to numbers one by one. Reference: https://dev.mysql.com/doc/refman/8.0/en/type-conversion.html We cannot fix the issue at the point where `$dataForUpdate` is generated (`\Magento\InventoryIndexer\Model\Queue\GetSalabilityDataForUpdate::execute`), since this logic is reused elsewhere and changing the data type could introduce side effects. However, in this specific function—where the data is used to build the SQL query—we can explicitly cast the SKU to a string. This prevents MySQL from performing a full table scan and ensures proper query behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… status after an order is placed
The input parameter
$dataForUpdateuses SKU as the array key. Since SKUs can be numeric, PHP will automatically cast such keys to integers when used in an array. Reference: https://www.php.net/manual/en/language.types.array.php "Specifically, strings that represent valid decimal integers will be converted to integers"As a result, the generated SQL query may contain
sku=3938599instead ofsku='3938599'. This leads MySQL to perform implicit type conversion, causing a full table scan where every row is loaded into memory and compared by converting string values to numbers one by one. Reference: https://dev.mysql.com/doc/refman/8.0/en/type-conversion.htmlWe cannot fix the issue at the point where
$dataForUpdateis generated (\Magento\InventoryIndexer\Model\Queue\GetSalabilityDataForUpdate::execute), since this logic is reused elsewhere and changing the data type could introduce side effects. However, in this specific function—where the data is used to build the SQL query—we can explicitly cast the SKU to a string. This prevents MySQL from performing a full table scan and ensures proper query behavior.