TPC-H tools的使用

1. 首先从TPC官网上下载TPC-H tools的压缩包,网址为:http://www.tpc.org/tpc_documents_current_versions/current_specifications.asp;

2. 解压;

3. 使用Visual Studio打开项目tpch.sln(dbgen目录下);

4. 右键dbgen项目,选择生成,然后将dbgen\Debug目录下的dbgen.exe拷贝到dbgen目录下;

5. 此时,通过cmd到dbgen目录下,便可根据命令“dbgen-vf -s 1”生成测试数据库实例(-s后面的是Scale Facter因子);

6. 后缀名为“.tbl”即为生成的数据。

7. 然后我在MySQL数据库上建立一个数据库,名为“tpch”;

8. 所有的建表语句在文件dss.ddl中,但是原始文件中没有主外键的约束,所以我自己添加了主外键的约束,注意LINEITEM与PARTSUPP之间存在混合引用的关系,具体建表语句如下:

DROP TABLE IF EXISTS LINEITEM;

DROP TABLE IF EXISTS ORDERS;

DROP TABLE IF EXISTS CUSTOMER;

DROP TABLE IF EXISTS PARTSUPP;

DROP TABLE IF EXISTS SUPPLIER;

DROP TABLE IF EXISTS PART;

DROP TABLE IF EXISTS NATION;

DROP TABLE IF EXISTS REGION;

CREATE TABLE REGION  ( R_REGIONKEY  INTEGER NOT NULL,
                            R_NAME       CHAR(25) NOT NULL,
                            R_COMMENT    VARCHAR(152),
							PRIMARY KEY(R_REGIONKEY));

CREATE TABLE NATION  ( N_NATIONKEY  INTEGER NOT NULL,
                            N_NAME       CHAR(25) NOT NULL,
                            N_REGIONKEY  INTEGER NOT NULL,
                            N_COMMENT    VARCHAR(152),
							PRIMARY KEY(N_NATIONKEY),
							FOREIGN KEY(N_REGIONKEY) REFERENCES REGION(R_REGIONKEY));			
							
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,
						  PRIMARY KEY(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,
							 PRIMARY KEY(S_SUPPKEY),
							 FOREIGN KEY(S_NATIONKEY) REFERENCES NATION(N_NATIONKEY));

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,
							 PRIMARY KEY(PS_PARTKEY, PS_SUPPKEY),
							 FOREIGN KEY(PS_PARTKEY) REFERENCES PART(P_PARTKEY),
							 FOREIGN KEY(PS_SUPPKEY) REFERENCES SUPPLIER(S_SUPPKEY));

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,
							 PRIMARY KEY(C_CUSTKEY),
							 FOREIGN KEY(C_NATIONKEY) REFERENCES NATION(N_NATIONKEY));
							  
CREATE TABLE ORDERS  ( O_ORDERKEY       INTEGER 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,
						   PRIMARY KEY(O_ORDERKEY),
						   FOREIGN KEY(O_CUSTKEY) REFERENCES CUSTOMER(C_CUSTKEY));

CREATE TABLE LINEITEM ( L_ORDERKEY    INTEGER 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,
							 PRIMARY KEY(L_ORDERKEY, L_LINENUMBER),				 
							 FOREIGN KEY(L_PARTKEY, L_SUPPKEY) REFERENCES PARTSUPP(PS_PARTKEY, PS_SUPPKEY));

9. 然后开始数据导入,具体导入命令如下(下述命令不能正常运行的话,则在登录MySQL客户端时加“--local-infile”):

LOAD DATA LOCAL INFILE '~/tpchdata/region.tbl' INTO TABLE REGION FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/nation.tbl' INTO TABLE NATION FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/part.tbl' INTO TABLE PART FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/supplier.tbl' INTO TABLE SUPPLIER FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/partsupp.tbl' INTO TABLE PARTSUPP FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/customer.tbl' INTO TABLE CUSTOMER FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/orders.tbl' INTO TABLE ORDERS FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
LOAD DATA LOCAL INFILE '~/tpchdata/lineitem.tbl' INTO TABLE LINEITEM FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';

10. 右键项目qgen,选择生成,然后将dbgen\Debug目录下的qgen.exe拷贝到dbgen目录下,并把dbgen\queries文件夹中的sql文件拷出来到目录dbgen\下

11. 利用命令“qgen-d 1 > _1.sql”生成实例化的SQL,一直运行22次便可得到实例化的22个query(每次需指定query的序号)。

12. 然后就可以利用实例化的query进行测试啦。



©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值