Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 2BA5EB5DBD8 for ; Mon, 22 Aug 2011 10:26:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 66351-06 for ; Mon, 22 Aug 2011 13:26:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from acidenitrix.villemain.org (acidenitrix.villemain.org [91.121.90.165]) by mail.postgresql.org (Postfix) with ESMTP id 0C080B5DBF6 for ; Mon, 22 Aug 2011 10:25:59 -0300 (ADT) Received: from localhost ([127.0.0.1] helo=dim) by acidenitrix.villemain.org with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1QvUVp-0004hB-TQ; Mon, 22 Aug 2011 15:25:57 +0200 Received: by dim (Postfix, from userid 1000) id 19EAD403DF; Mon, 22 Aug 2011 15:25:57 +0200 (CEST) From: Dimitri Fontaine To: Tom Lane Cc: Dimitri Fontaine , "Hitoshi Harada" , pgsql-bugs@postgresql.org Subject: Re: BUG #6172: DROP EXTENSION error without CASCADE Organization: 2ndQuadrant References: <201108211644.p7LGibJ1064013@wwwmaster.postgresql.org> <10160.1313967820@sss.pgh.pa.us> User-Mail-Address: dimitri@2ndQuadrant.fr Date: Mon, 22 Aug 2011 15:25:57 +0200 In-Reply-To: <10160.1313967820@sss.pgh.pa.us> (Tom Lane's message of "Sun, 21 Aug 2011 19:03:40 -0400") Message-ID: <878vqla87u.fsf@hi-media-techno.com> User-Agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201108/132 X-Sequence-Number: 30944 Tom Lane writes: > I'm betting it's got something to do with > http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=eb15f26d577a11319b9429fb84f752a0135918db You're right, once more. Here's what I understand is happening from reading the code. No patch attached, the scope of change I did is not calling for one. I include full analysis in case you want to fix it in another way, I could have missed something important here. For reference, the error we're tracking begins with: ERROR: cannot drop extension cube because other objects depend on it DETAIL: operator <>(cube,cube) depends on function cube_ne(cube,cube) The problem is that the following SQL will create the <> operator as a Shell Operator then complete its definition later. CREATE OPERATOR = ( LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_eq, COMMUTATOR = '=', NEGATOR = '<>', RESTRICT = eqsel, JOIN = eqjoinsel, MERGES ); Here it's quite obvious that the '<>' operator (created as a shell) is missing the dependency: ~:54320=# select oid, oprname from pg_operator where oprleft = 'cube'::regtype and oprright = 'cube'::regtype and oprname in ('=', '<>'); oid | oprname -------+--------- 16421 | <> 16422 | = (2 rows) ~:54320=# select * from pg_depend where classid = 'pg_operator'::regclass and objid in (16421, 16422); classid | objid | objsubid | refclassid | refobjid | refobjsubid | deptype ---------+-------+----------+------------+----------+-------------+--------- 2617 | 16421 | 0 | 1255 | 16393 | 0 | n 2617 | 16421 | 0 | 1247 | 16386 | 0 | n 2617 | 16421 | 0 | 1247 | 16386 | 0 | n 2617 | 16421 | 0 | 2615 | 2200 | 0 | n 2617 | 16422 | 0 | 3079 | 16385 | 0 | e 2617 | 16422 | 0 | 1255 | 16392 | 0 | n 2617 | 16422 | 0 | 1247 | 16386 | 0 | n 2617 | 16422 | 0 | 1247 | 16386 | 0 | n 2617 | 16422 | 0 | 2615 | 2200 | 0 | n (9 rows) The code in pg_operator.c records the dependency on the Extension both for a shell operator (in OperatorShellMake) and for a complete operator, in OperatorCreate. But in makeOperatorDependencies() we find the following piece of code: /* In case we are updating a shell, delete any existing entries */ deleteDependencyRecordsFor(myself.classId, myself.objectId, false); false is for bool skipExtensionDeps. And now at the end of the same function, dependency is recorded back, except in some case: oldext = getExtensionOfObject(object->classId, object->objectId); if (OidIsValid(oldext)) { /* If already a member of this extension, nothing to do */ if (oldext == CurrentExtensionObject) return; The problem lies in catalog scans and SnapshotNow, I think. My fix is to have deleteDependencyRecordsFor use true for skipExtensionDeps. Then: ~:54320=# drop extension cube; DROP EXTENSION Regards, -- Dimitri Fontaine http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support