41
41
42
42
43
43
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 ,
45
45
EST_ERROR_AQO , EST_ERROR , NEXECS_AQO , NEXECS , TOTAL_NCOLS
46
46
} aqo_stat_cols ;
47
47
48
48
typedef enum {
49
- QT_QUERYID = 0 , QT_QUERY_STRING , QT_TOTAL_NCOLS
49
+ QT_QUERYID = 0 , QT_DBID , QT_QUERY_STRING , QT_TOTAL_NCOLS
50
50
} aqo_qtexts_cols ;
51
51
52
52
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 ,
54
54
AD_OIDS , AD_TOTAL_NCOLS
55
55
} aqo_data_cols ;
56
56
57
57
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 ,
59
59
AQ_TOTAL_NCOLS
60
60
} aqo_queries_cols ;
61
61
@@ -283,6 +283,7 @@ aqo_stat_store(uint64 queryid, bool use_aqo, AqoStatArgs *stat_arg,
283
283
qid = entry -> queryid ;
284
284
memset (entry , 0 , sizeof (StatEntry ));
285
285
entry -> queryid = qid ;
286
+ entry -> dbid = MyDatabaseId ;
286
287
}
287
288
288
289
if (!append_mode )
@@ -292,6 +293,7 @@ aqo_stat_store(uint64 queryid, bool use_aqo, AqoStatArgs *stat_arg,
292
293
{
293
294
memset (entry , 0 , sizeof (StatEntry ));
294
295
entry -> queryid = queryid ;
296
+ entry -> dbid = MyDatabaseId ;
295
297
}
296
298
297
299
sz = stat_arg -> cur_stat_slot_aqo * sizeof (entry -> est_error_aqo [0 ]);
@@ -414,6 +416,7 @@ aqo_query_stat(PG_FUNCTION_ARGS)
414
416
while ((entry = hash_seq_search (& hash_seq )) != NULL )
415
417
{
416
418
values [QUERYID ] = Int64GetDatum (entry -> queryid );
419
+ values [DBID ] = ObjectIdGetDatum (entry -> dbid );
417
420
values [NEXECS ] = Int64GetDatum (entry -> execs_without_aqo );
418
421
values [NEXECS_AQO ] = Int64GetDatum (entry -> execs_with_aqo );
419
422
values [EXEC_TIME_AQO ] = PointerGetDatum (form_vector (entry -> exec_time_aqo , entry -> cur_stat_slot_aqo ));
@@ -443,6 +446,8 @@ aqo_stat_reset(void)
443
446
hash_seq_init (& hash_seq , stat_htab );
444
447
while ((entry = hash_seq_search (& hash_seq )) != NULL )
445
448
{
449
+ if (entry -> dbid != MyDatabaseId )
450
+ continue ;
446
451
if (!hash_search (stat_htab , & entry -> queryid , HASH_REMOVE , NULL ))
447
452
elog (PANIC , "[AQO] hash table corrupted" );
448
453
num_remove ++ ;
@@ -1110,6 +1115,7 @@ aqo_qtext_store(uint64 queryid, const char *query_string)
1110
1115
}
1111
1116
1112
1117
entry -> queryid = queryid ;
1118
+ entry -> dbid = MyDatabaseId ;
1113
1119
size = size > querytext_max_size ? querytext_max_size : size ;
1114
1120
entry -> qtext_dp = dsa_allocate0 (qtext_dsa , size );
1115
1121
@@ -1186,6 +1192,7 @@ aqo_query_texts(PG_FUNCTION_ARGS)
1186
1192
Assert (DsaPointerIsValid (entry -> qtext_dp ));
1187
1193
ptr = dsa_get_address (qtext_dsa , entry -> qtext_dp );
1188
1194
values [QT_QUERYID ] = Int64GetDatum (entry -> queryid );
1195
+ values [QT_DBID ] = ObjectIdGetDatum (entry -> dbid );
1189
1196
values [QT_QUERY_STRING ] = CStringGetTextDatum (ptr );
1190
1197
tuplestore_putvalues (tupstore , tupDesc , values , nulls );
1191
1198
}
@@ -1393,6 +1400,8 @@ aqo_data_store(uint64 fs, int fss, AqoDataArgs *data, List *reloids)
1393
1400
errhint ("Increase value of aqo.fss_max_items on restart of the instance" )));
1394
1401
return false;
1395
1402
}
1403
+
1404
+ entry -> dbid = MyDatabaseId ;
1396
1405
1397
1406
entry -> cols = data -> cols ;
1398
1407
entry -> rows = data -> rows ;
@@ -1803,6 +1812,7 @@ aqo_data(PG_FUNCTION_ARGS)
1803
1812
1804
1813
values [AD_FS ] = Int64GetDatum (entry -> key .fs );
1805
1814
values [AD_FSS ] = Int32GetDatum ((int ) entry -> key .fss );
1815
+ values [AD_DBID ] = ObjectIdGetDatum (entry -> dbid );
1806
1816
values [AD_NFEATURES ] = Int32GetDatum (entry -> cols );
1807
1817
1808
1818
/* Fill values from the DSA data chunk */
@@ -1961,6 +1971,7 @@ aqo_queries(PG_FUNCTION_ARGS)
1961
1971
while ((entry = hash_seq_search (& hash_seq )) != NULL )
1962
1972
{
1963
1973
values [AQ_QUERYID ] = Int64GetDatum (entry -> queryid );
1974
+ values [AQ_DBID ] = ObjectIdGetDatum (entry -> dbid );
1964
1975
values [AQ_FS ] = Int64GetDatum (entry -> fs );
1965
1976
values [AQ_LEARN_AQO ] = BoolGetDatum (entry -> learn_aqo );
1966
1977
values [AQ_USE_AQO ] = BoolGetDatum (entry -> use_aqo );
@@ -2006,20 +2017,25 @@ aqo_queries_store(uint64 queryid,
2006
2017
& found );
2007
2018
2008
2019
/* Initialize entry on first usage */
2009
- if (!found && action == HASH_FIND )
2020
+ if (!found )
2010
2021
{
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 ;
2021
2036
}
2022
2037
2038
+
2023
2039
if (!null_args -> fs_is_null )
2024
2040
entry -> fs = fs ;
2025
2041
if (!null_args -> learn_aqo_is_null )
@@ -2146,6 +2162,7 @@ aqo_queries_find(uint64 queryid, QueryContextData *ctx)
2146
2162
2147
2163
LWLockAcquire (& aqo_state -> queries_lock , LW_SHARED );
2148
2164
entry = (QueriesEntry * ) hash_search (queries_htab , & queryid , HASH_FIND , & found );
2165
+ assert (entry -> dbid == MyDatabaseId );
2149
2166
if (found )
2150
2167
{
2151
2168
ctx -> query_hash = entry -> queryid ;
0 commit comments