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 1wFao0-005Kxh-1m for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Apr 2026 16:52:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wFanz-00EU2X-2C for pgsql-bugs@arkaria.postgresql.org; Wed, 22 Apr 2026 16:52:03 +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 1wFanz-00EU2P-0x for pgsql-bugs@lists.postgresql.org; Wed, 22 Apr 2026 16:52:03 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wFanx-00000002HTY-0DKL for pgsql-bugs@lists.postgresql.org; Wed, 22 Apr 2026 16:52:02 +0000 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-b8f9568e074so966295466b.0 for ; Wed, 22 Apr 2026 09:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776876719; cv=none; d=google.com; s=arc-20240605; b=JA400Pfntmjg3CZYxO2ea6g0ltITwSSCMsM4eczZJEJLsZJH0RSAWWuB/sSvamzJh5 bWLXgVBDqm58fA8dA2VoJhYVy9I2zhdfOhFQJEIZZwkMbE3QyPTPwv5UwFml+4iOFWrx Vb4Vz+nvq3BVL9MP+gKEHBoMEDW/7PrBw6Ssa4iD3c3WXmHBcvQ7nX19Zz2YmrXCRjig RgHT5HJpOOUHNyCZ/iXLblxkFPjgBbHtOvmDoxB3wHGa4udPBexB+RW6QC8rJT5tV/qk MSfZA5QiVGVDmrzmSDrNLQm+KHeAu9p16XTpa5wJ6C2uXVIbeTpKmwiPBSQlu0RSxeEi eHcw== 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=8qcABFIlrp5VYcdzCd/C7VDmhSPkZ63gCQxy/wEBuDM=; fh=eq4N0ZJ8hrEgR38nsBqR0qT98+sD9swSO80XeCQALy8=; b=eWIpau3msSq6dk1OM0IDVLqNWixfTrHNaRTHh5lgFjJuUmqWZ/+PR8wGRtJu3hSBlB I3gWzcu8+AkFELemQe7CIFDuk+5QhNgKJkW48mUjqUDJo+zWgxTMzDiwoaNeRcqRmkbd WfZ9mpdh8RKyPUNwIYDWZvdXeaSntnsrvKXcXS6fmisLJEx5ltUAl8DrScb/WYqe+yVh lpLTCJS+8hKljfqDweUnqCYNfNYsUhddqlF92hNWmnPSSmcJH7FcTy1ANG0nfsbpODsz /6lO1PnsDKx5dfPXECnPXhxVv4oH141BmefTMoh+QjcM+K/svikSDe/xoFGyPnbZNQrk FIfA==; 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=1776876719; x=1777481519; 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=8qcABFIlrp5VYcdzCd/C7VDmhSPkZ63gCQxy/wEBuDM=; b=KHBXcC9yyUoc0poNPDcpTt+SGA003CjxiO5VgH4ZNjKHKds0o1okCri+YjzGsoVTy9 6zVQuti4RD8yinNRnDbP+e64HmH9rk/BaEe5M4+lPTQq4I1GJNk35SmDzg1b83tSL0DP tXqI2XU+pUWFj4WMD73jRfaA0HhPkmoX45aDdVWf1kTnWwrIpJ2sdzcfEAoAYhJOPXNg k/yf3EPCRjFuD2C97hwIepMTHOjyyzTJXq2v2BSn35ZwS6FeqUXwdczyD4m79HDnNOeO NIHgUwbtjf/B6vqF+7+qyihDEvxrcTuc12Uk+JYtQC6R0CvLlY8EQao92nED5kDeGc4H hnlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776876719; x=1777481519; 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=8qcABFIlrp5VYcdzCd/C7VDmhSPkZ63gCQxy/wEBuDM=; b=X0UgEerP6psuQ7jQI2yvn1hv2S94gtmGN6ccWQEZt7axdk0QwAE3maneVdOVSLWrIM jCMWRUDDdTTu6V2CMqcBEVBjB5pMveYEWs0CHE8Lo5eG9qGYBnfYAR83hJOMgQoeo0C1 T/IpfdZqrCvfBe8WXfszotO4/7PTbddmNQ1VEwIZ6nfh5ObYFKpVSQh1gZHSUXRJ/IsX Pmccx+IU2YFFB+GP7Aq7qw8z8jEfy0JQMeCpJIrh8JLd4JgZusBpNkqtD3v90vkonMnh cSy1hw5WI5Yy0D2MRlUuDRzvkk9xbL0g3WrnpSSrUS8UFgn2kDarDlHbeYP/fCeegpLf IU9Q== X-Gm-Message-State: AOJu0Yymh3wNPux+/kEFVmoiMReCCMcddC9B3eE/i52XPJtrivsiQB/f 38PG3XwFWOUmmaNRYV/nq0NSWiBdWtepIR4rjnuXbMLieOZYDzXXlxlRvlU11bA8PezLYOrFUHJ NOxn1+52xp02mkNBpP6fCHgdJtd1leuo= X-Gm-Gg: AeBDievjs8seOqb0YRHCfbvWr0RnofqgnQvfaLZgXQiMARNUxJ1piB8RtQLtbLIn83P e2ZHZrMAosZ/1hve1y1h4XXwdle+cAbKcWizLQwEJ1GpSgpORXj8WxhchaKUmY+t0+f685qzLZ1 zZn+psa5cF/phTQLigA3L2GSlP/C4Qknh4sfh3DRqyV1dr02PbY1lR27THOdjHM6R6JIP63/vfk LLiqqBXeHka3/6715SoqiRzUeEs08yLZM3xonMxCcXwam0PHDaHI5c0+HSiQ+h6RuXxaVXlX8u4 4Q+3R3Dkikr+yyJaLyo1UuPA/jixtEqIom/vlvUm6cUEHgMuMtg= X-Received: by 2002:a17:907:849:b0:b9c:69df:4d7b with SMTP id a640c23a62f3a-ba41aeefa42mr1207391066b.39.1776876718348; Wed, 22 Apr 2026 09:51:58 -0700 (PDT) MIME-Version: 1.0 References: <119bd418-1d7a-42c7-9270-86f3b6696399@gmail.com> In-Reply-To: From: Masahiko Sawada Date: Wed, 22 Apr 2026 09:51:18 -0700 X-Gm-Features: AQROBzA49jt8j2vI_ULZMP5qZhsWude9OzegbXDJboZ_xM2p-Vvo1zJHjczGcnM 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 Fri, Apr 17, 2026 at 2:26=E2=80=AFPM Andrei Lepikhov = wrote: > > On 16/04/2026 19:58, Masahiko Sawada wrote: > > On Thu, Apr 16, 2026 at 1:26=E2=80=AFAM Andrei Lepikhov wrote: > >> > >> On 16/04/2026 10:11, Masahiko Sawada wrote: > >>> On Thu, Apr 16, 2026 at 12:13=E2=80=AFAM Andrei Lepikhov wrote: > >>> -- Random TIDs test. The offset numbers are randomized and must be -- > >>> unique and ordered. INSERT INTO hideblocks (blockno) SELECT > >>> do_set_block_offsets(blkno, array_agg(DISTINCT greatest((random() * > >>> :maxoffset)::int, 1))::int2[]) FROM generate_series(1, 100) > >>> num_offsets, generate_series(1000, 1100, 1) blkno GROUP BY blkno; > >> > >> Alright, I used an explicit sort in reverse order to make sure the tes= t is > >> stable. I usually create modules that may change different paths, cost= s, and > >> orders, and using random can make things unpredictable. But for this s= pecific > >> test, I don't see any risk. > >> > >>> > >>> While I agree that we need to sort the offset numbers, I think it > >>> would be better to make sure the offset numbers in the array to be > >>> sorted in a test_tidstore.sql file where required, instead of doing s= o > >>> for all cases. > >> > >> I'm not sure I follow. Are you saying that do_set_block_offsets should= n't sort > >> the incoming offsets? > > > > No, I wanted to mean that if we sort the given array in > > do_set_block_offsets() as the proposed patch does, we end up always > > sorting arrays even if the sorting is no actually required (e.g., when > > executing "SELECT do_set_block_offsets(1, > > array[1,2,3,4,100]::int2[]);"). So an alternative idea to stabilize > > the regression test would be to create a SQL function to return a list > > of sorted offsets and use it where it's required. While the patch gets > > a little bigger, It would also help simplify the tests somewhat by > > removing the redundant codes. I've attached the patch for this idea. > > Ok. No objections. Both changes are just test routines registered by the > test_tidstore module. > > I decided to add C code, mostly following the idea that we reuse examples= from > the Postgres codebase when writing our patches/extensions. An explicit > demonstration of the sort contract on the TidStoreSetBlockOffsets() call = might > help developers who don't read function comments each time. 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? Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com