含metric_name与metric_value列的转置表是否有标准命名?
Entity-Attribute-Value (EAV) Model: The Standard Name for Transposed Dynamic Tables
Hey there! That transposed table structure you're describing has a widely recognized standard name: Entity-Attribute-Value (EAV) Model.
Let me break this down clearly:
- A typical "wide" or flat database table stores all attributes of an entity as columns, with one row representing a complete record of that entity.
- The EAV model flips this paradigm entirely: each row represents just a single attribute-value pair for an entity. It relies on three core columns to organize data:
entity_id: A unique identifier for the entity being trackedattribute_name: The name of the metric/attribute being recordedattribute_value: The actual value associated with that attribute
As you noted, EAV shines when the number of collected metrics changes frequently. Unlike wide tables, which require altering the table schema (via ALTER TABLE commands) every time you add or remove a metric, EAV lets you simply add or remove rows to accommodate new attributes—no schema changes needed.
It’s worth noting that EAV has trade-offs too:
- Querying multiple attributes for an entity often requires joining the table to itself multiple times or using aggregate functions, which can be less performant than querying a wide table.
- The
attribute_valuecolumn usually needs to be a generic data type (likeVARCHAR) to support different metric types, which can complicate data validation and type consistency.
内容的提问来源于stack exchange,提问作者user2989038
相关产品推荐
相关产品推荐

