Skip to content

Commit 69ead79

Browse files
author
Alexandra Pervushina
committed
Fix test; change order of output params
1 parent 2bc6fea commit 69ead79

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

aqo--1.6.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,48 +167,48 @@ COMMENT ON FUNCTION aqo_reset(oid) IS
167167
CREATE FUNCTION aqo_data (
168168
OUT fs bigint,
169169
OUT fss integer,
170-
OUT dbid Oid,
171170
OUT nfeatures integer,
172171
OUT features double precision[][],
173172
OUT targets double precision[],
174173
OUT reliability double precision[],
175-
OUT oids Oid[]
174+
OUT oids Oid[],
175+
OUT dbid bigint
176176
)
177177
RETURNS SETOF record
178178
AS 'MODULE_PATHNAME', 'aqo_data'
179179
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
180180

181181
CREATE FUNCTION aqo_queries (
182182
OUT queryid bigint,
183-
OUT dbid Oid,
184183
OUT fs bigint,
185184
OUT learn_aqo boolean,
186185
OUT use_aqo boolean,
187186
OUT auto_tuning boolean,
188187
OUT smart_timeout bigint,
189-
OUT count_increase_timeout bigint
188+
OUT count_increase_timeout bigint,
189+
OUT dbid bigint
190190
)
191191
RETURNS SETOF record
192192
AS 'MODULE_PATHNAME', 'aqo_queries'
193193
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
194194

195195
CREATE FUNCTION aqo_query_stat (
196196
OUT queryid bigint,
197-
OUT dbid oid,
198197
OUT execution_time_with_aqo double precision[],
199198
OUT execution_time_without_aqo double precision[],
200199
OUT planning_time_with_aqo double precision[],
201200
OUT planning_time_without_aqo double precision[],
202201
OUT cardinality_error_with_aqo double precision[],
203202
OUT cardinality_error_without_aqo double precision[],
204203
OUT executions_with_aqo bigint,
205-
OUT executions_without_aqo bigint
204+
OUT executions_without_aqo bigint,
205+
OUT dbid bigint
206206
)
207207
RETURNS SETOF record
208208
AS 'MODULE_PATHNAME', 'aqo_query_stat'
209209
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
210210

211-
CREATE FUNCTION aqo_query_texts(OUT queryid bigint, OUT dbid Oid, OUT query_text text)
211+
CREATE FUNCTION aqo_query_texts(OUT queryid bigint, OUT query_text text, OUT dbid bigint)
212212
RETURNS SETOF record
213213
AS 'MODULE_PATHNAME', 'aqo_query_texts'
214214
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;

sql/multiple_databases.sql

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SELECT x1,y1 FROM A LEFT JOIN b ON A.x1 = B.y1 WHERE x1 = 5 AND x2 = 5;') AS str
3737
WHERE str NOT LIKE 'Query Identifier%' and str NOT LIKE '%Memory%' and str NOT LIKE '%Sort Method%';
3838

3939
SELECT count(*) FROM aqo_data();
40-
SELECT count(*) FROM aqo_queries;();
40+
SELECT count(*) FROM aqo_queries();
4141
SELECT count(*) FROM aqo_query_texts();
4242
SELECT count(*) FROM aqo_query_stat();
4343

@@ -49,20 +49,35 @@ set aqo.join_threshold = 0;
4949
set aqo.show_details = on;
5050
set aqo.mode = learn;
5151
set aqo.use = on;
52-
select * from aqo_reset(NULL);
5352

