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

Commit92c4c26

Browse files
committed
Move memory accounting Asserts for Result Cache code
In9eacee2, I included some code to verify the cache's memory trackingis correct by counting up the number of entries and the memory they useeach time we evict something from the cache. Those values are thencompared to the expected values using Assert. The problem is that thisrequires looping over the entire cache hash table each time we evict anentry from the cache. That can be pretty expensive, as noted by PavelStehule.Here we move this memory accounting checking code so that we only verifyit on cassert builds once when shutting down the Result Cache node.Aside from the performance increase, this has two distinct advantages:1) We do the memory checks at the last possible moment before destroying the cache. This means we'll now catch accounting problems that might sneak in after a cache eviction.2) We now do the memory Assert checks when there were no cache evictions. This increases the coverage.One small disadvantage is that we'll now miss any memory tracking issuesthat somehow managed to resolve themselves by the end of execution.However, it seems to me that such a memory tracking problem would be quiteunlikely, and likely somewhat less harmful if one were to exist.In passing, adjust the loop over the hash table to use the standardsimplehash.h method of iteration.Reported-by: Pavel StehuleDiscussion:https://postgr.es/m/CAFj8pRAzgoSkdEiqrKbT=7yG9FA5fjUAP3jmJywuDqYq6Ki5ug@mail.gmail.com
1 parenta55a984 commit92c4c26

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

‎src/backend/executor/nodeResultCache.c

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -298,41 +298,6 @@ remove_cache_entry(ResultCacheState *rcstate, ResultCacheEntry *entry)
298298

299299
dlist_delete(&entry->key->lru_node);
300300

301-
#ifdefUSE_ASSERT_CHECKING
302-
303-
/*
304-
* Validate the memory accounting code is correct in assert builds. XXX is
305-
* this too expensive for USE_ASSERT_CHECKING?
306-
*/
307-
{
308-
inti,
309-
count;
310-
uint64mem=0;
311-
312-
count=0;
313-
for (i=0;i<rcstate->hashtable->size;i++)
314-
{
315-
ResultCacheEntry*entry=&rcstate->hashtable->data[i];
316-
317-
if (entry->status==resultcache_SH_IN_USE)
318-
{
319-
ResultCacheTuple*tuple=entry->tuplehead;
320-
321-
mem+=EMPTY_ENTRY_MEMORY_BYTES(entry);
322-
while (tuple!=NULL)
323-
{
324-
mem+=CACHE_TUPLE_BYTES(tuple);
325-
tuple=tuple->next;
326-
}
327-
count++;
328-
}
329-
}
330-
331-
Assert(count==rcstate->hashtable->members);
332-
Assert(mem==rcstate->mem_used);
333-
}
334-
#endif
335-
336301
/* Remove all of the tuples from this entry */
337302
entry_purge_tuples(rcstate,entry);
338303

@@ -977,6 +942,35 @@ ExecInitResultCache(ResultCache *node, EState *estate, int eflags)
977942
void
978943
ExecEndResultCache(ResultCacheState*node)
979944
{
945+
#ifdefUSE_ASSERT_CHECKING
946+
/* Validate the memory accounting code is correct in assert builds. */
947+
{
948+
intcount;
949+
uint64mem=0;
950+
resultcache_iteratori;
951+
ResultCacheEntry*entry;
952+
953+
resultcache_start_iterate(node->hashtable,&i);
954+
955+
count=0;
956+
while ((entry=resultcache_iterate(node->hashtable,&i))!=NULL)
957+
{
958+
ResultCacheTuple*tuple=entry->tuplehead;
959+
960+
mem+=EMPTY_ENTRY_MEMORY_BYTES(entry);
961+
while (tuple!=NULL)
962+
{
963+
mem+=CACHE_TUPLE_BYTES(tuple);
964+
tuple=tuple->next;
965+
}
966+
count++;
967+
}
968+
969+
Assert(count==node->hashtable->members);
970+
Assert(mem==node->mem_used);
971+
}
972+
#endif
973+
980974
/*
981975
* When ending a parallel worker, copy the statistics gathered by the
982976
* worker back into shared memory so that it can be picked up by the main

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp