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.98.2) (envelope-from ) id 1x7F5v-00000000Egi-0Izs for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Sep 2026 16:36:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x7F5t-00000005Yks-15Mj for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Sep 2026 16:36:17 +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.98.2) (envelope-from ) id 1x7F5s-00000005Ykh-3M3W for pgsql-hackers@lists.postgresql.org; Thu, 17 Sep 2026 16:36:16 +0000 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x7F5q-00000000Anq-3jZE for pgsql-hackers@lists.postgresql.org; Thu, 17 Sep 2026 16:36:15 +0000 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-482f633cd78so591414f8f.1 for ; Thu, 17 Sep 2026 09:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1789662973; x=1790267773; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to:content-type; bh=qn84b/lUB0PE3wLNw1o67CJtwjW3tgYeT4xekbLgZsI=; b=hGxXcIE2DIhgH41EQDjQmObjFU39csCSaouj4mu5Fy9Zx26xM8ton243zUtXefu5rD 21ZOAb++4+JN4DE3ajfpneZwzwkYAcpmUuNy5q080NpzhKcfNtdGJnSzpG3Gzb1lv711 12xtvBBdDzfxdPHax3ueHQ9F8glJsWrnsCPJbuTceOFt5XL1bCHusuzbAPmzLxm6xIwt Mk0B5hRp15RLO2gvp1HmrV6nkPHCZkuIegJAI0FKQ9+IxokmvLw3JbW/26B4KYmW90Lv cAmO0E4MT8RdKcgT94+JhzluTr0LiY8hL7zKqkredX1twQDbafXfS9S6+WlyV9y7DNEh QxKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789662973; x=1790267773; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=qn84b/lUB0PE3wLNw1o67CJtwjW3tgYeT4xekbLgZsI=; b=xkwaLIe78yhdzHJa87VO7zzZKJSiza+90pTCe3f3JGAXXrmzd3jQbD7oEXAnc0jF0a AJgaC7YIZT0wfoFlyJRG6VWkSpkJmGeyeRpt7jerWAe1nE7194lCph6MIStLl12aYSJ1 ynmbrbBfZfAbmxk395wTL3QfmdsbMI04FbcF6Wn/tsVuMDqQ67Kt0c62Ms77rUelZtyn rMeh6BjPayeWeyBR21YDz3phw2b6yYpAKq8O3uR4RPAxDRvyRKR/eQ5tvqvkq0hky7sS sbm29dJOjI1TfyNrztW1rpENE9SkV4adNAEej+OG0SLOxYn4octbZjFECuAkM9qZfaTS SO4w== X-Forwarded-Encrypted: i=1; AKwUvBy6YBFp8rAdXZcPm17gK11ZjvQRhGIphVKiJeSmBhCbWTRk/YCjqmb4k2gE77uk4Q/Yc7A+cS98adxXVOrQ@lists.postgresql.org X-Gm-Message-State: AFuF++kDt8O1qGE36nUyizw3pZeWMNO1PKepsqheh2cNzpVOnMY3a4C5 Y8lmVsp2IUXcxEBdZnagfG00HoxnPs0vdDv9vV7ElOQZbaqd+o29bqlNH8lTrhrVOPk= X-Gm-Gg: AYBFou2mi0DGhIW01gjIYphgMXG8fI08DdF21kHd34mmsIIXzgmmsd5uTmbVb2kPpsU C5q1eJxRliP0oKcxnzdnj/YCExr8mi9SaoSdTTDR6g/vNi0XZkxE1e2OPhQcoUaqQTTk8Ufvoe4 kIxGaGBZmxkP1OBlMDiGajrH4Yg3R6ofUQfzRCaLsRlRvxlC1UrmrcbzCu5hbgXq/BdRSjKCtxc ybdQYx3b7Tt7t1WFm5M6jX14RfbECeiI6/ZhKEJjdHwZUXVII/zNdJi6P3q9VK/yO5xwJv49AZ4 kM4nLaMMh8wx0kxgN0jl2JS96vhKNytdMhIBj8BQbZ/R9papBtbRsrsZ/X2qviaGXtp32MJXlhL YtJN7dlKXuhSA6k2TSRGy83DNwJjQx8Ec14NGevl72DDlhYcQA1wDqTM8JGF1ykHuoIypzzsyyn oFrH8x9AWf1iCG1Qgl04XEU1Z00SYUDKswebYQAx4zkB5aYl2ywOX59zuNVdNfj7U5n7YckNx/0 MyiobXrGNJicrSNoCWJP94= X-Received: by 2002:a5d:5d13:0:b0:487:1072:a103 with SMTP id ffacd0b85a97d-4871072a188mr9793591f8f.5.1789662972672; Thu, 17 Sep 2026 09:36:12 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4870bef7642sm15192268f8f.5.2026.09.17.09.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2026 09:36:12 -0700 (PDT) From: Antonin Houska To: shihao zhong cc: alvherre@kurilemu.de, pgsql-hackers@lists.postgresql.org Subject: Re: REPACK enhancements In-reply-to: References: <109367.1781614382@localhost> <108776.1784105248@localhost> <224072.1789577949@localhost> Comments: In-reply-to shihao zhong message dated "Wed, 16 Sep 2026 22:03:49 -0400." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <38164.1789662971.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Thu, 17 Sep 2026 18:36:11 +0200 Message-ID: <38165.1789662971@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk shihao zhong wrote: > Here are my review for v03-0004 > = > 1. = > In copy_table_data(), the old "else use_sort =3D false" belonged to the > "OldIndex !=3D NULL && btree" test. After the change, the same "else" be= longs > to "if (!concurrent)", and the inner test has no else. > On my machine VACUUM FULL pg_am segfaults in > tuplesort_begin_cluster() with indexRel =3D NULL. = > = > This also makes 14 tests fail, with "bool use_sort =3D false;" all tests= pass. Yes, it looks like use_sort is can be left uninitialized in some cases. > 2. = > Looks like some rows are lost when the table grows/gap fill. > = > heapScan->rs_nblocks is fixed when the scan starts. At a range boundary,= = > changes to blocks at or beyond rs_nblocks are not in [range_start, range= _end), = > so they are skipped. The next snapshot can see those tuples, but the sca= n never > reaches those blocks. > = > The attached extend.spec has 5 blocks. It uses > repack_snapshot_after =3D 2, pauses at the first boundary, and inserts 1= 00 > rows. 70 of them go to blocks 5 to 7 and are missing after REPACK. Interestiong. I think we need to get the new rows from new blocks each tim= e we process the concurrent changes. > The boundary is only checked when the scan returns a tuple. If blocks 2 = and > 3 are empty (DELETE plus VACUUM, which is a common reason to run REPACK)= , > the scan passes them silently. The boundary fires at block 4, and > finalize_block_range() replays with the old range_end (2). Rows inserted > into blocks 2 and 3 after the scan passed them are skipped, and the scan > does not go back. gap.spec loses 40 of 40 inserted rows. > = > One quick fix made the rows come back and kept the suites > green. It passes "cur" instead of the old end to > repack_process_concurrent_changes(), and it treats any block >=3D > rs_nblocks as in range. It may be cleaner to drive the ranges by block > number, for example with heap_setscanlimits(), than by the first tuple > returned. ok, I think I understand the problem. > 3. Synchronized seqscan > = > table_beginscan() allows syncscan, so on a table larger than > shared_buffers / 4 the scan can start in the middle. range_start is neve= r > updated after that. Once the scan wraps to block 0, "blkno < range_start= " > is true for every tuple, and every tuple goes through > finalize_block_range(). = I had the wraparound in mind when writing the patch, but it's possible tha= t I missed something. I don't understand how "blkno < range_start" is true for every tuple, since finalize_block_range() should update the range boundaries. I need to spend more time on it. > I tested a 100 block table with shared_buffers =3D 1MB, after a cursor h= ad left the = > scan position at block 48. With ynchronize_seqscans =3D off, REPACK doe= s 6 = > boundaries in 0.8 s. With it on, it did 34 boundaries in 60s+. On a larg= e table > this would not finish in any useful time... = > = > I think the simplest fix is table_beginscan_strat(..., allow_sync =3D > false) in the CONCURRENTLY case. Then the wraparound code can go away. I'd prefer handling the wraparound correctly. > 4. Assertion > = > The new Assert(!IsolationUsesXactSnapshot()) is not guarded by the > transaction block check: > SET default_transaction_isolation =3D 'repeatable read'; > REPACK (CONCURRENTLY) t; > TRAP: failed Assert("!IsolationUsesXactSnapshot()"), File: "repack.c" > This needs an error, or the new transaction should force READ COMMITTED. Probably ERROR. > Would you be ok if I post fixes for some of these as patches on top of y= our series? > I know parts of the design are still open, but I think code is easier to= discuss > than a description. Definitely. (Please prepend the diffs with "nocfbot" so that cfbot ignores= them.) Thanks! -- = Antonin Houska Web: https://www.cybertec-postgresql.com