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 1sgOhl-001eA7-5o for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Aug 2024 13:15:21 +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 1sgOhj-00HV6j-3I for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Aug 2024 13:15:19 +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 1sgOhi-00HV6b-NS for pgsql-hackers@lists.postgresql.org; Tue, 20 Aug 2024 13:15:19 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sgOhg-000ZUh-Q1 for pgsql-hackers@postgresql.org; Tue, 20 Aug 2024 13:15:18 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2d3eda6603cso3126998a91.3 for ; Tue, 20 Aug 2024 06:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724159715; x=1724764515; darn=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=8z3oigbP3V7Dm2cPyW/EKjIwEnZHbH4Ny5N22N5vTz4=; b=QA4C6Sx7x25RDplpqLgZRtzS2lVofGWEqUEkHnO983zNYEtuySdcUNv917jy51DW8U 9ilo4TV73J9W3vMH+iEuvFLlj9ZOu5Z2btrmgZtTCsDi1YGji5kfBHeWmO3GjpFBzEld EpkNgnqSA2cpYW2VFMHphXxLFPM3BjceDRaQ1Gwh2oXb7JVeJ2deGaz5SXJ5TlTsh7rI yeA/vVlGLzKgpz0OSSPaHvi7l10ZnBbMPmJeVpN4d32FjXbgsvTuCmrXouDsniQpbpXH LJAK0rYvlBZN5NbSB6k/GrHWy2jKWGMPrEU5nXaMo6JL9bQVhdfcfPhYSPdvzIxWyUNk bVAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724159715; x=1724764515; h=content-transfer-encoding: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=8z3oigbP3V7Dm2cPyW/EKjIwEnZHbH4Ny5N22N5vTz4=; b=BTKCQAWnMiIdlStgP4s2ork8iqOCMQ4uUkgqGLnBcR1Q9No+31bQal2NxhkYbM+DWh 7V6mHxl/TJgplChHjm/ZS1J+r5UGNQMn1czD0bJxrZxqdbTFCqc5yA4wOfFXcUrtyC8A UOn3G0oorlCN/2YVsdNduzzQTjEWMQ8al5JltlDCCP5JRmAai6Wryv5TGP+eU3CAdr62 mbFEaxACyHal9IxqRS91Yfji/SfPWBh3LZpk9gJbN3DqeZ9bQz9evxRnSaM8xTlnyQ+l mGmY1bzg+mlPfVAK9rqSVdoG3vGhm0zkBoVYs7OOwiCaXFiudw7xUB+U1kPqKQUjS+uH saIw== X-Forwarded-Encrypted: i=1; AJvYcCXsxYC4yvg4ZidjdX79F4Rcw1tqe+BkXpwP3JUYK8h9a5QTgUZJGKW3rOHw7YR5OwAc2Io/Nl7ImDAeD8AQ@postgresql.org X-Gm-Message-State: AOJu0Yzm1i8/w095wSZKTNgIQTUEr5TQf24I4rKcKjXf+24ixN9pZfZw 7Dnsxr7SF3qwuchRe0/9p78vo8Kt/DhE/ofmKDmhj3AQWTsVxg7vkMvGnMQeygtr/7C8Wvk3Idv 8HwcRtEJ6zAuW8OUt17s3WSKSWpA= X-Google-Smtp-Source: AGHT+IF/oCRjfe0dqBki3nNuDYZEg32/x/Yq5OH3jivP4i+60qfm8GRanwq1t4UxbnRGBI08lxQ6GfOQdjjnXlWs+2g= X-Received: by 2002:a17:90a:c38e:b0:2d2:453:12cb with SMTP id 98e67ed59e1d1-2d3dfc1f571mr14456218a91.2.1724159714819; Tue, 20 Aug 2024 06:15:14 -0700 (PDT) MIME-Version: 1.0 References: <202406191709.jbvpf7d7hl6g@alvherre.pgsql> <1386845.1724086454@sss.pgh.pa.us> <1393410.1724089927@sss.pgh.pa.us> In-Reply-To: From: Amit Langote Date: Tue, 20 Aug 2024 22:14:58 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Robert Haas Cc: Tom Lane , Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown 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 Tue, Aug 20, 2024 at 3:21=E2=80=AFAM Robert Haas = wrote: > On Mon, Aug 19, 2024 at 1:52=E2=80=AFPM Tom Lane wrot= e: > > Robert Haas writes: > > > But that seems somewhat incidental to what this thread is about. > > > > Perhaps. But if we're running into issues related to that, it might > > be good to set aside the long-term goal for a bit and come up with > > a cleaner answer for intra-session locking. That could allow the > > pruning problem to be solved more cleanly in turn, and it'd be > > an improvement even if not. > > Maybe, but the pieces aren't quite coming together for me. Solving > this would mean that if we execute a stale plan, we'd be more likely > to get a good error and less likely to get a bad, nasty-looking > internal error, or a crash. That's good on its own terms, but we don't > really want user queries to produce errors at all, so I don't think > we'd feel any more free to rearrange the order of operations than we > do today. Yeah, it's unclear whether executing a potentially stale plan is an acceptable tradeoff compared to replanning, especially if it occurs rarely. Personally, I would prefer that it is. > > > Do you have a view on what the way forward might be? > > > > I'm fresh out of ideas at the moment, other than having a hope that > > divide-and-conquer (ie, solving subproblems first) might pay off. > > Fair enough, but why do you think that the original approach of > creating a data structure from within the plan cache mechanism > (probably via a call into some new executor entrypoint) and then > feeding that through to ExecutorRun() time can't work? That would be ExecutorStart(). The data structure need not be referenced after ExecInitNode(). > Is it possible > you latched onto some non-optimal decisions that the early versions of > the patch made, rather than there being a fundamental problem with the > concept? > > I actually thought the do-it-at-executorstart-time approach sounded > pretty good, even though we might have to abandon planstate tree > initialization partway through, right up until Amit started talking > about moving ExecutorStart() from PortalRun() to PortalStart(), which > I have a feeling is going to create a bigger problem than we can > solve. I think if we want to save that approach, we should try to > figure out if we can teach the plancache to replan one query from a > list without replanning the others, which seems like it might allow us > to keep the order of major operations unchanged. Otherwise, it makes > sense to me to have another go at the other approach, at least to make > sure we understand clearly why it can't work. +1 --=20 Thanks, Amit Langote