Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyNct-00007z-2F for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Jan 2013 14:17:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TyNcs-0003Ii-IP for pgsql-bugs@arkaria.postgresql.org; Thu, 24 Jan 2013 14:17:58 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyNcq-0003Ha-RX for pgsql-bugs@postgresql.org; Thu, 24 Jan 2013 14:17:57 +0000 Received: from moutng.kundenserver.de ([212.227.126.186]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TyNco-00064J-Uy for pgsql-bugs@postgresql.org; Thu, 24 Jan 2013 14:17:56 +0000 Received: from anarazel.de (p5DDC49C5.dip.t-dialin.net [93.220.73.197]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0LoMUn-1Ue4AC0MgL-00fsns; Thu, 24 Jan 2013 15:17:53 +0100 Received: by anarazel.de (Postfix, from userid 1000) id F2E7F1C0173; Thu, 24 Jan 2013 15:17:51 +0100 (CET) Date: Thu, 24 Jan 2013 15:17:51 +0100 From: Andres Freund To: Sandro Santilli Cc: pgsql-bugs@postgresql.org Subject: Re: cache lookup failed from empty plpythonu function Message-ID: <20130124141751.GB21296@awork2.anarazel.de> References: <20130124140336.GJ3157@gnash> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130124140336.GJ3157@gnash> X-Provags-ID: V02:K0:qRtLH55LFpLmHqu4pBgWMbEzdtQ3c9yzN1fpNQtfw84 xSN78D/7jrL3nxwEXqUCkXw4pUOnR2tvLu3Kazct4Zz5C3CN+b HkEVZfxbkhjeNqRWzzt+mVjb7ZswQRMCXsjzhIBxKEWQuBy7kc cK2YWtuYH8NJ58mH5BVJNkZJKWzUy6ENFMDp8xnMEPQ4GstSEh 4r8ZomjceLRTLDRqP71fngocd/tKYNLbtnJmrPy6lI+km3ENa1 dJwNjpHGWWBoLL8v4u6/ZeJ8FzCKl2prDWhtaphlGj3OyFTLbU P17lUp5btqtXBzZTxz2Hu9rxNV2oZRj6V3TmTWSL99fxx2CPPN BP6I64HiXlcswSb4QTL3ZSkkJvQhr2AGjOVQam4we X-Pg-Spam-Score: -1.9 (-) 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 On 2013-01-24 15:03:36 +0100, Sandro Santilli wrote: > I've found a bug in plpythonu resulting in a "cache lookup" failure. > Here's the SQL to reproduce (thanks Andres): > > CREATE EXTENSION plpythonu; > CREATE OR REPLACE FUNCTION t() RETURNS trigger AS 'pass' LANGUAGE 'plpythonu'; > CREATE TABLE a(); > CREATE TABLE b(); > CREATE TRIGGER check_quota AFTER INSERT ON a FOR EACH ROW EXECUTE PROCEDURE t(); > INSERT INTO a DEFAULT VALUES; > DROP TABLE a; > CREATE TRIGGER check_quota > AFTER INSERT ON b FOR EACH ROW EXECUTE PROCEDURE t(); > INSERT INTO b DEFAULT VALUES; > --ERROR: cache lookup failed for relation 20200 > --Time: 0.570 ms > -- cleanup with DROP TABLE b; DROP FUNCTION t(); > > Logs show: > > ERROR: XX000: cache lookup failed for relation 3694414 > LOCATION: PLy_procedure_argument_valid, plpython.c:1469 > > Andres (in IRC #postgresql) said: > > hm, I think I see the problem. The caching there looks pretty > broken to me. > i.e. the caching doesn't work *at all* if a function is used > as a trigger for more than one table and this is just fallout > of that. > Looks like a typo to me, procedure_get should use the table's > oid instead of fn_oid when doing lookups in PLy_trigger_cache. ISTM the caching code for plpythonu trigger functions has been broken for some time. The bug seem to be that PLy_procedure_get looks up the function in a separate cache for trigger functions (PLy_trigger_cache) but still only uses the function oid for lookup. So the same function can be looked up for two tables and when the cached entry originally refers to the old table that has been dropped we see the above error. The fix seems tob e to make PLy_trigger_cache have a key of (reloid, fn_oid) instead of just fn_oid. Other suggestions? Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs