且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

EAV - 在电子商务案例中,真的是一个反模式吗?

更新时间:2022-11-16 08:56:24

了解为什么EAV经常很有用被认为是一种反模式,而且这些批评对你的个案有多好。了解为什么这么多人被吸引到EAV以及他们看到的积极好处也很有用。



大多数EAV数据库的最大问题是几乎不可能写任何一种系统和综合的提取或报告系统,以便将数据转化为有用的信息。



在精心设计的关系数据库中给出良好管理的数据时,可在不到一小时的工作中开发的相同类型的报告可能需要数周才能在EAV数据库中开发。原因是数据基本上是未分析的数据,而不考虑其固有的逻辑结构。



事实证明,与某些原因其他人如此吸引EAV。您可以完全绕过数据分析。逻辑数据库设计实际上是自动的,因为所有的EAV数据库都具有相同的表格结构。当你建立一个,你已经构建了它们。



这给你一个处理一些事情,在任何情况下,你可能会考虑。数据库的逻辑结构是否真的是动态和不可知的?或者人们刚刚得出这个结论,因为时间表没有时间进行数据分析和数据库设计?



如何使用数据?人们期望做一种通常在数据库中预期数据的检索类型?还是他们计划把每一次尝试的检索作为对未知领域的探索?



在你的具体情况下,我会问一下这个重要的要求将产品数据合并在一起,即使每个公司都拥有自己的产品和属性知识库?如果这真的永远不会发生,也许你会没事的。如果没有,***先进行管理,实现使用这些数据的难度。


I'm in the process of building a new system which will require an extendable data model. It's quite complex, but the part of the system which requires this structure is very relatable to the product part of an ecommerce system, so I'll use that as a case.

Imagine a set of companies. Each company has a range of products, which has some basic attributes such as name, sku, description, price etc. Alongside these basic attributes, the company should be able to create n custom product attributes, which belongs to the company (i.e. Foo Corp. shouldn't be able to see Acme Inc.'s custom attributes). Beside that, each company should be able to translate these attributes for each product; so each custom attribute value is basically constructed from an attribute, a product, language and a value.

I do understand that the EAV structure is an anti-pattern if you store an fixed amount of attributes and the one in need of extending the amount of attributes isn't the owner of the system.

So my question is - how would you achieve this? It the EAV structure really an anti pattern in this case? Magento is a classic example of someone using this design, and it kinda seems like they built a monster and had to 'fix' it by implementing flat index tables. But are there any other database design pattern that allows for this amount of flexibility?

It's useful to understand why EAV is so often considered an anti-pattern, and how well those criticisms apply to your case. It's also useful to understand why so many people are drawn to EAV, and what positive benefits they see in it.

The biggest problem with most EAV databases is that it is nearly impossible to write any kind of systematic and integrated extraction or reporting system, in order to turn the data into useful information.

The same sort of report that can be developed in less than an hour's work when given well managed data in a well designed relational database can take weeks to develop in an EAV database. The reason is that the data is fundamentally unanalyzed data that has been stored without regard for its inherent logical structure.

This turns out to be very closely related to the reason why some other people are so drawn to EAV. You can bypass data analysis completely. And logical database design is practically automatic, since all EAV databases have the same table structure. When you've built one, you've built them all.

This gives you a handle on a few things to look for in any case you might consider. Is the logical structure of the database truly dynamic and unknowable? Or are people just jumping to that conclusion, because the schedule allows no time for data analysis and database design?

How will the data be used? Are people expecting to do the kind of retrieval that is classically expected of data in a database? Or are they planning on treating each attempted retrieval as an exploration into uncharted territory?

In your particular case, I would ask how long it's going to be before somebody "important" asks for product data to be combined across companies, even though each of them maintains its own knowledge base of products and attributes? If that's really never going to happen, maybe you will be ok. If not, you'd better move on before management realizes how hard it is to use this data.