forked from electrum/tpch-dbgen
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·160 lines (143 loc) · 4.9 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# default configuration
# user: "postgres"
# database: "postgres"
# host: "localhost"
# primary port: "5432"
# data scale: 1
pg_user=postgres
pg_database=postgres
pg_host=localhost
pg_port=5432
data_scale=10
is_run=-1
test_case=18
clean=
option=""
usage () {
cat <<EOF
1) Use default configuration to build
./build.sh
2) Use limited configuration to build
./build.sh --user=postgres --db=postgres --host=localhost --port=5432 --scale=1
3) Run the test case
./build.sh --run
4) Run the target test case
./build.sh --run=3. run the 3rd case.
5) Run the target test case with option
./build.sh --run --option="set polar_enable_px = on;"
6) Clean the test data. This step will drop the database or tables, remove csv
and tbl files
./build.sh --clean
7) Quick build TPC-H with 100MB scale of data
./build.sh --scale=0.1
EOF
exit 0;
}
for arg do
val=`echo "$arg" | sed -e 's;^--[^=]*=;;'`
case "$arg" in
--user=*) pg_user="$val";;
--db=*) pg_database="$val";;
--host=*) pg_host="$val";;
--port=*) pg_port="$val";;
--scale=*) data_scale="$val";;
--run) is_run=on ;;
--run=*) is_run=on;
test_case="$val"
;;
--option=*) option="$val";;
--clean) clean=on ;;
-h|--help) usage ;;
*) echo "wrong options : $arg";
exit 1
;;
esac
done
export PGPORT=$pg_port
export PGHOST=$pg_host
export PGDATABASE=$pg_database
export PGUSER=$pg_user
function gen_query_sql() {
DIR=.
rm -rf $DIR/finals
mkdir $DIR/finals
cp $DIR/queries/*.sql $DIR
for FILE in $(find $DIR -maxdepth 1 -name "[0-9]*.sql")
do
DIGIT=$(echo $FILE | tr -cd '[[:digit:]]')
./qgen $DIGIT > $DIR/finals/$DIGIT.sql
sed 's/^select/explain select/' $DIR/finals/$DIGIT.sql > $DIR/finals/$DIGIT.explain.sql
done
rm *.sql
}
function run_query_sql() {
DIR=.
if [[ $test_case -ne "-1" && $test_case -ne "on" ]]
then
echo "####################### $test_case.sql ###########################"
echo "####################### $test_case.sql ###########################" >> $DIR/result
psql -c "$option" -c "\timing" -f $DIR/finals/$test_case.explain.sql -qa >> $DIR/result
psql -c "$option" -c "\timing" -f $DIR/finals/$test_case.sql -qa >> $DIR/result
else
for i in `seq 1 22`
do
echo "####################### $i.sql ###########################"
echo "####################### $i.sql ###########################" >> $DIR/result
psql -c "$option" -c "\timing" -f $DIR/finals/$i.explain.sql -qa >> $DIR/result
psql -c "$option" -c "\timing" -f $DIR/finals/$i.sql -qa >> $DIR/result
done
fi
}
# run the tpch test
if [[ $is_run == "on" ]];
then
run_query_sql;
exit;
fi
# clean the tpch test data
if [[ $clean == "on" ]];
then
make clean
if [[ $pg_database == "postgres" ]];
then
echo "drop all the tpch tables"
psql -c "drop table customer cascade"
psql -c "drop table lineitem cascade"
psql -c "drop table nation cascade"
psql -c "drop table orders cascade"
psql -c "drop table part cascade"
psql -c "drop table partsupp cascade"
psql -c "drop table region cascade"
psql -c "drop table supplier cascade"
else
echo "drop the tpch database: $PGDATABASE"
psql -c "drop database $PGDATABASE" -d postgres
fi
exit;
fi
###################### PHASE 1: compile ######################
make -f makefile.suite
##################### PHASE 2: generate data ######################
rm -rf *.tbl
./dbgen -s $data_scale
###################### PHASE 3: create table ######################
if [[ $PGDATABASE != "postgres" ]];
then
echo "create the tpch database: $PGDATABASE"
psql -c "create database $PGDATABASE" -d postgres
fi
psql -f dss.ddl
###################### PHASE 4: load data ######################
psql -c "\COPY nation FROM 'nation.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY region FROM 'region.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY part FROM 'part.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY supplier FROM 'supplier.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY partsupp FROM 'partsupp.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY customer FROM 'customer.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY orders FROM 'orders.tbl' WITH (FORMAT csv, DELIMITER '|');"
psql -c "\COPY lineitem FROM 'lineitem.tbl' WITH (FORMAT csv, DELIMITER '|');"
###################### PHASE 5: add primary and foreign key ######################
psql -f dss.ri
##################### PHASE 6: generate query sql in final dir ######################
gen_query_sql;