Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use EAV database design model or a lot of tables

I started a new application and now I am looking at two paths and don't know which is good way to continue.
I am building something like eCommerce site. I have a categories and subcategories.
The problem is that there are different type of products on site and each has different properties. And site must be filterable by those product properties.
This is my initial database design:

Products{ProductId, Name, ProductCategoryId}
ProductCategories{ProductCategoryId, Name, ParentId}
CategoryProperties{CategoryPropertyId, ProductCategoryId, Name}
ProductPropertyValues{ProductId, CategoryPropertyId, Value}

Now after some analysis I see that this design is actually EAV model and I read that people usually don't recommend this design.
It seems that dynamic sql queries are required for everything.

That's one way and I am looking at it right now.

Another way that I see is probably named a LOT WORK WAY but if it's better I want to go there. To make table

Product{ProductId, CategoryId, Name, ManufacturerId}

and to make table inheritance in database wich means to make tables like

Cpus{ProductId ....}
HardDisks{ProductId ....}
MotherBoards{ProductId ....}
erc. for each product (1 to 1 relation).

I understand that this will be a very large database and very large application domain but is it better, easier and performance better than the option one with EAV design.

like image 656
1110 Avatar asked Jan 14 '23 00:01

1110


2 Answers

EAV is rarely a win. In your case I can see the appeal of EAV given that different categories will have different attributes and this will be hard to manage otherwise. However, suppose someone wants to search for "all hard drives with more than 3 platters, using a SATA interface, spinning at 10k rpm?" Your query in EAV will be painful. If you ever want to support a query like that, EAV is out.

There are other approaches however. You could consider an XML field with extended data or, if you are on PostgreSQL 9.2, a JSON field (XML is easier to search though). This would give you a significantly larger range of possible searches without the headaches of EAV. The tradeoff would be that schema enforcement would be harder.

like image 117
Chris Travers Avatar answered Jan 19 '23 12:01

Chris Travers


This questions seems to discuss the issue in greater detail.

Apart from performance, extensibility and complexity discussed there, also take into account:

  • SQL databases such as SQL Server have full-text search features; so if you have a single field describing the product - full text search will index it and will be able to provide advanced semantic searches

  • take a look at no-sql systems that are all the rage right now; scalability should be quite good with them and they provide support for non-structured data such as the one you have. Hadoop and Casandra are good starting points.

like image 39
Bogdan Gavril MSFT Avatar answered Jan 19 '23 10:01

Bogdan Gavril MSFT