Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dfelton/7737da5863ee345b9bd8a78b2c8654d2 to your computer and use it in GitHub Desktop.

Select an option

Save dfelton/7737da5863ee345b9bd8a78b2c8654d2 to your computer and use it in GitHub Desktop.
Finds unused catalog_product eav attributes

Unused catalog_product EAV attributes

SELECT queries for finding unused catalog_product EAV attributes.

-- Datetime attributes
SELECT `ea`.`attribute_code`
FROM `eav_attribute` AS `ea`
LEFT JOIN
`catalog_product_entity_datetime` AS `datetime`
ON `datetime`.`attribute_id` = `ea`.`attribute_id`
AND `datetime`.`value` <> ''
AND `datetime`.`value` IS NOT NULL
WHERE
`ea`.`backend_type` = 'datetime'
AND
`ea`.`entity_type_id` = (
SELECT `entity_type_id`
FROM `eav_entity_type`
WHERE `entity_type_code` = 'catalog_product'
)
AND
`datetime`.`value` IS NULL
ORDER BY
`ea`.`attribute_code`
;
-- Decimal attributes
SELECT `ea`.`attribute_code`
FROM `eav_attribute` AS `ea`
LEFT JOIN
`catalog_product_entity_decimal` AS `decimal`
ON `decimal`.`attribute_id` = `ea`.`attribute_id`
AND `decimal`.`value` <> ''
AND `decimal`.`value` IS NOT NULL
WHERE
`ea`.`backend_type` = 'decimal'
AND
`ea`.`entity_type_id` = (
SELECT `entity_type_id`
FROM `eav_entity_type`
WHERE `entity_type_code` = 'catalog_product'
)
AND
`decimal`.`value` IS NULL
AND
`ea`.`attribute_code` <> 'tier_price'
AND
`ea`.`attribute_code` <> 'group_price'
ORDER BY
`ea`.`attribute_code`
;
-- Integer attributes
SELECT `ea`.`attribute_code`
FROM `eav_attribute` AS `ea`
LEFT JOIN
`catalog_product_entity_int` AS `int`
ON `int`.`attribute_id` = `ea`.`attribute_id`
AND `int`.`value` <> ''
AND `int`.`value` IS NOT NULL
WHERE
`ea`.`backend_type` = 'int'
AND
`ea`.`entity_type_id` = (
SELECT `entity_type_id`
FROM `eav_entity_type`
WHERE `entity_type_code` = 'catalog_product'
)
AND
`int`.`value` IS NULL
ORDER BY
`ea`.`attribute_code`
;
-- Text attributes
SELECT `ea`.`attribute_code`
FROM `eav_attribute` AS `ea`
LEFT JOIN
`catalog_product_entity_text` AS `text`
ON `text`.`attribute_id` = `ea`.`attribute_id`
AND `text`.`value` <> ''
AND `text`.`value` IS NOT NULL
WHERE
`ea`.`backend_type` = 'text'
AND
`ea`.`entity_type_id` = (
SELECT `entity_type_id`
FROM `eav_entity_type`
WHERE `entity_type_code` = 'catalog_product'
)
AND
`text`.`value` IS NULL
ORDER BY
`ea`.`attribute_code`
;
-- Varchar attributes
SELECT `ea`.`attribute_code`
FROM `eav_attribute` AS `ea`
LEFT JOIN
`catalog_product_entity_varchar` AS `varchar`
ON `varchar`.`attribute_id` = `ea`.`attribute_id`
AND `varchar`.`value` <> ''
AND `varchar`.`value` IS NOT NULL
WHERE
`ea`.`backend_type` = 'varchar'
AND
`ea`.`entity_type_id` = (
SELECT `entity_type_id`
FROM `eav_entity_type`
WHERE `entity_type_code` = 'catalog_product'
)
AND
`varchar`.`value` IS NULL
ORDER BY
`ea`.`attribute_code`
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment