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 1w9qMI-001oQ6-0l for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 20:15:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w9qMG-00Bscz-21 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2026 20:15:41 +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.96) (envelope-from ) id 1w9qMG-00Bscr-15 for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 20:15:40 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w9qMD-00000000xWx-3W1x for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2026 20:15:40 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b886fc047d5so658211566b.3 for ; Mon, 06 Apr 2026 13:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775506536; cv=none; d=google.com; s=arc-20240605; b=FdNyIpdd9FRnYLpVstwo/ajvLzvBCUYVZouMsmoOPgWUnLBgu5onZ97bvaTL5ozuzP Ogf4bIdpe//ZWvCbP5gVJRQKxQJ0taxhV+WOkKdNqRBmjccfn6Qa8Diu0pNfc2LAQ4KA ncCzdP5kAECfkVvG60Iz4DJzjDvfgfagFo1dOYJbHrEyNrkVIsJG4Bb6ccwIRQjR4xN+ p5b7aIx7ARKVCPxPJCqSuW7FuLD8qWWAa4dVfLS/ivVjFVNgRzmEVphf/MG6zCFjCrY/ hDJrLRDp7WtrZwt0s84cJwU+ohF4vV9T86lAGcbSZI9mBXUMMevSUbnqqFzlzC5GAYH5 D++g== 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=7wNF74GALTTm7vwOixkXqqyWDXbUhB9/z+tAEneG+xg=; fh=H7IIIV4Z3iTTvyt6mFP8q8oiqtKesg7ri5D34n/ydwM=; b=HafeueoomJZv4KrE9s6We3DQ60hAnJbIB4doZhVMWeXYoB84e4eBcfmbyNT9381zf7 XBVaYcgkE711JnTnfAtPXE/NhlTh2JWPYHsVpmycic/jbGGN2jYOCVRVDZQCbjxTAuA9 yssqFXqBt2a734iYJB0onREXZNdoMJ8CsQsYC9pPactfG3r0hikux2MIXiGBKH2iPY9x KiBjDWzoRbqwwL+jxVrF3hj936pdPy2UQQUJqs4PIW+zkRDEco6PZR/WbGtNEjuBGOry GV3Q/nfsZ7t/7k6iNeF12tUj0Ts3qPi8gLFTySGNrgBkyh9ISRNvI6geFLIsTzE1aK0T Fpqw==; 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=1775506536; x=1776111336; 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=7wNF74GALTTm7vwOixkXqqyWDXbUhB9/z+tAEneG+xg=; b=Wb6b+VoHhHofpc4UC0EQO4MqChY7kmkG6o/cwh2PSqeKHOZ5koWCXBKuNvJIvEp7HK H9DLWndmRP6uepUj+w2LiLF9FgeD58ka+z45AiJFP+7b9oNKnKcmpooI+ghXs/6NYNCV Iv7XcmTi28cWCU1ogvUS9or0LyJhZZG5j1IRSaHZnLnjwBKZxt54CWdlLPA1Iy4UAbdI 5Oq0DU0Fjqq3qtfbiUY+spdl81lfP+GgpOkVKMQCni4e+uISQJEN0ttIsVAU0lqeYzoW fdQuXMXigMEKsQxsHu2Cuj+mzCVCAgWnLe8aPzOzUi6MAuQGZvpL/TM+i+r3Vhj5XdSo okcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775506536; x=1776111336; 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=7wNF74GALTTm7vwOixkXqqyWDXbUhB9/z+tAEneG+xg=; b=lDamzzljqk4Zf5fMxw0tqanhpneb45W62v+eO4BBA/D5xXwMYEwziuqtQAl1ljQezk irNPu1XZLipc5CE/LxurzaLU2GgeQLx1R5fWcijjmba6QvrCdCNwCSE7OtWoq7yEvurE HENeJADSPa0BXe5th7cyx+/RIV5E5NoZA3FQLRXfjHdrSJGgjyjU5mRWbKRePPjT1kXD CypAdBhXheDnUHrFnrrc3n3uKl0VVRnctv0f9Nr/nXhPU3BJ6ZTj9FnOCZkLvXtmCPMe 41Z9dPokPTx6R4qzCQrVnQJDrW7EHEU0Mo5LY6UaPtaqJQ67qEkdouIgbEzAjIzbOi1N q1Ow== X-Forwarded-Encrypted: i=1; AJvYcCW3CxiZDhe+YDK7XI0ACaFpRmz/IvYj4KYKUDBpDm+NGXcLLITDss3nKzJR3uduiIPqnFo9Ma6+RdiApRpM@lists.postgresql.org X-Gm-Message-State: AOJu0YzBoDUufhYLy/WJ5SkytJE9o99H1ae93ti343ok7QXmXOC+8Jw4 ChfPXWCtl12jGhsGgMdigT2Nd1EB1SX4qpWDIwsNdmWSW1VPhJWqCyNmaoUNIjJrMRD0pc5UOBY tnn5E0s2RrDGt+jgDPSyowNqUBr/Pt28= X-Gm-Gg: AeBDiesko11x3SDBF0RGo+1qPIDNhomqSeF4UUWSSJDiZOjXU//wX+7kH6oeX/GV9VZ TRaENoik053vu8VQElc6kviuHHG5ChSSSKSzx+lodYwpI5j/ULvudVE6Cjlad6FQC9BO9nwjHUm Zk6rKB6clhFj12HrDDmzQUOv4DHaEEtq7ESstXYbKfnw7RUBqKWWdNgJulx4iqjm+34/9j4Fmgu TUmZDajQk5jFgSzWRLAqbdPln437a4rOREpHNsepxMm9fi4UjBRw4eQwiyTIgaMv41B4KA7MULd pt/QysnnctYwJnVri/2LPRh2a6beLK9V1kaszSw= X-Received: by 2002:a17:907:c002:b0:b9b:6869:bab0 with SMTP id a640c23a62f3a-b9c672f45b8mr784570866b.2.1775506536080; Mon, 06 Apr 2026 13:15:36 -0700 (PDT) MIME-Version: 1.0 References: <3683430.1775173413@sss.pgh.pa.us> <3817825.1775240432@sss.pgh.pa.us> <3877210.1775272486@sss.pgh.pa.us> <386d8c06-0f96-40bb-b1b1-107db209c676@gmail.com> <2e7bdb5d-68ba-4c65-9931-a865ab6fc3d2@gmail.com> In-Reply-To: From: Robert Haas Date: Mon, 6 Apr 2026 16:15:21 -0400 X-Gm-Features: AQROBzAVOUkv6E0Qw5eAuTP5KOHUMgzolvlbRaBdE-FahoLGFOrwT_XJb8Q0jt8 Message-ID: Subject: Re: pg_plan_advice To: Alexander Lakhin Cc: Tom Lane , Lukas Fittl , Andrei Lepikhov , PostgreSQL Hackers 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 Sun, Apr 5, 2026 at 8:00=E2=80=AFAM Alexander Lakhin wrote: > And another error, which might be interesting to you: > CREATE EXTENSION tsm_system_time; > CREATE TABLE t(i int); > SELECT 1 FROM (SELECT i FROM t TABLESAMPLE system_time (1000)), LATERAL (= SELECT i LIMIT 1); > > ERROR: XX000: plan node has no RTIs: 378 > LOCATION: pgpa_build_scan, pgpa_scan.c:200 Thanks also for this report. The plan looks like this: Nested Loop (cost=3D0.00..154.75 rows=3D2550 width=3D4) -> Materialize (cost=3D0.00..78.25 rows=3D2550 width=3D4) -> Sample Scan on t (cost=3D0.00..65.50 rows=3D2550 width=3D4) Sampling: system_time ('1000'::double precision) -> Limit (cost=3D0.00..0.01 rows=3D1 width=3D4) -> Result (cost=3D0.00..0.01 rows=3D1 width=3D4) And it's unhappy because it's expecting the Materialize node to be the RTI-bearing node. In a turn of events that will probably shock nobody here, I also didn't quite realize that a Materialize node could get inserted here. It's kind of a problem, too, because what if the sides of the join were switched? Then we'd have a Nested Loop with an inner Materialize node and would conclude that the strategy was PGS_NESTLOOP_MATERIALIZE, when in reality it would be PGS_NESTLOOP_PLAIN plus a Materialize node inserted at the scan level, so the generated advice would be incorrect. I guess the fix is probably to view a Materialize node on top of a Sample Scan for a !repeatable_across_scans tsmhandler as part of the scan, which is kind of annoying but probably doable. Not for the first time, I really wish we stored an RTI set in every plan node, or (maybe more economically) had some kind of enum in key plan nodes indicating why the node was inserted. Right now, pg_plan_advice does a lot of reading the tea leaves, which is great in that it avoids bloating Plan trees with additional metadata, but a little scary in terms of being able to be certain that one will get the right answer reliably. I'll work on a fix. --=20 Robert Haas EDB: http://www.enterprisedb.com