Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f54edd

Browse files
author
Alexandra Pervushina
committed
replace fs with DataEntry* in fss_neighbours htab
1 parent2a69432 commit1f54edd

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
returnsize;
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
booltblOverflow;
13021302
HASHACTIONaction;
13031303
boolresult;
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_keyprev_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
intnoids=-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_keykey= {.fs=entry->fs, .fss=lfirst_int(lc)};
21692167
boolfound;
2170-
boolhas_prev_fs= false;
2171-
boolhas_next_fs= false;
2172-
DataEntry*current_entry;
2173-
DataEntry*prev_entry;
2174-
DataEntry*next_entry;
2168+
boolhas_prev= false;
2169+
boolhas_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_keyneighbour_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
int64fss;/* just for alignment */
5656
}data_key;
5757

58-
typedefstructfs_list
58+
typedefstructDataEntryDataEntry;
59+
typedefstructneigbour_listneigbour_list;
60+
61+
structneigbour_list
5962
{
60-
uint64prev_fs;
61-
uint64next_fs;
62-
}fs_list;
63+
DataEntry*prev;
64+
DataEntry*next;
65+
};
6366

64-
typedefstructDataEntry
67+
structDataEntry
6568
{
6669
data_keykey;
67-
fs_listlist;
70+
neigbour_listlist;
6871

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

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

9295
typedefstructNeighboursEntry
9396
{
94-
int64fss;
95-
uint64fs;
97+
int64fss;
98+
DataEntry*data;
9699
}NeighboursEntry;
97100

98101
externintquerytext_max_size;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp