Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita33461d

Browse files
committed
First step of the AQO UI modifying. Remove some dubious functions.
After this commit, UI of AQO should be consistent with content of wiki page:https://github.com/postgrespro/aqo/wiki/User-Interface
1 parent678cfaf commita33461d

File tree

8 files changed

+169
-63
lines changed

8 files changed

+169
-63
lines changed

‎aqo--1.4--1.5.sql

Lines changed: 111 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
--
1111
DROPTABLEpublic.aqo_data CASCADE;
1212
CREATETABLEpublic.aqo_data (
13-
fspace_hashbigintNOT NULLREFERENCESpublic.aqo_queriesON DELETE CASCADE,
14-
fsspace_hashintNOT NULL,
15-
nfeaturesintNOT NULL,
16-
featuresdouble precision[][],
17-
targetsdouble precision[],
18-
oidsoid [] DEFAULTNULL,
19-
reliabilitydouble precision []
13+
fspace_hashbigintNOT NULLREFERENCESpublic.aqo_queriesON DELETE CASCADE,
14+
fsspace_hashintNOT NULL,
15+
nfeaturesintNOT NULL,
16+
featuresdouble precision[][],
17+
targetsdouble precision[],
18+
oidsoid [] DEFAULTNULL,
19+
reliabilitydouble precision []
2020
);
2121
CREATEUNIQUE INDEXaqo_fss_access_idxONpublic.aqo_data (fspace_hash, fsspace_hash);
2222

@@ -79,14 +79,19 @@ $$ LANGUAGE plpgsql;
7979
DROPFUNCTIONpublic.top_time_queries;
8080
DROPFUNCTIONpublic.aqo_drop;
8181
DROPFUNCTIONpublic.clean_aqo_data;
82+
DROPFUNCTIONpublic.show_cardinality_errors;
83+
DROPFUNCTION array_mse;
84+
DROPFUNCTION array_avg;
85+
DROPFUNCTIONpublic.aqo_ne_queries;-- Not needed anymore due to changing in the logic
86+
DROPFUNCTIONpublic.aqo_clear_hist;-- Should be renamed and reworked
8287

8388
--
8489
-- Show execution time of queries, for which AQO has statistics.
8590
-- controlled - show stat on executions where AQO was used for cardinality
8691
-- estimations, or not used (controlled = false).
8792
-- Last case is possible in disabled mode with aqo.force_collect_stat = 'on'.
8893
--
89-
CREATE OR REPLACEFUNCTIONpublic.show_execution_time(controlledboolean)
94+
CREATE OR REPLACEFUNCTIONpublic.aqo_execution_time(controlledboolean)
9095
RETURNS TABLE(numbigint, idbigint, fshashbigint, exec_time float, nexecsbigint)
9196
AS $$
9297
BEGIN
@@ -120,7 +125,7 @@ ELSE
120125
SELECT
121126
aq.query_hashAS queryid,
122127
aq.fspace_hashAS fs_hash,
123-
array_avg(execution_time_without_aqo)AS exectime,
128+
(SELECTAVG(t)FROM unnest(execution_time_without_aqo) t)AS exectime,
124129
executions_without_aqoAS execs
125130
FROMpublic.aqo_queries aqJOINpublic.aqo_query_stat aqs
126131
ONaq.query_hash=aqs.query_hash
@@ -131,28 +136,31 @@ END IF;
131136
END;
132137
$$ LANGUAGE plpgsql;
133138

134-
COMMENT ON FUNCTION public.show_execution_time(boolean) IS
139+
COMMENT ON FUNCTION public.aqo_execution_time(boolean) IS
135140
'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.';
136141

137-
CREATE OR REPLACEFUNCTIONpublic.aqo_drop_class(idbigint)
142+
--
143+
-- Remove all information about a query class from AQO storage.
144+
--
145+
CREATE OR REPLACEFUNCTIONpublic.aqo_drop_class(queryidbigint)
138146
RETURNSintegerAS $$
139147
DECLARE
140148
fsbigint;
141149
numinteger;
142150
BEGIN
143-
IF (id=0) THEN
144-
raise EXCEPTION'[AQO] Cannot remove basic class %.',id;
151+
IF (queryid=0) THEN
152+
raise EXCEPTION'[AQO] Cannot remove basic class %.',queryid;
145153
END IF;
146154

