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

Commit 239dac9

Browse files
Merge pull request #17 from kulaginm/stable12-CVE-2020-14350
Fix CVE-2020-14350
2 parents 6cfbea6 + b53bbbd commit 239dac9

File tree

6 files changed

+820
-52
lines changed

6 files changed

+820
-52
lines changed

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ regression.out
88
*.gcov
99
tags
1010

11-
aqo--?.?.sql

‎Makefile‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ REGRESS = aqo_disabled \
1313
aqo_intelligent \
1414
aqo_forced \
1515
aqo_learn \
16-
schema
16+
schema \
17+
aqo_CVE-2020-14350
1718

1819
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
1920

20-
TAP_TESTS = 1
21-
22-
DATA = aqo--1.0.sql aqo--1.0--1.1.sql aqo--1.1--1.2.sql
23-
DATA_built = aqo--1.2.sql
21+
DATA = aqo--1.0.sql aqo--1.0--1.1.sql aqo--1.1--1.2.sql aqo--1.2.sql
2422

2523
MODULE_big = aqo
2624
ifdef USE_PGXS
@@ -34,6 +32,3 @@ include $(top_builddir)/src/Makefile.global
3432
include $(top_srcdir)/contrib/contrib-global.mk
3533
endif
3634

37-
38-
$(DATA_built): $(DATA)
39-
cat $+ > $@

