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 1uS08s-001wya-C4 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Jun 2025 21:16:22 +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 1uS08q-00569A-Dp for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Jun 2025 21:16:21 +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 1uS08q-005692-3H for pgsql-hackers@lists.postgresql.org; Wed, 18 Jun 2025 21:16:20 +0000 Received: from mail-vk1-xa2e.google.com ([2607:f8b0:4864:20::a2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uS08o-002pKI-17 for pgsql-hackers@postgresql.org; Wed, 18 Jun 2025 21:16:20 +0000 Received: by mail-vk1-xa2e.google.com with SMTP id 71dfb90a1353d-5316a5e4c6cso31185e0c.1 for ; Wed, 18 Jun 2025 14:16:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750281377; x=1750886177; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mgdgN9XM8VxK0XJS6ua6UfjI9pfP0N2cSrDof4vN1xY=; b=F1hYBPIwIRaZsmUpUSD2jV64WRnbM9tNiwiaeQHR6ydnQnAC7P0LFuJXTL5sW63GNO V/zFI5o/ekeYHbCl808L1jHsez3zrk+XVrTl1sQ0xtVgrcc9RwrULsP74+dkrbyHtKdU idDhys+hEIiyH4nfYUXl8oy6+C/Lg/1pR8g0cqIXVwK1x2UdJltMxwiIBP4AEKLo0g7q tQqmdhWxKNaayfxFyL8BEteTGFpTDwNLlrsod3eSS9DQSj2WHOOv0MYWHYLQSyTodr15 vG//32WiLbLXHisGxtZ55IhTQXbV4NgbkhXwi6DRChipfkjRCxvB/JkO0HFzYFYW+Q/8 9Ovw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750281377; x=1750886177; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mgdgN9XM8VxK0XJS6ua6UfjI9pfP0N2cSrDof4vN1xY=; b=WJKPRRPsODAn0aJskxn5fFVYb+TDl0hYf/kmygeF/iCwbYUObZvo9fGdC3tX7iLbAd tqGBfSyo1flx02i0FiSgubqpMlcEEta/9QDmcBzWbU1PRrTZWG8GUDjvnzOw977G8e6X qdQORVpnc46NefalXK9LrYoomUXHQeKGMHeTMucpEfdPlW6PoPWLggTmqNqkWPS9Fq/H QZMIDa5G4Bs/iz26TrCW5hkIOvpAhd8eV13Sel0IroIZwYJhX8D4wYa3eJmZz/Db3akE E3Su5UAvPhvG5TCbqvg5lJSSf5kFtcR/3/g3aRgN22N+7EG3zbTlF/DWoEK5XI2Afxgn cczg== X-Forwarded-Encrypted: i=1; AJvYcCXbkXymTrtlUGr46THK9SKSFxT6hG1Qv/nVOgqjDpqP1ixdcKRyVPuH+qcZpI1SpSvtw8qHwZ7MSCeJaTKv@postgresql.org X-Gm-Message-State: AOJu0YypIm+0Nr9WQmVoPiU7+qLAaT8YcoDkluNxCJkea/8+1vAXMzk3 4X5cuR8zZl+2MdEAgbswRHm9x3WR4BD3WzRjFBOH5ZKzP8xS1SBJzq8wB2Yc+Hx1KkyMHw3qqKe 1xR9z1ZBvjP5filGuPo6c5fMiG9DpKfz1UTfhick= X-Gm-Gg: ASbGnctpwvoRtizx7O0WPEYaWqyi4j9xETOk34NH+0KK2VtnGZsky5Q/jNhPguUY3zr jH/0cJ5CQ+gy8csEQZtPfcvsvJLb5ns3xqb4DXNT+c/hLyjV2bDEFEfzPEqQe04AfnxfmEC4OYZ GS6n0pr52UoC/xf8PimaNKISpbYTVl6ZkRElkTGVf7O8A= X-Google-Smtp-Source: AGHT+IGo5I5ldjSPDGFd3zHZQePNQkseSbegr7EBn1Inu3n9E7y75nQRt1EIjoI+9iu42KAwEhoGsqMigouZy+SOl2c= X-Received: by 2002:a05:6122:2b1a:b0:530:720b:abe9 with SMTP id 71dfb90a1353d-531497442d1mr11794409e0c.7.1750281376794; Wed, 18 Jun 2025 14:16:16 -0700 (PDT) MIME-Version: 1.0 References: <202505181556.3n6oiowvntyr@alvherre.pgsql> In-Reply-To: From: Mihail Nikalayeu Date: Wed, 18 Jun 2025 23:15:28 +0200 X-Gm-Features: AX0GCFumMzzKK7Bc3tw-3dR3Zo3WnCuSqm57ioeVHHZiA7M3IOQjr7mjlxJUCKU Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Sergey Sargsyan Cc: =?UTF-8?Q?=C3=81lvaro_Herrera?= , Andres Freund , Michael Paquier , PostgreSQL Hackers , Andrey Borodin , Melanie Plageman , Matthias van de Meent Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, Sergey! > Today I encountered a segmentation fault caused by the patch v20-0007-Add= -Datum-storage-support-to-tuplestore.patch. During the merge phase, I inser= ted some tuples into the table so that STIR would have data for the validat= ion phase. The segfault occurred during a call to tuplestore_end(). > > The root cause is that a few functions in the tuplestore code still assum= e that all stored data is a pointer and thus attempt to pfree it. This assu= mption breaks when datumByVal is used, as the data is stored directly and n= ot as a pointer. In particular, tuplestore_end(), tuplestore_trim(), and tu= plestore_clear() incorrectly try to free such values. > > When addressing this, please also ensure that context memory accounting i= s handled properly: we should not increment or decrement the remaining cont= ext memory size when cleaning or trimming datumByVal entries, since no actu= al memory was allocated for them. > > Interestingly, I=E2=80=99m surprised you haven=E2=80=99t hit this segfaul= t yourself. Are you perhaps testing on an older system where INT8OID is pas= sed by reference? Or is your STIR always empty during the validation phase? Thanks for pointing that out. It looks like tuplestore_trim and tuplestore_clear are broken, while tuplestore_end seems to be correct but fails due to previous heap corruption. In my case, tuplestore_trim and tuplestore_clear aren't called at all - that's why the issue wasn't detected. I'm not sure why; perhaps some recent changes in your codebase are affecting that? Please run a stress test (if you've already applied the in-place fix for the tuplestore): ninja && meson test --suite setup && meson test --print-errorlogs --suite pg_amcheck *006* This will help ensure everything else is working correctly on your system. > One more point: I noticed you modified the index_create() function signat= ure. You added the relpersistence parameter, which seems unnecessary=E2=80= =94 > this can be determined internally by checking if it=E2=80=99s an auxiliar= y index, in which case the index should be marked as unlogged. You also add= ed an > auxiliaryIndexOfOid argument (do not remember exact naming, but was used = for dependency). It might be cleaner to pass this via the IndexInfo structu= re > instead. index_create() already has dozens of mouthful arguments, and ext= ernal extensions > (like pg_squeeze) still rely on the old signature, so minimizing changes = to the function interface would improve compatibility. Yes, that=E2=80=99s probably a good idea. I was trying to keep it simple fr= om the perspective of parameters to avoid dealing with some of the tricky internal logic. But you're right - it=E2=80=99s better to stick with the old signature. Best regards, Mikhail.