-
Notifications
You must be signed in to change notification settings - Fork 54
/
aqo--1.5--1.6.sql
116 lines (101 loc) · 3.21 KB
/
aqo--1.5--1.6.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* contrib/aqo/aqo--1.5--1.6.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "ALTER EXTENSION aqo UPDATE TO '1.6'" to load this file. \quit
DROP VIEW aqo_queries;
DROP FUNCTION aqo_enable_query;
DROP FUNCTION aqo_disable_query;
DROP FUNCTION aqo_cleanup;
DROP FUNCTION aqo_queries;
CREATE FUNCTION aqo_enable_class(queryid bigint)
RETURNS void
AS 'MODULE_PATHNAME', 'aqo_enable_query'
LANGUAGE C STRICT VOLATILE;
CREATE FUNCTION aqo_disable_class(queryid bigint)
RETURNS void
AS 'MODULE_PATHNAME', 'aqo_disable_query'
LANGUAGE C STRICT VOLATILE;
--
-- Remove unneeded rows from the AQO ML storage.
-- For common feature space, remove rows from aqo_data only.
-- For custom feature space - remove all rows related to the space from all AQO
-- tables even if only one oid for one feature subspace of the space is illegal.
-- Returns number of deleted rows from aqo_queries and aqo_data tables.
--
CREATE FUNCTION aqo_cleanup(OUT nfs integer, OUT nfss integer)
RETURNS record
AS 'MODULE_PATHNAME', 'aqo_cleanup'
LANGUAGE C STRICT VOLATILE;
COMMENT ON FUNCTION aqo_cleanup() IS
'Remove unneeded rows from the AQO ML storage';
--
-- Update or insert an aqo_query_texts
-- table record for given 'queryid'.
--
CREATE FUNCTION aqo_query_texts_update(
queryid bigint, query_text text)
RETURNS bool
AS 'MODULE_PATHNAME', 'aqo_query_texts_update'
LANGUAGE C VOLATILE;
--
-- Update or insert an aqo_query_stat
-- table record for given 'queryid'.
--
CREATE FUNCTION aqo_query_stat_update(
queryid bigint,
execution_time_with_aqo double precision[],
execution_time_without_aqo double precision[],
planning_time_with_aqo double precision[],
planning_time_without_aqo double precision[],
cardinality_error_with_aqo double precision[],
cardinality_error_without_aqo double precision[],
executions_with_aqo bigint,
executions_without_aqo bigint)
RETURNS bool
AS 'MODULE_PATHNAME', 'aqo_query_stat_update'
LANGUAGE C VOLATILE;
--
-- Update or insert an aqo_data
-- table record for given 'fs' & 'fss'.
--
CREATE FUNCTION aqo_data_update(
fs bigint,
fss integer,
nfeatures integer,
features double precision[][],
targets double precision[],
reliability double precision[],
oids Oid[])
RETURNS bool
AS 'MODULE_PATHNAME', 'aqo_data_update'
LANGUAGE C VOLATILE;
/*
* VIEWs to discover AQO data.
*/
CREATE FUNCTION aqo_queries (
OUT queryid bigint,
OUT fs bigint,
OUT learn_aqo boolean,
OUT use_aqo boolean,
OUT auto_tuning boolean,
OUT smart_timeout bigint,
OUT count_increase_timeout bigint
)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'aqo_queries'
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
CREATE VIEW aqo_queries AS SELECT * FROM aqo_queries();
CREATE FUNCTION aqo_memory_usage(
OUT name text,
OUT allocated_size int,
OUT used_size int
)
RETURNS SETOF record
AS $$
SELECT name, total_bytes, used_bytes FROM pg_backend_memory_contexts
WHERE name LIKE 'AQO%'
UNION
SELECT name, allocated_size, size FROM pg_shmem_allocations
WHERE name LIKE 'AQO%';
$$ LANGUAGE SQL;
COMMENT ON FUNCTION aqo_memory_usage() IS
'Show allocated sizes and used sizes of aqo`s memory contexts and hash tables';