147-
SELECT fspace_hashFROMpublic.aqo_queriesWHERE (query_hash=id) INTO fs;
155+
SELECT fspace_hashFROMpublic.aqo_queriesWHERE (query_hash=queryid) INTO fs;
148156

149157
IF (fs ISNULL) THEN
150-
raise WARNING'[AQO] Nothing to remove for the class %.',id;
158+
raise WARNING'[AQO] Nothing to remove for the class %.',queryid;
151159
RETURN0;
152160
END IF;
153161

154-
IF (fs<>id) THEN
155-
raise WARNING'[AQO] Removing query class has non-generic feature space value: id = %, fs = %.',id, fs;
162+
IF (fs<>queryid) THEN
163+
raise WARNING'[AQO] Removing query class has non-generic feature space value: id = %, fs = %.',queryid, fs;
156164
END IF;
157165

158166
SELECTcount(*)FROMpublic.aqo_dataWHERE fspace_hash= fs INTO num;
@@ -161,7 +169,7 @@ BEGIN
161169
* Remove the only from aqo_queries table. All other data will be removed by
162170
* CASCADE deletion.
163171
*/
164-
DELETEFROMpublic.aqo_queriesWHERE query_hash=id;
172+
DELETEFROMpublic.aqo_queriesWHERE query_hash=queryid;
165173
RETURN num;
166174
END;
167175
$$ LANGUAGE plpgsql;
@@ -179,8 +187,8 @@ COMMENT ON FUNCTION public.aqo_drop_class(bigint) IS
179187
CREATE OR REPLACEFUNCTIONpublic.aqo_cleanup(OUT nfsinteger, OUT nfssinteger)
180188
AS $$
181189
DECLARE
182-
fsbigint;
183-
fssinteger;
190+
fsbigint;
191+
fssinteger;
184192
BEGIN
185193
-- Save current number of rows
186194
SELECTcount(*)FROM aqo_queries INTO nfs;
@@ -209,3 +217,86 @@ $$ LANGUAGE plpgsql;
209217

210218
COMMENT ON FUNCTION public.aqo_cleanup() IS
211219
'Remove unneeded rows from the AQO ML storage';
220+
221+
--
222+
-- Get cardinality error of queries the last time they were executed.
223+
-- IN:
224+
-- controlled - show queries executed under a control of AQO (true);
225+
-- executed without an AQO control, but AQO has a stat on the query (false).
226+
--
227+
-- OUT:
228+
-- num - sequental number. Smaller number corresponds to higher error.
229+
-- id - ID of a query.
230+
-- fshash - feature space. Usually equal to zero or ID.
231+
-- error - AQO error that calculated on plan nodes of the query.
232+
-- nexecs - number of executions of queries associated with this ID.
233+
--
234+
CREATE OR REPLACEFUNCTIONpublic.aqo_cardinality_error(controlledboolean)
235+
RETURNS TABLE(numbigint, idbigint, fshashbigint, error float, nexecsbigint)
236+
AS $$
237+
BEGIN
238+
IF (controlled) THEN
239+
RETURN QUERY
240+
SELECT
241+
row_number() OVER (ORDER BY (cerror, query_id, fs_hash)DESC)AS nn,
242+
query_id, fs_hash, cerror, execs
243+
FROM (
244+
SELECT
245+
aq.query_hashAS query_id,
246+
aq.fspace_hashAS fs_hash,
247+
cardinality_error_with_aqo[array_length(cardinality_error_with_aqo,1)]AS cerror,
248+
executions_with_aqoAS execs
249+
FROMpublic.aqo_queries aqJOINpublic.aqo_query_stat aqs
250+
ONaq.query_hash=aqs.query_hash
251+
WHERE TRUE= ANY (SELECT unnest(cardinality_error_with_aqo)IS NOT NULL)
252+
)AS q1
253+
ORDER BY nnASC;
254+
ELSE
255+
RETURN QUERY
256+
SELECT
257+
row_number() OVER (ORDER BY (cerror, query_id, fs_hash)DESC)AS nn,
258+
query_id, fs_hash, cerror, execs
259+
FROM (
260+
SELECT
261+
aq.query_hashAS query_id,
262+
aq.fspace_hashAS fs_hash,
263+
(SELECTAVG(t)FROM unnest(cardinality_error_without_aqo) t)AS cerror,
264+
executions_without_aqoAS execs
265+
FROMpublic.aqo_queries aqJOINpublic.aqo_query_stat aqs
266+
ONaq.query_hash=aqs.query_hash
267+
WHERE TRUE= ANY (SELECT unnest(cardinality_error_without_aqo)IS NOT NULL)
268+
)AS q1
269+
ORDER BY (nn)ASC;
270+
END IF;
271+
END;
272+
$$ LANGUAGE plpgsql;
273+
274+
COMMENT ON FUNCTION public.aqo_cardinality_error(boolean) IS
275+
'Get cardinality error of queries the last time they were executed. Order queries according to an error value.';
276+
277+
--
278+
-- Remove all learning data for query with given ID.
279+
-- Can be used in the case when user don't want to drop preferences and
280+
-- accumulated statistics on a query class, but tries to re-learn AQO on this
281+
-- class.
282+
-- Returns a number of deleted rows in the aqo_data table.
283+
--
284+
CREATE OR REPLACEFUNCTIONpublic.aqo_reset_query(queryidbigint)
285+
RETURNSintegerAS $$
286+
DECLARE
287+
numinteger;
288+
fsbigint;
289+
BEGIN
290+
IF (queryid=0) THEN
291+
raise WARNING'[AQO] Reset common feature space.'
292+
END IF;
293+
294+
SELECT fspace_hashFROMpublic.aqo_queriesWHERE query_hash= queryid INTO fs;
295+
SELECTcount(*)FROMpublic.aqo_dataWHERE fspace_hash= fs INTO num;
296+
DELETEFROMpublic.aqo_dataWHERE fspace_hash= fs;
297+
RETURN num;
298+
END;
299+
$$ LANGUAGE plpgsql;
300+
301+
COMMENT ON FUNCTION public.aqo_reset_query(bigint) IS
302+
'Remove from AQO storage only learning data for given QueryId.';

‎expected/gucs.out

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SHOW aqo.show_hash;
1919
off
2020
(1 row)
2121

22-
SHOWaqo.show_details;
22+
SHOW aqo.show_details;
2323
aqo.show_details
2424
------------------
2525
off
@@ -31,7 +31,7 @@ SHOW aqo.force_collect_stat;
3131
off
3232
(1 row)
3333

34-
SHOWaqo.mode;
34+
SHOW aqo.mode;
3535
aqo.mode
3636
------------
3737
controlled
@@ -68,13 +68,13 @@ EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF)
6868
(6 rows)
6969

7070
-- Check existence of the interface functions.
71-
SELECT obj_description('public.show_cardinality_errors'::regproc::oid);
71+
SELECT obj_description('public.aqo_cardinality_error'::regproc::oid);
7272
obj_description
7373
---------------------------------------------------------------------------------------------------------------
7474
Get cardinality error of queries the last time they were executed. Order queries according to an error value.
7575
(1 row)
7676

77-
SELECT obj_description('public.show_execution_time'::regproc::oid);
77+
SELECT obj_description('public.aqo_execution_time'::regproc::oid);
7878
obj_description
7979
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
8080
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.
@@ -92,25 +92,31 @@ SELECT obj_description('public.aqo_cleanup'::regproc::oid);
9292
Remove unneeded rows from the AQO ML storage
9393
(1 row)
9494

95-
\df show_cardinality_errors
96-
List of functions
97-
Schema | Name | Result data type | Argument data types | Type
98-
--------+-------------------------+------------------------------------------------------------------------------------+---------------------+------
99-
public | show_cardinality_errors | TABLE(num bigint, id bigint, fshash bigint, error double precision, nexecs bigint) | controlled boolean | func
95+
SELECT obj_description('public.aqo_reset_query'::regproc::oid);
96+
obj_description
97+
---------------------------------------------------------------
98+
Remove from AQO storage only learning data for given QueryId.
99+
(1 row)
100+
101+
\df aqo_cardinality_error
102+
List of functions
103+
Schema | Name | Result data type | Argument data types | Type
104+
--------+-----------------------+------------------------------------------------------------------------------------+---------------------+------
105+
public | aqo_cardinality_error | TABLE(num bigint, id bigint, fshash bigint, error double precision, nexecs bigint) | controlled boolean | func
100106
(1 row)
101107

102-
\dfshow_execution_time
108+
\dfaqo_execution_time
103109
List of functions
104-
Schema | Name| Result data type | Argument data types | Type
105-
--------+---------------------+----------------------------------------------------------------------------------------+---------------------+------
106-
public |show_execution_time | TABLE(num bigint, id bigint, fshash bigint, exec_time double precision, nexecs bigint) | controlled boolean | func
110+
Schema | Name | Result data type | Argument data types | Type
111+
--------+--------------------+----------------------------------------------------------------------------------------+---------------------+------
112+
public |aqo_execution_time | TABLE(num bigint, id bigint, fshash bigint, exec_time double precision, nexecs bigint) | controlled boolean | func
107113
(1 row)
108114

109115
\df aqo_drop_class
110116
List of functions
111117
Schema | Name | Result data type | Argument data types | Type
112118
--------+----------------+------------------+---------------------+------
113-
public | aqo_drop_class | integer |id bigint | func
119+
public | aqo_drop_class | integer |queryid bigint | func
114120
(1 row)
115121

116122
\df aqo_cleanup
@@ -120,4 +126,11 @@ SELECT obj_description('public.aqo_cleanup'::regproc::oid);
120126
public | aqo_cleanup | record | OUT nfs integer, OUT nfss integer | func
121127
(1 row)
122128

129+
\df aqo_reset_query
130+
List of functions
131+
Schema | Name | Result data type | Argument data types | Type
132+
--------+-----------------+------------------+---------------------+------
133+
public | aqo_reset_query | integer | queryid bigint | func
134+
(1 row)
135+
123136
DROP EXTENSION aqo;

‎expected/top_queries.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ SELECT count(*) AS cnt FROM ttp WHERE cnt % 100 = 0;
2121
0
2222
(1 row)
2323

24-
SELECT num FROMshow_execution_time(true); -- Just for checking, return zero.
24+
SELECT num FROMaqo_execution_time(true); -- Just for checking, return zero.
2525
num
2626
-----
2727
(0 rows)
2828

29-
SELECT num FROMshow_execution_time(false);
29+
SELECT num FROMaqo_execution_time(false);
3030
num
3131
-----
3232
1
@@ -35,7 +35,7 @@ SELECT num FROM show_execution_time(false);
3535

