Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2108020

Browse files
author
Alexandra Pervushina
committed
Add dbid
1 parent 5793965 commit 2108020

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

aqo--1.6.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ COMMENT ON FUNCTION aqo_reset() IS
161161
CREATE FUNCTION aqo_data (
162162
OUT fs bigint,
163163
OUT fss integer,
164+
OUT db_id Oid,
164165
OUT nfeatures integer,
165166
OUT features double precision[][],
166167
OUT targets double precision[],
@@ -173,6 +174,7 @@ LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
173174

174175
CREATE FUNCTION aqo_queries (
175176
OUT queryid bigint,
177+
OUT db_id Oid,
176178
OUT fs bigint,
177179
OUT learn_aqo boolean,
178180
OUT use_aqo boolean,
@@ -186,6 +188,7 @@ LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
186188

187189
CREATE FUNCTION aqo_query_stat (
188190
OUT queryid bigint,
191+
OUT db_id Oid,
189192
OUT execution_time_with_aqo double precision[],
190193
OUT execution_time_without_aqo double precision[],
191194
OUT planning_time_with_aqo double precision[],
@@ -199,7 +202,7 @@ RETURNS SETOF record
199202
AS 'MODULE_PATHNAME', 'aqo_query_stat'
200203
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
201204

202-
CREATE FUNCTION aqo_query_texts(OUT queryid bigint, OUT query_text text)
205+
CREATE FUNCTION aqo_query_texts(OUT queryid bigint, OUT dbid Oid, OUT query_text text)
203206
RETURNS SETOF record
204207
AS 'MODULE_PATHNAME', 'aqo_query_texts'
205208
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;

storage.c

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@
4141

4242

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

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

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

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

@@ -283,6 +283,7 @@ aqo_stat_store(uint64 queryid, bool use_aqo, AqoStatArgs *stat_arg,
283283
qid = entry->queryid;
284284
memset(entry, 0, sizeof(StatEntry));
285285
entry->queryid = qid;
286+
entry->dbid = MyDatabaseId;
286287
}
287288

288289
if (!append_mode)
@@ -292,6 +293,7 @@ aqo_stat_store(uint64 queryid, bool use_aqo, AqoStatArgs *stat_arg,
292293
{
293294
memset(entry, 0, sizeof(StatEntry));
294295
entry->queryid = queryid;
296+
entry->dbid = MyDatabaseId;
295297
}
296298

297299
sz = stat_arg->cur_stat_slot_aqo * sizeof(entry->est_error_aqo[0]);
@@ -414,6 +416,7 @@ aqo_query_stat(PG_FUNCTION_ARGS)
414416
while ((entry = hash_seq_search(&hash_seq)) != NULL)
415417
{
416418
values[QUERYID] = Int64GetDatum(entry->queryid);
419+
values[DBID] = ObjectIdGetDatum(entry->dbid);
417420
values[NEXECS] = Int64GetDatum(entry->execs_without_aqo);
418421
values[NEXECS_AQO] = Int64GetDatum(entry->execs_with_aqo);
419422
values[EXEC_TIME_AQO] = PointerGetDatum(form_vector(entry->exec_time_aqo, entry->cur_stat_slot_aqo));
@@ -443,6 +446,8 @@ aqo_stat_reset(void)
443446
hash_seq_init(&hash_seq, stat_htab);
444447
while ((entry = hash_seq_search(&hash_seq)) != NULL)
445448
{
449+
if (entry->dbid != MyDatabaseId)
450+
continue;
446451
if (!hash_search(stat_htab, &entry->queryid, HASH_REMOVE, NULL))
447452
elog(PANIC, "[AQO] hash table corrupted");
448453
num_remove++;
@@ -1110,6 +1115,7 @@ aqo_qtext_store(uint64 queryid, const char *query_string)
11101115
}
11111116

11121117
entry->queryid = queryid;
1118+
entry->dbid = MyDatabaseId;
11131119
size = size > querytext_max_size ? querytext_max_size : size;
11141120
entry->qtext_dp = dsa_allocate0(qtext_dsa, size);
11151121

@@ -1186,6 +1192,7 @@ aqo_query_texts(PG_FUNCTION_ARGS)
11861192
Assert(DsaPointerIsValid(entry->qtext_dp));
11871193
ptr = dsa_get_address(qtext_dsa, entry->qtext_dp);
11881194
values[QT_QUERYID] = Int64GetDatum(entry->queryid);
1195+
values[QT_DBID] = ObjectIdGetDatum(entry->dbid);
11891196
values[QT_QUERY_STRING] = CStringGetTextDatum(ptr);
11901197
tuplestore_putvalues(tupstore, tupDesc, values, nulls);
11911198
}
@@ -1393,6 +1400,8 @@ aqo_data_store(uint64 fs, int fss, AqoDataArgs *data, List *reloids)
13931400
errhint("Increase value of aqo.fss_max_items on restart of the instance")));
13941401
return false;
13951402
}
1403+
1404+
entry->dbid = MyDatabaseId;
13961405

13971406
entry->cols = data->cols;
13981407
entry->rows = data->rows;
@@ -1803,6 +1812,7 @@ aqo_data(PG_FUNCTION_ARGS)
18031812

18041813
values[AD_FS] = Int64GetDatum(entry->key.fs);
18051814
values[AD_FSS] = Int32GetDatum((int) entry->key.fss);
1815+
values[AD_DBID] = ObjectIdGetDatum(entry->dbid);
18061816
values[AD_NFEATURES] = Int32GetDatum(entry->cols);
18071817

18081818
/* Fill values from the DSA data chunk */
@@ -1961,6 +1971,7 @@ aqo_queries(PG_FUNCTION_ARGS)
19611971
while ((entry = hash_seq_search(&hash_seq)) != NULL)
19621972
{
19631973
values[AQ_QUERYID] = Int64GetDatum(entry->queryid);
1974+
values[AQ_DBID] = ObjectIdGetDatum(entry->dbid);
19641975
values[AQ_FS] = Int64GetDatum(entry->fs);
19651976
values[AQ_LEARN_AQO] = BoolGetDatum(entry->learn_aqo);
19661977
values[AQ_USE_AQO] = BoolGetDatum(entry->use_aqo);
@@ -2006,20 +2017,25 @@ aqo_queries_store(uint64 queryid,
20062017
&found);
20072018

20082019
/* Initialize entry on first usage */
2009-
if (!found && action == HASH_FIND)
2020+
if (!found)
20102021
{
2011-
/*
2012-
* Hash table is full. To avoid possible problems - don't try to add
2013-
* more, just exit
2014-
*/
2015-
LWLockRelease(&aqo_state->queries_lock);
2016-
ereport(LOG,
2017-
(errcode(ERRCODE_OUT_OF_MEMORY),
2018-
errmsg("[AQO] Queries storage is full. No more feature spaces can be added."),
2019-
errhint("Increase value of aqo.fs_max_items on restart of the instance")));
2020-
return false;
2022+
if (action == HASH_FIND)
2023+
{
2024+
/*
2025+
* Hash table is full. To avoid possible problems - don't try to add
2026+
* more, just exit
2027+
*/
2028+
LWLockRelease(&aqo_state->queries_lock);
2029+
ereport(LOG,
2030+
(errcode(ERRCODE_OUT_OF_MEMORY),
2031+
errmsg("[AQO] Queries storage is full. No more feature spaces can be added."),
2032+
errhint("Increase value of aqo.fs_max_items on restart of the instance")));
2033+
return false;
2034+
}
2035+
entry->dbid = MyDatabaseId;
20212036
}
20222037

2038+
20232039
if (!null_args->fs_is_null)
20242040
entry->fs = fs;
20252041
if (!null_args->learn_aqo_is_null)
@@ -2146,6 +2162,7 @@ aqo_queries_find(uint64 queryid, QueryContextData *ctx)
21462162

21472163
LWLockAcquire(&aqo_state->queries_lock, LW_SHARED);
21482164
entry = (QueriesEntry *) hash_search(queries_htab, &queryid, HASH_FIND, &found);
2165+
assert(entry->dbid == MyDatabaseId);
21492166
if (found)
21502167
{
21512168
ctx->query_hash = entry->queryid;

storage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
typedef struct StatEntry
2222
{
2323
uint64 queryid; /* The key in the hash table, should be the first field ever */
24+
Oid dbid;
2425

2526
int64 execs_with_aqo;
2627
int64 execs_without_aqo;
@@ -64,6 +65,7 @@ typedef struct AqoStatArgs
6465
typedef struct QueryTextEntry
6566
{
6667
uint64 queryid;
68+
Oid dbid;
6769

6870
/* Link to DSA-allocated memory block. Can be shared across backends */
6971
dsa_pointer qtext_dp;
@@ -78,6 +80,7 @@ typedef struct data_key
7880
typedef struct DataEntry
7981
{
8082
data_key key;
83+
Oid dbid;
8184

8285
/* defines a size and data placement in the DSA memory block */
8386
int cols; /* aka nfeatures */
@@ -95,6 +98,7 @@ typedef struct DataEntry
9598
typedef struct QueriesEntry
9699
{
97100
uint64 queryid;
101+
Oid dbid;
98102

99103
uint64 fs;
100104
bool learn_aqo;

0 commit comments

Comments
 (0)