Fix caching detection for PostgreSQL 16+ versions#274
Open
ashenBlade wants to merge 6 commits intohydradatabase:mainfrom
Open
Fix caching detection for PostgreSQL 16+ versions#274ashenBlade wants to merge 6 commits intohydradatabase:mainfrom
ashenBlade wants to merge 6 commits intohydradatabase:mainfrom
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).
Contributor
|
do you happen to have a test case that exposes the issue? |
Contributor
Author
|
Yes. That case passed, at least |
Contributor
|
@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 |
Contributor
|
Maybe use |
Contributor
Author
|
No, we do not free garbage.
But
|
Contributor
|
I've added a regression test, you can add it to your MR. +1 vote for your approach |
tests were given in hydradatabase#273
Contributor
Author
|
Thanks, @ivan-v-kush. I've added these tests to my branch and they pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For caching separate
MemoryContextcontext is used. And to detect thatStringInfoinstance is cached we useMemoryContextContainsfunction.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
repallocrealStringInfowith this struct and setcachedmember 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