AI Reports

Magento 2 troubleshooting › Database

What is row_id in Adobe Commerce, and when do you join on it instead of entity_id?

Short answer: Adobe Commerce (and Magento Commerce Cloud) keeps a version of a product, category, CMS page or rule for each scheduled update. row_id identifies one version; entity_id identifies the thing itself. Attribute values and some link tables join on row_id, and you must pick the current version.

On Magento Open Source, row_id doesn't exist and everything joins on entity_id. On Adobe Commerce, copying an Open Source query usually runs without errors but returns wrong or duplicate rows.

Check it step by step

These queries only read data. Run them on a copy of your database if you can, or ask your developer to. If your tables have a prefix (set in app/etc/env.php), add it to each table name.

1. Is this database Adobe Commerce?

Works on Magento Open Source and Adobe Commerce:

SELECT COUNT(*) AS has_row_id
FROM information_schema.columns
WHERE table_schema = DATABASE()
  AND table_name = 'catalog_product_entity'
  AND column_name = 'row_id';

1 means Adobe Commerce: use the row_id joins below.

2. Which tables join on row_id

Works on Magento Open Source and Adobe Commerce:

SELECT table_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
  AND column_name = 'row_id'
ORDER BY table_name;

Typical results: catalog_product_entity_* and catalog_category_entity_* value tables, tier prices, media gallery links, catalogrule_customer_group, salesrule_website, cms_page_store. Order, customer, stock, website and URL rewrite tables still use entity_id.

3. The versions of one product

Adobe Commerce only:

SET @sku = 'ABC-123';  -- your SKU
SELECT row_id, entity_id, created_in, updated_in,
       FROM_UNIXTIME(created_in) AS valid_from,
       IF(updated_in >= 2147483647, 'open', FROM_UNIXTIME(updated_in)) AS valid_to
FROM catalog_product_entity
WHERE sku = @sku
ORDER BY created_in;

The current version is the row where created_in <= UNIX_TIMESTAMP() AND updated_in > UNIX_TIMESTAMP(). Always add that filter, or scheduled versions double your results.

How to fix it

Related

Gaurav Harsh

Gaurav Harsh is a Magento developer who works on large Adobe Commerce stores and builds AI Reports, a Magento extension for asking your store's data questions in plain English. LinkedIn