Skip to content

S13 7840 #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
- uses: actions/checkout@v3
- name: "Define PostreSQL major version"
run: |
echo "$(ls -la)"
patch_name=$(ls aqo_*.patch|tail -1)
echo "CORE_PATCH_NAME=$patch_name" >> $GITHUB_ENV

Expand Down Expand Up @@ -49,7 +48,6 @@ jobs:
run: |
git clone -b $PG_BRANCH --depth=1 --single-branch https://github.com/postgres/postgres.git $GITHUB_WORKSPACE/../pg
cd $GITHUB_WORKSPACE/../pg
ls -la
cp -r ../aqo contrib/aqo
patch -p1 --no-backup-if-mismatch < contrib/aqo/$CORE_PATCH_NAME

Expand All @@ -70,7 +68,7 @@ jobs:
env CLIENTS=50 THREADS=50 make -C contrib/aqo check

- name: Archive artifacts
if: ${{ always() }}
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: make_check_logs
Expand Down
90 changes: 46 additions & 44 deletions .github/workflows/installchecks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,68 @@ jobs:
steps:

# Set major PostgreSQL version for all underlying steps
- name: "Extract Postgres major version number"
- uses: actions/checkout@v3
- name: "Define PostreSQL major version"
run: |
PG_MAJOR_VERSION=$(echo "$BRANCH_NAME" | grep --only-matching 'stable[0-9].' | grep --only-matching '[0-9].')
patch_name=$(ls aqo_*.patch|tail -1)
echo "CORE_PATCH_NAME=$patch_name" >> $GITHUB_ENV

# Declare PG_MAJOR_VERSION as a environment variable
echo "PG_MAJOR_VERSION=$PG_MAJOR_VERSION" >> $GITHUB_ENV
echo "CORE_BRANCH_NAME=REL_${PG_MAJOR_VERSION}_STABLE" >> $GITHUB_ENV
echo "AQO_PATCH_NAME=aqo_pg$PG_MAJOR_VERSION.patch" >> $GITHUB_ENV
- name: "Set proper names for the master case"
# we can get number, otherwise set up master
vers_number=$(echo "$patch_name"|tr -d -c 0-9)
echo "PG_MAJOR_VERSION=$vers_number" >> $GITHUB_ENV

branch_name="REL_${vers_number}_STABLE"
echo "PG_BRANCH=$branch_name" >> $GITHUB_ENV

- name: "Set master branch name, if needed"
if: env.PG_MAJOR_VERSION == ''
run: |
echo "PG_MAJOR_VERSION=master" >> $GITHUB_ENV
echo "CORE_BRANCH_NAME=master" >> $GITHUB_ENV
echo "AQO_PATCH_NAME=aqo_master.patch" >> $GITHUB_ENV
branch_name="master"
echo "PG_BRANCH=$branch_name" >> $GITHUB_ENV

- name: "Preparations"
- name: "Environment (debug output)"
if: ${{ always() }}
run: |
sudo apt install libipc-run-perl libxml2-utils libxml2-dev xsltproc libxslt1-dev

echo "Deploying to production server on branch" $BRANCH_NAME
echo "Use PostgreSQL branch $PG_BRANCH (patch: $CORE_PATCH_NAME)"
echo "Deploying to production server on branch" $BRANCH_NAME "(PG $PG_BRANCH)"
git config --global user.email "[email protected]"
git config --global user.name "CI PgPro admin"
git clone https://github.com/postgres/postgres.git pg
cd pg
git checkout $CORE_BRANCH_NAME
git clone https://github.com/postgrespro/aqo.git contrib/aqo
git -C contrib/aqo checkout $BRANCH_NAME
patch -p1 --no-backup-if-mismatch < contrib/aqo/$AQO_PATCH_NAME
COPT="-Werror"
CONFIGURE_OPTS="--prefix=`pwd`/tmp_install --enable-tap-tests --enable-cassert"
echo "CONFIGURE_OPTS=$CONFIGURE_OPTS" >> $GITHUB_ENV
echo "COPT=$COPT" >> $GITHUB_ENV

