Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dqjqW-0007PT-MM for pgsql-bugs@arkaria.postgresql.org; Sat, 09 Sep 2017 17:47:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dqjqV-0004kz-OY for pgsql-bugs@arkaria.postgresql.org; Sat, 09 Sep 2017 17:47:07 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dqjqU-0004kS-1L for pgsql-bugs@postgresql.org; Sat, 09 Sep 2017 17:47:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dqjqM-0000hd-GQ for pgsql-bugs@postgresql.org; Sat, 09 Sep 2017 17:47:04 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v89HkuwG005243; Sat, 9 Sep 2017 13:46:56 -0400 From: Tom Lane To: matthew.r.maurer@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14809: Heap Corruption with deeply nested triggers. In-reply-to: <20170909074855.25630.65205@wrigleys.postgresql.org> References: <20170909074855.25630.65205@wrigleys.postgresql.org> Comments: In-reply-to matthew.r.maurer@gmail.com message dated "Sat, 09 Sep 2017 07:48:55 -0000" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <5090.1504978970.0@sss.pgh.pa.us> Date: Sat, 09 Sep 2017 13:46:56 -0400 Message-ID: <5242.1504979216@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5090.1504978970.1@sss.pgh.pa.us> 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 ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="clique.sql"; charset="us-ascii" Content-ID: <5090.1504978970.2@sss.pgh.pa.us> Content-Description: clique.sql Content-Transfer-Encoding: quoted-printable -- 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 bigi= nt); CREATE TABLE facts.same_clique (id serial PRIMARY KEY, arg0 bigint, arg1 bi= gint); -- 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 =3D 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 =3D NEW.arg0) ON CONFLICT DO NOTHING; RETURN NULL; END; $reach_trans$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_reach_trans_1 AFTER INSERT ON facts.reachabl= e 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 F= ROM facts.reachable as t0 WHERE NEW.arg1 =3D t0.arg0 AND NEW.arg0 =3D t0.ar= g1) ON CONFLICT DO NOTHING; RETURN NULL; END; $scc$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_scc_0 AFTER INSERT ON facts.reachable FOR EA= CH 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 FRO= M facts.reachable as t0 WHERE t0.arg1 =3D NEW.arg0 AND t0.arg0 =3D NEW.arg1= ) ON CONFLICT DO NOTHING; RETURN NULL; END; $scc$ LANGUAGE plpgsql; CREATE TRIGGER holmes_rule_scc_1 AFTER INSERT ON facts.reachable FOR EA= CH ROW EXECUTE PROCEDURE holmes_rule_scc_1(); ; CREATE FUNCTION insert_for_clique(iters int) RETURNS VOID as $$ DECLARE counter integer :=3D 0; BEGIN LOOP EXIT WHEN counter =3D iters; INSERT INTO facts.edge (arg0, arg1) values (counter, counter + 1);=20 counter :=3D counter + 1; END LOOP; INSERT INTO facts.edge (arg0, arg1) values (counter, 0); END ; $$ LANGUAGE plpgsql; SELECT insert_for_clique(1000); ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs ------- =_aaaaaaaaaa0--