Skip to content

Commit 031c0c8

Browse files
Alexandra Pervushinadanolivo
Alexandra Pervushina
authored andcommitted
Port remaining functions from stable13
Currently has problems with aqo_cleanup() function
1 parent 1c3c088 commit 031c0c8

Some content is hidden

Large Commits have some content hidden by default. Use the searcx below for content that may be hidden.

69 files changed

+5762
-2193
lines changed

‎./workflows/c-cpp.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: C/C++ CI for the stable14 branch.
1+
name: 'C/C++ CI for the stable13'
22

33
on:
44
push:
5-
branches: [ stable14 ]
5+
branches: [ stable13 ]
66
pull_request:
7-
branches: [ stable14 ]
7+
branches: [ stable13 ]
88

99
jobs:
1010
build:
@@ -19,9 +19,9 @@ jobs:
1919
git config --global user.name "CI PgPro admin"
2020
git clone https://.com/postgres/postgres.git pg
2121
cd pg
22-
git checkout REL_14_STABLE
22+
git checkout REL_13_STABLE
2323
./configure --prefix=`pwd`/tmp_install
2424
git subtree add --prefix=contrib/aqo https://.com/postgrespro/aqo.git $_REF
25-
-p1 --no-backup-if-mismatch < contrib/aqo/aqo_pg14.
25+
-p1 --no-backup-if-mismatch < contrib/aqo/aqo_pg13.
2626
make -j4 > /dev/null && make -j4 -C contrib > /dev/null
2727
env CLIENTS=50 THREADS=50 make -C contrib/aqo check

‎Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# contrib/aqo/Makefile
22

33
EXTENSION = aqo
4-
EXTVERSION = 1.4
4+
EXTVERSION = 1.5
55
PGFILEDESC = "AQO - Adaptive Query Optimization"
66
MODULE_big = aqo
7-
OBJS = aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o \
8-
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o \
9-
selectivity_cache.o storage.o utils.o learn_cache.o aqo_shared.o $(WIN32RES)
7+
OBJS = $(WIN32RES) \
8+
aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o \
9+
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o \
10+
selectivity_cache.o storage.o utils.o learn_cache.o aqo_shared.o
1011

1112
TAP_TESTS = 1
1213

@@ -24,7 +25,11 @@ REGRESS = aqo_disabled \
2425
clean_aqo_data \
2526
plancache \
2627
statement_timeout \
27-
top_queries
28+
temp_tables \
29+
top_queries \
30+
relocatable\
31+
look_a_like \
32+
feature_subspace
2833

2934
fdw_srcdir = $(top_srcdir)/contrib/postgres_fdw
3035
stat_srcdir = $(top_srcdir)/contrib/pg_stat_statements
@@ -33,7 +38,7 @@ EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
3338
EXTRA_INSTALL = contrib/postgres_fdw contrib/pg_stat_statements
3439

3540
DATA = aqo--1.0.sql aqo--1.0--1.1.sql aqo--1.1--1.2.sql aqo--1.2.sql \
36-
aqo--1.2--1.3.sql aqo--1.3--1.4.sql
41+
aqo--1.2--1.3.sql aqo--1.3--1.4.sql aqo--1.4--1.5.sql
3742

3843
ifdef USE_PGXS
3944
PG_CONFIG ?= pg_config

‎README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ To avoid compatibility issues, the following branches in the git-repository are
1313
* `stable9_6`.
1414
* `stable11` - for PG v10 and v11.
1515
* `stable12` - for PG v12.
16-
* `stable13` - for PG v13
17-
* `stable14` - for PG v14
18-
* the `master` branch of the AQO repository correctly works with PGv15 and the PostgreSQL `master` branch.
16+
* the `master` branch of the AQO repository correctly works with PGv13 and the PostgreSQL `master` branch.
1917

2018
The module contains a and an extension. has to be applied to the
2119
sources of PostgresSQL. affects header files, that is why PostgreSQL
@@ -214,7 +212,7 @@ execution of such query type. Disabling of AQO usage is reasonable for that
214212
cases in which query execution time increases after applying AQO. It happens
215213
sometimes because of cost models incompleteness.
216214

217-
`Fspace_hash` setting is for extra advanced AQO tuning. It may be changed manually
215+
`fs` setting is for extra advanced AQO tuning. It may be changed manually
218216
to optimize a number of queries using the same model. It may decrease the
219217
amount of memory for models and even the query execution time, but also it
220218
may cause the bad AQO's behavior, so please use it only if you know exactly
@@ -232,7 +230,7 @@ ignored.
232230

