TPC-H Refresh Function 規範分析

當數據庫達到一定的成熟度,向大客戶推廣時,必定會被要求跑 TPC-H,特別是當你標稱爲 HTAP 數據庫時。

跑 TPC-H 就需要對 TPC-H 的一些基本要求有一個大致瞭解,最核心的兩組概念是:

  • Query:Power Run, ThroughPut Run
  • Modify: RF1, RF2

本文基於 TPC-H 規範文檔,並結合 dbgen 實驗結果來介紹 RF1、RF2 的核心知識點。

基本概念

query 以及 refresh function 的概念定義如下:
5.1.2

power test、throughput test 的概念如下:
在這裏插入圖片描述

刷新比例

2.5.1
每一輪 Refresh Function,需要更新 ORDERS、LINEITEM 表 0.1% 的行。也就是說,對於 SF=100 的情況需要更新 600,000,000/1000 = 60w 行(SF與行數關係參考我的這篇文章

事務要求

2.5.2
每一輪 Refresh Function 中涉及到的事務個數不作任何限制,也就是說,可以所有數據在一個事務裏裏更新完,也可以每一組數據對應一個小事務。總體原則是:
要滿足業務層的一致性。從 ORDER 表裏刪除一個訂單時, LINEITEM 中對應的數據也要在一個事務裏刪掉。

所以,這就對我們提出了一個挑戰:通過外部工具直接更新 LINEITEM、ORDER 表,就要求外部工具滿足這個事務特性。像 LOAD DATA 這種工具就無法完成這個任務,它無法保證事務性。

Refresh Function 實現

2.5.3
可以使用任何語言,包括 SQL,Python 腳本等等。

Refresh Function 1

在這裏插入圖片描述在這裏插入圖片描述
Refresh Function 1 實現的功能是向系統中新增訂單。每個訂單向 ORDERS 表中插入一行,同時向 LINEITEM 表插入 1 到 7 行,表示每個訂單包含 1 到 7 種商品。

但是 RF1 並不要求用戶真的實現這樣一個 LOOP。一次性把要插入的數據準備好後一次性 LOAD 到系統中,也是允許的。這裏的例子只是說明插入的數據需要遵循什麼樣的數據規範。

Refresh Function 2

2.7
Refresh Function 負責模擬刪除訂單。從 dbgen 的生成結果看,它只生成了 delete.1 這個文件,這個文件裏的每一行會用於刪除 ORDERS 表和 LINEITEMS 表。所以一般要求在 L_ORDERKEY 上建立索引,不然性能慘不忍睹。

DBGen

要插入的數據必須通過 dbgen 來生成,舉個例子:

./dbgen -s 100 -U 1 -S 1

輸出如下:

[raywill@>/tpch/gen_data/test]
$ll
total 93008
-rwxr-xr-x 1 raywill users   111862 May  6 16:22 dbgen
-rwxr-xr-x 1 raywill users    11815 May  6 12:01 dists.dss
-rw-r--r-- 1 raywill users 77773330 May  6 16:22 lineitem.tbl.u1
-rw-r--r-- 1 raywill users 17334921 May  6 16:22 orders.tbl.u1

[raywill@>/tpch/gen_data/test]
$./dbgen -s 100 -U 1 -v
TPC-H Population Generator (Version 2.17.0)
Copyright Transaction Processing Performance Council 1994 - 2010
Generating update pair #1 for orders/lineitem tables/
Preloading text ... 100%
done.

[raywill@>/tpch/gen_data/test]
$ll
total 94156
-rwxr-xr-x 1 raywill users   111862 May  6 16:22 dbgen
-rw-r--r-- 1 raywill users  1172209 May  6 16:23 delete.1
-rwxr-xr-x 1 raywill users    11815 May  6 12:01 dists.dss
-rw-r--r-- 1 raywill users 77773330 May  6 16:23 lineitem.tbl.u1
-rw-r--r-- 1 raywill users 17334921 May  6 16:23 orders.tbl.u1

[raywill@>/tpch/gen_data/test]
$wc -l delete.1 orders.tbl.u1 lineitem.tbl.u1 
  150000 delete.1
  150000 orders.tbl.u1
  599976 lineitem.tbl.u1
  899976 total

如果希望生成多個文件,修改 -U 參數即可,例如:

[raywill@>/tpch/gen_data/test]
$./dbgen -s 100 -U 3 -v
TPC-H Population Generator (Version 2.17.0)
Copyright Transaction Processing Performance Council 1994 - 2010
Generating update pair #1 for orders/lineitem tables/
Preloading text ... 100%
done.
Generating update pair #2 for orders/lineitem tablesdone.
Generating update pair #3 for orders/lineitem tablesdone.

[raywill@>/tpch/gen_data/test]
$ll
total 283752
-rwxr-xr-x 1 raywill users   111862 May  6 16:22 dbgen
-rw-r--r-- 1 raywill users  1172209 May  6 16:32 delete.1
-rw-r--r-- 1 raywill users  1250001 May  6 16:32 delete.2
-rw-r--r-- 1 raywill users  1350000 May  6 16:32 delete.3
-rwxr-xr-x 1 raywill users    11815 May  6 12:01 dists.dss
-rw-r--r-- 1 raywill users 77773330 May  6 16:32 lineitem.tbl.u1
-rw-r--r-- 1 raywill users 78038149 May  6 16:32 lineitem.tbl.u2
-rw-r--r-- 1 raywill users 78567787 May  6 16:32 lineitem.tbl.u3
-rw-r--r-- 1 raywill users 17334921 May  6 16:32 orders.tbl.u1
-rw-r--r-- 1 raywill users 17410558 May  6 16:32 orders.tbl.u2
-rw-r--r-- 1 raywill users 17517475 May  6 16:32 orders.tbl.u3

[raywill@>/tpch/gen_data/test]
$wc -l delete.* lineitem.* lineitem.*
   150000 delete.1
   150000 delete.2
   150000 delete.3
   599976 lineitem.tbl.u1
   599805 lineitem.tbl.u2
   600680 lineitem.tbl.u3
   599976 lineitem.tbl.u1
   599805 lineitem.tbl.u2
   600680 lineitem.tbl.u3

Power Test 規範

在這裏插入圖片描述
一輪 power test 首先要執行一次 RF 1 新增訂單,然後做查詢,然後執行一次 RF2 刪除一批訂單。

總結

關於 Refresh Function,瞭解到這麼多,基本就有一個大體概念。總結一下,要點包括:

  • 更新的表
  • 更新的行數
  • 事務要求
  • 更新的模式,即 RF1負責新增,RF2負責刪除

附錄

規範文檔

http://www.tpc.org/tpc_documents_current_versions/pdf/tpc-h_v2.17.1.pdf

縮寫

system under test (SUT)
scale factor (SF)

contact

如果你對這部分內容感興趣,歡迎微信聯繫:hustos

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章