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

Skip to content

Commit 16e9ef5

Browse files
author
Alexandra Pervushina
committed
fix neighbours htab, fix list when performing aqo_cleanup
1 parent 7d6bd37 commit 16e9ef5

File tree

2 files changed

+71
-27
lines changed

2 files changed

+71
-27
lines changed

storage.c

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,18 +1291,17 @@ _compute_data_dsa(const DataEntry *entry)
12911291
bool
12921292
aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
12931293
{
1294-
DataEntry *entry;
1295-
bool found;
1296-
data_key key = {.fs = fs, .fss = fss};
1297-
fs_list neighbour_list = {0};
1298-
int i;
1299-
char *ptr;
1300-
ListCell *lc;
1301-
size_t size;
1302-
bool tblOverflow;
1303-
HASHACTION action;
1304-
bool result;
1305-
uint64 *prev_fs;
1294+
DataEntry *entry;
1295+
bool found;
1296+
data_key key = {.fs = fs, .fss = fss};
1297+
int i;
1298+
char *ptr;
1299+
ListCell *lc;
1300+
size_t size;
1301+
bool tblOverflow;
1302+
HASHACTION action;
1303+
bool result;
1304+
NeighboursEntry *prev_fs;
13061305

13071306
Assert(!LWLockHeldByMe(&aqo_state->data_lock));
13081307

@@ -1392,25 +1391,23 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13921391

13931392
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
13941393

1395-
prev_fs = (uint64 *) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
1394+
prev_fs = (NeighboursEntry *) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
13961395
if (!found)
13971396
{
1398-
//*prev_fs = fs;
1399-
memcpy(prev_fs, &entry->key.fs, sizeof(uint64));
1397+
entry->list.prev_fs = fs;
1398+
entry->list.next_fs = fs;
14001399
}
14011400
else
14021401
{
1403-
data_key prev_key = {.fs = *prev_fs, .fss = fss};
1402+
data_key prev_key = {.fs = prev_fs->fs, .fss = fss};
14041403
DataEntry *prev;
14051404

14061405
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;
1406+
prev->list.next_fs = fs;
1407+
entry->list.next_fs = fs;
1408+
entry->list.prev_fs = prev->key.fs;
14101409
}
1411-
1412-
prev_fs = (uint64 *) hash_search(fss_neighbours, &fss, HASH_FIND, &found);
1413-
elog(NOTICE, "%d 🗿🔫", found);
1410+
prev_fs->fs = entry->key.fs;
14141411

14151412
LWLockRelease(&aqo_state->neighbours_lock);
14161413

@@ -1421,8 +1418,6 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
14211418

14221419
memcpy(ptr, &key, sizeof(data_key)); /* Just for debug */
14231420
ptr += sizeof(data_key);
1424-
memcpy(ptr, &neighbour_list, sizeof(fs_list));
1425-
ptr += sizeof(fs_list);
14261421
if (entry->cols > 0)
14271422
{
14281423
for (i = 0; i < entry->rows; i++)
@@ -2170,9 +2165,52 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21702165
/* Remove junk records from aqo_data */
21712166
foreach(lc, junk_fss)
21722167
{
2173-
data_key key = {.fs = entry->fs, .fss = lfirst_int(lc)};
2174-
//TODO fix fs list
2175-
hash_search(fss_neighbours, &lfirst_int(lc), HASH_REMOVE, NULL);
2168+
data_key key = {.fs = entry->fs, .fss = lfirst_int(lc)};
2169+
bool found;
2170+
bool has_prev_fs = false;
2171+
bool has_next_fs = false;
2172+
DataEntry *current_entry;
2173+
DataEntry *prev_entry;
2174+
DataEntry *next_entry;
2175+
NeighboursEntry *fss_htab_entry;
2176+
2177+
/* fix fs list */
2178+
current_entry = (DataEntry *) hash_search(data_htab, &key, HASH_FIND, &found);
2179+
if (found)
2180+
{
2181+
data_key neighbour_key = {.fs = current_entry->list.prev_fs, .fss = key.fss};
2182+
2183+
if (key.fs != current_entry->list.prev_fs)
2184+
{
2185+
prev_entry = (DataEntry *) hash_search(data_htab, &neighbour_key, HASH_FIND, &has_prev_fs);
2186+
}
2187+
2188+
neighbour_key.fs = current_entry->list.next_fs;
2189+
if (key.fs != current_entry->list.next_fs)
2190+
{
2191+
next_entry = (DataEntry *) hash_search(data_htab, &neighbour_key, HASH_FIND, &has_next_fs);
2192+
}
2193+
2194+
if (has_prev_fs)
2195+
prev_entry->list.next_fs = has_next_fs ? current_entry->list.next_fs : prev_entry->key.fs;
2196+
if (has_next_fs)
2197+
next_entry->list.prev_fs = has_prev_fs ? current_entry->list.prev_fs : next_entry->key.fs;
2198+
2199+
}
2200+
2201+
/* Fix or remove neighbours htab entry*/
2202+
fss_htab_entry = (NeighboursEntry *) hash_search(fss_neighbours, &key.fss, HASH_FIND, &found);
2203+
if (found && fss_htab_entry->fs == key.fs)
2204+
{
2205+
if (has_prev_fs)
2206+
{
2207+
fss_htab_entry->fs = prev_entry->key.fs;
2208+
}
2209+
else
2210+
{
2211+
hash_search(fss_neighbours, &key.fss, HASH_REMOVE, NULL);
2212+
}
2213+
}
21762214
(*fss_num) += (int) _aqo_data_remove(&key);
21772215
}
21782216

storage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ typedef struct QueriesEntry
8989
bool auto_tuning;
9090
} QueriesEntry;
9191

92+
typedef struct NeighboursEntry
93+
{
94+
int64 fss;
95+
uint64 fs;
96+
} NeighboursEntry;
97+
9298
extern int querytext_max_size;
9399
extern int dsm_size_max;
94100

0 commit comments

Comments
 (0)