| From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
|---|---|
| To: | pgpool-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: pool_search_relcach does not consider session local cache case |
| Date: | 2026-03-26 00:55:41 |
| Message-ID: | 20260326.095541.1427711606336049810.ishii@postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgpool-hackers |
>> 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2026-03-26 08:07:16 | Re: Rotate SSL certificates on reload (SIGHUP) without restart |
| Previous Message | Bob Ross | 2026-03-25 11:04:03 | Re: Rotate SSL certificates on reload (SIGHUP) without restart |