233231
If `aqo.mode` is `'learn'`, then the normalized query hash appends to aqo_queries
234232
with the default settings `learn_aqo=true`, `use_aqo=true`, `auto_tuning=false`, and
235-
`fspace_hash = query_hash` which means that AQO uses separate machine learning
233+
`fs = queryid` which means that AQO uses separate machine learning
236234
model for this query type optimization. After that the query is processed as if
237235
it already was in aqo_queries.
238236

‎aqo--1.4--1.5.sql

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/* contrib/aqo/aqo--1.4--1.5.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "ALTER EXTENSION aqo UPDATE TO '1.5'" to load this file. \quit
5+
6+
/* Remove old interface of the extension */
7+
DROP FUNCTION array_mse;
8+
DROP FUNCTION array_avg;
9+
DROP FUNCTION public.aqo_clear_hist; -- Should be renamed and reworked
10+
DROP FUNCTION public.aqo_disable_query;
11+
DROP FUNCTION public.aqo_drop;
12+
DROP FUNCTION public.aqo_enable_query;
13+
DROP FUNCTION public.aqo_ne_queries; -- Not needed anymore due to changing in the logic
14+
DROP FUNCTION public.aqo_status;
15+
DROP FUNCTION public.clean_aqo_data;
16+
DROP FUNCTION public.show_cardinality_errors;
17+
DROP FUNCTION public.top_time_queries;
18+
DROP TABLE public.aqo_data CASCADE;
19+
DROP TABLE public.aqo_queries CASCADE;
20+
DROP TABLE public.aqo_query_texts CASCADE;
21+
DROP TABLE public.aqo_query_stat CASCADE;
22+
23+
24+
/*
25+
* VIEWs to discover AQO data.
26+
*/
27+
CREATE FUNCTION aqo_queries (
28+
OUT queryid bigint,
29+
OUT fs bigint,
30+
OUT learn_aqo boolean,
31+
OUT use_aqo boolean,
32+
OUT auto_tuning boolean
33+
)
34+
RETURNS SETOF record
35+
AS 'MODULE_PATHNAME', 'aqo_queries'
36+
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
37+
38+
CREATE FUNCTION aqo_query_texts(OUT queryid bigint, OUT query_text text)
39+
RETURNS SETOF record
40+
AS 'MODULE_PATHNAME', 'aqo_query_texts'
41+
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
42+
43+
CREATE FUNCTION aqo_query_stat (
44+
OUT queryid bigint,
45+
OUT execution_time_with_aqo double precision[],
46+
OUT execution_time_without_aqo double precision[],
47+
OUT planning_time_with_aqo double precision[],
48+
OUT planning_time_without_aqo double precision[],
49+
OUT cardinality_error_with_aqo double precision[],
50+
OUT cardinality_error_without_aqo double precision[],
51+
OUT executions_with_aqo bigint,
52+
OUT executions_without_aqo bigint
53+
)
54+
RETURNS SETOF record
55+
AS 'MODULE_PATHNAME', 'aqo_query_stat'
56+
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
57+
58+
CREATE FUNCTION aqo_data (
59+
OUT fs bigint,
60+
OUT fss integer,
61+
OUT nfeatures integer,
62+
OUT features double precision[][],
63+
OUT targets double precision[],
64+
OUT reliability double precision[],
65+
OUT oids Oid[]
66+
)
67+
RETURNS SETOF record
68+
AS 'MODULE_PATHNAME', 'aqo_data'
69+
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
70+
71+
CREATE VIEW aqo_query_stat AS SELECT * FROM aqo_query_stat();
72+
CREATE VIEW aqo_query_texts AS SELECT * FROM aqo_query_texts();
73+
CREATE VIEW aqo_data AS SELECT * FROM aqo_data();
74+
CREATE VIEW aqo_queries AS SELECT * FROM aqo_queries();
75+
76+
/* UI functions */
77+
78+
79+
CREATE FUNCTION aqo_enable_query(queryid bigint)
80+
RETURNS void
81+
AS 'MODULE_PATHNAME', 'aqo_enable_query'
82+
LANGUAGE C STRICT VOLATILE;
83+
84+
CREATE FUNCTION aqo_disable_query(queryid bigint)
85+
RETURNS void
86+
AS 'MODULE_PATHNAME', 'aqo_enable_query'
87+
LANGUAGE C STRICT VOLATILE;
88+
89+
CREATE FUNCTION aqo_queries_update(
90+
queryid bigint, fs bigint, learn_aqo bool, use_aqo bool, auto_tuning bool)
91+
RETURNS bool
92+
AS 'MODULE_PATHNAME', 'aqo_queries_update'
93+
LANGUAGE C VOLATILE;
94+
95+
--
96+
-- Get cardinality error of queries the last time they were executed.
97+
-- IN:
98+
-- controlled - show queries executed under a control of AQO (true);
99+
-- executed without an AQO control, but AQO has a stat on the query (false).
100+
--
101+
-- OUT:
102+
-- num - sequental number. Smaller number corresponds to higher error.
103+
-- id - ID of a query.
104+
-- fshash - feature space. Usually equal to zero or ID.
105+
-- error - AQO error that calculated on plan nodes of the query.
106+
-- nexecs - number of executions of queries associated with this ID.
107+
--
108+
CREATE OR REPLACE FUNCTION aqo_cardinality_error(controlled boolean)
109+
RETURNS TABLE(num integer, id bigint, fshash bigint, error double precision, nexecs bigint)
110+
AS 'MODULE_PATHNAME', 'aqo_cardinality_error'
111+
LANGUAGE C STRICT VOLATILE;
112+
COMMENT ON FUNCTION aqo_cardinality_error(boolean) IS
113+
'Get cardinality error of queries the last time they were executed. Order queries according to an error value.';
114+
115+
--
116+
-- Show execution time of queries, for which AQO has statistics.
117+
-- controlled - show stat on executions where AQO was used for cardinality
118+
-- estimations, or not used (controlled = false).
119+
-- Last case is possible in disabled mode with aqo.force_collect_stat = 'on'.
120+
--
121+
CREATE OR REPLACE FUNCTION aqo_execution_time(controlled boolean)
122+
RETURNS TABLE(num integer, id bigint, fshash bigint, exec_time double precision, nexecs bigint)
123+
AS 'MODULE_PATHNAME', 'aqo_execution_time'
124+
LANGUAGE C STRICT VOLATILE;
125+
COMMENT ON FUNCTION aqo_execution_time(boolean) IS
126+
'Get execution time of queries. If controlled = true (AQO could advise cardinality estimations), show time of last execution attempt. Another case (AQO not used), return an average value of execution time across all known executions.';
127+
128+
--
129+
-- Remove query class settings, text, statistics and ML data from AQO storage.
130+
-- Return number of FSS records, removed from the storage.
131+
--
132+
CREATE OR REPLACE FUNCTION aqo_drop_class(queryid bigint)
133+
RETURNS integer
134+
AS 'MODULE_PATHNAME', 'aqo_drop_class'
135+
LANGUAGE C STRICT VOLATILE;
136+
COMMENT ON FUNCTION aqo_drop_class(bigint) IS
137+
'Remove info about an query class from AQO ML knowledge base.';
138+
139+
--
140+
-- Remove unneeded rows from the AQO ML storage.
141+
-- For common feature space, remove rows from aqo_data only.
142+
-- For custom feature space - remove all rows related to the space from all AQO
143+
-- tables even if only one oid for one feature subspace of the space is illegal.
144+
-- Returns number of deleted rows from aqo_queries and aqo_data tables.
145+
--
146+
CREATE OR REPLACE FUNCTION aqo_cleanup(OUT nfs integer, OUT nfss integer)
147+
AS 'MODULE_PATHNAME', 'aqo_cleanup'
148+
LANGUAGE C STRICT VOLATILE;
149+
COMMENT ON FUNCTION aqo_cleanup() IS
150+
'Remove unneeded rows from the AQO ML storage';
151+
152+
--
153+
-- Remove all records in the AQO storage.
154+
-- Return number of rows removed.
155+
--
156+
CREATE FUNCTION aqo_reset() RETURNS bigint
157+
AS 'MODULE_PATHNAME', 'aqo_reset'
158+
LANGUAGE C PARALLEL SAFE;
159+
COMMENT ON FUNCTION aqo_reset() IS
160+
'Reset all data gathered by AQO';

0 commit comments

Comments
 (0)