大家好,我是大D。
不知是否有小伙伴们疑问,为什么列式存储会广泛地应用在 OLAP 领域,和行式存储相比,它的优势在哪里?今天我们一起来对比下这两种存储方式的差别。
其实,列式存储并不是一项新技术,最早可以追溯到 1983 年的论文 Cantor。然而,受限于早期的硬件条件和应用场景,传统的事务型数据库(OLTP)如 Oracle、MySQL 等关系型数据库都是以行的方式来存储数据的。
直到近几年分析型数据库(OLAP)的兴起,列式存储这一概念又变得流行,如 HBase、Cassandra 等大数据相关的数据库都是以列的方式来存储数据的。
对于 OLAP 场景,大多都是对一整行记录进行增删改查操作的,那么行式存储采用以行的行式在磁盘上存储数据就是一个不错的选择。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:64eadc82-88a1-45c6-9ecc-7df2aa7264d6
[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:915df71a-5643-433d-933c-04b49022cdb0
举个例子,下图为员工信息emp表。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:c0981379-6093-4f0d-802d-324d5eb936cd
[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:395f85a7-07c0-4bb4-82dd-4d07465bb3c6
对于 emp 表,要查询部门 dept 为 A 的所有员工的名字。
<span class="hljs-keyword">select <span class="hljs-keyword">name <span class="hljs-keyword">from emp <span class="hljs-keyword">where dept = A<br></span></span></span></span>
由于 dept 的值是离散地存储在磁盘中,在查询过程中,需要磁盘转动多次,才能完成数据的定位和返回结果。
对于 OLAP 场景,一个典型的查询需要遍历整个表,进行分组、排序、聚合等操作,这样一来行式存储中把一整行记录存放在一起的优势就不复存在了。而且,分析型 SQL 常常不会用到所有的列,而仅仅对其中某些需要的的列做运算,那一行中无关的列也不得不参与扫描。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:c93513cd-1163-49d4-984d-7ca8171d0cec
[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:0ea19e45-c083-4aca-9d37-015fe651b7fa
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:29170f73-5a77-48fa-8f59-7331c6dbb191
[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:a15ef299-21e8-4745-a121-771cef90bcbb
还是上面例子中的查询,由于在列式存储中 dept 的值是按照顺序存储在磁盘上的,因此磁盘只需要顺序查询和返回结果即可。
列式存储不仅具有按需查询来提高效率的优势,由于同一列的数据属于同一种类型,如数值类型,字符串类型等,相似度很高,还可以选择使用合适的编码压缩可减少数据的存储空间,进而减少IO提高读取性能。
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:66c5db03-eaab-41fb-bf11-a0067b5657e4
[En]
[TencentCloudSDKException] code:FailedOperation.ServiceIsolate message:service is stopped due to arrears, please recharge your account in Tencent Cloud requestId:f98ff67d-4d34-47c3-ac77-8a7d1d9e1630
非常欢迎大家加我微信:Abox_0226,备注「进群」,有关大数据技术的问题在群里一起探讨。
Original: https://www.cnblogs.com/datadance/p/16281634.html
Author: Data跳动
Title: 为什么列式存储会被广泛用在 OLAP 中?
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/562885/
转载文章受原作者版权保护。转载请注明原作者出处!