Skip to content

Commit 922c510

Browse files
committed
Force create aqo-related database objects into the public schema.
Now aqo is not relocatable extension. It uses the public schema for service database objects. It is made for code simplification reason. A simple test on this property is included. Per report from Jim Finnerty.
1 parent e51400c commit 922c510

File tree

5 files changed

+106
-32
lines changed

5 files changed

+106
-32
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ OBJS = aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o \
88
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o \
99
selectivity_cache.o storage.o utils.o $(WIN32RES)
1010

11-
REGRESS = aqo_disabled aqo_controlled aqo_intelligent aqo_forced aqo_learn
11+
REGRESS = aqo_disabled \
12+
aqo_controlled \
13+
aqo_intelligent \
14+
aqo_forced \
15+
aqo_learn \
16+
schema
17+
1218
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
1319

1420
DATA = aqo--1.0.sql aqo--1.0--1.1.sql

aqo--1.0--1.1.sql

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

33

4-
DROP INDEX aqo_query_texts_query_hash_idx CASCADE;
5-
DROP INDEX aqo_queries_query_hash_idx CASCADE;
6-
DROP INDEX aqo_query_stat_idx CASCADE;
7-
DROP INDEX aqo_fss_access_idx CASCADE;
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;
88

9-
CREATE UNIQUE INDEX aqo_fss_access_idx ON aqo_data (fspace_hash, fsspace_hash);
9+
CREATE UNIQUE INDEX aqo_fss_access_idx ON public.aqo_data (fspace_hash, fsspace_hash);
1010

1111

1212
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 format('ALTER TABLE %s RENAME to %s',
31-
aqo_migrate_to_1_1_get_pk('aqo_queries'),
31+
aqo_migrate_to_1_1_get_pk('public.aqo_queries'),
3232
'aqo_queries_query_hash_idx');
3333

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

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

aqo--1.0.sql

Lines changed: 22 additions & 22 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 aqo_queries (
4+
CREATE TABLE public.aqo_queries (
55
query_hash int PRIMARY KEY,
66
learn_aqo boolean NOT NULL,
77
use_aqo boolean NOT NULL,
88
fspace_hash int NOT NULL,
99
auto_tuning boolean NOT NULL
1010
);
1111

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

17-
CREATE TABLE aqo_query_stat (
18-
query_hash int PRIMARY KEY REFERENCES aqo_queries ON DELETE CASCADE,
17+
CREATE TABLE public.aqo_query_stat (
18+
query_hash int PRIMARY KEY REFERENCES public.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,42 +26,42 @@ CREATE TABLE aqo_query_stat (
2626
executions_without_aqo bigint
2727
);
2828

29-
CREATE TABLE aqo_data (
30-
fspace_hash int NOT NULL REFERENCES aqo_queries ON DELETE CASCADE,
29+
CREATE TABLE public.aqo_data (
30+
fspace_hash int NOT NULL REFERENCES public.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 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);
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);
4242

43-
ALTER TABLE aqo_data ALTER COLUMN features SET STORAGE MAIN;
44-
ALTER TABLE aqo_data ALTER COLUMN targets SET STORAGE MAIN;
45-
ALTER TABLE aqo_query_stat
43+
ALTER TABLE public.aqo_data ALTER COLUMN features SET STORAGE MAIN;
44+
ALTER TABLE public.aqo_data ALTER COLUMN targets SET STORAGE MAIN;
45+
ALTER TABLE public.aqo_query_stat
4646
ALTER COLUMN execution_time_with_aqo SET STORAGE MAIN;
47-
ALTER TABLE aqo_query_stat
47+
ALTER TABLE public.aqo_query_stat
4848
ALTER COLUMN execution_time_without_aqo SET STORAGE MAIN;
49-
ALTER TABLE aqo_query_stat
49+
ALTER TABLE public.aqo_query_stat
5050
ALTER COLUMN planning_time_with_aqo SET STORAGE MAIN;
51-
ALTER TABLE aqo_query_stat
51+
ALTER TABLE public.aqo_query_stat
5252
ALTER COLUMN planning_time_without_aqo SET STORAGE MAIN;
53-
ALTER TABLE aqo_query_stat
53+
ALTER TABLE public.aqo_query_stat
5454
ALTER COLUMN cardinality_error_without_aqo SET STORAGE MAIN;
55-
ALTER TABLE aqo_query_stat
55+
ALTER TABLE public.aqo_query_stat
5656
ALTER COLUMN cardinality_error_with_aqo SET STORAGE MAIN;
5757

58-
INSERT INTO aqo_queries VALUES (0, false, false, 0, false);
59-
INSERT INTO aqo_query_texts VALUES (0, 'COMMON feature space (do not delete!)');
58+
INSERT INTO public.aqo_queries VALUES (0, false, false, 0, false);
59+
INSERT INTO public.aqo_query_texts VALUES (0, 'COMMON feature space (do not delete!)');
6060
-- a virtual query for COMMON feature space
6161

6262
CREATE FUNCTION invalidate_deactivated_queries_cache() RETURNS trigger
6363
AS 'MODULE_PATHNAME' LANGUAGE C;
6464

6565
CREATE TRIGGER aqo_queries_invalidate AFTER UPDATE OR DELETE OR TRUNCATE
66-
ON aqo_queries FOR EACH STATEMENT
66+
ON public.aqo_queries FOR EACH STATEMENT
6767
EXECUTE PROCEDURE invalidate_deactivated_queries_cache();

expected/schema.out

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
DROP EXTENSION IF EXISTS aqo CASCADE;
2+
NOTICE: extension "aqo" does not exist, skipping
3+
DROP SCHEMA IF EXISTS test CASCADE;
4+
NOTICE: schema "test" does not exist, skipping
5+
-- Check Zero-schema path behaviour
6+
CREATE SCHEMA IF NOT EXISTS test;
7+
SET search_path TO test;
8+
DROP SCHEMA IF EXISTS test CASCADE;
9+
CREATE EXTENSION aqo; -- fail
10+
ERROR: no schema has been selected to create in
11+
-- Check default schema switching after AQO initialization
12+
CREATE SCHEMA IF NOT EXISTS test1;
13+
SET search_path TO test1, public;
14+
CREATE EXTENSION aqo;
15+
SET aqo.mode = 'intelligent';
16+
CREATE TABLE test (id SERIAL, data TEXT);
17+
INSERT INTO test (data) VALUES ('string');
18+
SELECT * FROM test;
19+
id | data
20+
----+--------
21+
1 | string
22+
(1 row)
23+
24+
SELECT * FROM public.aqo_query_texts;
25+
query_hash | query_text
26+
------------+--------------------------------------------
27+
0 | COMMON feature space (do not delete!)
28+
1136691690 | INSERT INTO test (data) VALUES ('string');
29+
868705076 | SELECT * FROM test;
30+
826229959 | SELECT * FROM public.aqo_query_texts;
31+
(4 rows)
32+
33+
SELECT * FROM public.aqo_queries;
34+
query_hash | learn_aqo | use_aqo | fspace_hash | auto_tuning
35+
------------+-----------+---------+-------------+-------------
36+
0 | f | f | 0 | f
37+
1136691690 | t | f | 1136691690 | t
38+
868705076 | t | f | 868705076 | t
39+
826229959 | t | f | 826229959 | t
40+
2145866904 | t | f | 2145866904 | t
41+
(5 rows)
42+
43+
DROP SCHEMA IF EXISTS test1 CASCADE;
44+
NOTICE: drop cascades to 2 other objects
45+
DETAIL: drop cascades to extension aqo
46+
drop cascades to table test

sql/schema.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DROP EXTENSION IF EXISTS aqo CASCADE;
2+
DROP SCHEMA IF EXISTS test CASCADE;
3+
4+
-- Check Zero-schema path behaviour
5+
CREATE SCHEMA IF NOT EXISTS test;
6+
SET search_path TO test;
7+
DROP SCHEMA IF EXISTS test CASCADE;
8+
CREATE EXTENSION aqo; -- fail
9+
10+
-- Check default schema switching after AQO initialization
11+
CREATE SCHEMA IF NOT EXISTS test1;
12+
SET search_path TO test1, public;
13+
CREATE EXTENSION aqo;
14+
SET aqo.mode = 'intelligent';
15+
16+
CREATE TABLE test (id SERIAL, data TEXT);
17+
INSERT INTO test (data) VALUES ('string');
18+
19+
SELECT * FROM test;
20+
SELECT * FROM public.aqo_query_texts;
21+
SELECT * FROM public.aqo_queries;
22+
DROP SCHEMA IF EXISTS test1 CASCADE;

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