"cache reference leak" issue happened when using sepgsql module

From: Michael Luo <mkluo666(at)outlook(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: michael luo <zhengcheng(dot)luo(at)ww-it(dot)cn>
Subject: "cache reference leak" issue happened when using sepgsql module
Date: 2020-04-16 13:46:12
Message-ID: BYAPR08MB5606D1453D7F50E2AF4D2FD29AD80@BYAPR08MB5606.namprd08.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
sepgsql_bug_fix.patch application/octet-stream 426 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-04-16 13:53:46 Re: cleaning perl code
Previous Message Tomas Vondra 2020-04-16 12:51:01 Re: sqlsmith crash incremental sort