10000 Fix after review · postgrespro/aqo@dbd9159 · GitHub
[go: up one dir, main page]

Skip to content

Commit dbd9159

Browse files
author
Alexandra Pervushina
committed
Fix after review
1 parent bcd1092 commit dbd9159

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

storage.c

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,19 +1395,18 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
13951395
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
13961396

13971397
prev = (NeighboursEntry *) hash_search(fss_neighbours, &key.fss, HASH_ENTER, &found);
1398-
if (!found)
1399-
{
1400-
entry->list.prev = NULL;
1401-
entry->list.next = NULL;
1402-
}
1403-
else
1398+
1399+
/* A new element contains backward link to the first element list and
1400+
* the first element contains toward link to the new element.
1401+
* The new element has become the first element of the list.
1402+
*/
1403+
if (found)
14041404
{
1405-
prev->data->list.next = entry;
1406-
entry->list.next = NULL;
1407-
entry->list.prev = prev->data;
1405+
prev->data->neighbour_refs.next = entry;
1406+
entry->neighbour_refs.prev = prev->data;
14081407
}
14091408
prev->data = entry;
1410-
1409+
aqo_state->neighbours_changed = true;
14111410
LWLockRelease(&aqo_state->neighbours_lock);
14121411
}
14131412

@@ -1590,6 +1589,9 @@ load_aqo_data(uint64 fs, int fss, OkNNrdata *data, List **reloids,
15901589
neighbour_entry = (NeighboursEntry *) hash_search(fss_neighbours, &fss, HASH_FIND, &found);
15911590
entry = found ? neighbour_entry->data : NULL;
15921591

1592+
/*
1593+
* Go through the list, starting from the first element and go to back.
1594+
*/
15931595
while (entry != NULL)
15941596
{
15951597
List *tmp_oids = NIL;
@@ -1620,7 +1622,11 @@ load_aqo_data(uint64 fs, int fss, OkNNrdata *data, List **reloids,
16201622

16211623
build_knn_matrix(data, temp_data);
16221624

1623-
entry = entry->list.prev;
1625+
/*
1626+
* We have a backward oriented list since the first element always stay
1627+
* the last element of list, so go to the next element on the backward link.
1628+
*/
1629+
entry = entry->neighbour_refs.prev;
16241630
}
16251631
LWLockRelease(&aqo_state->neighbours_lock);
16261632
}
@@ -1758,15 +1764,15 @@ _aqo_data_clean(uint64 fs)
17581764
entry->data_dp = InvalidDsaPointer;
17591765

17601766
/* fix neighbour list */
1761-
if (entry->list.next)
1767+
if (entry->neighbour_refs.next)
17621768
has_next = true;
1763-
if (entry->list.prev)
1769+
if (entry->neighbour_refs.prev)
17641770
has_prev = true;
17651771

17661772
if (has_prev)
1767-
entry->list.prev->list.next = has_next ? entry->list.next : NULL;
1773+
entry->neighbour_refs.prev->neighbour_refs.next = has_next ? entry->neighbour_refs.next : NULL;
17681774
if (has_next)
1769-
entry->list.next->list.prev = has_prev ? entry->list.prev : NULL;
1775+
entry->neighbour_refs.next->neighbour_refs.prev = has_prev ? entry->neighbour_refs.prev : NULL;
17701776

17711777
/* Fix or remove neighbours htab entry*/
17721778
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
@@ -1775,14 +1781,23 @@ _aqo_data_clean(uint64 fs)
17751781
{
17761782
if (has_prev)
17771783
{
1778-
fss_htab_entry->data = entry->list.prev;
1784+
fss_htab_entry->data = entry->neighbour_refs.prev;
17791785
}
17801786
else
17811787
{
17821788
hash_search(fss_neighbours, &entry->key.fss, HASH_REMOVE, NULL);
17831789
}
1790+
/*
1791+
* We found element in Neibours hash table and made change:
1792+
* either delete element of table or replace its value.
1793+
*/
1794+
aqo_state->neighbours_changed = true;
17841795
}
17851796
LWLockRelease(&aqo_state->neighbours_lock);
1797+
<<<<<<< HEAD
1798+
=======
1799+
1800+
>>>>>>> c4dbd74 (Fix after review)
17861801

17871802
if (!hash_search(data_htab, &entry->key, HASH_REMOVE, NULL))
17881803
elog(ERROR, "[AQO] hash table corrupted");
@@ -2323,15 +2338,15 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
23232338
entry = (DataEntry *) hash_search(data_htab, &key, HASH_FIND, &found);
23242339
if (found)
23252340
{
2326-
if (entry->list.next)
2341+
if (entry->neighbour_refs.next)
23272342
has_next = true;
2328-
if (entry->list.prev)
2343+
if (entry->neighbour_refs.prev)
23292344
has_prev = true;
23302345

23312346
if (has_prev)
2332-
entry->list.prev->list.next = has_next ? entry->list.next : NULL;
2347+
entry->neighbour_refs.prev->neighbour_refs.next = has_next ? entry->neighbour_refs.next : NULL;
23332348
if (has_next)
2334-
entry->list.next->list.prev = has_prev ? entry->list.prev : NULL;
2349+
entry->neighbour_refs.next->neighbour_refs.prev = has_prev ? entry->neighbour_refs.prev : NULL;
23352350

23362351
/* Fix or remove neighbours htab entry*/
23372352
LWLockAcquire(&aqo_state->neighbours_lock, LW_EXCLUSIVE);
@@ -2340,12 +2355,17 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
23402355
{
23412356
if (has_prev)
23422357
{
2343-
fss_htab_entry->data = entry->list.prev;
2358+
fss_htab_entry->data = entry->neighbour_refs.prev;
23442359
}
23452360
else
23462361
{
23472362
hash_search(fss_neighbours, &key.fss, HASH_REMOVE, NULL);
23482363
}
2364+
/*
2365+
* We found element in Neibours hash table and made change:
2366+
* either delete element of table or replace its value.
2367+
*/
2368+
aqo_state->neighbours_changed = true;
23492369
}
23502370
LWLockRelease(&aqo_state->neighbours_lock);
23512371
}

storage.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ typedef struct data_key
5656
} data_key;
5757

5858
typedef struct DataEntry DataEntry;
59-
typedef struct neigbour_list neigbour_list;
59+
typedef struct neighbour_references neighbour_references;
6060

61-
struct neigbour_list
61+
struct neighbour_references
6262
{
6363
DataEntry *prev;
6464
DataEntry *next;
@@ -67,7 +67,7 @@ struct neigbour_list
6767
struct DataEntry
6868
{
6969
data_key key;
70-
neigbour_list list;
70+
neighbour_references neighbour_refs;
7171

7272
/* defines a size and data placement in the DSA memory block */
7373
int cols; /* aka nfeatures */

0 commit comments

Comments
 (0)
0