-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix caching detection for PostgreSQL 16+ versions #274
base: main
Are you sure you want to change the base?
Conversation
To detect cached StringInfo instance we repalloc decorator structure with 'cache' flag - this instance created in cached memory context. Older versions used 'MemoryContextContains' function which is not available in newer versions (deleted).
do you happen to have a test case that exposes the issue? |
Yes. That case passed, at least |
@ashenBlade don't we need somehow to take into account also static void
EvictCache(uint64 size)
{
...
StringInfo str = entry->store;
if (str->data) {
pfree(str->data);
}
pfree(str);
...
}
static void
EvictCache(uint64 size)
{
...
StringInfo str = entry->store;
if (str->data) {
pfree(str->data);
}
pfree(str);
...
}
void
FreeChunkData(ChunkData *chunkData)
{
...
for (columnIndex = 0; columnIndex < chunkData->columnCount; columnIndex++)
{
if (chunkData->existsArray[columnIndex] != NULL)
{
pfree(chunkData->existsArray[columnIndex]);
}
if (chunkData->valueArray[columnIndex] != NULL)
{
pfree(chunkData->valueArray[columnIndex]);
}
}
...
} So we pfree a garbage |
Maybe use
|
No, we do not free garbage.
But
|
I've added a regression test, you can add it to your MR. +1 vote for your approach |
tests were given in hydradatabase#273
Thanks, @ivan-v-kush. I've added these tests to my branch and they pass |
For caching separate
MemoryContext
context is used. And to detect thatStringInfo
instance is cached we useMemoryContextContains
function.But this works only for PG below 16 version - starting from 16 header, which used to contain pointer to
MemoryContext
, now used as special value with bitfields. So now this function can not be used - it just incorrect.I fixed this in such way. For PG <16 behaviour does not change - we use
MemoryContextContains
. But for newer we create special decorator like this:When we saved string info to cache we
repalloc
realStringInfo
with this struct and setcached
member totrue
(otherwise tofalse
). It should not hit performance, because size of struct isn't really big and we just do noop (inrepalloc
).This fixes bug described in #273