Skip to content

Commit e810d1d

Browse files
Andrey Kazarinovdanolivo
authored andcommitted
[PGPRO-6374] relocatable aqo
1 parent 8a99337 commit e810d1d

20 files changed

+266
-142
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ REGRESS = aqo_disabled \
2525
plancache \
2626
statement_timeout \
2727
temp_tables \
28-
top_queries
28+
top_queries \
29+
relocatable
2930

3031
fdw_srcdir = $(top_srcdir)/contrib/postgres_fdw
3132
stat_srcdir = $(top_srcdir)/contrib/pg_stat_statements

aqo--1.0--1.1.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
ALTER TABLE public.aqo_query_texts ALTER COLUMN query_text TYPE text;
1+
ALTER TABLE aqo_query_texts ALTER COLUMN query_text TYPE text;
22

33

4-
DROP INDEX public.aqo_queries_query_hash_idx CASCADE;
5-
DROP INDEX public.aqo_query_texts_query_hash_idx CASCADE;
6-
DROP INDEX public.aqo_query_stat_idx CASCADE;
7-
DROP INDEX public.aqo_fss_access_idx CASCADE;
4+
DROP INDEX aqo_queries_query_hash_idx CASCADE;
5+
DROP INDEX aqo_query_texts_query_hash_idx CASCADE;
6+
DROP INDEX aqo_query_stat_idx CASCADE;
7+
DROP INDEX aqo_fss_access_idx CASCADE;
88

99
CREATE UNIQUE INDEX aqo_fss_access_idx
10-
ON public.aqo_data (fspace_hash, fsspace_hash);
10+
ON aqo_data (fspace_hash, fsspace_hash);
1111

1212

1313
CREATE OR REPLACE FUNCTION aqo_migrate_to_1_1_get_pk(rel regclass) RETURNS regclass AS $$
@@ -28,15 +28,15 @@ $$ LANGUAGE plpgsql;
2828
DO $$
2929
BEGIN
3030
EXECUTE pg_catalog.format('ALTER TABLE %s RENAME to %s',
31-
aqo_migrate_to_1_1_get_pk('public.aqo_queries'),
31+
aqo_migrate_to_1_1_get_pk('aqo_queries'),
3232
'aqo_queries_query_hash_idx');
3333

3434
EXECUTE pg_catalog.format('ALTER TABLE %s RENAME to %s',
35-
aqo_migrate_to_1_1_get_pk('public.aqo_query_texts'),
35+
aqo_migrate_to_1_1_get_pk('aqo_query_texts'),
3636
'aqo_query_texts_query_hash_idx');
3737

3838
EXECUTE pg_catalog.format('ALTER TABLE %s RENAME to %s',
39-
aqo_migrate_to_1_1_get_pk('public.aqo_query_stat'),
39+
aqo_migrate_to_1_1_get_pk('aqo_query_stat'),
4040
'aqo_query_stat_idx');
4141
END
4242
$$;

aqo--1.0.sql

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
22
\echo Use "CREATE EXTENSION aqo" to load this file. \quit
33

