hot data precache bug fix

This commit is contained in:
peitingwei 2023-03-30 19:40:59 +08:00
parent 6dc26f4fc2
commit f0be4235d8
3 changed files with 10 additions and 3 deletions

View File

@ -792,15 +792,15 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum,
*/
pgstat_count_buffer_read(reln);
/* precache index */
if (isPreCacheIndex && preCacheIndexNode == reln->rd_node.relNode)
if (isPreCacheIndex && !isPreCacheIndexDone && preCacheIndexNode == reln->rd_node.relNode)
{
BlockNumber precacheblocks;
precacheblocks = smgrnblocks(reln->rd_smgr, forkNum);
for(BlockNumber i=0; i < precacheblocks; i++)
{
ReadBuffer_common(reln->rd_smgr, reln->rd_rel->relpersistence, forkNum, i, mode, strategy, &hit);
ReleaseBuffer(ReadBuffer_common(reln->rd_smgr, reln->rd_rel->relpersistence, forkNum, i, mode, strategy, &hit));
}
isPreCacheIndex = false;
isPreCacheIndexDone = true;
}
buf = ReadBuffer_common(reln->rd_smgr, reln->rd_rel->relpersistence,

View File

@ -88,6 +88,7 @@
*/
bool isPreCacheTable = false;
bool isPreCacheIndex = false;
bool isPreCacheIndexDone = false;
bool needPreCacheEscape = false;
Oid preCacheIndexNode = 0;
const char *debug_query_string; /* client-supplied query string */
@ -1219,6 +1220,10 @@ exec_simple_query(const char *query_string)
{
needPreCacheEscape = true;
}
else
{
needPreCacheEscape = false;
}
/*
* Run the portal to completion, and then drop it (and the receiver).
*/
@ -4515,6 +4520,7 @@ PostgresMain(int argc, char *argv[], bool PrivateConn,
else if (strstr(query_string, "precache index ") != NULL && query_string - strstr(query_string, "precache index ") == 0)
{
isPreCacheIndex = true;
isPreCacheIndexDone = false;
exec_simple_query(query_string + strlen("precache index "));
isPreCacheIndex = false;
}

View File

@ -81,6 +81,7 @@ extern int bulk_io_in_progress_count;
extern bool isPreCacheTable;
extern bool isPreCacheIndex;
extern bool isPreCacheIndexDone
extern bool needPreCacheEscape;
extern Oid preCacheIndexNode;