public inbox for [email protected]
help / color / mirror / Atom feedpool_search_relcach does not consider session local cache case
3+ messages / 1 participants
[nested] [flat]
* pool_search_relcach does not consider session local cache case
@ 2026-03-20 02:53 Tatsuo Ishii <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Tatsuo Ishii @ 2026-03-20 02:53 UTC (permalink / raw)
To: [email protected]
While looking into https://github.com/pgpool/pgpool2/issues/154
I found a bug with pool_search_relcach.
pool_search_relcache does not consider the session local cache case
such as temp table search. It creates the search result in shared
relation cache even if the relation cache is session local. As a
result subsequent query against the session local cache is returned
from the shared relation cache. This could cause wrong
result. Example:
create table t1(i int);
select * from t1; -- info "t1 is not a temp table" is registered in shared cache
drop table t1;
create temp table t1(i int);
select * from t1; -- shared cache tells that t1 is not temp table and it could be load balanced,
-- it could access non existent table from standby nodes.
Fix is, to not register a temp table to shared relation cache if it's
a session local cache.
Patch attached.
Best regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pool_search_relcach does not consider session local cache case
@ 2026-03-25 09:46 Tatsuo Ishii <[email protected]>
parent: Tatsuo Ishii <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Tatsuo Ishii @ 2026-03-25 09:46 UTC (permalink / raw)
To: [email protected]
> While looking into https://github.com/pgpool/pgpool2/issues/154
> I found a bug with pool_search_relcach.
>
> pool_search_relcache does not consider the session local cache case
> such as temp table search. It creates the search result in shared
> relation cache even if the relation cache is session local. As a
> result subsequent query against the session local cache is returned
> from the shared relation cache. This could cause wrong
> result. Example:
>
> create table t1(i int);
> select * from t1; -- info "t1 is not a temp table" is registered in shared cache
> drop table t1;
> create temp table t1(i int);
> select * from t1; -- shared cache tells that t1 is not temp table and it could be load balanced,
> -- it could access non existent table from standby nodes.
>
> Fix is, to not register a temp table to shared relation cache if it's
> a session local cache.
>
> Patch attached.
Patch pushed to down to v4.4. A test is also added down to v4.5
(v4.4's test script is not suitable to apply the same patch as master
- v4.5).
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: pool_search_relcach does not consider session local cache case
@ 2026-03-26 00:55 Tatsuo Ishii <[email protected]>
parent: Tatsuo Ishii <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: Tatsuo Ishii @ 2026-03-26 00:55 UTC (permalink / raw)
To: [email protected]
>> While looking into https://github.com/pgpool/pgpool2/issues/154
>> I found a bug with pool_search_relcach.
>>
>> pool_search_relcache does not consider the session local cache case
>> such as temp table search. It creates the search result in shared
>> relation cache even if the relation cache is session local. As a
>> result subsequent query against the session local cache is returned
>> from the shared relation cache. This could cause wrong
>> result. Example:
>>
>> create table t1(i int);
>> select * from t1; -- info "t1 is not a temp table" is registered in shared cache
>> drop table t1;
>> create temp table t1(i int);
>> select * from t1; -- shared cache tells that t1 is not temp table and it could be load balanced,
>> -- it could access non existent table from standby nodes.
>>
>> Fix is, to not register a temp table to shared relation cache if it's
>> a session local cache.
>>
>> Patch attached.
>
> Patch pushed to down to v4.4. A test is also added down to v4.5
> (v4.4's test script is not suitable to apply the same patch as master
> - v4.5).
Even with this commit I see this: I repeated the sequence above
twice. Each cycle should produce the same result but actually it
doen't. In the second cycle "select * from t1;" is executed. At this
point t1 is an ordinary table and the select is expected to be
forwarded to standby but actually it's not.
select * from t1; -- expected to forward to standby
psql:b.sql:15: NOTICE: DB node id: 0 statement: select * from t1; -- Problem!
I think the reason is in pool_at_command_success().
/*
* If the query was CREATE TEMP TABLE, discard temp table relcache
* because we might have had persistent table relation cache which has
* table name as the temp table.
*/
if (IsA(node, CreateStmt))
{
CreateStmt *create_table_stmt = (CreateStmt *) node;
if (create_table_stmt->relation->relpersistence == 't')
discard_temp_table_relcache();
}
So, when a temp table is created, local relation cache for temporary
table is deleted. But when an ordinary table is created, it is not
deleted. Thus the select hits the temp table cache and fowarded to
primary. I will invest further how I can fix this.
=============================================================================
-- the first cycle
drop table t1;
psql:b.sql:2: NOTICE: DB node id: 0 statement: drop table t1;
psql:b.sql:2: ERROR: table "t1" does not exist
create table t1(i int); -- create ordinary table
psql:b.sql:3: NOTICE: DB node id: 0 statement: create table t1(i int);
CREATE TABLE
select pg_sleep(1); -- wait for 1 second so that standy gets replicated
psql:b.sql:4: NOTICE: DB node id: 0 statement: select pg_sleep(1);
pg_sleep
----------
(1 row)
select * from t1; -- expected to forward to standby
psql:b.sql:5: NOTICE: DB node id: 1 statement: select * from t1;
i
---
(0 rows)
drop table t1;
psql:b.sql:6: NOTICE: DB node id: 0 statement: drop table t1;
DROP TABLE
create temp table t1(i int); -- create temp table
psql:b.sql:7: NOTICE: DB node id: 0 statement: create temp table t1(i int);
CREATE TABLE
select pg_sleep(1); -- wait for 1 second so that standy gets replicated
psql:b.sql:8: NOTICE: DB node id: 0 statement: select pg_sleep(1);
pg_sleep
----------
(1 row)
select * from t1; -- expected to forward to primary
psql:b.sql:9: NOTICE: DB node id: 0 statement: select * from t1;
i
---
(0 rows)
-- the second cycle
drop table t1;
psql:b.sql:12: NOTICE: DB node id: 0 statement: drop table t1;
DROP TABLE
create table t1(i int); -- create ordinary table
psql:b.sql:13: NOTICE: DB node id: 0 statement: create table t1(i int);
CREATE TABLE
select pg_sleep(1); -- wait for 1 second so that standy gets replicated
psql:b.sql:14: NOTICE: DB node id: 0 statement: select pg_sleep(1);
pg_sleep
----------
(1 row)
select * from t1; -- expected to forward to standby
psql:b.sql:15: NOTICE: DB node id: 0 statement: select * from t1; -- Problem!
i
---
(0 rows)
drop table t1;
psql:b.sql:16: NOTICE: DB node id: 0 statement: drop table t1;
DROP TABLE
create temp table t1(i int); -- create temp table
psql:b.sql:17: NOTICE: DB node id: 0 statement: create temp table t1(i int);
CREATE TABLE
select pg_sleep(1); -- wait for 1 second so that standy gets replicated
psql:b.sql:18: NOTICE: DB node id: 0 statement: select pg_sleep(1);
pg_sleep
----------
(1 row)
select * from t1; -- expected to forward to primary
psql:b.sql:19: NOTICE: DB node id: 0 statement: select * from t1;
i
---
(0 rows)
=============================================================================
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-03-26 00:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-20 02:53 pool_search_relcach does not consider session local cache case Tatsuo Ishii <[email protected]>
2026-03-25 09:46 ` Tatsuo Ishii <[email protected]>
2026-03-26 00:55 ` Tatsuo Ishii <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox