Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53c1781

Browse files
author
Alexandra Pervushina
committed
Add fss_neighbours hash table
1 parent 1275c61 commit 53c1781

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

aqo--1.4--1.5.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DROP TABLE public.aqo_queries CASCADE;
2020
DROP TABLE public.aqo_query_texts CASCADE;
2121
DROP TABLE public.aqo_query_stat CASCADE;
2222

23-
2423
/*
2524
* VIEWs to discover AQO data.
2625
*/
@@ -62,7 +61,9 @@ CREATE FUNCTION aqo_data (
6261
OUT features double precision[][],
6362
OUT targets double precision[],
6463
OUT reliability double precision[],
65-
OUT oids Oid[]
64+
OUT oids Oid[],
65+
OUT prev_fs bigint,
66+
OUT next_fs bigint
6667
)
6768
RETURNS SETOF record
6869
AS 'MODULE_PATHNAME', 'aqo_data'

aqo_shared.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ aqo_init_shmem(void)
184184
qtexts_htab = NULL;
185185
data_htab = NULL;
186186
queries_htab = NULL;
187+
fss_neighbours = NULL;
187188

188189
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
189190
aqo_state = ShmemInitStruct("AQO", sizeof(AQOSharedState), &found);
@@ -209,6 +210,7 @@ aqo_init_shmem(void)
209210
LWLockInitialize(&aqo_state->queries_lock, LWLockNewTrancheId());
210211
}
211212

213+
/* Init shared memory hash for partial aqo data table*/
212214
info.keysize = sizeof(htab_key);
213215
info.entrysize = sizeof(htab_entry);
214216
fss_htab = ShmemInitHash("AQO hash",
@@ -239,6 +241,12 @@ aqo_init_shmem(void)
239241
queries_htab = ShmemInitHash("AQO Queries HTAB", fs_max_items, fs_max_items,
240242
&info, HASH_ELEM | HASH_BLOBS);
241243

244+
/* Shared memory hash table for fss neighbours */
245+
info.keysize = sizeof(int);
246+
info.entrysize = sizeof(DataEntry*);
247+
fss_neighbours = ShmemInitHash("AQO fss neighbours HTAB", fss_max_items, fss_max_items,
248+
&info, HASH_ELEM | HASH_BLOBS);
249+
242250
LWLockRelease(AddinShmemInitLock);
243251
LWLockRegisterTranche(aqo_state->lock.tranche, "AQO");
244252
LWLockRegisterTranche(aqo_state->stat_lock.tranche, "AQO Stat Lock Tranche");
@@ -287,6 +295,7 @@ aqo_memsize(void)
287295
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(QueryTextEntry)));
288296
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(DataEntry)));
289297
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(QueriesEntry)));
298+
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(DataEntry*)));
290299

291300
return size;
292301
}

storage.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ typedef enum {
5252

5353
typedef enum {
5454
AD_FS = 0, AD_FSS, AD_NFEATURES, AD_FEATURES, AD_TARGETS, AD_RELIABILITY,
55-
AD_OIDS, AD_TOTAL_NCOLS
55+
AD_OIDS, AD_PREV_FS, AD_NEXT_FS, AD_TOTAL_NCOLS
5656
} aqo_data_cols;
5757

5858
typedef enum {
@@ -74,6 +74,7 @@ dsa_area *qtext_dsa = NULL;
7474
HTAB *data_htab = NULL;
7575
dsa_area *data_dsa = NULL;
7676
HTAB *deactivated_queries = NULL;
77+
HTAB *fss_neighbours = NULL;
7778

7879
/* Used to check data file consistency */
7980
static const uint32 PGAQO_FILE_HEADER = 123467589;
@@ -1293,13 +1294,15 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
12931294
DataEntry *entry;
12941295
bool found;
12951296
data_key key = {.fs = fs, .fss = fss};
1297+
fs_list neighbour_list = {0};
12961298
int i;
12971299
char *ptr;
12981300
ListCell *lc;
12991301
size_t size;
13001302
bool tblOverflow;
13011303
HASHACTION action;
13021304
bool result;
1305+
DataEntry** prev;
13031306

13041307
Assert(!LWLockHeldByMe(&aqo_state->data_lock));
13051308

@@ -1383,12 +1386,32 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13831386
ptr = (char *) dsa_get_address(data_dsa, entry->data_dp);
13841387
Assert(ptr != NULL);
13851388

1389+
/*
1390+
* Find prev fss
1391+
*/
1392+
1393+
prev = (DataEntry **) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
1394+
if (!found)
1395+
{
1396+
*prev = entry;
1397+
}
1398+
else
1399+
{
1400+
(*prev)->list.next_fs = fss;
1401+
}
1402+
neighbour_list.prev_fs = (*prev)->key.fs;
1403+
1404+
prev = (DataEntry **) hash_search(fss_neighbours, &fss, HASH_FIND, &found);
1405+
elog(NOTICE, "%d", found);
1406+
13861407
/*
13871408
* Copy AQO data into allocated DSA segment
13881409
*/
13891410

13901411
memcpy(ptr, &key, sizeof(data_key)); /* Just for debug */
13911412
ptr += sizeof(data_key);
1413+
memcpy(ptr,&neighbour_list, sizeof(fs_list));
1414+
ptr += sizeof(fs_list);
13921415
if (entry->cols > 0)
13931416
{
13941417
for (i = 0; i < entry->rows; i++)
@@ -1652,6 +1675,8 @@ aqo_data(PG_FUNCTION_ARGS)
16521675
values[AD_FS] = Int64GetDatum(entry->key.fs);
16531676
values[AD_FSS] = Int32GetDatum((int) entry->key.fss);
16541677
values[AD_NFEATURES] = Int32GetDatum(entry->cols);
1678+
values[AD_PREV_FS] = Int64GetDatum(entry->list.prev_fs);
1679+
values[AD_NEXT_FS] = Int64GetDatum(entry->list.next_fs);
16551680

16561681
/* Fill values from the DSA data chunk */
16571682
Assert(DsaPointerIsValid(entry->data_dp));
@@ -2135,6 +2160,8 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21352160
foreach(lc, junk_fss)
21362161
{
21372162
data_key key = {.fs = entry->fs, .fss = lfirst_int(lc)};
2163+
//TODO fix fs list
2164+
hash_search(fss_neighbours, &lfirst_int(lc), HASH_REMOVE, NULL);
21382165
(*fss_num) += (int) _aqo_data_remove(&key);
21392166
}
21402167

storage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ typedef struct data_key
5555
int64 fss; /* just for alignment */
5656
} data_key;
5757

58+
typedef struct fs_list
59+
{
60+
int64 prev_fs;
61+
int64 next_fs;
62+
} fs_list;
63+
5864
typedef struct DataEntry
5965
{
6066
data_key key;
67+
fs_list list;
6168

6269
/* defines a size and data placement in the DSA memory block */
6370
int cols; /* aka nfeatures */
@@ -89,6 +96,7 @@ extern HTAB *stat_htab;
8996
extern HTAB *qtexts_htab;
9097
extern HTAB *queries_htab; /* TODO */
9198
extern HTAB *data_htab; /* TODO */
99+
extern HTAB *fss_neighbours;
92100

93101
extern StatEntry *aqo_stat_store(uint64 queryid, bool use_aqo, double plan_time,
94102
double exec_time, double est_error);

0 commit comments

Comments
 (0)