Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 4A6C71337B50 for ; Sun, 5 Dec 2010 07:40:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 56082-05 for ; Sun, 5 Dec 2010 11:40:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.anarazel.de (mail.anarazel.de [217.115.131.40]) by mail.postgresql.org (Postfix) with ESMTP id 891A61337B43 for ; Sun, 5 Dec 2010 07:40:04 -0400 (AST) Received: from alap2.localnet (unknown [89.204.137.27]) by mail.anarazel.de (Postfix) with ESMTPSA id 952FB448004; Sun, 5 Dec 2010 12:40:02 +0100 (CET) From: Andres Freund To: pgsql-bugs@postgresql.org Subject: Re: BUG #5784: CREATE INDEX USING GIN complains about array containing null values yet none exist Date: Sun, 5 Dec 2010 12:39:23 +0100 User-Agent: KMail/1.13.5 (Linux/2.6.36-rc6-andres-00006-g4193d91; KDE/4.5.1; x86_64; ; ) Cc: "Martin Atukunda" References: <201012050650.oB56opvM090787@wwwmaster.postgresql.org> In-Reply-To: <201012050650.oB56opvM090787@wwwmaster.postgresql.org> MIME-Version: 1.0 Message-Id: <201012051239.23510.andres@anarazel.de> Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/34 X-Sequence-Number: 28840 Hi, On Sunday 05 December 2010 07:50:51 Martin Atukunda wrote: > > CREATE INDEX USING GIN complains about array containing null values yet > none exist. > > Take the following SQL as an example. > > -- >8 -- > > BEGIN; > CREATE TABLE t (id serial primary key, apps bigint[]); > INSERT INTO t (apps) VALUES ('{1,2,3,4}'); > INSERT INTO t (apps) VALUES ('{1,2,3,4}'); > > -- insert an array with one element as a null value > INSERT INTO t (apps) VALUES ('{1,2,3,NULL}'); > > -- remove the null value > UPDATE t SET apps[4] = -1 WHERE apps[4] IS NULL; > > -- the create index fails > CREATE INDEX t_apps_idx ON t USING GIN(apps); > > COMMIT; > > -- 8< -- > > > note that index creatiion succeeds if I first create the index without > inserting a row containing an array with a null element. Due to the wonders of MVCC the old row is still available in the heap. Best read the docs about what MVCC means. And as pg's indexes don't care about visibility it will still try to index the "old" row. Andres