3636
-- Without the AQO control queries with and without temp tables are logged.
3737
SELECT query_text,nexecs
38-
FROMshow_execution_time(false) ce, aqo_query_texts aqt
38+
FROMaqo_execution_time(false) ce, aqo_query_texts aqt
3939
WHERE ce.id = aqt.query_hash
4040
ORDER BY (md5(query_text));
4141
query_text | nexecs
@@ -64,7 +64,7 @@ SELECT count(*) FROM (SELECT x, y FROM t2 GROUP BY GROUPING SETS ((x,y), (x), (y
6464
31
6565
(1 row)
6666

67-
SELECT num, to_char(error, '9.99EEEE') FROMshow_cardinality_errors(false) AS te
67+
SELECT num, to_char(error, '9.99EEEE') FROMaqo_cardinality_error(false) AS te
6868
WHERE te.fshash = (
6969
SELECT fspace_hash FROM aqo_queries
7070
WHERE aqo_queries.query_hash = (
@@ -78,15 +78,15 @@ WHERE te.fshash = (
7878
(1 row)
7979

8080
-- Should return zero
81-
SELECT count(*) FROMshow_cardinality_errors(true);
81+
SELECT count(*) FROMaqo_cardinality_error(true);
8282
count
8383
-------
8484
0
8585
(1 row)
8686

8787
-- Fix list of logged queries
8888
SELECT query_text,nexecs
89-
FROMshow_cardinality_errors(false) ce, aqo_query_texts aqt
89+
FROMaqo_cardinality_error(false) ce, aqo_query_texts aqt
9090
WHERE ce.id = aqt.query_hash
9191
ORDER BY (md5(query_text));
9292
query_text | nexecs

‎expected/unsupported.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ SELECT * FROM
459459
JOINS: 0
460460
(13 rows)
461461

462-
-- AQOneed to predict total fetched tuples in a table.
462+
-- AQOneeds to predict total fetched tuples in a table.
463463
--
464464
-- At a non-leaf node we have prediction about input tuples - is a number of
465465
-- predicted output rows in underlying node. But for Scan nodes we don't have
@@ -541,7 +541,7 @@ EXPLAIN (COSTS OFF)
541541
-- XXX: Do we stuck into an unstable behavior of an error value?
542542
-- Live with this variant of the test for some time.
543543
SELECT to_char(error, '9.99EEEE')::text AS error, query_text
544-
FROM public.show_cardinality_errors(true) cef, aqo_query_texts aqt
544+
FROM public.aqo_cardinality_error(true) cef, aqo_query_texts aqt
545545
WHERE aqt.query_hash = cef.id
546546
ORDER BY (md5(query_text),error) DESC;
547547
error | query_text
@@ -587,7 +587,7 @@ SELECT public.aqo_cleanup();
587587

588588
-- Look for any remaining queries in the ML storage.
589589
SELECT to_char(error, '9.99EEEE')::text AS error, query_text
590-
FROM public.show_cardinality_errors(true) cef, aqo_query_texts aqt
590+
FROM public.aqo_cardinality_error(true) cef, aqo_query_texts aqt
591591
WHERE aqt.query_hash = cef.id
592592
ORDER BY (md5(query_text),error) DESC;
593593
error | query_text

‎sql/gucs.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ CREATE EXTENSION aqo;
55
SHOWaqo.join_threshold;
66
SHOWaqo.learn_statement_timeout;
77
SHOWaqo.show_hash;
8-
SHOWaqo.show_details;
8+
SHOWaqo.show_details;
99
SHOWaqo.force_collect_stat;
10-
SHOWaqo.mode;
10+
SHOWaqo.mode;
1111

1212
SETaqo.mode='learn';
1313
SETaqo.show_details= true;
@@ -23,14 +23,16 @@ EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF)
2323
SELECT xFROM t;
2424

2525
-- Check existence of the interface functions.
26-
SELECT obj_description('public.show_cardinality_errors'::regproc::oid);
27-
SELECT obj_description('public.show_execution_time'::regproc::oid);
26+
SELECT obj_description('public.aqo_cardinality_error'::regproc::oid);
27+
SELECT obj_description('public.aqo_execution_time'::regproc::oid);
2828
SELECT obj_description('public.aqo_drop_class'::regproc::oid);
2929
SELECT obj_description('public.aqo_cleanup'::regproc::oid);
30+
SELECT obj_description('public.aqo_reset_query'::regproc::oid);
3031

31-
\dfshow_cardinality_errors
32-
\dfshow_execution_time
32+
\dfaqo_cardinality_error
33+
\dfaqo_execution_time
3334
\df aqo_drop_class
3435
\df aqo_cleanup
36+
\df aqo_reset_query
3537

3638
DROP EXTENSION aqo;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp