1. 用sql语言创建数据库DB_test,代码参考https://blog.csdn.net/m0_75112455/article/details/143257034?spm=1001.2014.3001.5502
创建成功
2. 进行数据的导入
(1)下载TPC-H文件
(2)将tbl文件导入到数据库
use DB_test;
GO
drop table PART;
CREATE TABLE PART
(P_PARTKEY int primary key,
P_NAME varchar(55),
P_MFGR char(25),
P_BRAND char(10),
P_TYPE varchar(25),
P_SIZE int,
P_CONTAINER char(10),
P_RETAILPRICE decimal,
P_COMMENT varchar(23))
TRUNCATE TABLE PART;
BULK INSERT PART
FROM"D:\part.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
drop table REGION;
CREATE TABLE REGION
(R_REGIONKEY INT PRIMARY KEY,
R_NAME CHAR(25),
R_COMMENT VARCHAR(152))
TRUNCATE TABLE REGION;
BULK INSERT REGION
FROM"D:\tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\region.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
drop table NATION
CREATE TABLE NATION
(N_NATIONKEY INT PRIMARY KEY,
N_NAME CHAR(25),
N_REGIONKEY INT FOREIGN KEY REFERENCES REGION(R_REGIONKEY),
N_COMMENT VARCHAR(152))
TRUNCATE TABLE NATION;
BULK INSERT NATION
FROM"D: \tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\nation.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
/*drop table SUPPLIER*/
CREATE TABLE SUPPLIER
(S_SUPPKEY int PRIMARY KEY,
S_NAME char(25),
S_ADDRESS varchar(40),
S_NATIONKEY INT FOREIGN KEY REFERENCES NATION(N_NATIONKEY),
S_PHONE CHAR(15),
S_ACCTBAL DECIMAL,
S_COMMENT VARCHAR(101))
TRUNCATE TABLE SUPPLIER;
BULK INSERT SUPPLIER
FROM"D:\ tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\supplier.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
/*drop table PARTSUPP*/
CREATE TABLE PARTSUPP
(PS_PARTKEY INT FOREIGN KEY REFERENCES PART(P_PARTKEY),
PS_SUPPKEY INT FOREIGN KEY REFERENCES SUPPLIER(S_SUPPKEY),
PS_AVAILQTY INT,
PS_SUPPLYCOST DECIMAL,
PS_COMMENT VARCHAR(199),
PRIMARY KEY(PS_PARTKEY,PS_SUPPKEY))
TRUNCATE TABLE PARTSUPP;
BULK INSERT PARTSUPP
FROM"D: \tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\partsupp.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
/*drop table CUSTOMER*/
CREATE TABLE CUSTOMER
(C_CUSTKEY INT PRIMARY KEY,
C_NAME VARCHAR(25),
C_ADDRESS VARCHAR(40),
C_NATIONKEY INT FOREIGN KEY REFERENCES NATION(N_NATIONKEY),
C_PHONE CHAR(15),
C_ACCTBAL DECIMAL,
C_MKTSEGMENT CHAR(10),
C_COMMENT VARCHAR(117))
TRUNCATE TABLE CUSTOMER;
BULK INSERT CUSTOMER
FROM"D: \tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\customer.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
/*drop table ORDERS*/
CREATE TABLE ORDERS
(O_ORDERKEY INT PRIMARY KEY,
O_CUSTKEY INT,
O_ORDERSTATUS CHAR(1),
O_TOTALPRICE DECIMAL,
O_ORDERDATE DATE,
O_ORDERPRIORITY CHAR(15),
O_CLERK CHAR(15),
O_SHIPPRIORITY INT,
O_COMMENT VARCHAR(79),
FOREIGN KEY(O_CUSTKEY) REFERENCES CUSTOMER(C_CUSTKEY))
TRUNCATE TABLE ORDERS;
BULK INSERT ORDERS
FROM"D: \tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\orders.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
/*drop table LINEITEM*/
CREATE TABLE LINEITEM
(L_ORDERKEY INT FOREIGN KEY REFERENCES ORDERS(O_ORDERKEY),
L_PARTKEY INT FOREIGN KEY REFERENCES PART(P_PARTKEY),
L_SUPPKEY INT FOREIGN KEY REFERENCES SUPPLIER(S_SUPPKEY),
L_LINENUMBER INT,
L_QUANTITY DECIMAL,
L_EXTENDEDPRICE DECIMAL,
L_DISCOUNT DECIMAL,
L_TAX DECIMAL,
L_RETURNFLAG CHAR(1),
L_LINESTATUS CHAR(1),
L_SHIPDATE DATE,
L_COMMITDATE DATE,
L_SHIPINSTRUCT CHAR(25),
L_SHIPMODE CHAR(50),
L_COMMENT VARCHAR(60),
PRIMARY KEY(L_ORDERKEY,L_LINENUMBER))
TRUNCATE TABLE LINEITEM;
BULK INSERT LINEITEM
FROM"D: \tpc-h-tool-3.0.0\TPC-H_Tools_v3.0.0\dbgen\lineitem.tbl"
WITH
(TABLOCK, DATAFILETYPE='char', CODEPAGE='raw', FIELDTERMINATOR = '|',ROWTERMINATOR='|\n')
导入成功:
3. 测试索引的性能
(1)清楚缓冲区
(2)未使用索引时
(i)统计IO的耗费时间
(ii)查看长期计划:点击“查询”->“显示估计的执行计划”,可见最后走的是全标扫描
(3)使用索引后:
(i)创建索引
(ii)统计IO的耗费时间,相比未建立索引前,逻辑读取次数、预读读取次数都少了很多
(iii)查看长期计划,可见数据库走的是索引进行查询
标签:char,INT,CHAR,索引,tbl,KEY,SQL,TABLE,sever From: https://blog.csdn.net/m0_75112455/article/details/143257132