Magento implements the Entity-Attribute-Value (EAV) model. This means that Magento (Adobe Commerce) can manage any amount of entities. And these entities may have any amount of assigned attributes.
The EAV model is an abstraction that allows extending Magento (Adobe Commerce) functionality by adding more entities or more attributes without writing too much boilerplate code.
What are Magento 2 entities?
As an eCommerce platform responsible for most of the processes of online retail businesses, Magento (Adobe Commerce) has to manage multiple entities. Here is their schema:
Each of these entities may have attributes that describe each instance of that entity. Products may have color, and categories may have a description. Managing entity attributes is a very important process. Magento handles it using the EAV model.
How are attributes of entities managed?
This model stores data in the following way:
- All entity types are stored in the
eav_entity_type
table, where identifiers of each entity type are declared, such as product, category, and order entities. - All attributes of all entities are stored in a table called
eav_attribute
. This table declares the identifiers of each attribute.
By implementing the Entity-Attribute-Value (EAV) model, Magento can manage any amount of entities. Understand how Magento manages multiple entities in this quick read.
➡️ One attribute can only be mapped to one entity. This means thename
of a product is a different attribute from thename
of a category. Even though the attribute code might match, the identifiers will not. - The attribute groups are stored in the
eav_entity_attribute
table. It declares an identifier of attribute groups. Attribute groups are only used by product attributes in Magento. - All attribute values mapped to each instance of each entity are stored in the
<TYPE #N>_entity_<FORMAT>
tables. You should look up the values of attributes of each entity (<TYPE>
) here. Just make sure that you are aware of the data type (<FORMAT>
) of that attribute.- What are possible data-type (
<FORMAT>
) suffixes?_datetime
_decimal
_int
_text
_varchar
- What are possible entity (
<TYPE>
) prefixes?catalog_category_
catalog_product_
customer_
customer_address_
- What are examples of these tables?
customer_entity_int
catalog_category_entity_datetime
catalog_product_entity_decimal
- What are possible data-type (
And this is how the EAV model works! We have skipped over a few tables to avoid confusion.
- What tables are not included in this schema?
This schema excludes 7 unused tables. These tables always confuse developers and are never used in practice. These are the following tables:eav_entity
eav_entity_datetime
eav_entity_decimal
eav_entity_int
eav_entity_store
eav_entity_text
eav_entity_varchar
Why is entity information indexed?
As you may see, the information on each entity attribute is split into several tables. Given 100,000 entities and 400 attributes, there will be 100,000,000 entries in attribute tables. This is very hard to manage for any SQL engine, especially when querying entities by their attribute value.
To improve the situation and remove some load from the SQL database, the NoSQL database is used. The NoSQL database allows for a very quick lookup of data but lacks the ability to quickly relate data to one another. This means the NoSQL database stores an array of documents and is capable of quickly searching through them. Magento uses Elasticsearch as a NoSQL database.
- What is the old way of data indexing?
In the past, Magento 2 used the concept of SQL flat tables for data indexing. The word “flat” comes from the process of data flattening. A row for each entity and a column per attribute are created. This allowed quick data querying but required even more resources for an SQL database. - How are indexes kept up to date?
Magento has 3 ways of keeping the index up-to-date:- An automatic one (
onSave
), which updates an index on each entity or attribute modification - A semi-automatic one (
onSchedule
), which updates an index once in a time-period - Manual one (using CLI), which requires a CLI command to run
- An automatic one (
Need help with Magento (Adobe Commerce) development? scandiweb is the largest certified Magento developer team in the world, and we can get the hassle out of web development, design, and the whole eCommerce optimization process. Ask us how you can get a dedicated eCommerce growth team today. Or send us a message about your specific needs.
Share on: