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 1uRvj2-000tbN-2d for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Jun 2025 16:33:24 +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 1uRviz-002goe-Vh for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Jun 2025 16:33:22 +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 1uRviz-002goW-Kg for pgsql-hackers@lists.postgresql.org; Wed, 18 Jun 2025 16:33:22 +0000 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uRviy-002n71-0L for pgsql-hackers@postgresql.org; Wed, 18 Jun 2025 16:33:21 +0000 Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7d0a0bcd3f3so115284785a.1 for ; Wed, 18 Jun 2025 09:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750264398; x=1750869198; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=9ACRlR7w3gt4/5j43NNKNSu9IwGqk2nUPvSEyBv4oVk=; b=B5eDyyE3mIEqlgdCpSjdnLurrm4zhK8jzXENBJWJsrMaM3bt8DJLxSclni31xVPCdp wzZKeXToqWw0cBKzbLPruSVYNfUz46Tk0UbUYrtwJcA2Al3KkYxyTD6dRVC44i5zFG22 QBR5IaHRgupSiLTG3DCC2rOyRzh+xzE5E0IEm5/oQize+W5qW67ackrDNRSsPse6TvqY wYHPEBLTAU+KUIOBiDmBj4Y6jqud+MS/3PNbw7Y2g2HtVP6JkXkcsqqy2O+w1CICbd9/ WCaKTYCPAWpBiUMOcX69W24VU2zXfXP9UVnusPJDvVzMK5ZljciVBiwI5FT8YiolYWQf scyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750264398; x=1750869198; h=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=9ACRlR7w3gt4/5j43NNKNSu9IwGqk2nUPvSEyBv4oVk=; b=DKFmE61egnDwqjsHSOsySHMfYq7znenZ3vdio3E1NTC5WZkMXX1weeHjVGDZAJdap2 vWGdQiotDcW3H1z8mDyX4KdU3lHsEXwz5v4P8Q86vOX3hxm6mYiMf1s1dIZjm9aHeLfI NfFs0f3wllpYvonOgacqTW2gnzz1lSXcp/B14Iu5NYgKmywaSmCdxD9YvIYEqKXTjwKG RN0tahymcP/INarYyJQAXLXYvbTi3YLZvOSAf6ZLRcv9FoQEXORsIACF/u3f6Ahzx0Yx fDghv7L+3Srm1J+vt7wq3PIupFk/XVDav0Lni4yNEAyXzmXlmLruMbdPpTRBNU0ME0S5 yEgQ== X-Forwarded-Encrypted: i=1; AJvYcCVkG0F4QnjwPVl2uofTIVZTYv9vCQSc1a9cvahpO773LotZbM+Q0bVcZe7SJrqBaxOawNSWLKQOPyfyna3M@postgresql.org X-Gm-Message-State: AOJu0YzbQ11eJ2lv0ar4NAleExB7SlflmLxkKqtpvS2lnfH06YIUfgNh o3gNCdJCSFMync/cIVM/h+zkF1qKVrvKDXwS1+BCEgvk9vNRIF9y84/MaYctLrsBxQmFXOMNmVD aMOUPrr4JYkcNlhLSTOv0DptiwKaW8jo= X-Gm-Gg: ASbGncvcznMmxBWuUuBG1ATktEUe4qIhwvJeOPQ6n3FVC7HXa9iiRsxB3JUtBy1Z0ER 9LWYhSVrKMPvVQGdSIEneFPrhpIZi3AZoRNRqeVR9UAeG+upDvDKOKll8Qu/sY0RMe2R/XhQ6gN 5B2q3nQVkmPkjBOGNmyUDrr1m5LQ4Qlx/JQjN/RmUnCFYk0A== X-Google-Smtp-Source: AGHT+IE3yWBkO2t5CAobqV8JTH9PPpiEicciqUYA0YXx2mm0d6noy0DQSQ2XAVcQUDtdgH8tsCgMbkG+9CiLZvNnHGs= X-Received: by 2002:a05:620a:40ca:b0:7d3:ce9a:565b with SMTP id af79cd13be357-7d3f16f3f35mr30912185a.14.1750264398351; Wed, 18 Jun 2025 09:33:18 -0700 (PDT) MIME-Version: 1.0 References: <202505181556.3n6oiowvntyr@alvherre.pgsql> In-Reply-To: From: Sergey Sargsyan Date: Wed, 18 Jun 2025 19:33:07 +0300 X-Gm-Features: Ac12FXyCw7c-I-Qyumk4jRXRoI3Hn3ravRsaGalzQigJNGvMxIgL5B8fByPaJmk Message-ID: Subject: Re: Revisiting {CREATE INDEX, REINDEX} CONCURRENTLY improvements To: Mihail Nikalayeu Cc: =?UTF-8?Q?=C3=81lvaro_Herrera?= , Andres Freund , Michael Paquier , PostgreSQL Hackers , Andrey Borodin , Melanie Plageman , Matthias van de Meent Content-Type: multipart/alternative; boundary="000000000000ba133a0637db2f73" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ba133a0637db2f73 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Today I encountered a segmentation fault caused by the patch v20-0007-Add-Datum-storage-support-to-tuplestore.patch. During the merge phase, I inserted some tuples into the table so that STIR would have data for the validation phase. The segfault occurred during a call to tuplestore_end(). The root cause is that a few functions in the tuplestore code still assume that all stored data is a pointer and thus attempt to pfree it. This assumption breaks when datumByVal is used, as the data is stored directly and not as a pointer. In particular, tuplestore_end(), tuplestore_trim(), and tuplestore_clear() incorrectly try to free such values. When addressing this, please also ensure that context memory accounting is handled properly: we should not increment or decrement the remaining context memory size when cleaning or trimming datumByVal entries, since no actual memory was allocated for them. Interestingly, I=E2=80=99m surprised you haven=E2=80=99t hit this segfault = yourself. Are you perhaps testing on an older system where INT8OID is passed by reference? Or is your STIR always empty during the validation phase? One more point: I noticed you modified the index_create() function signature. You added the relpersistence parameter, which seems unnecessary=E2=80=94this can be determined internally by checking if it=E2= =80=99s an auxiliary index, in which case the index should be marked as unlogged. You also added an auxiliaryIndexOfOid argument (do not remember exact naming, but was used for dependency). It might be cleaner to pass this via the IndexInfo structure instead. index_create() already has dozens of mouthful arguments, and external extensions (like pg_squeeze) still rely on the old signature, so minimizing changes to the function interface would improve compatibility. Best regards, Sergey On Wed, Jun 18, 2025, 1:50=E2=80=AFPM Mihail Nikalayeu wrote: > Hello, Sergey! > > > In patch > v20-0006-Add-STIR-access-method-and-flags-related-to-auxi.patch, within t= he > "StirMarkAsSkipInserts" function, a critical section appears to be left > unclosed. This resulted in an assertion failure during ANALYZE of a table > containing a leftover STIR index. > Thanks, good catch. I'll add it to batch fix with the other things. > > Best regards, > Mikhail. > --000000000000ba133a0637db2f73 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

To= day I encountered a segmentation fault caused by the patch v20-0007-Add-Dat= um-storage-support-to-tuplestore.patch. During the merge phase, I inserted = some tuples into the table so that STIR would have data for the validation = phase. The segfault occurred during a call to tuplestore_end().

The root cause is that a few functions in= the tuplestore code still assume that all stored data is a pointer and thu= s attempt to pfree it. This assumption breaks when datumByVal is used, as t= he data is stored directly and not as a pointer. In particular, tuplestore_= end(), tuplestore_trim(), and tuplestore_clear() incorrectly try to free su= ch values.

When addressi= ng this, please also ensure that context memory accounting is handled prope= rly: we should not increment or decrement the remaining context memory size= when cleaning or trimming datumByVal entries, since no actual memory was a= llocated for them.

Inter= estingly, I=E2=80=99m surprised you haven=E2=80=99t hit this segfault yours= elf. Are you perhaps testing on an older system where INT8OID is passed by = reference? Or is your STIR always empty during the validation phase?
<= div dir=3D"auto">
One more point: I noticed you = modified the index_create() function signature. You added the relpersistenc= e parameter, which seems unnecessary=E2=80=94this can be determined interna= lly by checking if it=E2=80=99s an auxiliary index, in which case the index= should be marked as unlogged. You also added an auxiliaryIndexOfOid argume= nt (do not remember exact naming, but was used for dependency). It might be= cleaner to pass this via the IndexInfo structure instead. index_create() a= lready has dozens of mouthful arguments, and external extensions (like pg_s= queeze) still rely on the old signature, so minimizing changes to the funct= ion interface would improve compatibility.

Best regards,=C2=A0
Sergey=C2=A0<= /div>

On Wed, Jun 18, 2025, 1:50=E2=80=AFPM Mihail Nikalayeu <miha= ilnikalayeu@gmail.com> wrote: