"cache reference leak" issue happened when using sepgsql module - Mailing list pgsql-hackers

From Michael Luo
Subject "cache reference leak" issue happened when using sepgsql module
Date
Msg-id BYAPR08MB5606D1453D7F50E2AF4D2FD29AD80@BYAPR08MB5606.namprd08.prod.outlook.com
Whole thread Raw
Responses Re: "cache reference leak" issue happened when using sepgsql module  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi !

When using sepgsql module, I got warning "WARNING:  cache reference leak”. 
```
postgres=# UPDATE range_parted set c = 95 WHERE a = 'b' and b > 10 and c > 100 returning (range_parted), *;
WARNING:  cache reference leak: cache pg_attribute (7), tuple 38/54 has count 1
WARNING:  cache reference leak: cache pg_attribute (7), tuple 39/56 has count 1
WARNING:  cache reference leak: cache pg_attribute (7), tuple 53/51 has count 1
WARNING:  cache reference leak: cache pg_attribute (7), tuple 53/50 has count 1
 range_parted  | a | b  | c  | d  | e 
---------------+---+----+----+----+---
 (b,15,95,16,) | b | 15 | 95 | 16 | 
 (b,17,95,19,) | b | 17 | 95 | 19 | 
(2 rows)

UPDATE 2
postgres=# 
```
I am using the codes of Postgres REL_12_STABLE branch.
This issue can be reproduced by the SQLs below, and I test that on CentOS7 with “permissive” mode of SeLinux.

```
CREATE TABLE range_parted (a text, b bigint, c numeric, d int, e varchar) PARTITION BY RANGE (b);
CREATE TABLE part_b_10_b_20 (e varchar, c numeric, a text, b bigint, d int) PARTITION BY RANGE (c);
ALTER TABLE range_parted ATTACH PARTITION part_b_10_b_20 FOR VALUES FROM (10) TO (20);
CREATE TABLE part_c_100_200 (e varchar, c numeric, a text, b bigint, d int);
ALTER TABLE part_c_100_200 DROP COLUMN e, DROP COLUMN c, DROP COLUMN a;
ALTER TABLE part_c_100_200 ADD COLUMN c numeric, ADD COLUMN e varchar, ADD COLUMN a text;
ALTER TABLE part_c_100_200 DROP COLUMN b;
ALTER TABLE part_c_100_200 ADD COLUMN b bigint;
CREATE TABLE part_c_1_100 (e varchar, d int, c numeric, b bigint, a text);
ALTER TABLE part_b_10_b_20 ATTACH PARTITION part_c_1_100 FOR VALUES FROM (1) TO (100);
ALTER TABLE part_b_10_b_20 ATTACH PARTITION part_c_100_200 FOR VALUES FROM (100) TO (200);

\set init_range_parted 'truncate range_parted; insert into range_parted VALUES(''b'', 12, 96, 1), (''b'', 13, 97, 2), (''b'', 15, 105, 16), (''b'', 17, 105, 19)'
:init_range_parted;
UPDATE range_parted set c = 95 WHERE a = 'b' and b > 10 and c > 100 returning (range_parted), *;
```

The patch attached to fix this issue, please check it.

```
--- a/contrib/sepgsql/dml.c
+++ b/contrib/sepgsql/dml.c
@@ -69,7 +69,10 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
  continue;
 
  if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
+ {
+ ReleaseSysCache(tuple);
  continue;
+ }
 
  index = attno - FirstLowInvalidHeapAttributeNumber;
````





骆政丞 / Michael Luo
成都文武信息技术有限公司 / ChengDu WenWu Information Technology Co.,Ltd.
地址:成都高新区天府软件园 D 区 5 栋 1705                官网:http://w3.ww-it.cn.



Attachment

pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: sqlsmith crash incremental sort
Next
From: Tom Lane
Date:
Subject: Re: cleaning perl code