54-
-- Only see info from current database.
53+
CREATE TABLE a (x1 int, x2 int, x3 int);
54+
INSERT INTO a (x1, x2, x3) SELECT mod(ival,10), mod(ival,10), mod(ival,10) FROM generate_series(1,100) As ival;
55+
56+
CREATE OR REPLACE FUNCTION expln(query_string text) RETURNS SETOF text AS $$
57+
BEGIN
58+
RETURN QUERY
59+
EXECUTE format('EXPLAIN (ANALYZE, VERBOSE, COSTS OFF, TIMING OFF, SUMMARY OFF) %s', query_string);
60+
RETURN;
61+
END;
62+
$$ LANGUAGE PLPGSQL;
63+
64+
SELECT str AS result
65+
FROM expln('
66+
SELECT * FROM a WHERE x1 > 1;') AS str
67+
WHERE str NOT LIKE 'Query Identifier%' and str NOT LIKE '%Memory%' and str NOT LIKE '%Sort Method%';
68+
5569
SELECT count(*) FROM aqo_data();
56-
SELECT count(*) FROM aqo_queries;();
70+
SELECT count(*) FROM aqo_queries();
5771
SELECT count(*) FROM aqo_query_texts();
5872
SELECT count(*) FROM aqo_query_stat();
59-
-- Remove plan from other DB.
73+
74+
-- Remove aqo info from other DB.
6075
SELECT aqo_reset(:old_dbid);
6176

6277
-- Reconnect to old DB.
6378
\c :old_db - - :old_port
6479
SELECT count(*) FROM aqo_data();
65-
SELECT count(*) FROM aqo_queries;();
80+
SELECT count(*) FROM aqo_queries();
6681
SELECT count(*) FROM aqo_query_texts();
6782
SELECT count(*) FROM aqo_query_stat();
6883
SELECT aqo_reset(NULL);

storage.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@
4141

4242

4343
typedef enum {
44-
QUERYID = 0, DBID, EXEC_TIME_AQO, EXEC_TIME, PLAN_TIME_AQO, PLAN_TIME,
45-
EST_ERROR_AQO, EST_ERROR, NEXECS_AQO, NEXECS, TOTAL_NCOLS
44+
QUERYID = 0, EXEC_TIME_AQO, EXEC_TIME, PLAN_TIME_AQO, PLAN_TIME,
45+
EST_ERROR_AQO, EST_ERROR, NEXECS_AQO, NEXECS, DBID, TOTAL_NCOLS
4646
} aqo_stat_cols;
4747

4848
typedef enum {
49-
QT_QUERYID = 0, QT_DBID, QT_QUERY_STRING, QT_TOTAL_NCOLS
49+
QT_QUERYID = 0, QT_QUERY_STRING, QT_DBID, QT_TOTAL_NCOLS
5050
} aqo_qtexts_cols;
5151

5252
typedef enum {
53-
AD_FS = 0, AD_FSS, AD_DBID, AD_NFEATURES, AD_FEATURES, AD_TARGETS, AD_RELIABILITY,
54-
AD_OIDS, AD_TOTAL_NCOLS
53+
AD_FS = 0, AD_FSS, AD_NFEATURES, AD_FEATURES, AD_TARGETS, AD_RELIABILITY,
54+
AD_OIDS, AD_DBID, AD_TOTAL_NCOLS
5555
} aqo_data_cols;
5656

5757
typedef enum {
58-
AQ_QUERYID = 0, AQ_DBID, AQ_FS, AQ_LEARN_AQO, AQ_USE_AQO, AQ_AUTO_TUNING, AQ_SMART_TIMEOUT, AQ_COUNT_INCREASE_TIMEOUT,
59-
AQ_TOTAL_NCOLS
58+
AQ_QUERYID = 0, AQ_FS, AQ_LEARN_AQO, AQ_USE_AQO, AQ_AUTO_TUNING, AQ_SMART_TIMEOUT, AQ_COUNT_INCREASE_TIMEOUT,
59+
AQ_DBID, AQ_TOTAL_NCOLS
6060
} aqo_queries_cols;
6161

6262
typedef void* (*form_record_t) (void *ctx, size_t *size);
@@ -424,7 +424,7 @@ aqo_query_stat(PG_FUNCTION_ARGS)
424424
while ((entry = hash_seq_search(&hash_seq)) != NULL)
425425
{
426426
values[QUERYID] = Int64GetDatum(entry->key.queryid);
427-
values[DBID] = ObjectIdGetDatum(entry->key.dbid);
427+
values[DBID] = UInt64GetDatum(entry->key.dbid);
428428
values[NEXECS] = Int64GetDatum(entry->execs_without_aqo);
429429
values[NEXECS_AQO] = Int64GetDatum(entry->execs_with_aqo);
430430
values[EXEC_TIME_AQO] = PointerGetDatum(form_vector(entry->exec_time_aqo, entry->cur_stat_slot_aqo));
@@ -1202,7 +1202,6 @@ aqo_query_texts(PG_FUNCTION_ARGS)
12021202
Assert(DsaPointerIsValid(entry->qtext_dp));
12031203
ptr = dsa_get_address(qtext_dsa, entry->qtext_dp);
12041204
values[QT_QUERYID] = Int64GetDatum(entry->key.queryid);
1205-
values[QT_DBID] = ObjectIdGetDatum(entry->key.dbid);
12061205
values[QT_QUERY_STRING] = CStringGetTextDatum(ptr);
12071206
tuplestore_putvalues(tupstore, tupDesc, values, nulls);
12081207
}
@@ -1829,7 +1828,7 @@ aqo_data(PG_FUNCTION_ARGS)
18291828

18301829
values[AD_FS] = Int64GetDatum(entry->key.fs);
18311830
values[AD_FSS] = Int32GetDatum((int) entry->key.fss);
1832-
values[AD_DBID] = ObjectIdGetDatum(entry->key.dbid);
1831+
values[AD_DBID] = UInt64GetDatum(entry->key.dbid);
18331832
values[AD_NFEATURES] = Int32GetDatum(entry->cols);
18341833

18351834
/* Fill values from the DSA data chunk */
@@ -1991,7 +1990,7 @@ aqo_queries(PG_FUNCTION_ARGS)
19911990
while ((entry = hash_seq_search(&hash_seq)) != NULL)
19921991
{
19931992
values[AQ_QUERYID] = Int64GetDatum(entry->key.queryid);
1994-
values[AQ_DBID] = ObjectIdGetDatum(entry->key.dbid);
1993+
values[AQ_DBID] = UInt64GetDatum(entry->key.dbid);
19951994
values[AQ_FS] = Int64GetDatum(entry->fs);
19961995
values[AQ_LEARN_AQO] = BoolGetDatum(entry->learn_aqo);
19971996
values[AQ_USE_AQO] = BoolGetDatum(entry->use_aqo);
@@ -2345,9 +2344,6 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
23452344
List *actual_fss = NIL;
23462345
ListCell *lc;
23472346

2348-
if (entry->key.dbid != (uint64) MyDatabaseId && entry->key.queryid != 0)
2349-
continue;
2350-
23512347
/* Scan aqo_data for any junk records related to this FS */
23522348
hash_seq_init(&hash_seq2, data_htab);
23532349
while ((dentry = hash_seq_search(&hash_seq2)) != NULL)
@@ -2751,14 +2747,14 @@ aqo_query_texts_update(PG_FUNCTION_ARGS)
27512747
bool res = false;
27522748

27532749
/* Do nothing if any arguments are NULLs */
2754-
if ((PG_ARGISNULL(QT_QUERYID) || PG_ARGISNULL(QT_QUERY_STRING)))
2750+
if ((PG_ARGISNULL(0) || PG_ARGISNULL(1)))
27552751
PG_RETURN_BOOL(false);
27562752

2757-
if (!(queryid = PG_GETARG_INT64(QT_QUERYID)))
2753+
if (!(queryid = PG_GETARG_INT64(0)))
27582754
/* Do nothing for default feature space */
27592755
PG_RETURN_BOOL(false);
27602756

2761-
str = PG_GETARG_TEXT_PP(QT_QUERY_STRING);
2757+
str = PG_GETARG_TEXT_PP(1);
27622758
str_len = VARSIZE_ANY_EXHDR(str) + 1;
27632759
if (str_len > querytext_max_size)
27642760
str_len = querytext_max_size;

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