@@ -1395,19 +1395,18 @@ aqo_data_store(uint64 fs, int fss, OkNNrdata *data, List *reloids)
1395
1395
LWLockAcquire (& aqo_state -> neighbours_lock , LW_EXCLUSIVE );
1396
1396
1397
1397
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 )
1404
1404
{
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 ;
1408
1407
}
1409
1408
prev -> data = entry ;
1410
-
1409
+ aqo_state -> neighbours_changed = true;
1411
1410
LWLockRelease (& aqo_state -> neighbours_lock );
1412
1411
}
1413
1412
@@ -1590,6 +1589,9 @@ load_aqo_data(uint64 fs, int fss, OkNNrdata *data, List **reloids,
1590
1589
neighbour_entry = (NeighboursEntry * ) hash_search (fss_neighbours , & fss , HASH_FIND , & found );
1591
1590
entry = found ? neighbour_entry -> data : NULL ;
1592
1591
1592
+ /*
1593
+ * Go through the list, starting from the first element and go to back.
1594
+ */
1593
1595
while (entry != NULL )
1594
1596
{
1595
1597
List * tmp_oids = NIL ;
@@ -1620,7 +1622,11 @@ load_aqo_data(uint64 fs, int fss, OkNNrdata *data, List **reloids,
1620
1622
1621
1623
build_knn_matrix (data , temp_data );
1622
1624
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 ;
1624
1630
}
1625
1631
LWLockRelease (& aqo_state -> neighbours_lock );
1626
1632
}
@@ -1758,15 +1764,15 @@ _aqo_data_clean(uint64 fs)
1758
1764
entry -> data_dp = InvalidDsaPointer ;
1759
1765
1760
1766
/* fix neighbour list */
1761
- if (entry -> list .next )
1767
+ if (entry -> neighbour_refs .next )
1762
1768
has_next = true;
1763
- if (entry -> list .prev )
1769
+ if (entry -> neighbour_refs .prev )
1764
1770
has_prev = true;
1765
1771
1766
1772
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 ;
1768
1774
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 ;
1770
1776
1771
1777
/* Fix or remove neighbours htab entry*/
1772
1778
LWLockAcquire (& aqo_state -> neighbours_lock , LW_EXCLUSIVE );
@@ -1775,14 +1781,23 @@ _aqo_data_clean(uint64 fs)
1775
1781
{
1776
1782
if (has_prev )
1777
1783
{
1778
- fss_htab_entry -> data = entry -> list .prev ;
1784
+ fss_htab_entry -> data = entry -> neighbour_refs .prev ;
1779
1785
}
1780
1786
else
1781
1787
{
1782
1788
hash_search (fss_neighbours , & entry -> key .fss , HASH_REMOVE , NULL );
1783
1789
}
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;
1784
1795
}
1785
1796
LWLockRelease (& aqo_state -> neighbours_lock );
1797
+ <<<<<<< HEAD
1798
+ == = == ==
1799
+
1800
+ >>>>>>> c4dbd74 (Fix after review )
1786
1801
1787
1802
if (!hash_search (data_htab , & entry -> key , HASH_REMOVE , NULL ))
1788
1803
elog (ERROR , "[AQO] hash table corrupted" );
@@ -2323,15 +2338,15 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
2323
2338
entry = (DataEntry * ) hash_search (data_htab , & key , HASH_FIND , & found );
2324
2339
if (found )
2325
2340
{
2326
- if (entry -> list .next )
2341
+ if (entry -> neighbour_refs .next )
2327
2342
has_next = true;
2328
- if (entry -> list .prev )
2343
+ if (entry -> neighbour_refs .prev )
2329
2344
has_prev = true;
2330
2345
2331
2346
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 ;
2333
2348
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 ;
2335
2350
2336
2351
/* Fix or remove neighbours htab entry*/
2337
2352
LWLockAcquire (& aqo_state -> neighbours_lock , LW_EXCLUSIVE );
@@ -2340,12 +2355,17 @@ cleanup_aqo_database(bool gentle, int *fs_num, int *fss_num)
2340
2355
{
2341
2356
if (has_prev )
2342
2357
{
2343
- fss_htab_entry -> data = entry -> list .prev ;
2358
+ fss_htab_entry -> data = entry -> neighbour_refs .prev ;
2344
2359
}
2345
2360
else
2346
2361
{
2347
2362
hash_search (fss_neighbours , & key .fss , HASH_REMOVE , NULL );
2348
2363
}
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;
2349
2369
}
2350
2370
LWLockRelease (& aqo_state -> neighbours_lock );
2351
2371
}
0 commit comments