8000 fss_neighbours saves fs · postgrespro/aqo@c00ed3f · GitHub
[go: up one dir, main page]

Skip to content

Commit c00ed3f

Browse files
author
Alexandra Pervushina
committed
fss_neighbours saves fs
1 parent 32a4f0e commit c00ed3f

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

aqo_shared.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ aqo_init_shmem(void)
200200
aqo_state->stat_changed = false;
201201
aqo_state->data_changed = false;
202202
aqo_state->queries_changed = false;
203+
aqo_state->neighbours_changed = false;
203204

204205
LWLockInitialize(&aqo_state->lock, LWLockNewTrancheId());
205206
LWLockInitialize(&aqo_state->stat_lock, LWLockNewTrancheId());
206207
LWLockInitialize(&aqo_state->qtexts_lock, LWLockNewTrancheId());
207208
LWLockInitialize(&aqo_state->data_lock, LWLockNewTrancheId());
208209
LWLockInitialize(&aqo_state->queries_lock, LWLockNewTrancheId());
210+
LWLockInitialize(&aqo_state->neighbours_lock, LWLockNewTrancheId());
209211
}
210212

211213
/* Init shared memory hash for partial aqo data table*/
@@ -241,7 +243,7 @@ aqo_init_shmem(void)
241243

242244
/* Shared memory hash table for fss neighbours */
243245
info.keysize = sizeof(int);
244-
info.entrysize = sizeof(DataEntry*);
246+
info.entrysize = sizeof(uint64);
245247
fss_neighbours = ShmemInitHash("AQO fss neighbours HTAB", fss_max_items, fss_max_items,
246248
&info, HASH_ELEM | HASH_BLOBS);
247249

@@ -252,6 +254,7 @@ aqo_init_shmem(void)
252254
LWLockRegisterTranche(aqo_state->qtext_trancheid, "AQO Query Texts Tranche");
253255
LWLockRegisterTranche(aqo_state->data_lock.tranche, "AQO Data Lock Tranche");
254256
LWLockRegisterTranche(aqo_state->queries_lock.tranche, "AQO Queries Lock Tranche");
257+
LWLockRegisterTranche(aqo_state->neighbours_lock.tranche, "AQO Neighbours Lock Tranche");
255258

256259
if (!IsUnderPostmaster && !found)
257260
{
@@ -293,7 +296,7 @@ aqo_memsize(void)
293296
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(QueryTextEntry)));
294297
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(DataEntry)));
295298
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(QueriesEntry)));
296-
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(DataEntry*)));
299+
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(uint64)));
297300

298301
return size;
299302
}

aqo_shared.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ typedef struct AQOSharedState
4242

4343
LWLock queries_lock; /* lock for access to queries storage */
4444
bool queries_changed;
45+
46+
LWLock neighbours_lock; /* lock for access to queries storage */
47+
bool neighbours_changed;
4548
} AQOSharedState;
4649

4750

storage.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13021302
bool tblOverflow;
13031303
HASHACTION action;
13041304
bool result;
1305-
DataEntry** prev;
1305+
uint64 *prev_fs;
13061306

13071307
Assert(!LWLockHeldByMe(&aqo_state->data_lock));
13081308

@@ -1387,29 +1387,41 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13871387
Assert(ptr != NULL);
13881388

13891389
/*
1390-
* Find prev fss
1390+
* Find prev fs with the same fss
13911391
*/
13921392

1393-
prev = (DataEntry **) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
1393+
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
1394+
1395+
prev_fs = (uint64 *) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
13941396
if (!found)
13951397
{
1396-
prev = memcpy(palloc(sizeof(DataEntry **)), entry, sizeof(DataEntry **));
1397-
//*prev = entry;
1398+
//*prev_fs = fs;
1399+
memcpy(prev_fs, &entry->key.fs, sizeof(uint64));
13981400
}
13991401
else
14001402
{
1401-
(*prev)->list.next_fs = fss;
1402-
neighbour_list.prev_fs = (*prev)->key.fs;
1403+
data_key prev_key = {.fs = *prev_fs, .fss = fss};
1404+
DataEntry *prev;
1405+
1406+
prev = (DataEntry *) hash_search(data_htab, &prev_key, HASH_FIND, NULL);
1407+
//prev->list.next_fs = fs;
1408+
memcpy(&prev->list.next_fs, &fs, sizeof(uint64));
1409+
neighbour_list.prev_fs = prev->key.fs;
14031410
}
14041411

1412+
prev_fs = (uint64 *) hash_search(fss_neighbours, &fss, HASH_FIND, &found);
1413+
elog(NOTICE, "%d 🗿🔫", found);
1414+
1415+
LWLockRelease(&aqo_state->neighbours_lock);
1416+
14051417

14061418
/*
14071419
* Copy AQO data into allocated DSA segment
14081420
*/
14091421

14101422
memcpy(ptr, &key, sizeof(data_key)); /* Just for debug */
14111423
ptr += sizeof(data_key);
1412-
memcpy(ptr,&neighbour_list, sizeof(fs_list));
1424+
memcpy(ptr, &neighbour_list, sizeof(fs_list));
14131425
ptr += sizeof(fs_list);
14141426
if (entry->cols > 0)
14151427
{

storage.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ typedef struct data_key
5757

5858
typedef struct fs_list
5959
{
60-
int64 prev_fs;
61-
int64 next_fs;
60+
uint64 prev_fs;
61+
uint64 next_fs;
6262
} fs_list;
6363

6464
typedef struct DataEntry

0 commit comments

Comments
 (0)
0