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

Fix incorrect table name during catalog product indexing #7256

Merged
merged 1 commit into from
Nov 8, 2016
Merged

Fix incorrect table name during catalog product indexing #7256

merged 1 commit into from
Nov 8, 2016

Conversation

nagno
Copy link

@nagno nagno commented Oct 31, 2016

The left join used an incorrect table name and it added way more rows for a single entity than it should. The entity id wasn't unique anymore, which failed the insert part of the SQL query.

This bug is not released yet in any version, only exists in the develop branch. I really hope this time you will be faster than the usual and merge it in before you release the bug in a "stable" version.

The left join used an incorrect table name and it added way more rows for a single entity than it should
and the entity id wasn't unique anymore, which failed the insert part of the SQL query.
@nagno
Copy link
Author

nagno commented Nov 2, 2016

@valdislav as you introduced the bug, this fix might be interesting for you. It would be good to get the fix into the core before the bug gets released in a new magento version and causes issues for everyone who are using flat tables.
Thanks!

@valdislav
Copy link
Contributor

valdislav commented Nov 2, 2016

@nagno Yes, we will pick up fix as soon as possible. Big thanks for your contribution.

Internal ticket: MAGETWO-60397

@MomotenkoNatalia MomotenkoNatalia added Component: Catalog Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Nov 2, 2016
@valdislav
Copy link
Contributor

The left join used an incorrect table name and it added way more rows for a single entity than it should. The entity id wasn't unique anymore, which failed the insert part of the SQL query.

As for entity_id it could be primary in attribute tables in community edition, but it could be replaced by another auto incremented field and will not represent an unique row in table. It is not recommended to use custom row SQL queries to product attribute tables, please use API. If for some reasons you can not, For retrieving link field with product and related tables please use Metadata for product:
https://github.com/magento/magento2/pull/7256/files#diff-56587e255646121ddf3a8b375569b579R211

$this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField()

@nagno
Copy link
Author

nagno commented Nov 2, 2016

We came across with the issue when we were reindexing in EE, but in this case that not is the source of the issue.
As you can see in the fix, you are using this:

$select->joinLeft(
    $temporaryValueTableName,
    sprintf('e.%1$s = %2$s.%1$s', $linkField, $temporaryTableName),
    $columnValueNames
);

So you are joining the $temporaryValueTableName table but using the $temporaryTableName table in the ON clause of the SQL query.
The generated left join looked something like this:

LEFT JOIN `catalog_product_entity_int_tmp_indexer_value` ON e.row_id = catalog_product_entity_int_tmp_indexer.row_id

So your left join table and the table in the condition is not the same.
It should be like this

LEFT JOIN `catalog_product_entity_int_tmp_indexer_value` ON e.row_id = catalog_product_entity_int_tmp_indexer_value.row_id

Which is resolved by the fix.

Let me know if you have any further questions regarding the issue or the fix. We don't have any customisation around that area.

@mmansoor-magento mmansoor-magento merged commit ae49bb6 into magento:develop Nov 8, 2016
magento-devops-reposync-svc pushed a commit that referenced this pull request Dec 18, 2021
Sync 2.4-develop changes with 2.4.4-beta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants