存储对象在数据库中

问题描述:

我有很多对象,每个都可以有许多不同的属性。很多属性重叠,例如,许多对象都有属性name。
由于有很多类型的对象,如果有一组对象具有相同的属性集合,那么它将需要大量的表。

I have lot of objects, each can have many different kind of attributes. a lot of the attributes overlap, for example, many objects have the attribute "name". Since there are many type of objects, if there is a table constructed for each set of objects with same set of attributes, it will take lot of tables.

目前我使用的是一个mysql,它是以这种方式存储的。

Currently I'm using a mysql, and it is stored this way.

object_id|attribute_id|data

有这样的几个表,不同的表有不同类型的数据。
例如,在整数表中,它只存储整数

There are a few tables like this, different table have different type of data. For example, in a Integer table, it only store integers

所以我可以在系统中存储所有类型的对象,并且仍然可以进行过滤并根据属性的数据进行排序。它使查询有点复杂,我不认为这是有效的。

So I can store all kind of object in the system and it is still possible to do filtering and sorting according to the data of the attributes. It make queries a bit more complex and I don't think it is efficient.

这是唯一的方式在mysql或其他关系数据库中做?
我应该尝试为这个问题找到其他数据库模型吗?

Is this is only way to do it in mysql or other relational databases? Should I try to find other database models for this problem?

EDIT
我做了一些研究我需要的是一个具有SQL力量的面向文档的数据库。

EDIT I did some research, it seems what I need is a Document-oriented database with the power of SQL.

如果你想用 RDBMS 类似文档的数据库,我想你应该看看 mongoDB

If you want to go with a RDBMS-like document-oriented database, I think you should look into mongoDB:


的MongoDB是桥接键/值存储(其中
是快速和高度可扩展的)和
之间的
差距传统的RDBMS系统(在功能上是
) p>

A key goal of MongoDB is to bridge the gap between key/value stores (which are fast and highly scalable) and traditional RDBMS systems (which are deep in functionality).