HBase中多列族有什么优势?

What are the advantages of multiple column families in HBase?

我想使用 HBase 作为我的应用程序的数据库。我有一个 table 有多个列。我现在需要决定我应该使用多少个列族,一个还是多个。如果不止一个,各有什么优缺点。

已经在official HBase guide中记录了,看一下粗体的语句:

  1. On the number of column families

HBase currently does not do well with anything above two or three column families so keep the number of column families in your schema low. Currently, flushing and compactions are done on a per Region basis so if one column family is carrying the bulk of the data bringing on flushes, the adjacent families will also be flushed though the amount of data they carry is small. When many column families the flushing and compaction interaction can make for a bunch of needless i/o loading (To be addressed by changing flushing and compaction to work on a per column family basis). For more information on compactions, see compaction.

Try to make do with one column family if you can in your schemas. Only introduce a second and third column family in the case where data access is usually column scoped; i.e. you query one column family or the other but usually not both at the one time.

33.1. Cardinality of ColumnFamilies

Where multiple ColumnFamilies exist in a single table, be aware of the cardinality (i.e., number of rows). If ColumnFamilyA has 1 million rows and ColumnFamilyB has 1 billion rows, ColumnFamilyA’s data will likely be spread across many, many regions (and RegionServers). This makes mass scans for ColumnFamilyA less efficient.

一个很好的例子是分析 table 包含每日、每月、每年和总计列系列,每个列系列都有自己的 TTL 设置(过期时间)和每个日期范围(天、月)的列, 年...),它们是不同的范围,当您查询 table 时,您通常一次只获取一种类型的聚合,即:检索最近 30 天的每日统计数据


如果您想了解更多关于架构设计的信息,请查看 Amandeep Khurana 的精彩 Introduction to HBase schema design