SyntaxStudy
Sign Up
MySQL EAV Pattern and Its Pitfalls
MySQL Intermediate 4 min read

EAV Pattern and Its Pitfalls

Entity-Attribute-Value

EAV stores arbitrary attributes as rows (entity_id, attribute_name, value). Flexible but hard to query, slow to aggregate, and breaks type safety. Use JSON columns instead.

Example
-- EAV (anti-pattern for most cases)
CREATE TABLE product_attrs (
  product_id INT,
  attr_name  VARCHAR(50),
  attr_value VARCHAR(255)
);

-- To get color and size, requires two JOINs
-- Better: use JSON column or separate typed columns
Pro Tip

EAV is tempting for flexibility but creates query complexity — prefer JSON columns in MySQL 5.7+.