Skip to content

Commit 398d200

Browse files
committed
Add couple of github actions flows on each push event: - run make installcheck over an instance in different modes. - run JOB benchmark [1] on a self hosted runner.
Utility scripts stores in the .github folder. Branch name is a key to define the name of suitable PostgreSQL core branch: use "stable[XX]" phrase in the name of git branch to trigger compiling and launch of this commit with REL_[XX]_STABLE branch of the core. If the branch name doesn't contain such a phrase, use master branch. TODO: ===== 1. Add 'long' JOB test (parallel strategy disabled). 2. Add JOB test which would be executed up to full convergency of learning on each query. 3. Add installchecks with reusage of existed database and the AQO extension installed (sanity checks will be definitely broken but still). 4. Additional queries [2] can be a marker for successful learning. [1] https://github.com/danolivo/jo-bench [2] https://github.com/RyanMarcus/imdb_pg_dataset
1 parent 012e118 commit 398d200

10 files changed

+577
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
ulimit -c unlimited
3+
4+
# Kill all orphan processes
5+
pkill -U `whoami` -9 -e postgres
6+
pkill -U `whoami` -9 -e pgbench
7+
pkill -U `whoami` -9 -e psql
8+
9+
sleep 1
10+
11+
M=`pwd`/PGDATA
12+
U=`whoami`
13+
14+
rm -rf $M || true
15+
mkdir $M
16+
rm -rf logfile.log || true
17+
18+
export LC_ALL=C
19+
export LANGUAGE="en_US:en"
20+
initdb -D $M --locale=C
21+
22+
# PG Version-specific settings
23+
ver=$(pg_ctl -V | egrep -o "[0-9]." | head -1)
24+
echo "PostgreSQL version: $ver"
25+
if [ $ver -gt 13 ]
26+
then
27+
echo "compute_query_id = 'regress'" >> $M/postgresql.conf
28+
fi
29+
30+
# Speed up the 'Join Order Benchmark' test
31+
echo "shared_buffers = 1GB" >> $M/postgresql.conf
32+
echo "work_mem = 128MB" >> $M/postgresql.conf
33+
echo "fsync = off" >> $M/postgresql.conf
34+
echo "autovacuum = 'off'" >> $M/postgresql.conf
35+
36+
# AQO preferences
37+
echo "shared_preload_libraries = 'aqo, pg_stat_statements'" >> $M/postgresql.conf
38+
echo "aqo.mode = 'disabled'" >> $M/postgresql.conf
39+
echo "aqo.join_threshold = 0" >> $M/postgresql.conf
40+
echo "aqo.force_collect_stat = 'off'" >> $M/postgresql.conf
41+
echo "aqo.fs_max_items = 10000" >> $M/postgresql.conf
42+
echo "aqo.fss_max_items = 20000" >> $M/postgresql.conf
43+
44+
pg_ctl -w -D $M -l logfile.log start
45+
createdb $U
46+
psql -c "CREATE EXTENSION aqo;"
47+
psql -c "CREATE EXTENSION pg_stat_statements"

.github/scripts/job/check_result.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# ##############################################################################
4+
#
5+
#
6+
# ##############################################################################
7+
8+
# Show error delta (Negative result is a signal of possible issue)
9+
result=$(psql -t -c "SELECT count(*) FROM aqo_cardinality_error(true) c JOIN aqo_cardinality_error(false) o USING (id) WHERE (o.error - c.error) < 0")
10+
11+
if [ $result -gt 0 ]; then
12+
exit 1;
13+
fi
14+
15+
exit 0;

.github/scripts/job/dump_knowledge.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# ##############################################################################
4+
#
5+
# Make dump of a knowledge base
6+
#
7+
# ##############################################################################
8+
9+
psql -c "CREATE TABLE aqo_data_dump AS SELECT * FROM aqo_data;"
10+
psql -c "CREATE TABLE aqo_queries_dump AS SELECT * FROM aqo_queries;"
11+
psql -c "CREATE TABLE aqo_query_texts_dump AS SELECT * FROM aqo_query_texts;"
12+
psql -c "CREATE TABLE aqo_query_stat_dump AS SELECT * FROM aqo_query_stat;"
13+
14+
pg_dump --table='aqo*' -f knowledge_base.dump $PGDATABASE
15+
16+
psql -c "DROP TABLE aqo_data_dump, aqo_queries_dump, aqo_query_texts_dump, aqo_query_stat_dump"
17+

.github/scripts/job/job_pass.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
# ##############################################################################
4+
#
5+
# Pass each JOB query over the DBMS instance. Use $1 to specify a number of
6+
# iterations, if needed.
7+
#
8+
# Results:
9+
# - explains.txt - explain of each query
10+
# - job_onepass_aqo_stat.dat - short report on execution time
11+
# - knowledge_base.dump - dump of the AQO knowledge base
12+
#
13+
# ##############################################################################
14+
15+
echo "The Join Order Benchmark 1Pass"
16+
echo -e "Query Number\tITER\tQuery Name\tExecution Time, ms" > report.txt
17+
echo -e "Clear a file with explains" > explains.txt
18+
19+
if [ $# -eq 0 ]
20+
then
21+
ITERS=1
22+
else
23+
ITERS=$1
24+
fi
25+
26+
echo "Execute JOB with the $ITERS iterations"
27+
28+
filenum=1
29+
for file in $JOB_DIR/queries/*.sql
30+
do
31+
# Get filename
32+
short_file=$(basename "$file")
33+
34+
echo -n "EXPLAIN (ANALYZE, VERBOSE, FORMAT JSON) " > test.sql
35+
cat $file >> test.sql
36+
37+
for (( i=1; i<=$ITERS; i++ ))
38+
do
39+
result=$(psql -f test.sql)
40+
echo -e $result >> explains.txt
41+
exec_time=$(echo $result | sed -n 's/.*"Execution Time": \([0-9]*\.[0-9]*\).*/\1/p')
42+
echo -e "$filenum\t$short_file\t$i\t$exec_time" >> report.txt
43+
echo -e "$filenum\t$i\t$short_file\t$exec_time"
44+
done
45+
filenum=$((filenum+1))
46+
done
47+
48+
# Show total optimizer error in the test
49+
psql -c "SELECT sum(error) AS total_error FROM aqo_cardinality_error(false)"
50+
psql -c "SELECT sum(error) AS total_error_aqo FROM aqo_cardinality_error(true)"
51+
52+
# Show error delta (Negative result is a signal of possible issue)
53+
psql -c "
54+
SELECT id, (o.error - c.error) AS errdelta
55+
FROM aqo_cardinality_error(true) c JOIN aqo_cardinality_error(false) o
56+
USING (id)
57+
"
58+

.github/scripts/job/load_imdb.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
psql -f $JOB_DIR/schema.sql
4+
psql -vdatadir="'$JOB_DIR'" -f $JOB_DIR/copy.sql
5+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# ##############################################################################
4+
#
5+
# Test conditions No.1: Quick pass in 'disabled' mode with statistics and
6+
# forced usage of a bunch of parallel workers.
7+
#
8+
# - Disabled mode with a stat gathering and AQO details in explain
9+
# - Force usage of parallel workers aggressively
10+
# - Enable pg_stat_statements statistics
11+
#
12+
# ##############################################################################
13+
14+
# AQO specific settings
15+
psql -c "ALTER SYSTEM SET aqo.mode = 'disabled'"
16+
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
17+
psql -c "ALTER SYSTEM SET aqo.show_details = 'on'"
18+
psql -c "ALTER SYSTEM SET aqo.show_hash = 'on'"
19+
20+
# Core settings: force parallel workers
21+
psql -c "ALTER SYSTEM SET max_parallel_workers_per_gather = 16"
22+
psql -c "ALTER SYSTEM SET force_parallel_mode = 'on'"
23+
psql -c "ALTER SYSTEM SET from_collapse_limit = 20"
24+
psql -c "ALTER SYSTEM SET join_collapse_limit = 20"
25+
psql -c "ALTER SYSTEM SET parallel_setup_cost = 1.0"
26+
psql -c "ALTER SYSTEM SET parallel_tuple_cost = 0.00001"
27+
psql -c "ALTER SYSTEM SET min_parallel_table_scan_size = 0"
28+
psql -c "ALTER SYSTEM SET min_parallel_index_scan_size = 0"
29+
30+
# pg_stat_statements
31+
psql -c "ALTER SYSTEM SET pg_stat_statements.track = 'all'"
32+
psql -c "ALTER SYSTEM SET pg_stat_statements.track_planning = 'on'"
33+
34+
psql -c "SELECT pg_reload_conf();"
35+
36+
# Enable all previously executed queries which could be disabled
37+
psql -c "
38+
SELECT count(*) FROM aqo_queries, LATERAL aqo_disable_class(queryid)
39+
WHERE queryid <> 0
40+
"
41+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# ##############################################################################
4+
#
5+
# Test conditions No.2: Learn mode with forced parallel workers
6+
#
7+
# - Disabled mode with a stat gathering and AQO details in explain
8+
# - Force usage of parallel workers aggressively
9+
# - Enable pg_stat_statements statistics
10+
#
11+
# ##############################################################################
12+
13+
# AQO specific settings
14+
psql -c "ALTER SYSTEM SET aqo.mode = 'learn'"
15+
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'off'"
16+
psql -c "ALTER SYSTEM SET aqo.show_details = 'on'"
17+
psql -c "ALTER SYSTEM SET aqo.show_hash = 'on'"
18+
psql -c "ALTER SYSTEM SET aqo.join_threshold = 0"
19+
psql -c "ALTER SYSTEM SET aqo.wide_search = 'off'"
20+
21+
# Core settings: force parallel workers
22+
psql -c "ALTER SYSTEM SET max_parallel_workers_per_gather = 16"
23+
psql -c "ALTER SYSTEM SET force_parallel_mode = 'on'"
24+
psql -c "ALTER SYSTEM SET from_collapse_limit = 20"
25+
psql -c "ALTER SYSTEM SET join_collapse_limit = 20"
26+
psql -c "ALTER SYSTEM SET parallel_setup_cost = 1.0"
27+
psql -c "ALTER SYSTEM SET parallel_tuple_cost = 0.00001"
28+
psql -c "ALTER SYSTEM SET min_parallel_table_scan_size = 0"
29+
psql -c "ALTER SYSTEM SET min_parallel_index_scan_size = 0"
30+
31+
# pg_stat_statements
32+
psql -c "ALTER SYSTEM SET pg_stat_statements.track = 'all'"
33+
psql -c "ALTER SYSTEM SET pg_stat_statements.track_planning = 'on'"
34+
35+
psql -c "SELECT pg_reload_conf();"
36+
37+
# Enable all previously executed queries which could be disabled
38+
psql -c "
39+
SELECT count(*) FROM aqo_queries, LATERAL aqo_enable_class(queryid)
40+
WHERE queryid <> 0
41+
"
42+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# ##############################################################################
4+
#
5+
# Test conditions No.3: Freeze ML base and forced parallel workers
6+
#
7+
# - Disabled mode with a stat gathering and AQO details in explain
8+
# - Force usage of parallel workers aggressively
9+
# - Enable pg_stat_statements statistics
10+
#
11+
# ##############################################################################
12+
13+
# AQO specific settings
14+
psql -c "ALTER SYSTEM SET aqo.mode = 'frozen'"
15+
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'off'"
16+
psql -c "ALTER SYSTEM SET aqo.show_details = 'on'"
17+
psql -c "ALTER SYSTEM SET aqo.show_hash = 'on'"
18+
psql -c "ALTER SYSTEM SET aqo.join_threshold = 0"
19+
psql -c "ALTER SYSTEM SET aqo.wide_search = 'off'"
20+
21+
# Core settings: force parallel workers
22+
psql -c "ALTER SYSTEM SET max_parallel_workers_per_gather = 16"
23+
psql -c "ALTER SYSTEM SET force_parallel_mode = 'on'"
24+
psql -c "ALTER SYSTEM SET from_collapse_limit = 20"
25+
psql -c "ALTER SYSTEM SET join_collapse_limit = 20"
26+
psql -c "ALTER SYSTEM SET parallel_setup_cost = 1.0"
27+
psql -c "ALTER SYSTEM SET parallel_tuple_cost = 0.00001"
28+
psql -c "ALTER SYSTEM SET min_parallel_table_scan_size = 0"
29+
psql -c "ALTER SYSTEM SET min_parallel_index_scan_size = 0"
30+
31+
# pg_stat_statements
32+
psql -c "ALTER SYSTEM SET pg_stat_statements.track = 'all'"
33+
psql -c "ALTER SYSTEM SET pg_stat_statements.track_planning = 'on'"
34+
35+
psql -c "SELECT pg_reload_conf();"
36+
37+
# Enable all previously executed queries which could be disabled
38+
psql -c "
39+
SELECT count(*) FROM aqo_queries, LATERAL aqo_enable_class(queryid)
40+
WHERE queryid <> 0
41+
"
42+

0 commit comments

Comments
 (0)