- name: "Prepare PG directory"
run: |
sudo apt install libipc-run-perl libxml2-utils libxml2-dev xsltproc libxslt1-dev
git clone -b $PG_BRANCH --depth=1 --single-branch https://github.com/postgres/postgres.git $GITHUB_WORKSPACE/../pg
cd $GITHUB_WORKSPACE/../pg
cp -r ../aqo contrib/aqo
patch -p1 --no-backup-if-mismatch < contrib/aqo/$CORE_PATCH_NAME

- name: "Paths"
run: |
echo "$GITHUB_WORKSPACE/pg/contrib/aqo/.github/scripts/job" >> $GITHUB_PATH
ls -la pg/contrib/aqo/.github/scripts/job
echo "$GITHUB_WORKSPACE/pg/tmp_install/bin" >> $GITHUB_PATH
cd $GITHUB_WORKSPACE/../pg
echo "COPT=-Werror" >> $GITHUB_ENV
echo "CONFIGURE_OPTS=--prefix=`pwd`/tmp_install --enable-tap-tests --enable-cassert" >> $GITHUB_ENV
echo "$GITHUB_WORKSPACE/../pg/tmp_install/bin" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/../pg/contrib/aqo/.github/scripts/job" >> $GITHUB_PATH
echo "LD_LIBRARY_PATH=$GITHUB_WORKSPACE/pg/tmp_install/lib" >> $GITHUB_ENV
echo "PGDATABASE=`whoami`" >> $GITHUB_ENV
echo "PGHOST=localhost" >> $GITHUB_ENV
echo "PGDATA=PGDATA" >> $GITHUB_ENV
echo "PGUSER=`whoami`" >> $GITHUB_ENV
echo "PGPORT=5432" >> $GITHUB_ENV

- name: "Debug"
run: |
echo "paths: $PATH"
echo "PG_MAJOR_VERSION: $PG_MAJOR_VERSION, CORE_BRANCH_NAME: $CORE_BRANCH_NAME, AQO_PATCH_NAME: $AQO_PATCH_NAME, CONFIGURE_OPTS: $CONFIGURE_OPTS"

- name: "Compilation"
run: |
cd pg
./configure $CONFIGURE_OPTS CFLAGS="-O2"
cd $GITHUB_WORKSPACE/../pg
echo "paths: $PATH"
echo "COPT: $COPT"
echo "CONFIGURE_OPTS: $CONFIGURE_OPTS"
./configure $CONFIGURE_OPTS CFLAGS="-O2" > /dev/null
make -j4 > /dev/null && make -j4 -C contrib > /dev/null
make install >> make.log && make -C contrib install > /dev/null

- name: "Launch AQO instance"
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg

# Launch an instance with AQO extension
aqo_instance_launch.sh
Expand All @@ -84,29 +86,29 @@ jobs:
# Pass installcheck in disabled mode
- name: installcheck_disabled
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'off'"
psql -c "SELECT pg_reload_conf()"
make installcheck-world

- name: installcheck_disabled_forced_stat
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
psql -c "SELECT pg_reload_conf()"
make installcheck-world

- name: installcheck_frozen
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.mode = 'frozen'"
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
psql -c "SELECT pg_reload_conf()"
make installcheck-world

- name: installcheck_controlled
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.mode = 'controlled'"
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
psql -c "SELECT pg_reload_conf()"
Expand All @@ -115,7 +117,7 @@ jobs:
- name: installcheck_learn
continue-on-error: true
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.mode = 'learn'"
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
psql -c "SELECT pg_reload_conf()"
Expand All @@ -124,7 +126,7 @@ jobs:
- name: installcheck_intelligent
continue-on-error: true
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.mode = 'intelligent'"
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
psql -c "SELECT pg_reload_conf()"
Expand All @@ -133,18 +135,18 @@ jobs:
- name: installcheck_forced
continue-on-error: true
run: |
cd pg
cd $GITHUB_WORKSPACE/../pg
psql -c "ALTER SYSTEM SET aqo.mode = 'forced'"
psql -c "ALTER SYSTEM SET aqo.force_collect_stat = 'on'"
psql -c "SELECT pg_reload_conf()"
make -k installcheck-world

