Memory leak when querying GIN indexes

From: Julien Rouhaud <julien(dot)rouhaud(at)dalibo(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: "adrien(dot)nayrat" <adrien(dot)nayrat(at)dalibo(dot)com>
Subject: Memory leak when querying GIN indexes
Date: 2016-04-14 19:42:10
Message-ID: 570FF292.2060606@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

My colleague Adrien reported me a memory leak in GIN indexes while doing
some benchmark on several am.

Here is a test case to reproduce the issue:

CREATE TABLE test AS (
SELECT t
FROM generate_series(now(), now() + interval '10 day', '1 second')
AS d(t)
CROSS JOIN generate_series(1, 100) s
);
CREATE EXTENSON btree_gin;
CREATE INDEX ON test USING gin(t);

EXPLAIN ANALYZE SELECT * FROM test WHERE t >= now() and t < now() +
interval '10 day';

The last query will consume approximately 4GB of RAM (might need to
force index scan) in ExecutorState memory context.

I'm not at all familiar with GIN code, but naive attached patch seems to
fix the issue and not break anything. I can reproduce this issue up to 9.4.

Regards

--
Julien Rouhaud
http://dalibo.com - http://dalibo.org

Attachment Content-Type Size
fix_leak_gin_bitmap_v1.diff text/plain 491 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Verite 2016-04-14 19:59:52 Re: \crosstabview fixes
Previous Message David Steele 2016-04-14 19:13:11 Re: pg_basebackup creates a corrupt file for pg_stat_tmp and pg_replslot on a backup location