‎aqo--1.2.sql‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
2+
\echo Use "CREATE EXTENSION aqo" to load this file. \quit
3+
4+
CREATE TABLE public.aqo_queries (
5+
query_hash int CONSTRAINT aqo_queries_query_hash_idx PRIMARY KEY,
6+
learn_aqo boolean NOT NULL,
7+
use_aqo boolean NOT NULL,
8+
fspace_hash int NOT NULL,
9+
auto_tuning boolean NOT NULL
10+
);
11+
12+
CREATE TABLE public.aqo_query_texts (
13+
query_hash int CONSTRAINT aqo_query_texts_query_hash_idx PRIMARY KEY REFERENCES public.aqo_queries ON DELETE CASCADE,
14+
query_text text NOT NULL
15+
);
16+
17+
CREATE TABLE public.aqo_query_stat (
18+
query_hash int CONSTRAINT aqo_query_stat_idx PRIMARY KEY REFERENCES public.aqo_queries ON DELETE CASCADE,
19+
execution_time_with_aqo double precision[],
20+
execution_time_without_aqo double precision[],
21+
planning_time_with_aqo double precision[],
22+
planning_time_without_aqo double precision[],
23+
cardinality_error_with_aqo double precision[],
24+
cardinality_error_without_aqo double precision[],
25+
executions_with_aqo bigint,
26+
executions_without_aqo bigint
27+
);
28+
29+
CREATE TABLE public.aqo_data (
30+
fspace_hash int NOT NULL REFERENCES public.aqo_queries ON DELETE CASCADE,
31+
fsspace_hash int NOT NULL,
32+
nfeatures int NOT NULL,
33+
features double precision[][],
34+
targets double precision[]
35+
);
36+
37+
CREATE UNIQUE INDEX aqo_fss_access_idx ON public.aqo_data (fspace_hash, fsspace_hash);
38+
39+
INSERT INTO public.aqo_queries VALUES (0, false, false, 0, false);
40+
INSERT INTO public.aqo_query_texts VALUES (0, 'COMMON feature space (do not delete!)');
41+
-- a virtual query for COMMON feature space
42+
43+
CREATE FUNCTION invalidate_deactivated_queries_cache() RETURNS trigger
44+
AS 'MODULE_PATHNAME' LANGUAGE C;
45+
46+
CREATE TRIGGER aqo_queries_invalidate AFTER UPDATE OR DELETE OR TRUNCATE
47+
ON public.aqo_queries FOR EACH STATEMENT
48+
EXECUTE PROCEDURE invalidate_deactivated_queries_cache();
49+
50+
--
51+
-- Service functions
52+
--
53+
54+
-- Show query state at the AQO knowledge base
55+
CREATE FUNCTION public.aqo_status(hash int)
56+
RETURNS TABLE (
57+
"learn" BOOL,
58+
"use aqo" BOOL,
59+
"auto tune" BOOL,
60+
"fspace hash" INT,
61+
"t_naqo" TEXT,
62+
"err_naqo" TEXT,
63+
"iters" BIGINT,
64+
"t_aqo" TEXT,
65+
"err_aqo" TEXT,
66+
"iters_aqo" BIGINT
67+
)
68+
AS $func$
69+
SELECT learn_aqo,use_aqo,auto_tuning,fspace_hash,
70+
to_char(execution_time_without_aqo[n4],'9.99EEEE'),
71+
to_char(cardinality_error_without_aqo[n2],'9.99EEEE'),
72+
executions_without_aqo,
73+
to_char(execution_time_with_aqo[n3],'9.99EEEE'),
74+
to_char(cardinality_error_with_aqo[n1],'9.99EEEE'),
75+
executions_with_aqo
76+
FROM public.aqo_queries aq, public.aqo_query_stat aqs,
77+
(SELECT array_length(n1,1) AS n1, array_length(n2,1) AS n2,
78+
array_length(n3,1) AS n3, array_length(n4,1) AS n4
79+
FROM
80+
(SELECT cardinality_error_with_aqo AS n1,
81+
cardinality_error_without_aqo AS n2,
82+
execution_time_with_aqo AS n3,
83+
execution_time_without_aqo AS n4
84+
FROM public.aqo_query_stat aqs WHERE
85+
aqs.query_hash = $1) AS al) AS q
86+
WHERE (aqs.query_hash = aq.query_hash) AND
87+
aqs.query_hash = $1;
88+
$func$ LANGUAGE SQL;
89+
90+
CREATE FUNCTION public.aqo_enable_query(hash int)
91+
RETURNS VOID
92+
AS $func$
93+
UPDATE public.aqo_queries SET
94+
learn_aqo = 'true',
95+
use_aqo = 'true'
96+
WHERE query_hash = $1;
97+
$func$ LANGUAGE SQL;
98+
99+
CREATE FUNCTION public.aqo_disable_query(hash int)
100+
RETURNS VOID
101+
AS $func$
102+
UPDATE public.aqo_queries SET
103+
learn_aqo = 'false',
104+
use_aqo = 'false',
105+
auto_tuning = 'false'
106+
WHERE query_hash = $1;
107+
$func$ LANGUAGE SQL;
108+
109+
CREATE FUNCTION public.aqo_clear_hist(hash int)
110+
RETURNS VOID
111+
AS $func$
112+
DELETE FROM public.aqo_data WHERE fspace_hash=$1;
113+
$func$ LANGUAGE SQL;
114+
115+
-- Show queries that contains 'Never executed' nodes at the plan.
116+
CREATE FUNCTION public.aqo_ne_queries()
117+
RETURNS SETOF int
118+
AS $func$
119+
SELECT query_hash FROM public.aqo_query_stat aqs
120+
WHERE -1 = ANY (cardinality_error_with_aqo::double precision[]);
121+
$func$ LANGUAGE SQL;
122+
123+
CREATE FUNCTION public.aqo_drop(hash int)
124+
RETURNS VOID
125+
AS $func$
126+
DELETE FROM public.aqo_queries aq WHERE (aq.query_hash = $1);
127+
DELETE FROM public.aqo_data ad WHERE (ad.fspace_hash = $1);
128+
DELETE FROM public.aqo_query_stat aq WHERE (aq.query_hash = $1);
129+
DELETE FROM public.aqo_query_texts aq WHERE (aq.query_hash = $1);
130+
$func$ LANGUAGE SQL;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /