Skip to content

Commit 8e92486

Browse files
authored
chore(docs): update instructions to run TPC-H (#374)
Signed-off-by: Alex Chi <iskyzh@gmail.com>
1 parent 393aa1e commit 8e92486

File tree

9 files changed

+142
-12
lines changed

9 files changed

+142
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
*.db
33
.idea
4+
/tpch-dbgen

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TPCH_DBGEN_PATH := target/tpch-dbgen
1+
TPCH_DBGEN_PATH := tpch-dbgen
22

33
docs_check:
44
cargo doc --no-deps --document-private-items --all-features # TODO: docs check won't fail if there is warning, should be fixed later
@@ -37,4 +37,8 @@ tpch: $(TPCH_DBGEN_PATH)
3737
make -C $(TPCH_DBGEN_PATH)
3838
cd $(TPCH_DBGEN_PATH) && ./dbgen -f && mkdir -p tbl && mv *.tbl tbl
3939

40+
tpch-10gb: $(TPCH_DBGEN_PATH)
41+
make -C $(TPCH_DBGEN_PATH)
42+
cd $(TPCH_DBGEN_PATH) && ./dbgen -f -s 10 && mkdir -p tbl && mv *.tbl tbl
43+
4044
.PHONY: docs check fmt fmt_check clippy clippy_check build test docs_check clean tpch

docs/01-tpch.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ and run some simple queries in RisingLight.
77

88
### Use Make Recipe
99

10-
You may use the make recipe to download and generate TPC-H data.
10+
You may use the make recipe to download and generate TPC-H data (about 1GB in tbl format).
1111

1212
```
1313
make tpch
1414
```
1515

16-
The generated data will be placed under `target/tpch-dbgen/tbl` folder.
16+
If you want to run a larger query:
17+
18+
```
19+
make tpch-10gb
20+
```
21+
22+
The generated data will be placed under `tpch-dbgen/tbl` folder.
1723

1824
### Manual Generation
1925

@@ -30,7 +36,7 @@ Then, enter the tpch-dbgen directory and type `make all`, and it will generate s
3036
Finally, type the following command and wait for several seconds:
3137

3238
```
33-
./dbgen -s 1
39+
./dbgen
3440
```
3541

3642
This command will generate the data we want, which contains a table called `LINEITEM` with a size of 700MB.
@@ -88,6 +94,16 @@ select sum(L_LINENUMBER) from LINEITEM;
8894
select count(L_ORDERKEY), sum(L_LINENUMBER) from LINEITEM where L_ORDERKEY > 2135527;
8995
```
9096

97+
Or run real TPC-H queries:
98+
99+
```shell
100+
cargo run --release -- -f tests/sql/tpch/q1.sql
101+
cargo run --release -- -f tests/sql/tpch/q3.sql
102+
cargo run --release -- -f tests/sql/tpch/q5.sql
103+
cargo run --release -- -f tests/sql/tpch/q6.sql
104+
cargo run --release -- -f tests/sql/tpch/q10.sql
105+
```
106+
91107
## Clean Data
92108

93109
All data of RisingLight is stored in `risinglight.secondary.db` folder. Simply remove it

tests/sql/tpch/import.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
COPY CUSTOMER FROM 'target/tpch-dbgen/tbl/customer.tbl' ( DELIMITER '|' );
2-
COPY NATION FROM 'target/tpch-dbgen/tbl/nation.tbl' ( DELIMITER '|' );
3-
COPY ORDERS FROM 'target/tpch-dbgen/tbl/orders.tbl' ( DELIMITER '|' );
4-
COPY PART FROM 'target/tpch-dbgen/tbl/part.tbl' ( DELIMITER '|' );
5-
COPY PARTSUPP FROM 'target/tpch-dbgen/tbl/partsupp.tbl' ( DELIMITER '|' );
6-
COPY REGION FROM 'target/tpch-dbgen/tbl/region.tbl' ( DELIMITER '|' );
7-
COPY SUPPLIER FROM 'target/tpch-dbgen/tbl/supplier.tbl' ( DELIMITER '|' );
8-
COPY LINEITEM FROM 'target/tpch-dbgen/tbl/lineitem.tbl' ( DELIMITER '|' );
1+
COPY CUSTOMER FROM 'tpch-dbgen/tbl/customer.tbl' ( DELIMITER '|' );
2+
COPY NATION FROM 'tpch-dbgen/tbl/nation.tbl' ( DELIMITER '|' );
3+
COPY ORDERS FROM 'tpch-dbgen/tbl/orders.tbl' ( DELIMITER '|' );
4+
COPY PART FROM 'tpch-dbgen/tbl/part.tbl' ( DELIMITER '|' );
5+
COPY PARTSUPP FROM 'tpch-dbgen/tbl/partsupp.tbl' ( DELIMITER '|' );
6+
COPY REGION FROM 'tpch-dbgen/tbl/region.tbl' ( DELIMITER '|' );
7+
COPY SUPPLIER FROM 'tpch-dbgen/tbl/supplier.tbl' ( DELIMITER '|' );
8+
COPY LINEITEM FROM 'tpch-dbgen/tbl/lineitem.tbl' ( DELIMITER '|' );

tests/sql/tpch/q1.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
select
2+
l_returnflag,
3+
l_linestatus,
4+
sum(l_quantity) as sum_qty,
5+
sum(l_extendedprice) as sum_base_price,
6+
sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
7+
sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
8+
avg(l_quantity) as avg_qty,
9+
avg(l_extendedprice) as avg_price,
10+
avg(l_discount) as avg_disc,
11+
count(*) as count_order
12+
from
13+
lineitem
14+
where
15+
l_shipdate <= date '1998-12-01' - interval '71' day
16+
group by
17+
l_returnflag,
18+
l_linestatus
19+
order by
20+
l_returnflag,
21+
l_linestatus;

tests/sql/tpch/q10.sql

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
select
2+
c_custkey,
3+
c_name,
4+
sum(l_extendedprice * (1 - l_discount)) as revenue,
5+
c_acctbal,
6+
n_name,
7+
c_address,
8+
c_phone,
9+
c_comment
10+
from
11+
customer,
12+
orders,
13+
lineitem,
14+
nation
15+
where
16+
c_custkey = o_custkey
17+
and l_orderkey = o_orderkey
18+
and o_orderdate >= date '1993-10-01'
19+
and o_orderdate < date '1993-10-01' + interval '3' month
20+
and l_returnflag = 'R'
21+
and c_nationkey = n_nationkey
22+
group by
23+
c_custkey,
24+
c_name,
25+
c_acctbal,
26+
c_phone,
27+
n_name,
28+
c_address,
29+
c_comment
30+
order by
31+
revenue desc
32+
limit 20;

tests/sql/tpch/q3.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
select
2+
l_orderkey,
3+
sum(l_extendedprice * (1 - l_discount)) as revenue,
4+
o_orderdate,
5+
o_shippriority
6+
from
7+
customer,
8+
orders,
9+
lineitem
10+
where
11+
c_mktsegment = 'BUILDING'
12+
and c_custkey = o_custkey
13+
and l_orderkey = o_orderkey
14+
and o_orderdate < date '1995-03-15'
15+
and l_shipdate > date '1995-03-15'
16+
group by
17+
l_orderkey,
18+
o_orderdate,
19+
o_shippriority
20+
order by
21+
revenue desc,
22+
o_orderdate
23+
limit 10;

tests/sql/tpch/q5.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
select
2+
n_name,
3+
sum(l_extendedprice * (1 - l_discount)) as revenue
4+
from
5+
customer,
6+
orders,
7+
lineitem,
8+
supplier,
9+
nation,
10+
region
11+
where
12+
c_custkey = o_custkey
13+
and l_orderkey = o_orderkey
14+
and l_suppkey = s_suppkey
15+
and c_nationkey = s_nationkey
16+
and s_nationkey = n_nationkey
17+
and n_regionkey = r_regionkey
18+
and r_name = 'AFRICA'
19+
and o_orderdate >= date '1994-01-01'
20+
and o_orderdate < date '1994-01-01' + interval '1' year
21+
group by
22+
n_name
23+
order by
24+
revenue desc;

tests/sql/tpch/q6.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
select
2+
sum(l_extendedprice * l_discount) as revenue
3+
from
4+
lineitem
5+
where
6+
l_shipdate >= date '1994-01-01'
7+
and l_shipdate < date '1994-01-01' + interval '1' year
8+
and l_discount between 0.08 - 0.01 and 0.08 + 0.01
9+
and l_quantity < 24;

0 commit comments

Comments
 (0)