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.96) (envelope-from ) id 1wGPsr-006CCH-0f for pgsql-bugs@arkaria.postgresql.org; Fri, 24 Apr 2026 23:24:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wGPsp-007qva-0I for pgsql-bugs@arkaria.postgresql.org; Fri, 24 Apr 2026 23:24:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wGPso-007qvO-2h for pgsql-bugs@lists.postgresql.org; Fri, 24 Apr 2026 23:24:26 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wGPsm-00000002e9T-1BTT for pgsql-bugs@lists.postgresql.org; Fri, 24 Apr 2026 23:24:25 +0000 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-35f9ab079bdso5650044a91.2 for ; Fri, 24 Apr 2026 16:24:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777073064; cv=none; d=google.com; s=arc-20240605; b=TyEFFYB0+fk4kwiP4DlnYpHyHrjZ5zqHo635D/0O9Kd8gdVBdKSfNXE4dHo0/+zYtJ ni7UN7l0hdO4fSzgDEnvBwc7FGZ2Cro870KnAZOmu0vf1AJjGcCy0kk3uO1zUawYFg4G 2q2jrIK3hkSys8RZ7+IwwFEmD7ZUkrE+p8Ekc9nypiayibXm0azelJQwwBrn6JgBlfBI JhQnwUf88ZxJZlEF0+tracspe19T7cY/KY9P2RRJ1LSDfVARuIP2p9v+AVwGgpSb1y9V yegDHVmgqMNvoHnamZjsVJ/Qdho4EL2RgEWoZ8/Ja1cMgD+FZ+CfVmUbWRkK2qcQgZv2 eCyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fuk7oXqdqaSXz+m8dpq9zDc9iclZ+5STgiLIZFYwxtE=; fh=eq4N0ZJ8hrEgR38nsBqR0qT98+sD9swSO80XeCQALy8=; b=UXbA2xRzb8SiHrrR6utDDMR5qUA2v1BoWafCMxi9xxNRWOEV7MNSE0kmgdu7m771G7 WiDJEkd8GF8xO3mNUOtUH/U9yTYm1mPQeuT/iLAKTXxH2DPKva66uySSitEQwvHxwe2q 15jkbH1ayTz4ERBzW4uPJpFcTCKzwurDHkmt/V9cCdiAwgPz8aE5dr5w43mNif71+l/n lgyOUk+kyEICpjI5EZRUueXxyI+znO5waL65cKQn9dfqUr9yHwOTWUy26hCxu2Bn2NS+ 5EqxrC6TmQ2c2zqvl5K8cwx1SLKySfB9vsUwcgmM0un9a9gpijfjnbP3B0qP/1Ial6mG Q0Ng==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777073064; x=1777677864; darn=lists.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=fuk7oXqdqaSXz+m8dpq9zDc9iclZ+5STgiLIZFYwxtE=; b=Z9jFiRzHquwv4tr4T8f4JEaCzPE8IkylUbWPvkclsPX0c3NCWr1eHxlF6LhKfA0K2N ToKvwqN/HY3gCfLFVqEmqBlBHNvAz6yuzp7kqviLHxZiwI9BuQlkl8xGlRncdQf50kUC 98hiAKVothI8pAQAdRqIJM5U1rPXITBqU00JFohITfjZ47WVFopqVEps6LRrDoD3I0z8 ZN/hxZLOfY8jqFhpFEJnbZdjtok2CPM/bIyj7j5hTq72IeI6HXmRKTw7XQ/pVYDKUtRG IuvuIEKKZBZLt/g2ay+2fUj+dBjgYkU0uf/uvXlx0yTATjYigbV4WRhjA/0MgkmqUzYm lAzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777073064; x=1777677864; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fuk7oXqdqaSXz+m8dpq9zDc9iclZ+5STgiLIZFYwxtE=; b=SUI5iy5Dj9E08WStLHv6mhU1EmrcOQZTrXLgZ7lnHTsn7H3IV60TjtJxKnHyobAa+c x7r59c5y/9WwQCLRhLvreQhpIt0gBzym4yACD1aZZJTbGdGRIJwpsJ3Jaoo3zYm2PD9y 9/zkz7u4nyzEsrZx45VJKfMU5YuVLSbvomPE8yMC3+U4zsE3cXYmfhXpC2mrTV7V81wV EtFsOH63Y18/GMqSd64OBbmqwulIojupFkTt14aLBYTXmaRKEG2r22gtzowc4Glc/q6W 6s0MlcPT06oKw9+0wwu+FBaIST9Wt2DEZC/GciXrVLQXMFQUxg9roIx9DlHF8d7rLIE4 smjg== X-Gm-Message-State: AOJu0Yyck3Tk1UIC/Snlt9rB0Bma9DTXRB4aYaPfDSCZIewYUcOC3PhM 4yMkVlrYxq0tJh8fgbP3QEivHmkdasHPSRxQs0MSNdGDD7GKpkjDV7Wc/9++fqvJGXWNfdHooAs /CRW4D7hLaCfBEF+LmgAC3QwHgrUohxsHHWvwhww= X-Gm-Gg: AeBDietfJ9QRSOpDRm285+evXY0zuyMo0CI/4Gb5Vp4EGJfl1TRYnQEXjhqzewKZQAT IAW9XoF1rAmKW4w9dbZaH6Wr4Ga/q1aj7uRUW29v2Qdki0RsmMqafw2vL5YySoKoR6d5efDUlqQ xiEN6xiX/0AyDBAR/Bw6/itzyrPBcbOGDHBO17Os3/+tX1obRIe9gdwOBIpec3/i+xsgbCLF81H 3AzEQAuZ0ornR6rB5V5F6l9tLNzXrlGo3FwPb+qNsnL+BpduZ+JDkhp3oQpPix/9UxPF3bqyZmx ixbLbvHcj3IoUe7SfA5bbKCfcDRw61jCxMOY24+xDau83/c0d7UhpH8vCPNNnQ== X-Received: by 2002:a17:90b:2e45:b0:35b:e4f8:7cc7 with SMTP id 98e67ed59e1d1-36140473f8amr32392207a91.17.1777073063753; Fri, 24 Apr 2026 16:24:23 -0700 (PDT) MIME-Version: 1.0 References: <119bd418-1d7a-42c7-9270-86f3b6696399@gmail.com> <9dece148-3e1d-4b0f-b798-574988fe76fe@gmail.com> In-Reply-To: <9dece148-3e1d-4b0f-b798-574988fe76fe@gmail.com> From: Masahiko Sawada Date: Fri, 24 Apr 2026 16:23:46 -0700 X-Gm-Features: AQROBzCBNjfGSzN_h2mmkcbnjHyce2WfjHp-tvQiErwuPQDqbur6KJumTvlR9Hw Message-ID: Subject: Re: TRAP: failed Assert("offsets[i] > offsets[i - 1]"), File: "tidstore.c" To: Andrei Lepikhov Cc: PostgreSQL mailing lists 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 On Wed, Apr 22, 2026 at 10:23=E2=80=AFAM Andrei Lepikhov wrote: > > On 22/04/2026 18:51, Masahiko Sawada wrote: > > On Fri, Apr 17, 2026 at 2:26=E2=80=AFPM Andrei Lepikhov wrote: > >> > >> On 16/04/2026 19:58, Masahiko Sawada wrote: > > Understood. After more thoughts, I think your idea would be better. > > > > One thing still unclear to me is in which situation the query inthe > > test produces an array of unsorted offset numbers. While I understand > > it's not guaranteed that the DISTINCT clause returns the sorted > > result, doing DISTINCT in an aggregation function is using sort-based > > deduplication. I'd like to confirm that the queries in the test could > > end up producing the results that violate the assertion. Is it > > possible to do that by changing GUC parameters or something? > No, this is part of ongoing research into Postgres Optimizer vulnerabilit= ies. I > used two tools: pg_pathcheck [1] and pg-chaos-mode [2]. The first tool fi= nds > hidden dangling pointers in pathlists, which we are currently discussing = in > another thread. The second is a patch that makes the cost-based decision = random > to help uncover hidden or unwritten coding contracts. Thank you for the clarification! > Both tools are experimental and not meant for core use; they are only use= d to > trigger potential issues. In this case, I think the query picked a costly= sorted > path, which led to the crash. Does this imply that array_agg() could return unsorted results depending on the plan the optimizer chooses? Or is such a path currently never selected by the optimizer? I=E2=80=99m asking because if this scenario never occurs with the current optimizer, it might make sense to apply the patch only to HEAD (i.e., for PG20). On the other hand, backpatching to PG17 might be justified, given that DISTINCT does not guarantee sorted results in principle, and the fix could benefit extension development on stable branches. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com