Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5AE7AB5DC1B for ; Wed, 28 Sep 2011 13:50:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 83159-03 for ; Wed, 28 Sep 2011 16:50:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 6D5CBB5DBCE for ; Wed, 28 Sep 2011 13:50:18 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p8SGoCc8004739; Wed, 28 Sep 2011 12:50:12 -0400 (EDT) To: Josh Kupershmidt cc: Alvaro Herrera , depstein , mmoncure , Pg Bugs Subject: Re: Problems with ENUM type manipulation in 9.1 In-reply-to: References: <29F36C7C98AB09499B1A209D48EAA615B7653DBC8A@mail2a.alliedtesting.com> <29F36C7C98AB09499B1A209D48EAA615B7653DBCAB@mail2a.alliedtesting.com> <1317220852-sup-4032@alvh.no-ip.org> Comments: In-reply-to Josh Kupershmidt message dated "Wed, 28 Sep 2011 11:40:37 -0400" Date: Wed, 28 Sep 2011 12:50:12 -0400 Message-ID: <4738.1317228612@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201109/219 X-Sequence-Number: 31236 Josh Kupershmidt writes: >> Excerpts from depstein's message of mié sep 28 07:21:17 -0300 2011: >>> Anyway, the procedure that we used (based on >>> http://en.dklab.ru/lib/dklab_postgresql_enum/) does the necessary >>> checks before removing enum values. > Not exactly; that code is rife with race conditions. For instance, how > does the "Check data references" loop ensure that previously-checked > tables don't get a new row containing the forbidden enum_elem before > the function is finished? It's worse than that: even if you have in fact deleted all occurrences of a specific enum OID from the tables, that OID might still be lurking in a btree index on an enum column. If you delete the pg_enum entry, and the OID is odd (meaning that the pg_enum entry must be consulted to find out how to sort it), you just broke that index. You might think you could get out of that by VACUUM'ing to ensure that dead index entries get cleaned out, but that is not good enough. The problem OID could have gotten copied into a btree page boundary value or non-leaf-page entry. If that happens, the OID will most likely never disappear from the index, short of a REINDEX; and this is also the worst case for index corruption, since we must be able to compare other OID values to the non-leaf-page entry to figure out which leaf page to descend to in searches. In short, the reason why this type of code hasn't been adopted into core is that it doesn't work. regards, tom lane