【Greenplum】TPC性能測(cè)試指南
1叠必、準(zhǔn)備工作
1.1呆贿、Greenplum集群
集群版本 | 集群規(guī)格 | 集群節(jié)點(diǎn)數(shù) | 分片數(shù) | 測(cè)試類型 |
---|---|---|---|---|
6.1.0 | 4C/32G/320G SSD | 1P/1M/16Segment | 4 | TPC-B畏梆、TPC-C |
6.1.0 | 4C/32G/320G SSD | 1P/1M/32Segment | 4 | TPC-H |
1.2击纬、測(cè)試參考
網(wǎng)絡(luò)鏈接 |
---|
https://segmentfault.com/a/1190000022522888 |
https://segmentfault.com/a/1190000021947479/ |
https://cloud.tencent.com/developer/article/1344308 |
2牧氮、TPC-B
2.1去团、簡(jiǎn)介
TPC-B是由TPC(Transaction Processing Performance Council文搂,事務(wù)處理性能委員會(huì))提供的benchmark适刀,主要用于衡量一個(gè)系統(tǒng)每秒能夠處理的并發(fā)事務(wù)數(shù)。TPC-B不像TPC-C那樣模擬了現(xiàn)實(shí)生活中一個(gè)具體的交易場(chǎng)景煤蹭,其中的事務(wù)都是由簡(jiǎn)單SQL構(gòu)成的沒(méi)有語(yǔ)義的事務(wù)(事務(wù)中混雜了大表與小表的插入笔喉、更新與查詢操作),而且每個(gè)client的請(qǐng)求間也不會(huì)像TPC-C那樣會(huì)有一個(gè)human think time的間隔時(shí)間硝皂,而是一旦前一個(gè)事務(wù)執(zhí)行完成常挚,立馬會(huì)有下一個(gè)事務(wù)請(qǐng)求發(fā)出。因此稽物,TPC-B經(jīng)常用于對(duì)數(shù)據(jù)庫(kù)系統(tǒng)的事務(wù)性能壓測(cè)奄毡。TPC-B性能的衡量指標(biāo)是每秒處理的事務(wù)數(shù)量,即TPS(Transactions per Second)贝或。
2.2吼过、測(cè)試步驟
2.2.1、集群參數(shù)優(yōu)化(可選)
參數(shù) | 參數(shù)值 | 說(shuō)明 | 參數(shù)設(shè)置方式 |
---|---|---|---|
optimizer | off | 關(guān)閉針對(duì)AP場(chǎng)景的orca優(yōu)化器咪奖,對(duì)TP性能更友好盗忱。 | gpconfig -c optimizer -v off |
shared_buffers | 8GB | 將數(shù)據(jù)共享緩存調(diào)大。修改該參數(shù)需要重啟實(shí)例羊赵。 | gpconfig -c shared_buffers -v 8GB |
wal_buffers | 256MB | 將WAL日志緩存調(diào)大趟佃。修改該參數(shù)需要重啟實(shí)例。 | gpconfig -c wal_buffers -v 256MB |
log_statement | none | 將日志輸出關(guān)閉。 | gpconfig -c log_statement -v none |
random_page_cost | 10 | 將隨機(jī)訪問(wèn)代價(jià)開(kāi)銷調(diào)小揖闸,有利于查詢走索引揍堕。 | gpconfig -c random_page_cost -v 10 |
gp_resqueue_priority | off | 將resource queue關(guān)閉。需要重啟實(shí)例 | gpconfig -c gp_resqueue_priority -v off |
resource_scheduler | off | 將resource queue關(guān)閉汤纸。需要重啟實(shí)例 | gpconfig -c resource_scheduler -v off |
gp_enable_global_deadlock_detector | on | 控制是否開(kāi)啟全局死鎖檢測(cè)功能衩茸,打開(kāi)它才可以支持并發(fā)更新/刪除操作; | gpconfig -c gp_enable_global_deadlock_detector -v on |
checkpoint_segments | 2 | 影響checkpoint主動(dòng)刷盤的頻率贮泞,針對(duì)OLTP大量更新類語(yǔ)句適當(dāng)調(diào)小此設(shè)置會(huì)增加刷盤頻率楞慈,平均性能會(huì)有較明顯提升; | gpconfig -c checkpoint_segments -v 2 –skipvalidation |
2.2.2啃擦、測(cè)試工具準(zhǔn)備
工具 | 安裝說(shuō)明 |
---|---|
pgbench(version 9.5) | 源碼安裝:下載開(kāi)源數(shù)據(jù)庫(kù)PostgreSQL源碼囊蓝,然后到pgbench對(duì)應(yīng)的目錄中單獨(dú)對(duì)pgbench進(jìn)行編譯生成可執(zhí)行的二進(jìn)制文件。 |
pgbench(version 9.5) | 二進(jìn)制安裝:可以先直接yum install postgresql95-server來(lái)安裝PostgreSQL程序令蛉,此過(guò)程會(huì)自動(dòng)安裝pgbench工具聚霜。 |
2.2.3、測(cè)試數(shù)據(jù)準(zhǔn)備
測(cè)試數(shù)據(jù)總量
表名 | 數(shù)據(jù)量(行數(shù)) |
---|---|
pgbench_accounts | 1142400000 |
pgbench_branches | 11424 |
pgbench_history | 0 |
pgbench_tellers | 114240 |
pgbench使用珠叔,填充因子為100蝎宇,比例因子為11424
# 其中-F參數(shù)就是上文說(shuō)的裝填因子,-s值得是比例因子
./pgbench -i -F 100 -s 11424 -p port -h host -U user_name -d db_name
2.2.4祷安、測(cè)試執(zhí)行
執(zhí)行TPC-B負(fù)載
# -c指定了連接數(shù)據(jù)庫(kù)client數(shù)量姥芥,-j指定了建立連接使用的線程數(shù)量,推薦將兩者設(shè)置成一樣
# -T指定了測(cè)試執(zhí)行時(shí)間汇鞭,單位為秒
./pgbench -h host -p port -r -n -c 96 -j 96 -T 120 -f all.sql -U user_name -d db_name
all.sql
\set scale 11424
\set nbranches 1 * :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
\setrandom bid 1 :nbranches
\setrandom tid 1 :ntellers
\setrandom delta -5000 5000
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;
執(zhí)行只讀負(fù)載
# -c指定了連接數(shù)據(jù)庫(kù)client數(shù)量凉唐,-j指定了建立連接使用的線程數(shù)量,推薦將兩者設(shè)置成一樣
# -T指定了測(cè)試執(zhí)行時(shí)間霍骄,單位為秒
./pgbench -h host -p port -r -n -c 96 -j 96 -T 120 -f select.sql -U user_name -d db_name
select.sql
\set scale 11424
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
執(zhí)行只更新負(fù)載
# -c指定了連接數(shù)據(jù)庫(kù)client數(shù)量台囱,-j指定了建立連接使用的線程數(shù)量,推薦將兩者設(shè)置成一樣
# -T指定了測(cè)試執(zhí)行時(shí)間腕巡,單位為秒
./pgbench -h host -p port -r -n -c 96 -j 96 -T 120 -f update.sql -U user_name -d db_name
update.sql
\set scale 11424
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
\setrandom delta -5000 5000
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
執(zhí)行只插入負(fù)載
# -c指定了連接數(shù)據(jù)庫(kù)client數(shù)量玄坦,-j指定了建立連接使用的線程數(shù)量,推薦將兩者設(shè)置成一樣
# -T指定了測(cè)試執(zhí)行時(shí)間绘沉,單位為秒
./pgbench -h host -p port -r -n -c 96 -j 96 -T 120 -f insert.sql -U user_name -d db_name
insert.sql
\set scale 11424
\set nbranches 1 * :scale
\set ntellers 10 * :scale
\set naccounts 100000 * :scale
\setrandom aid 1 :naccounts
\setrandom bid 1 :nbranches
\setrandom tid 1 :ntellers
\setrandom delta -5000 5000
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
3煎楣、TPC-C
3.1、簡(jiǎn)介
TPC-C是由TPC(Transaction Processing Performance Council车伞,事務(wù)處理性能委員會(huì))提供的專門針對(duì)聯(lián)機(jī)交易處理系統(tǒng)的規(guī)范择懂,TPC-C模擬的是一個(gè)大型的商品批發(fā)銷售公司交易負(fù)載。這個(gè)事務(wù)負(fù)載主要由9張表組成另玖,主要涉及5類交易類型:新訂單生成(New-Order)困曙、訂單支付(Payment)表伦、發(fā)貨(Delivery)、訂單狀態(tài)查詢(Order-Status)慷丽、和庫(kù)存狀態(tài)查詢(Stock-Level)蹦哼。TPC-C測(cè)試使用吞吐量指標(biāo)(Transaction per minute,簡(jiǎn)稱tpmC)來(lái)衡量系統(tǒng)的性能要糊,其中所統(tǒng)計(jì)的事務(wù)指的是新訂單生成的事務(wù)纲熏,即以每分鐘新訂單生成的事務(wù)數(shù)來(lái)衡量系統(tǒng)的性能指標(biāo)(在標(biāo)準(zhǔn)的TPC-C測(cè)試中,新訂單的事務(wù)數(shù)量占總事務(wù)數(shù)的45%左右)锄俄。
3.2局劲、測(cè)試步驟
3.2.1、集群參數(shù)優(yōu)化(可選)
參數(shù) | 參數(shù)值 | 說(shuō)明 | 參數(shù)設(shè)置方式 |
---|---|---|---|
optimizer | off | 關(guān)閉針對(duì)AP場(chǎng)景的orca優(yōu)化器奶赠,對(duì)TP性能更友好佛南。 | gpconfig -c optimizer -v off |
shared_buffers | 8GB | 將數(shù)據(jù)共享緩存調(diào)大搔谴。修改該參數(shù)需要重啟實(shí)例窗轩。 | gpconfig -c shared_buffers -v 8GB |
wal_buffers | 256MB | 將WAL日志緩存調(diào)大检痰。修改該參數(shù)需要重啟實(shí)例。 | gpconfig -c wal_buffers -v 256MB |
log_statement | none | 將日志輸出關(guān)閉竹祷。 | gpconfig -c log_statement -v none |
random_page_cost | 10 | 將隨機(jī)訪問(wèn)代價(jià)開(kāi)銷調(diào)小谈跛,有利于查詢走索引羊苟。 | gpconfig -c random_page_cost -v 10 |
gp_resqueue_priority | off | 將resource queue關(guān)閉塑陵。需要重啟實(shí)例 | gpconfig -c gp_resqueue_priority -v off |
resource_scheduler | off | 將resource queue關(guān)閉。需要重啟實(shí)例 | gpconfig -c resource_scheduler -v off |
gp_enable_global_deadlock_detector | on | 控制是否開(kāi)啟全局死鎖檢測(cè)功能蜡励,打開(kāi)它才可以支持并發(fā)更新/刪除操作令花; | gpconfig -c gp_enable_global_deadlock_detector -v on |
checkpoint_segments | 2 | 影響checkpoint主動(dòng)刷盤的頻率,針對(duì)OLTP大量更新類語(yǔ)句適當(dāng)調(diào)小此設(shè)置會(huì)增加刷盤頻率凉倚,平均性能會(huì)有較明顯提升兼都; | gpconfig -c checkpoint_segments -v 2 –skipvalidation |
3.2.2、測(cè)試工具準(zhǔn)備
工具 | 安裝說(shuō)明 |
---|---|
benchmarksql | 軟件說(shuō)明:https://github.com/dreamedcheng/benchmarksql-5.0?spm=a2c4e.10696291.0.0.605719a4TUrbqS&file=benchmarksql-5.0 軟件安裝步驟: git clone https://github.com/dreamedcheng/benchmarksql-5.0.git yum install ant cd benchmarksql-5.0 ant |
3.2.3稽寒、測(cè)試數(shù)據(jù)準(zhǔn)備
測(cè)試數(shù)據(jù)總量
表名 | 數(shù)據(jù)量(行數(shù)) |
---|---|
bmsql_warehouse | 1000 |
bmsql_district | 10000 |
bmsql_customer | 30000000 |
bmsql_history | 30000000 |
bmsql_new_order | 9000000 |
bmsql_oorder | 30000000 |
bmsql_order_line | 299976737 |
bmsql_item | 100000 |
bmsql_stock | 100000000 |
使用benchmarksql工具生成1000個(gè)warehouse的數(shù)據(jù)集
· 創(chuàng)建測(cè)試用戶
CREATE USER benchmarksql WITH ENCRYPTED PASSWORD 'changeme';
CREATE DATABASE benchmarksql OWNER benchmarksql;
· 生成測(cè)試數(shù)據(jù)
-----------數(shù)據(jù)文件生成-----------
cd benchmarksql-5.0/run
./runLoader.sh gpdb.properties
-----------gpdb.properties文件內(nèi)容說(shuō)明-----------
db=postgres // 使用默認(rèn)的postgres
driver=org.postgresql.Driver // 使用默認(rèn)的org.postgresql.Drive
conn=jdbc:postgresql://host:port/benchmarksql //實(shí)例連接地址
user=benchmarksql // 連接實(shí)例的測(cè)試用戶
password=your_password // 對(duì)應(yīng)用戶的密碼
warehouses=1000 // 指定生成數(shù)據(jù)集warehouse的數(shù)量
loadWorkers=16 // 指定生成數(shù)據(jù)的線程數(shù)量扮碧,如果CPU core和內(nèi)存 夠用可以將其大小調(diào)大,這樣速度更快
fileLocation=/data/tpcc_1000/ // 指定生成數(shù)據(jù)的存儲(chǔ)目錄
數(shù)據(jù)加載
· 使用benchmarksql提供的tableCreates.sql進(jìn)行建表
psql -f tableCreates.sql -U user_name -d db_name -h host -p port
· 使用COPY命令導(dǎo)入數(shù)據(jù)
# 使用COPY方式將數(shù)據(jù)加載到數(shù)據(jù)庫(kù)中
psql -h host -d db_name -p your_port -U user_name -c "\copy bmsql_history from '/data/tpcc_1000/cust-hist.csv' with delimiter ',' null '';"
· 使用benchmarksql提供的indexCreates.sql進(jìn)行創(chuàng)建索引
psql -f indexCreates.sql -U user_name -d db_name -h host -p port
收集統(tǒng)計(jì)信息
analyze bmsql_warehouse;
analyze bmsql_district;
analyze bmsql_customer;
analyze bmsql_history;
analyze bmsql_new_order;
analyze bmsql_oorder;
analyze bmsql_order_line;
analyze bmsql_item;
analyze bmsql_stock;
3.3.4杏糙、測(cè)試執(zhí)行
-------------運(yùn)行測(cè)試腳本---------------
./runBenchmark.sh gpdb.properties
-----------gpdb.properties文件內(nèi)容說(shuō)明-----------
db=postgres // 使用默認(rèn)的postgres
driver=org.postgresql.Driver // 使用默認(rèn)的org.postgresql.Drive
conn=jdbc:postgresql://host:port/benchmarksql //adbpg實(shí)例連接地址
user=benchmarksql // 連接adbpg實(shí)例測(cè)試的用戶
password=your_password // 對(duì)應(yīng)用戶的密碼
terminals=128 // TPC-C測(cè)試的并發(fā)數(shù)
//To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0 // 使用默認(rèn)的0
//To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=10 // TPC-C執(zhí)行時(shí)間慎王,單位分鐘
//Number of total transactions per minute
limitTxnsPerMin=30000000 // 使用默認(rèn)的30000000
// 下面配置各個(gè)事務(wù)的比重,也使用如下給定的默認(rèn)值
//The following five values must add up to 100
//The default percentages of 45, 43, 4, 4 & 4 match the TPC-C spec
newOrderWeight=45
paymentWeight=43
orderStatusWeight=4
deliveryWeight=4
stockLevelWeight=4
4宏侍、TPC-H
4.1赖淤、簡(jiǎn)介
TPC-H(商業(yè)智能計(jì)算測(cè)試)是美國(guó)交易處理效能委員會(huì)(TPC,TransactionProcessing Performance Council) 組織制定的用來(lái)模擬決策支持類應(yīng)用的一個(gè)測(cè)試集。目前在學(xué)術(shù)界和工業(yè)界普遍采用它來(lái)評(píng)價(jià)決策支持技術(shù)方面應(yīng)用的性能谅河。TPC-H是根據(jù)真實(shí)的生產(chǎn)運(yùn)行環(huán)境來(lái)建模咱旱,模擬了一套銷售系統(tǒng)的數(shù)據(jù)倉(cāng)庫(kù)确丢。其共包含8個(gè)基本關(guān)系,數(shù)據(jù)量可設(shè)定從1G~3T不等吐限。其基準(zhǔn)測(cè)試共包含了22個(gè)查詢鲜侥,主要評(píng)價(jià)指標(biāo)各個(gè)查詢的響應(yīng)時(shí)間,即從提交查詢到結(jié)果返回所需時(shí)間诸典。其測(cè)試結(jié)果可綜合反映系統(tǒng)處理查詢時(shí)的能力剃毒。
4.2、測(cè)試步驟
4.2.1搂赋、測(cè)試工具準(zhǔn)備
工具 | 安裝說(shuō)明 | 使用說(shuō)明 |
---|---|---|
TPC-H dbgen | git clone https://github.com/gregrahn/tpch-kit.git cd tpch-kit/dbgen make MACHINE=LINUX DATABASE=POSTGRESQL |
./dbgen -help ./qgen -help |
4.2.2赘阀、測(cè)試數(shù)據(jù)準(zhǔn)備
測(cè)試數(shù)據(jù)總量:TPC-H 中使用SF描述數(shù)據(jù)量,1SF 對(duì)應(yīng)1GB 單位脑奠,1SF對(duì)應(yīng)的數(shù)據(jù)量只是8個(gè)表的總數(shù)據(jù)量不包括索引等空間占用基公,準(zhǔn)備數(shù)據(jù)時(shí)需預(yù)留更多空間,測(cè)試數(shù)據(jù)總量為1TB宋欺,即1000SF轰豆。
表名 | 數(shù)據(jù)條目數(shù) |
---|---|
customer | 15000w |
lineitem | 5999989709 |
nation | 25 |
orders | 150000w |
part | 20000w |
partsupp | 80000w |
region | 5 |
supplier | 1000w |
測(cè)試數(shù)據(jù)文件生成
· 聲明環(huán)境變量
export DSS_CONFIG=/.../tpch-kit/dbgen //tpch-kit/dbgen路徑
export DSS_QUERY=$DSS_CONFIG/queries
export DSS_PATH=/path-to-dir-for-output-files //輸出文件保存路徑
· 方式一:直接生成1TB數(shù)據(jù)文件
cd tpch-kit/dbgen
./dbgen -vf -s 1000
· 方式二:并行生成分片文件
#生成數(shù)據(jù)文件
#10個(gè)分片文件
for((i=1;i<=10;i++));
do
./dbgen -s 1000 -S $i -C 10 -f &
done
#處理生成的 tbl 文件,tbl文件每行最后會(huì)多1個(gè)'|'齿诞,可以用seed命令將每行后面的'|'去掉
sed -i 's/.$//' ./region.tbl &
sed -i 's/.$//' ./nation.tbl &
for((i=1;i<=10;i++));
do
sed -i 's/.$//' ./lineitem.tbl.$i &
sed -i 's/.$//' ./orders.tbl.$i &
sed -i 's/.$//' ./customer.tbl.$i &
sed -i 's/.$//' ./partsupp.tbl.$i &
sed -i 's/.$//' ./part.tbl.$i &
sed -i 's/.$//' ./supplier.tbl.$i &
done
建表語(yǔ)句
-- AO列存表酸休、不開(kāi)壓縮、設(shè)置復(fù)制表
create table nation (
n_nationkey integer not null,
n_name char(25) not null,
n_regionkey integer not null,
n_comment varchar(152))
with (appendonly=true, orientation=column)
distributed REPLICATED;
create table region (
r_regionkey integer not null,
r_name char(25) not null,
r_comment varchar(152))
with (appendonly=true, orientation=column)
distributed REPLICATED;
create table part (
p_partkey integer not null,
p_name varchar(55) not null,
p_mfgr char(25) not null,
p_brand char(10) not null,
p_type varchar(25) not null,
p_size integer not null,
p_container char(10) not null,
p_retailprice DECIMAL(15,2) not null,
p_comment varchar(23) not null)
with (appendonly=true, orientation=column)
distributed by (p_partkey);
create table supplier (
s_suppkey integer not null,
s_name char(25) not null,
s_address varchar(40) not null,
s_nationkey integer not null,
s_phone char(15) not null,
s_acctbal DECIMAL(15,2) not null,
s_comment varchar(101) not null)
with (appendonly=true, orientation=column)
distributed by (s_suppkey);
create table partsupp (
ps_partkey integer not null,
ps_suppkey integer not null,
ps_availqty integer not null,
ps_supplycost DECIMAL(15,2) not null,
ps_comment varchar(199) not null)
with (appendonly=true, orientation=column)
distributed by (ps_partkey);
create table customer (
c_custkey integer not null,
c_name varchar(25) not null,
c_address varchar(40) not null,
c_nationkey integer not null,
c_phone char(15) not null,
c_acctbal DECIMAL(15,2) not null,
c_mktsegment char(10) not null,
c_comment varchar(117) not null)
with (appendonly=true, orientation=column)
distributed by (c_custkey);
create table orders (
o_orderkey bigint not null,
o_custkey integer not null,
o_orderstatus char(1) not null,
o_totalprice DECIMAL(15,2) not null,
o_orderdate date not null,
o_orderpriority char(15) not null,
o_clerk char(15) not null,
o_shippriority integer not null,
o_comment varchar(79) not null)
with (appendonly=true, orientation=column)
distributed by (o_orderkey);
create table lineitem (
l_orderkey bigint not null,
l_partkey integer not null,
l_suppkey integer not null,
l_linenumber integer not null,
l_quantity DECIMAL(15,2) not null,
l_extendedprice DECIMAL(15,2) not null,
l_discount DECIMAL(15,2) not null,
l_tax DECIMAL(15,2) not null,
l_returnflag char(1) not null,
l_linestatus char(1) not null,
l_shipdate date not null,
l_commitdate date not null,
l_receiptdate date not null,
l_shipinstruct char(25) not null,
l_shipmode char(10) not null,
l_comment varchar(44) not null)
with (appendonly=true, orientation=column)
distributed by (l_orderkey);
數(shù)據(jù)導(dǎo)入
· COPY方式導(dǎo)入祷杈,SQL腳本參考
\copy nation from '/data/tpch_1t/nation.tbl' DELIMITER '|';
\copy region from '/data/tpch_1t/region.tbl' DELIMITER '|';
\copy supplier from '/data/tpch_1t/supplier.tbl' DELIMITER '|';
\copy part from '/data/tpch_1t/part.tbl' DELIMITER '|';
\copy partsupp from '/data/tpch_1t/partsupp.tbl' DELIMITER '|';
\copy customer from '/data/tpch_1t/customer.tbl' DELIMITER '|';
\copy orders from '/data/tpch_1t/orders.tbl' DELIMITER '|';
\copy lineitem from '/data/tpch_1t/lineitem.tbl' DELIMITER '|';
1斑司、可以psql連接到數(shù)據(jù)庫(kù)后,依次單條執(zhí)行上述SQL語(yǔ)句
2但汞、直接執(zhí)行腳本文件宿刮,方式如下
psql -f copy.sql -U user_name -d db_name -h host -p port
· 利用對(duì)象存儲(chǔ)和外部表導(dǎo)入
1、將數(shù)據(jù)文件上傳至JSS上
2私蕾、創(chuàng)建外部表
create extension jss;
create readable external table ext_nation ( n_nationkey int, n_name varchar(25), n_regionkey integer, n_comment varchar(152))
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
create readable external table ext_region ( R_REGIONKEY int, R_NAME CHAR(25),R_COMMENT VARCHAR(152))
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
CREATE readable external TABLE ext_lineitem ( l_orderkey bigint, l_partkey bigint, l_suppkey bigint,
l_linenumber bigint, l_quantity double precision, l_extendedprice double precision,
l_discount double precision, l_tax double precision, l_returnflag CHAR(1),
l_linestatus CHAR(1), l_shipdate DATE, l_commitdate DATE, l_receiptdate DATE,
l_shipinstruct CHAR(25), l_shipmode CHAR(10), l_comment VARCHAR(44))
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
CREATE readable external TABLE ext_orders ( o_orderkey bigint , o_custkey bigint, o_orderstatus CHAR(1) ,
o_totalprice double precision, o_orderdate DATE , o_orderpriority CHAR(15) , o_clerk CHAR(15) ,
o_shippriority bigint , o_comment VARCHAR(79) )
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
CREATE readable external TABLE ext_part ( p_partkey bigint , p_name VARCHAR(55) , p_mfgr CHAR(25) ,
p_brand CHAR(10) , p_type VARCHAR(25) , p_size bigint , p_container CHAR(10) ,
p_retailprice double precision , p_comment VARCHAR(23) )
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
CREATE readable external TABLE ext_partsupp ( ps_partkey bigint , ps_suppkey bigint ,
ps_availqty bigint , ps_supplycost double precision , ps_comment VARCHAR(199) )
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
CREATE readable external TABLE ext_supplier ( s_suppkey bigint , s_name CHAR(25) ,
s_address VARCHAR(40) , s_nationkey bigint , s_phone CHAR(15) , s_acctbal DECIMAL(15,2) ,
s_comment VARCHAR(101) )
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
CREATE readable external TABLE ext_customer ( c_custkey bigint , c_name VARCHAR(25) ,
c_address VARCHAR(40) , c_nationkey bigint , c_phone CHAR(15) , c_acctbal double precision ,
c_mktsegment CHAR(10) , c_comment VARCHAR(117) )
LOCATION('')
FORMAT 'TEXT' (DELIMITER '|' ) ;
3僵缺、將數(shù)據(jù)導(dǎo)入表中
insert into nation select * from ext_nation;
insert into region select * from ext_region;
insert into lineitem select * from ext_lineitem;
insert into orders select * from ext_orders;
insert into customer select * from ext_customer;
insert into part select * from ext_part;
insert into partsupp select * from ext_partsupp;
insert into supplier select * from ext_supplier;
收集統(tǒng)計(jì)信息
analyze nation;
analyze region;
analyze lineitem;
analyze orders;
analyze customer;
analyze part;
analyze partsupp;
analyze supplier;
4.2.3、測(cè)試執(zhí)行
· 生成測(cè)試22條測(cè)試sql
for ((i=1;i<=22;i++)); do
./qgen -v -c -s 1000 ${i} > /tmp/sf1000/tpch-q${i}.sql
done
· 執(zhí)行sql
- 依次手動(dòng)執(zhí)行22條sql語(yǔ)句或利用腳本執(zhí)行
total_cost=0
for i in {1..22}
do
echo "begin run Q${i}, /tmp/sf1000/tpch-q$i.sql , `date`"
begin_time=`date +%s.%N`
#psql -h ${實(shí)例連接地址} -p ${端口號(hào)} -U ${數(shù)據(jù)庫(kù)用戶} -f /tmp/sf1000/tpch-q${i}.sql > ./log/log_q${i}.out
rc=$?
end_time=`date +%s.%N`
cost=`echo "$end_time-$begin_time"|bc`
total_cost=`echo "$total_cost+$cost"|bc`
if [ $rc -ne 0 ] ; then
printf "run Q%s fail, cost: %.2f, totalCost: %.2f, `date`\n" $i $cost $total_cost
else
printf "run Q%s succ, cost: %.2f, totalCost: %.2f, `date`\n" $i $cost $total_cost
fi
done