具有“开放模式”的数据库 - 好或坏主意? [英] Database with "Open Schema" - Good or Bad Idea?

查看:111
本文介绍了具有“开放模式”的数据库 - 好或坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Reddit的联合创始人介绍了他们在向数百万用户推广时遇到的问题。可以获得摘要这里

The co-founder of Reddit gave a presentation on issues they had while scaling to millions of users. A summary is available here.

令我惊讶的是第3点:


表和数据表。在Reddit中的一切都是一个事物:用户,链接,评论,subreddits,奖励等。事情保持共同的属性,如上/下投票,类型和创建日期。数据表有三列:thing id,key,value。每个属性都有一行。有一个标题,网址,作者,垃圾邮件投票等行。当他们添加新功能,他们不必担心数据库了。

Instead, they keep a Thing Table and a Data Table. Everything in Reddit is a Thing: users, links, comments, subreddits, awards, etc. Things keep common attribute like up/down votes, a type, and creation date. The Data table has three columns: thing id, key, value. There’s a row for every attribute. There’s a row for title, url, author, spam votes, etc. When they add new features they didn’t have to worry about the database anymore. They didn’t have to add new tables for new things or worry about upgrades.

这似乎对我来说是一个可怕的想法,但是,它似乎已经解决了Reddit。这是一个好主意,但一般来说?

This seems like a terrible idea to me, but it seems to have worked out for Reddit. Is it a good idea in general, though? Or is it a peculiarity of Reddit that happened to work out for them?

推荐答案

这是一个称为 EAV 实体 - 属性值。它有它的用途。主要的例子是患者测试数据,其自然稀疏,因为可以运行数十万次测试,但是通常对于患者只存在少量测试。包含数十万列的表是愚蠢的,但是具有EAV的表是有意义的。

This is a data model known as EAV for entity-attribute-value. It has its uses. A prime example is patient test data which is naturally sparse since there are hundreds of thousands of tests which might be run, but typically only a handful are present for a patient. A table with hundreds of thousands of columns is silly, but a table with EAV makes good sense.

这篇关于具有“开放模式”的数据库 - 好或坏主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