4-
CREATE TABLE public.aqo_queries (
4+
CREATE TABLE aqo_queries (
55
query_hash bigint PRIMARY KEY,
66
learn_aqo boolean NOT NULL,
77
use_aqo boolean NOT NULL,
88
fspace_hash bigint NOT NULL,
99
auto_tuning boolean NOT NULL
1010
);
1111

12-
CREATE TABLE public.aqo_query_texts (
13-
query_hash bigint PRIMARY KEY REFERENCES public.aqo_queries ON DELETE CASCADE,
12+
CREATE TABLE aqo_query_texts (
13+
query_hash bigint PRIMARY KEY REFERENCES aqo_queries ON DELETE CASCADE,
1414
query_text varchar NOT NULL
1515
);
1616

17-
CREATE TABLE public.aqo_query_stat (
18-
query_hash bigint PRIMARY KEY REFERENCES public.aqo_queries ON DELETE CASCADE,
17+
CREATE TABLE aqo_query_stat (
18+
query_hash bigint PRIMARY KEY REFERENCES aqo_queries ON DELETE CASCADE,
1919
execution_time_with_aqo double precision[],
2020
execution_time_without_aqo double precision[],
2121
planning_time_with_aqo double precision[],
@@ -26,27 +26,27 @@ CREATE TABLE public.aqo_query_stat (
2626
executions_without_aqo bigint
2727
);
2828

29-
CREATE TABLE public.aqo_data (
30-
fspace_hash bigint NOT NULL REFERENCES public.aqo_queries ON DELETE CASCADE,
29+
CREATE TABLE aqo_data (
30+
fspace_hash bigint NOT NULL REFERENCES aqo_queries ON DELETE CASCADE,
3131
fsspace_hash int NOT NULL,
3232
nfeatures int NOT NULL,
3333
features double precision[][],
3434
targets double precision[],
3535
UNIQUE (fspace_hash, fsspace_hash)
3636
);
3737

38-
CREATE INDEX aqo_queries_query_hash_idx ON public.aqo_queries (query_hash);
39-
CREATE INDEX aqo_query_texts_query_hash_idx ON public.aqo_query_texts (query_hash);
40-
CREATE INDEX aqo_query_stat_idx ON public.aqo_query_stat (query_hash);
41-
CREATE INDEX aqo_fss_access_idx ON public.aqo_data (fspace_hash, fsspace_hash);
38+
CREATE INDEX aqo_queries_query_hash_idx ON aqo_queries (query_hash);
39+
CREATE INDEX aqo_query_texts_query_hash_idx ON aqo_query_texts (query_hash);
40+
CREATE INDEX aqo_query_stat_idx ON aqo_query_stat (query_hash);
41+
CREATE INDEX aqo_fss_access_idx ON aqo_data (fspace_hash, fsspace_hash);
4242

43-
INSERT INTO public.aqo_queries VALUES (0, false, false, 0, false);
44-
INSERT INTO public.aqo_query_texts VALUES (0, 'COMMON feature space (do not delete!)');
43+
INSERT INTO aqo_queries VALUES (0, false, false, 0, false);
44+
INSERT INTO aqo_query_texts VALUES (0, 'COMMON feature space (do not delete!)');
4545
-- a virtual query for COMMON feature space
4646

4747
CREATE FUNCTION invalidate_deactivated_queries_cache() RETURNS trigger
4848
AS 'MODULE_PATHNAME' LANGUAGE C;
4949

5050
CREATE TRIGGER aqo_queries_invalidate AFTER UPDATE OR DELETE OR TRUNCATE
51-
ON public.aqo_queries FOR EACH STATEMENT
51+
ON aqo_queries FOR EACH STATEMENT
5252
EXECUTE PROCEDURE invalidate_deactivated_queries_cache();

aqo--1.1--1.2.sql

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ $$ LANGUAGE plpgsql;
1414
DO $$
1515
BEGIN
1616
EXECUTE pg_catalog.format(
17-
'ALTER TABLE public.aqo_data DROP CONSTRAINT %s',
18-
aqo_migrate_to_1_2_get_pk('public.aqo_data'::regclass),
17+
'ALTER TABLE aqo_data DROP CONSTRAINT %s',
18+
aqo_migrate_to_1_2_get_pk('aqo_data'::regclass),
1919
'aqo_queries_query_hash_idx');
2020
END
2121
$$;
@@ -28,7 +28,7 @@ DROP FUNCTION aqo_migrate_to_1_2_get_pk(regclass);
2828
--
2929

3030
-- Show query state at the AQO knowledge base
31-
CREATE OR REPLACE FUNCTION public.aqo_status(hash bigint)
31+
CREATE OR REPLACE FUNCTION aqo_status(hash bigint)
3232
RETURNS TABLE (
3333
"learn" BOOL,
3434
"use aqo" BOOL,
@@ -49,58 +49,58 @@ SELECT learn_aqo,use_aqo,auto_tuning,fspace_hash,
4949
to_char(execution_time_with_aqo[n3],'9.99EEEE'),
5050
to_char(cardinality_error_with_aqo[n1],'9.99EEEE'),
5151
executions_with_aqo
52-
FROM public.aqo_queries aq, public.aqo_query_stat aqs,
52+
FROM aqo_queries aq, aqo_query_stat aqs,
5353
(SELECT array_length(n1,1) AS n1, array_length(n2,1) AS n2,
5454
array_length(n3,1) AS n3, array_length(n4,1) AS n4
5555
FROM
5656
(SELECT cardinality_error_with_aqo AS n1,
5757
cardinality_error_without_aqo AS n2,
5858
execution_time_with_aqo AS n3,
5959
execution_time_without_aqo AS n4
60-
FROM public.aqo_query_stat aqs WHERE
60+
FROM aqo_query_stat aqs WHERE
6161
aqs.query_hash = $1) AS al) AS q
6262
WHERE (aqs.query_hash = aq.query_hash) AND
6363
aqs.query_hash = $1;
6464
$func$ LANGUAGE SQL;
6565

66-
CREATE OR REPLACE FUNCTION public.aqo_enable_query(hash bigint)
66+
CREATE OR REPLACE FUNCTION aqo_enable_query(hash bigint)
6767
RETURNS VOID
6868
AS $func$
69-
UPDATE public.aqo_queries SET
69+
UPDATE aqo_queries SET
7070
learn_aqo = 'true',
7171
use_aqo = 'true'
7272
WHERE query_hash = $1;
7373
$func$ LANGUAGE SQL;
7474

75-
CREATE OR REPLACE FUNCTION public.aqo_disable_query(hash bigint)
75+
CREATE OR REPLACE FUNCTION aqo_disable_query(hash bigint)
7676
RETURNS VOID
7777
AS $func$
78-
UPDATE public.aqo_queries SET
78+
UPDATE aqo_queries SET
7979
learn_aqo = 'false',
8080
use_aqo = 'false',
8181
auto_tuning = 'false'
8282
WHERE query_hash = $1;
8383
$func$ LANGUAGE SQL;
8484

85-
CREATE OR REPLACE FUNCTION public.aqo_clear_hist(hash bigint)
85+
CREATE OR REPLACE FUNCTION aqo_clear_hist(hash bigint)
8686
RETURNS VOID
8787
AS $func$
88-
DELETE FROM public.aqo_data WHERE fspace_hash=$1;
88+
DELETE FROM aqo_data WHERE fspace_hash=$1;
8989
$func$ LANGUAGE SQL;
9090

9191
-- Show queries that contains 'Never executed' nodes at the plan.
92-
CREATE OR REPLACE FUNCTION public.aqo_ne_queries()
92+
CREATE OR REPLACE FUNCTION aqo_ne_queries()
9393
RETURNS SETOF int
9494
AS $func$
95-
SELECT query_hash FROM public.aqo_query_stat aqs
95+
SELECT query_hash FROM aqo_query_stat aqs
9696
WHERE -1 = ANY (cardinality_error_with_aqo::double precision[]);
9797
$func$ LANGUAGE SQL;
9898

99-
CREATE OR REPLACE FUNCTION public.aqo_drop(hash bigint)
99+
CREATE OR REPLACE FUNCTION aqo_drop(hash bigint)
100100
RETURNS VOID
101101
AS $func$
102-
DELETE FROM public.aqo_queries aq WHERE (aq.query_hash = $1);
103-
DELETE FROM public.aqo_data ad WHERE (ad.fspace_hash = $1);
104-
DELETE FROM public.aqo_query_stat aq WHERE (aq.query_hash = $1);
105-
DELETE FROM public.aqo_query_texts aq WHERE (aq.query_hash = $1);
102+
DELETE FROM aqo_queries aq WHERE (aq.query_hash = $1);
103+
DELETE FROM aqo_data ad WHERE (ad.fspace_hash = $1);
104+
DELETE FROM aqo_query_stat aq WHERE (aq.query_hash = $1);
105+
DELETE FROM aqo_query_texts aq WHERE (aq.query_hash = $1);
106106
$func$ LANGUAGE SQL;

aqo--1.2--1.3.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
ALTER TABLE public.aqo_data ADD COLUMN oids text [] DEFAULT NULL;
1+
ALTER TABLE aqo_data ADD COLUMN oids text [] DEFAULT NULL;
22

33
--
44
-- Remove data, related to previously dropped tables, from the AQO tables.
55
--
6-
CREATE OR REPLACE FUNCTION public.clean_aqo_data() RETURNS void AS $$
6+
CREATE OR REPLACE FUNCTION clean_aqo_data() RETURNS void AS $$
77
DECLARE
88
aqo_data_row aqo_data%ROWTYPE;
99
aqo_queries_row aqo_queries%ROWTYPE;
@@ -29,7 +29,7 @@ BEGIN
2929
END LOOP;
3030
END IF;
3131

32-
FOR aqo_queries_row IN (SELECT * FROM public.aqo_queries)
32+
FOR aqo_queries_row IN (SELECT * FROM aqo_queries)
3333
LOOP
3434
IF (delete_row = true AND fspace_hash_var <> 0 AND
3535
fspace_hash_var = aqo_queries_row.fspace_hash AND
@@ -87,7 +87,7 @@ $$ LANGUAGE plpgsql;
8787
--
8888
-- Top of queries with the highest value of execution time.
8989
--
90-
CREATE OR REPLACE FUNCTION public.top_time_queries(n int)
90+
CREATE OR REPLACE FUNCTION top_time_queries(n int)
9191
RETURNS TABLE(num bigint,
9292
fspace_hash bigint,
9393
query_hash bigint,
@@ -103,7 +103,7 @@ BEGIN
103103
aqo_queries.query_hash,
104104
to_char(array_avg(execution_time_without_aqo), '9.99EEEE')::float,
105105
to_char(array_mse(execution_time_without_aqo), '9.99EEEE')::float
106-
FROM public.aqo_queries INNER JOIN aqo_query_stat
106+
FROM aqo_queries INNER JOIN aqo_query_stat
107107
ON aqo_queries.query_hash = aqo_query_stat.query_hash
108108
GROUP BY (execution_time_without_aqo, aqo_queries.fspace_hash, aqo_queries.query_hash)
109109
ORDER BY execution_time DESC LIMIT n;
@@ -113,7 +113,7 @@ $$ LANGUAGE plpgsql;
113113
--
114114
-- Top of queries with largest value of total cardinality error.
115115
--
116-
CREATE OR REPLACE FUNCTION public.top_error_queries(n int)
116+
CREATE OR REPLACE FUNCTION top_error_queries(n int)
117117
RETURNS TABLE(num bigint,
118118
fspace_hash bigint,
119119
query_hash bigint,
@@ -129,7 +129,7 @@ BEGIN
129129
aqo_queries.query_hash,
130130
to_char(array_avg(cardinality_error_without_aqo), '9.99EEEE')::float,
131131
to_char(array_mse(cardinality_error_without_aqo), '9.99EEEE')::float
132-
FROM public.aqo_queries INNER JOIN aqo_query_stat
132+
FROM aqo_queries INNER JOIN aqo_query_stat
133133
ON aqo_queries.query_hash = aqo_query_stat.query_hash
134134
GROUP BY (cardinality_error_without_aqo, aqo_queries.fspace_hash, aqo_queries.query_hash)
135135
ORDER BY error DESC LIMIT n;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy