8000 replace fs with DataEntry* in fss_neighbours htab · postgrespro/aqo@1f54edd · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f54edd

Browse files
author
Alexandra Pervushina
committed
replace fs with DataEntry* in fss_neighbours htab
1 parent 2a69432 commit 1f54edd

File tree

3 files changed

+50
-60
lines changed

3 files changed

+50
-60
lines changed

aqo_shared.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ aqo_init_shmem(void)
243243

244244
/* Shared memory hash table for fss neighbours */
245245
info.keysize = sizeof(int);
246-
info.entrysize = sizeof(uint64);
246+
info.entrysize = sizeof(DataEntry *);
247247
fss_neighbours = ShmemInitHash("AQO fss neighbours HTAB", fss_max_items, fss_max_items,
248248
&info, HASH_ELEM | HASH_BLOBS);
249249

@@ -296,7 +296,7 @@ aqo_memsize(void)
296296
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(QueryTextEntry)));
297297
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(DataEntry)));
298298
size = add_size(size, hash_estimate_size(fs_max_items, sizeof(QueriesEntry)));
299-
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(uint64)));
299+
size = add_size(size, hash_estimate_size(fss_max_items, sizeof(DataEntry *)));
300300

301301
return size;
302302
}

storage.c

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13011301
bool tblOverflow;
13021302
HASHACTION action;
13031303
bool result;
1304-
NeighboursEntry *prev_fs;
1304+
NeighboursEntry *prev;
13051305

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

@@ -1389,28 +1389,25 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13891389
* Find prev fs with the same fss
13901390
*/
13911391

1392-
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
1392+
if (!found) {
1393+
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
13931394

1394-
prev_fs = (NeighboursEntry *) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
1395-
if (!found)
1396-
{
1397-
entry->list.prev_fs = fs;
1398-
entry->list.next_fs = fs;
1399-
}
1400-
else
1401-
{
1402-
data_key prev_key = {.fs = prev_fs->fs, .fss = fss};
1403-
DataEntry *prev;
1395+
prev = (NeighboursEntry *) hash_search(fss_neighbours, &fss, HASH_ENTER, &found);
1396+
if (!found)
1397+
{
1398+
entry->list.prev = NULL;
1399+
entry->list.next = NULL;
1400+
}
1401+
else
1402+
{
1403+
prev->data->list.next = entry;
1404+
entry->list.next = NULL;
1405+
entry->list.prev = prev->data;
1406+
}
1407+
prev->data = entry;
14041408

1405-
prev = (DataEntry *) hash_search(data_htab, &prev_key, HASH_FIND, NULL);
1406-
prev->list.next_fs = fs;
1407-
entry->list.next_fs = fs;
1408-
entry->list.prev_fs = prev->key.fs;
1409+
LWLockRelease(&aqo_state->neighbours_lock);
14091410
}
1410-
prev_fs->fs = entry->key.fs;
1411-
1412-
LWLockRelease(&aqo_state->neighbours_lock);
1413-
14141411

14151412
/*
14161413
* Copy AQO data into allocated DSA segment
@@ -1587,6 +1584,7 @@ load_aqo_data(uint64 fs, int fss, OkNNrdata *data, List **reloids,
15871584
int noids = -1;
15881585

15891586
found = false;
1587+
// TODO replace with hash
15901588
hash_seq_init(&hash_seq, data_htab);
15911589
while ((entry = hash_seq_search(&hash_seq)) != NULL)
15921590
{
@@ -1681,8 +1679,8 @@ aqo_data(PG_FUNCTION_ARGS)
16811679
values[AD_FS] = Int64GetDatum(entry->key.fs);
16821680
values[AD_FSS] = Int32GetDatum((int) entry->key.fss);
16831681
values[AD_NFEATURES] = Int32GetDatum(entry->cols);
1684-
values[AD_PREV_FS] = Int64GetDatum(entry->list.prev_fs);
1685-
values[AD_NEXT_FS] = Int64GetDatum(entry->list.next_fs);
1682+
values[AD_PREV_FS] = Int64GetDatum(entry->list.prev);
1683+
values[AD_NEXT_FS] = Int64GetDatum(entry->list.next);
16861684

16871685
/* Fill values from the DSA data chunk */
16881686
Assert(DsaPointerIsValid(entry->data_dp));
@@ -2167,44 +2165,33 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
21672165
{
21682166
data_key key = {.fs = entry->fs, .fss = lfirst_int(lc)};
21692167
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;
2168+
bool has_prev = false;
2169+
bool has_next = false;
2170+
DataEntry *entry;
21752171
NeighboursEntry *fss_htab_entry;
21762172

21772173
/* fix fs list */
2178-
current_entry = (DataEntry *) hash_search(data_htab, &key, HASH_FIND, &found);
2174+
entry = (DataEntry *) hash_search(data_htab, &key, HASH_FIND, &found);
21792175
if (found)
21802176
{
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-
2177+
if (entry->list.next)
2178+
has_next = true;
2179+
if (entry->list.prev)
2180+
has_prev = true;
2181+
2182+
if (has_prev)
2183+
entry->list.prev->list.next = has_next ? entry->list.next : NULL;
2184+
if (has_next)
2185+
entry->list.next->list.prev = has_prev ? entry->list.prev : NULL;
21992186
}
22002187

22012188
/* Fix or remove neighbours htab entry*/
22022189
fss_htab_entry = (NeighboursEntry *) hash_search(fss_neighbours, &key.fss, HASH_FIND, &found);
2203-
if (found && fss_htab_entry->fs == key.fs)
2190+
if (found && fss_htab_entry->data->key.fs == key.fs)
22042191
{
2205-
if (has_prev_fs)
2192+
if (has_prev)
22062193
{
2207-
fss_htab_entry->fs = prev_entry->key.fs;
2194+
fss_htab_entry->data = entry->list.prev;
22082195
}
22092196
else
22102197
{

storage.h

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

58-
typedef struct fs_list
58+
typedef struct DataEntry DataEntry;
59+
typedef struct neigbour_list neigbour_list;
60+
61+
struct neigbour_list
5962
{
60-
uint64 prev_fs;
61-
uint64 next_fs;
62-
} fs_list;
63+
DataEntry *prev;
64+
DataEntry *next;
65+
};
6366

64-
typedef struct DataEntry
67+
struct DataEntry
6568
{
6669
data_key key;
67-
fs_list list;
70+
neigbour_list list;
6871

6972
/* defines a size and data placement in the DSA memory block */
7073
int cols; /* aka nfeatures */
@@ -77,7 +80,7 @@ typedef struct DataEntry
7780
* matrix[][], targets[], reliability[], oids.
7881
*/
7982
dsa_pointer data_dp;
80-
} DataEntry;
83+
};
8184

8285
typedef struct QueriesEntry
8386
{
@@ -91,8 +94,8 @@ typedef struct QueriesEntry
9194

9295
typedef struct NeighboursEntry
9396
{
94-
int64 fss;
95-
uint64 fs;
97+
int64 fss;
98+
DataEntry *data;
9699
} NeighboursEntry;
97100

98101
extern int querytext_max_size;

0 commit comments

Comments
 (0)
0