S
S
Sergey2012-09-13 17:57:29
MySQL
Sergey, 2012-09-13 17:57:29

Storing object attributes in the database, how to be?

At the moment there is no need for this, but sometimes it appears. I thought of writing a component that would resolve the search / storage of attributes for some objects. But the question arose, how to store them then?
I usually store the attributes denormalized, as a serialized array on the object to which these attributes belong. Thus, maximum performance is achieved. The search is implemented by duplicating data in MongoDB.
But there are difficulties in keeping the attributes up to date (in fact, a perverted EAV structure is obtained). Requirements do not allow storing everything in mongo, only as a cache in fact. Does it make sense to store normalized (classic EAV) attributes in the database (mysql for example), duplicate them in the form of a cache for selections (a serialized array for the objects themselves), and also in Mongo (for search).
There is an idea to store only id attributes in a serialized form, store the attributes themselves in mysql, and already in Mongo to implement everything completely, both for search and for selections.
The task is spherical, not related to real projects. I just wonder.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Dyachuk, 2012-09-14
@Renius

1. Ruby has OpenStruct, look for an implementation for PHP
Rails allows you to serialize in OpenStruct
2. The world hasn’t come together like a wedge, you can use anything. My MySQL performs complex searches on normalized data in a matter of milliseconds with hundreds of thousands of records. PostgreSQL can do this even faster. You can use Sphinx to search.
3. Normalization of a large number of attributes has a reasonable limit. Recently wrote the table with 150 fields. To store all 150 fields of one object in a normalized form is nonsense and hellish work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question