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.94.2) (envelope-from ) id 1syzZl-003W7W-Q4 for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Oct 2024 20:15:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1syzZk-006axX-FI for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Oct 2024 20:15:56 +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.94.2) (envelope-from ) id 1syzZk-006axP-51 for pgsql-hackers@lists.postgresql.org; Thu, 10 Oct 2024 20:15:56 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1syzZh-000Fpa-Nc for pgsql-hackers@postgresql.org; Thu, 10 Oct 2024 20:15:55 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a994ecf79e7so217606866b.0 for ; Thu, 10 Oct 2024 13:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728591352; x=1729196152; darn=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=PH57QNVTv8Ofuh9uqy+Pw3om92byKunKEeK/TP3b9Nc=; b=LQ6GZ+FyQFXxcBf/QmMA/L0pL415p714mH7zG4zUKl7mHP91QH0Bg7jf2RLUiXDsJd +g0yCg/q67BGbpTUguhq4lUswq3wAzZ35iMd+fq9dKud1D9Xjjb4/9oejQo9E7P3CIpF Vl85WIX15WV3PDwtlF7j36sjqhLKQcdH75nESAZNwo6XbgDlymUsCCtaYhQUo2E0uOb+ sEL9Z6UcuIk5WpkMTdoSqA8uFGO3DMz5qYPtNIbn+2cpF/GuKv4yIluH0/JWigp0E63T iStLpf29JcR816lHIibtyZxyQUByIXTQ/dceCg6dJxzRY7Hpm2tGifvwWqDOBqG6r5+z 809A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728591352; x=1729196152; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PH57QNVTv8Ofuh9uqy+Pw3om92byKunKEeK/TP3b9Nc=; b=Z6hNzMvrAqiQd9zs/LvZpL6d7ZOlbOSiMsQ7j5DR3JmwAQTovKoARorpfKVBv4JGxe lXFnOaMdCVnL0dSSDkWDhfUqqJto07fSErTJ+H6FmcYZhfAk5t1mn4XhMwfOizTzkPdk mdOmOXFcwWBTRwAOOsipvkubt6WrLcVO8rMqp9VXzI+7bVZhl/NX9DM05XBvTF/9kaL8 0/lb+jkxM9Ly5vyBVdnGTVxjIrUUzLFVQ9pSNsCqZHt8KJs0i1SbUNqdu8ggQy5kN9CE Y+9nsMzJo6zU5MdNZDhNqbaQOAzTTGkuRQTbeS47AqD0Rl+Ph+NrDBVODjaBZeRFNBHJ OESQ== X-Forwarded-Encrypted: i=1; AJvYcCULqGQE92pOaEnFhfgsmbDnYlSxmWDC7h+oONHKQ9QfSohUzbt4caQCdwmRkx9p1wRVgmDObJ0K+HRlJGcn@postgresql.org X-Gm-Message-State: AOJu0YzmhwUBDZrkv9Vv8yWZ/goTFB/x/HfDakB7NJZuWxL4Hc1gyBx4 gGLLtiQPYG97NZgQFJk5Sba9X/jAfS4lMNyBm6vuTiQnuCxlbaJhCbJ1Hqxzp5bxGDeJ22PoYI5 4opUWuCaSars9ONsVXjJbfY+40dk= X-Google-Smtp-Source: AGHT+IFi1ilIo5bXuH1ZxCaTIgeo/ixTDMnctTQzCAgCjNJfYAZkzHeFmYSaw47nrA5TPALGFGx2pxV+2JmoSiPeDJw= X-Received: by 2002:a17:907:e2d7:b0:a99:585a:42a9 with SMTP id a640c23a62f3a-a99b94194d7mr16379166b.9.1728591351947; Thu, 10 Oct 2024 13:15:51 -0700 (PDT) MIME-Version: 1.0 References: <202406191709.jbvpf7d7hl6g@alvherre.pgsql> In-Reply-To: From: Robert Haas Date: Thu, 10 Oct 2024 16:15:40 -0400 Message-ID: Subject: Re: generic plans and "initial" pruning To: Amit Langote Cc: Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown , 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 Hi Amit, This is not a full review (sorry!) but here are a few comments. In general, I don't have a problem with this direction. I thought Tom's previous proposal of abandoning ExecInitNode() in medias res if we discover that we need to replan was doable and I still think that, but ISTM that this approach needs to touch less code, because abandoning ExecInitNode() partly through means we could have leftover state to clean up in any node in the PlanState tree, and as we've discussed, ExecEndNode() isn't necessarily prepared to clean up a PlanState tree that was only partially processed by ExecInitNode(). As far as I can see in the time I've spent looking at this today, 0001 looks pretty unobjectionable (with some exceptions that I've noted below). I also think 0003 looks pretty safe. It seems like partition pruning moves backward across a pretty modest amount of code that does pretty well-defined things. Basically, initialization-time pruning now happens before other types of node initialization, and before setting up row marks. I do however find the changes in 0002 to be less obviously correct and less obviously safe; see below for some notes about that. In 0001, the name root_parent_relids doesn't seem very clear to me, and neither does the explanation of what it does. You say "'root_parent_relids' identifies the relation to which both the parent plan and the PartitionPruneInfo given by 'part_prune_index' belong." But it's a set, so what does it mean to identify "the" relation? It's a set of relations, not just one. And why does the name include the word "root"? It's neither the PlannerGlobal object, which we often call root, nor is it the root of the partitioning hierarchy. To me, it looks like it's just the set of relids that we can potentially prune. I don't see why this isn't just called "relids", like the field from which it's copied: + pruneinfo->root_parent_relids = parentrel->relids; It just doesn't seem very root-y or very parent-y. - node->part_prune_info = partpruneinfo; + Extra blank line. In 0002, the handling of ExprContexts seems a little bit hard to understand. Sometimes we're using the PlanState's ExprContext, and sometimes we're using a separate context owned by the PartitionedRelPruningData's context, and it's not exactly clear why that is or what the consequences are. Likewise I wouldn't mind some more comments or explanation in the commit message of the changes in this patch related to EState objects. I can't help wondering if the changes here could have either semantic implications (like expression evaluation can produce different results than before) or performance implications (because we create objects that we didn't previously create). As noted above, this is really my only design-level concern about 0001-0003. Typo: partrtitioned Regrettably, I have not looked seriously at 0004 and 0005, so I can't comment on those. -- Robert Haas EDB: http://www.enterprisedb.com