# Save Artifacts
- name: Archive artifacts
if: ${{ failure() }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: ${{ env.AQO_VERSION }}-${{ env.CORE_BRANCH_NAME }}-${{ env.BRANCH_NAME }}-artifacts
name: ${{ env.AQO_VERSION }}-${{ env.PG_BRANCH }}-${{ env.CORE_PATCH_NAME }}-artifacts
path: |
pg/src/test/regress/regression.diffs
pg/logfile.log
Expand Down
11 changes: 9 additions & 2 deletions expected/statement_timeout.out
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SET statement_timeout = 80; -- [0.1s]
SELECT *, pg_sleep(0.1) FROM t;
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
ERROR: canceling statement due to statement timeout
RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;'); -- haven't any partial data
check_estimated_rows
----------------------
Expand All @@ -46,6 +47,7 @@ SET statement_timeout = 350;
SELECT *, pg_sleep(0.1) FROM t;
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
ERROR: canceling statement due to statement timeout
RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
check_estimated_rows
----------------------
Expand All @@ -64,6 +66,7 @@ SELECT *, pg_sleep(0.1) FROM t;
5 |
(5 rows)

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
check_estimated_rows
----------------------
Expand All @@ -84,6 +87,7 @@ SET statement_timeout = 80;
SELECT *, pg_sleep(0.1) FROM t; -- Not learned
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
ERROR: canceling statement due to statement timeout
RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
check_estimated_rows
----------------------
Expand All @@ -94,6 +98,7 @@ SET statement_timeout = 350;
SELECT *, pg_sleep(0.1) FROM t; -- Learn!
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
ERROR: canceling statement due to statement timeout
RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
check_estimated_rows
----------------------
Expand All @@ -111,6 +116,7 @@ SELECT *, pg_sleep(0.1) FROM t; -- Get reliable data
5 |
(5 rows)

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');
check_estimated_rows
----------------------
Expand All @@ -134,18 +140,19 @@ SELECT count(*) FROM aqo_data; -- Must be zero
SELECT x, pg_sleep(0.1) FROM t WHERE x > 0;
NOTICE: [AQO] Time limit for execution of the statement was expired. AQO tried to learn on partial data.
ERROR: canceling statement due to statement timeout
RESET statement_timeout;
SELECT count(*) FROM aqo_data; -- Must be one
count
-------
1
(1 row)

DROP TABLE t;
DROP FUNCTION check_estimated_rows;
SELECT true AS success FROM aqo_reset();
success
---------
t
(1 row)

DROP TABLE t;
DROP EXTENSION aqo;
DROP FUNCTION check_estimated_rows;
1 change: 1 addition & 0 deletions regress_schedule
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test: plancache
test: update_functions
# Performance-dependent test. Can be ignored if executes in containers or on slow machines
ignore: statement_timeout
test: statement_timeout
test: temp_tables
test: top_queries
test: relocatable
Expand Down
19 changes: 17 additions & 2 deletions sql/statement_timeout.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ SET aqo.learn_statement_timeout = 'on';

SET statement_timeout = 80; -- [0.1s]
SELECT *, pg_sleep(0.1) FROM t;

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;'); -- haven't any partial data

-- Don't learn because running node has smaller cardinality than an optimizer prediction
SET statement_timeout = 350;
SELECT *, pg_sleep(0.1) FROM t;

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');

-- We have a real learning data.
SET statement_timeout = 800;
SELECT *, pg_sleep(0.1) FROM t;

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');

-- Force to make an underestimated prediction
Expand All @@ -52,24 +58,33 @@ SELECT true AS success FROM aqo_reset();

SET statement_timeout = 80;
SELECT *, pg_sleep(0.1) FROM t; -- Not learned

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');

SET statement_timeout = 350;
SELECT *, pg_sleep(0.1) FROM t; -- Learn!

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');

SET statement_timeout = 550;
SELECT *, pg_sleep(0.1) FROM t; -- Get reliable data

RESET statement_timeout;
SELECT check_estimated_rows('SELECT *, pg_sleep(0.1) FROM t;');

-- Interrupted query should immediately appear in aqo_data
SELECT true AS success FROM aqo_reset();
SET statement_timeout = 500;
SELECT count(*) FROM aqo_data; -- Must be zero
SELECT x, pg_sleep(0.1) FROM t WHERE x > 0;

RESET statement_timeout;
SELECT count(*) FROM aqo_data; -- Must be one

SELECT true AS success FROM aqo_reset();
DROP TABLE t;
DROP EXTENSION aqo;
DROP FUNCTION check_estimated_rows;

SELECT true AS success FROM aqo_reset();
DROP EXTENSION aqo;