Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlhjy-0040IL-Hs for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Sep 2023 03:31:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qlhjw-008FMy-Qh for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Sep 2023 03:31:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlhjv-008FMf-4K for pgsql-bugs@lists.postgresql.org; Thu, 28 Sep 2023 03:31:01 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlhjm-0080t8-UO for pgsql-bugs@lists.postgresql.org; Thu, 28 Sep 2023 03:30:58 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E91E4320005D; Wed, 27 Sep 2023 23:30:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 27 Sep 2023 23:30:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1695871846; x=1695958246; bh=ES jmyUR3jPUQc+5Aelf4V+4ztY3NcwjmrAJDMPZ2+po=; b=iwpcmev/PKea1ck6LG 3s/ZgkHhaQ35rR4Qh5wpJzgC7bNd4ThWgC0pIY7UPBQ6jLZuXIk3x7i29q3WARpQ ISmGquMiLNNziI1kCj5Yv+r4j2Ys3f9rwi3gQOXQW1uiaxFBu6M2R+f7I/pca2K6 cKWC+gZtjtqXUtt6N5NPRCn8y0EWbYQc8A2nsVSyqRb5hOslxzOG7rADtQhWReaX c7g1AWrEDlhepVMw+UtsTzybbmxRwXpAC6rWfO0NzDxEozSf/2utgZ5F7Rru3bfa 6Xz8R5Y8Wwz3ZWfiErCD/nUaudAUVzjK7Zo2mYzaX6pCiaHyNjv4qvzslkt8RYxE EsmA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1695871846; x=1695958246; bh=ESjmyUR3jPUQc +5Aelf4V+4ztY3NcwjmrAJDMPZ2+po=; b=W9bogXPxX33JboC10gWIKe6VNbAsD WzTLK6IKbsf6tFNpN0xyaEv1K3b08rjIxDCUBVkpIWBH8OpyyEO/VqwwcSgVCiTA LmU4uzMx6OLNRlbO2kU191oiVHNpWaNpThUmAZgIiKo9kEz896J29sUYYr9muIk2 Xf7ziJ9w344tq1mMnaGWGv6XiYOG0cv8vbnXUVa4/zfShaYfL+fxD7XrYceyz7Nn 5Sfu76MadI6Tt+YY+4+6J7pzB4ltrMHHx+ch3hc1jzSqz9x0PWBgjQ/e+5HRao6N sWEb/t9yny5ntMUMECzJpST9Jahjsdwm4XSksQkqyeytL+US5Gf9l7ThA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvjedrtdehgdejfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhepfffhvf fukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhi vghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnh epvdegudeuhfdtueeltedtveejheehieevueeigeelteegleejleeiueeiheegvefhnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrg gvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Sep 2023 23:30:44 -0400 (EDT) Date: Thu, 28 Sep 2023 12:30:39 +0900 From: Michael Paquier To: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18135: Incorrect memory access occurs when attaching a partition with an index Message-ID: References: <18135-532f4a755e71e4d2@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="i0iUL1/uoNIfJPCV" Content-Disposition: inline In-Reply-To: <18135-532f4a755e71e4d2@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --i0iUL1/uoNIfJPCV Content-Type: multipart/mixed; boundary="W1+rAGyY6d5J2O3K" Content-Disposition: inline --W1+rAGyY6d5J2O3K Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 27, 2023 at 10:00:01AM +0000, PG Bug reporting form wrote: > executed under Valgrind, it leads to an incorrect memory access: > =3D=3D00:00:00:03.947 396156=3D=3D Invalid read of size 2 > =3D=3D00:00:00:03.947 396156=3D=3D at 0x2E323D: CompareIndexInfo (inde= x.c:2572) > =3D=3D00:00:00:03.947 396156=3D=3D by 0x3D009B: AttachPartitionEnsureI= ndexes > (tablecmds.c:18797) > =3D=3D00:00:00:03.947 396156=3D=3D by 0x3D8B4F: ATExecAttachPartition > (tablecmds.c:18578) > =3D=3D00:00:00:03.947 396156=3D=3D by 0x3D9A88: ATExecCmd (tablecmds.c= :5379) > =3D=3D00:00:00:03.947 396156=3D=3D by 0x3D9BC7: ATRewriteCatalogs > (tablecmds.c:5063) I have just tested that on HEAD and REL_16_STABLE, but fail to see this report, which is weird (3.19.0 here). Are you using any specific option of valgrind I should be aware of? Here is what I used, for reference: valgrind \ --suppressions=3D$PG_SOURCE/src/tools/valgrind.supp \ --trace-children=3Dyes --track-origins=3Dyes --read-var-info=3Dyes \ postgres -D REST_OF_ARGS > The function CompareIndexInfo() contains the code: > /* ignore expressions at this stage */ > if ((info1->ii_IndexAttrNumbers[i] !=3D InvalidAttrNumber) && > (attmap->attnums[info2->ii_IndexAttrNumbers[i] - 1] !=3D > info1->ii_IndexAttrNumbers[i])) > return false; >=20 > where info1->ii_IndexAttrNumbers[i] is checked for InvalidAttrNumber > (i. e. it's not an expression), but info2->ii_IndexAttrNumbers[i] is not. Anyway, I can see your point here. info2's first attnum is 0 so we look at an imaginary position in attmap->attnums. So, yes, that's wrong. > In addition, there is a check whether both indexes are (are not) > expression indexes, but it's placed below... Sure, but this makes the check a bit cheaper if the indexes to compare use expr and non-expr attributes at the same attnums, no? Except if I am missing something, the attached should be sufficient. -- Michael --W1+rAGyY6d5J2O3K Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="compare-index-mem.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 716de171a4..bbc9b262a0 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -2570,6 +2570,7 @@ CompareIndexInfo(const IndexInfo *info1, const IndexI= nfo *info2, =20 /* ignore expressions at this stage */ if ((info1->ii_IndexAttrNumbers[i] !=3D InvalidAttrNumber) && + (info2->ii_IndexAttrNumbers[i] !=3D InvalidAttrNumber) && (attmap->attnums[info2->ii_IndexAttrNumbers[i] - 1] !=3D info1->ii_IndexAttrNumbers[i])) return false; --W1+rAGyY6d5J2O3K-- --i0iUL1/uoNIfJPCV Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmUU818ACgkQnvQgOdby QH2gNg/9G6EX8emZsUg8GLrVJNmJVaHxEffchjH6nJVkUvtRMyZ3r2o9JPQgTKaH ciSBXsER+COBNE5v4SCuacPuTJCWzaiBgVeg063L3GzeddCUgEl2adOGYBc/Y62P kaUFUX2Xyh4QBvy5iAkwlU2fA2HOTKqyBCeG+/ekfmHT+Mf0x5nh3IvHESTFkbuf MZd4KB7wo9T62Onqfd/QPCmZD9Tb4jFbzs+XQJQzv89BSkjicBxotwSWID/GP10g czSHYnCIco8F8RzkpATWV/pX5WtpfpWxm4eUTNVUSpDMyVyokjifYku3F426HQco giEDAXyjDXTXhTHBznQrQm/9yQmdBuzf+l6HEopCr35Cg0G5Kasopbp/odE2vG1F n7t+sAvYCk+w/3fo+Un2C303xvHvC3IUsIR6wF8sq81owB0CQqn68eLOrYvxeHEb ultVsiNJFG6nekyLcQc/+KK5hJX4krsspYvW/W6eynX/IUB7bcyDOQiRPI7uy7ci sphfNsv3zJj8tHUqQMpds4h8gZDSGMHyNYHZFWSmbxujvtPIkchSl9y7kpBqtB4a mLVRJgZRnM/HQWZD4/Upn915C6/mwZtYHzQadWoko6Gvy/Nk5pnqJZzLv0tBcXbs ScFUWXDsrtDPXOgzGhoGt6e/tDZ5ooXq4m2bs1+D18pHai9E29E= =7PiK -----END PGP SIGNATURE----- --i0iUL1/uoNIfJPCV--