Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1j8TH0-0000b9-G6 for pgsql-committers@arkaria.postgresql.org; Sun, 01 Mar 2020 18:25:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j8TGz-0002mm-8q for pgsql-committers@arkaria.postgresql.org; Sun, 01 Mar 2020 18:25:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j8TGy-0002mf-U1 for pgsql-committers@lists.postgresql.org; Sun, 01 Mar 2020 18:25:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j8TGu-0003C2-QN for pgsql-committers@lists.postgresql.org; Sun, 01 Mar 2020 18:25:03 +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 021IOt57027004; Sun, 1 Mar 2020 13:24:56 -0500 From: Tom Lane To: Peter Geoghegan cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Add deduplication to nbtree. In-reply-to: References: Comments: In-reply-to Peter Geoghegan message dated "Wed, 26 Feb 2020 21:06:17 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27002.1583087095.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 01 Mar 2020 13:24:55 -0500 Message-ID: <27003.1583087095@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Geoghegan writes: > Add deduplication to nbtree. Coverity isn't very happy with the coding in _bt_update_posting(): *** CID 1460433: Memory - corruptions (ARRAY_VS_SINGLETON) /srv/coverity/git/pgsql-git/postgresql/src/backend/access/nbtree/nbtdedup.= c: 723 in _bt_update_posting() 717 { 718 if (d < vacposting->ndeletedtids && vacposting->deletetids[d] =3D= =3D i) 719 { 720 d++; 721 continue; 722 } >>> CID 1460433: Memory - corruptions (ARRAY_VS_SINGLETON) >>> Using "htids" as an array. This might corrupt or misinterpret adj= acent memory locations. 723 htids[ui++] =3D *BTreeTupleGetPostingN(origtuple, i); 724 } 725 Assert(ui =3D=3D nhtids); 726 Assert(d =3D=3D vacposting->ndeletedtids); 727 Assert(nhtids =3D=3D 1 || _bt_posting_valid(itup)); I can see its point: asserting after the fact that you didn't clobber memory isn't a terribly safe coding method, especially in a production build where you won't even have the asserts. Not sure if there's a better way though. regards, tom lane