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 1wF6aN-004kYm-2O for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Apr 2026 08:36:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wF6aN-007ZVr-02 for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Apr 2026 08:35:59 +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 1wF6aM-007ZVj-2O for pgsql-hackers@lists.postgresql.org; Tue, 21 Apr 2026 08:35:58 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wF6aK-00000002GlO-36iC for pgsql-hackers@lists.postgresql.org; Tue, 21 Apr 2026 08:35:58 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-43fe62837baso2376967f8f.3 for ; Tue, 21 Apr 2026 01:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776760556; cv=none; d=google.com; s=arc-20240605; b=eJa2q52a5KgpAH+hOk8btqCI8cgvyRXddV8v/jWNO89xkknuU5uOfD/h90Z8GkzhWO jca+GcCn2YMxgKX3n923rfObO46HyHYygzUD+ii9WkbrjHkKkK7+Jlj6ctY6cw0zjn7e XMvsLhYx7p5Moc0Qx5a+/JKzTPgCJ1hACoWX1I/HA/7cFTPskMhT+yshYsCMnxhXpF0C AAvu0m+KHVo6pufAQuRLgPY9v2wSOm85pvKNakx9Uk1U83galS3+3P3byudVt6F5a5Ms E4rxVh/YrgpeOk8eI0PGS8bAWsg63zkAT9LbG17q3TwWPMkQLa/yahYqMjrV4hmlhIlH FcgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=24v0MoZxOTK3BAux9EOmvRYSmygO4wUo6zo3pqPEyKc=; fh=vSFukzSd6k4mKCe/IJWyNimq1aMIJ3L5Nt0XxuimHH0=; b=Q/4oLlCLmoF+216akvTGHJfXQuzw59gd/eZp4DfMbd75ZbyQ0apO0Js+SjSOxtbu08 yf+iCaH3fSP4RMg5jlCazQuGFKlVmQ4EFAfZZ7TJusTKhmRywPdoFJH7AyD2aTnZbAs8 kHD2791ypxnjog6XxHrz9BSGWBsJCF2Zn1yBGtlvp6ni5AELE2QlMMah8cRli2+0E+jd 05TJjzQ0FSNXugPsPzG+JYqhjfrqCV42GhEgB5SMXTbLrDFGqWG9QBQtbdsgLFkXyQI+ TaR3XCNe/E8Myitmm7Vwgz583JH6exq1l04G4hZQ9axPOz0ZmzsPYfugXggZeH0tBJoO tX4g==; 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=1776760556; x=1777365356; darn=lists.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=24v0MoZxOTK3BAux9EOmvRYSmygO4wUo6zo3pqPEyKc=; b=PQKQcBAdAeVpB7cWD1nPlP8wT8J5OdeFGJNwkSygmgF3rZO507X25ZR14TXHdI306P AZDxWT7Zeka81hRmtSikpDQCO1Y0foKD9Ueu2aBiY3ho4YnqE1az1QYOI8RNt1xKP0q2 jlWCNwRekulHR3XBXQeJE4oBAA5AuTEccluJPU/JVKlMvSnQq2B46jSfUxBw+yQLuy09 CmyaREMjJUUEnN1DY58Xat9ucS+bhssoR40TxCaFchxiaaB2VQYI0BFIzgug8SATcWnn VKKeXXNlve/GYZ+Lcdk3IVFPo8Zm60mct/EDjZnq6iYoL9Jjrr0YcOp1YXzsKKZfXZeH NvLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776760556; x=1777365356; h=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=24v0MoZxOTK3BAux9EOmvRYSmygO4wUo6zo3pqPEyKc=; b=N1Su1GUmVyaG+1nS8ifab2eLSkMIdrjTvct668xFGKT/vsok3ZIGm+yuocpt3CXmuY WiWmT9OX3hiybiFWsjLc6ir8+eQzEI/2v/HgGvi+O7FYnT489iR8FMa1wxmqgmjBXgL2 q0VVAFWbUmaIJH/voZY2Pe8V62PLPC7P9fK9XEvY0jDEm7nKrVwsFX+Bxim/heGNJNYj jPXnxAL65ORKT+gl0gMw0JNJ3oi1kjXPPD5iGZQD1RjuPUhAcl9CUpfU1grb7Tg7cLQb 3c322TUDZ+7KbIFPddCEZwVrso9Fub4+GWlSlzJayo7/heqWhyEOEHmtGBVEZ38J+8Jj OYnA== X-Gm-Message-State: AOJu0YyVzT0ZJQwj5bgYVPwJcwpPPU37+7a4kgvw3h/M9BfhJ4wcxRe3 vhMCinGEBJujGu20B7vcBnxx5NMyccF5PZWzUX/o0DYX6yLTHSusS+fNa0btsEBS3WH+Vpd23eX F3K7IPfC1KKydWE7T0JyUx5B1wNKsjdQ= X-Gm-Gg: AeBDieu5UWa8vlgamLSK6lMmCSMH6Ti0Cs020FTSJhO6BO8zzR7C1bVku530YY46w0+ fXfe/nSrnV25FXjYhHlNXFATTf9xWPUsREZ0bHhwklPQjzEZEnbmbOHue0NF6ax2kpQFXYw9qVR EmpV6UoQ5tPisThLCxXZv87fRnD+efJ0KqkZyqjb2ga04xwUQSRAFza9mABxJOlxry7kZUDL5IN lDN3vVE5e3kMKIpFrwXrl90u0zdwh8I2Pa315OxGyesktPE+XlvhM5pFhYqBdhZhw3vMaV13CiD xfiF1y/qCou59JEdG/ZvG4loESh/WrrfaYc5+c2aXR6fYoqo8eI/PPO/8rtOKu1HayBKvtfsFVC n8tkZdFWIbnI7tDYqijY= X-Received: by 2002:a05:6000:25c4:b0:43c:f52b:8003 with SMTP id ffacd0b85a97d-43fe3dfd332mr25363535f8f.36.1776760555396; Tue, 21 Apr 2026 01:35:55 -0700 (PDT) MIME-Version: 1.0 References: <20be3d9d-4147-492a-b69c-d69a87a014a9@gmail.com> In-Reply-To: <20be3d9d-4147-492a-b69c-d69a87a014a9@gmail.com> From: David Rowley Date: Tue, 21 Apr 2026 20:35:42 +1200 X-Gm-Features: AQROBzBIlrAGvwdFO7ZfLxvLGezDCTH3DZ78HfMjkSz64o276mkaUUkU-TWAZK4 Message-ID: Subject: Re: A very quick observation of dangling pointers in Postgres pathlists To: Andrei Lepikhov Cc: PostgreSQL Hackers , Tom Lane Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 21 Apr 2026 at 19:29, Andrei Lepikhov wrote: > > On 17/04/2026 10:56, Andrei Lepikhov wrote: > > The best-known problematic code example causing this issue is > > apply_scanjoin_target_to_paths(), and the current_rel/final_rel game from commit > > 0927d2f46dd. Quickly fixing it, I see some more combinations have emerged: > > On closer inspection, it looks like all the detected cases come from the same > issue in create_ordered_paths. The ordered_rel has the same path in its pathlist > as the input_rel. Sometimes, this path is removed and freed from ordered_rel, > which leads to a dangling pointer in the child RelOptInfo. > > I've attached a patch that shows how to fix the issue. Some regression tests > change because of a hidden rule where a projection and its subpath have > different target lists. Right now, the patch always enforces a projection, even > if the target lists are the same. This is still open for discussion on whether > there's a better way to handle it. IMO, we should write a function like copy_path() or reparent_path(), which creates a copy of the given Path, or the latter also would copy then set the ->parent to the given RelOptInfo. Any time we use a path directly from the pathlist of another RelOptInfo, we should reparent or copy it. We could add an Assert in add_path() to check the new path has the correct parent to help us find the places where we forget to do this. David