pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: matthew.r.maurer@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14809: Heap Corruption with deeply nested triggers.
Date: Sat, 09 Sep 2017 13:46:56 -0400
Message-ID: <5242.1504979216@sss.pgh.pa.us> (raw)
In-Reply-To: <20170909074855.25630.65205@wrigleys.postgresql.org>
References: <20170909074855.25630.65205@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

matthew.r.maurer@gmail.com writes:
> Log looks like: https://bpaste.net/show/4c1d3940ca27
> https://data.maurer.codes/clique.sql contains a reproduction case.

For the archives' sake, it'd have been better to include the test case.
The test isn't very large so I'll attach it below.

> On my machine, this consistently causes the glibc heap assertion in about 9
> seconds on a fresh database. If you get "ERROR:  stack depth limit exceeded"
> you may need to increase your max_stack_depth to observe the error (mine was
> 2MB, but is a release build, debug builds might need more to hit this).

I tried a few different max_stack_depth settings on both 9.6 and HEAD,
but was unable to reproduce a crash.  I see either a clean "stack depth
limit exceeded" failure, or successful completion of the query (at
stack depths above circa 3MB for me).  Tested on RHEL6 x86_64; maybe
some other platform would show the problem.

			regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

clique.sql (text/plain, 3.0K) download -- General initialization CREATE SCHEMA facts; -- Define predicates CREATE TABLE facts.edge (id serial PRIMARY KEY, arg0 bigint, arg1 bigint); CREATE TABLE facts.reachable (id serial PRIMARY KEY, arg0 bigint, arg1 bigint); CREATE TABLE facts.same_clique (id serial PRIMARY KEY, arg0 bigint, arg1 bigint); -- Restrict predicates to contain unique facts CREATE UNIQUE INDEX pred_edge_unique ON facts.edge (arg0,arg1); CREATE UNIQUE INDEX pred_reachable_unique ON facts.reachable (arg0,arg1); CREATE UNIQUE INDEX pred_same_clique_unique ON facts.same_clique (arg0,arg1); -- Add triggers to automate rules CREATE FUNCTION holmes_rule_reach_edge_0() RETURNS trigger AS $reach_edge$ BEGIN INSERT INTO facts.reachable (arg0, arg1) (SELECT NEW.arg0, NEW.arg1 ) ON CONFLICT DO NOTHING; RETURN NULL; END; $reach_edge$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_reach_edge_0 AFTER INSERT ON facts.edge FOR EACH ROW EXECUTE PROCEDURE holmes_rule_reach_edge_0(); ; CREATE FUNCTION holmes_rule_reach_trans_0() RETURNS trigger AS $reach_trans$ BEGIN INSERT INTO facts.reachable (arg0, arg1) (SELECT NEW.arg0, t0.arg1 FROM facts.reachable as t0 WHERE NEW.arg1 = t0.arg0) ON CONFLICT DO NOTHING; RETURN NULL; END; $reach_trans$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_reach_trans_0 AFTER INSERT ON facts.edge FOR EACH ROW EXECUTE PROCEDURE holmes_rule_reach_trans_0(); CREATE FUNCTION holmes_rule_reach_trans_1() RETURNS trigger AS $reach_trans$ BEGIN INSERT INTO facts.reachable (arg0, arg1) (SELECT t0.arg0, NEW.arg1 FROM facts.edge as t0 WHERE t0.arg1 = NEW.arg0) ON CONFLICT DO NOTHING; RETURN NULL; END; $reach_trans$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_reach_trans_1 AFTER INSERT ON facts.reachable FOR EACH ROW EXECUTE PROCEDURE holmes_rule_reach_trans_1(); ; CREATE FUNCTION holmes_rule_scc_0() RETURNS trigger AS $scc$ BEGIN INSERT INTO facts.same_clique (arg0, arg1) (SELECT NEW.arg0, NEW.arg1 FROM facts.reachable as t0 WHERE NEW.arg1 = t0.arg0 AND NEW.arg0 = t0.arg1) ON CONFLICT DO NOTHING; RETURN NULL; END; $scc$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_scc_0 AFTER INSERT ON facts.reachable FOR EACH ROW EXECUTE PROCEDURE holmes_rule_scc_0(); CREATE FUNCTION holmes_rule_scc_1() RETURNS trigger AS $scc$ BEGIN INSERT INTO facts.same_clique (arg0, arg1) (SELECT t0.arg0, t0.arg1 FROM facts.reachable as t0 WHERE t0.arg1 = NEW.arg0 AND t0.arg0 = NEW.arg1) ON CONFLICT DO NOTHING; RETURN NULL; END; $scc$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_scc_1 AFTER INSERT ON facts.reachable FOR EACH ROW EXECUTE PROCEDURE holmes_rule_scc_1(); ; CREATE FUNCTION insert_for_clique(iters int) RETURNS VOID as $$ DECLARE counter integer := 0; BEGIN LOOP EXIT WHEN counter = iters; INSERT INTO facts.edge (arg0, arg1) values (counter, counter + 1); counter := counter + 1; END LOOP; INSERT INTO facts.edge (arg0, arg1) values (counter, 0); END ; $$ LANGUAGE plpgsql; SELECT insert_for_clique(1000);

view thread (5+ messages)  latest in thread

Message-ID: <5242.1504979216@sss.pgh.pa.us>
Permalink:  ../5242.1504979216@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5242.1504979216@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, matthew.r.maurer@gmail.com
  Subject: Re: BUG #14809: Heap Corruption with deeply nested triggers.
  In-Reply-To: <5242.1504979216@sss.pgh.pa.us>
  References: <20170909074855.25630.65205@wrigleys.postgresql.org> <5242.1504979216@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox