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 1sgkih-007ARq-TG for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Aug 2024 12:45:48 +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 1sgkif-00AdBD-Kl for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Aug 2024 12:45:46 +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.94.2) (envelope-from ) id 1sgkif-00Ad9S-Ab for pgsql-hackers@lists.postgresql.org; Wed, 21 Aug 2024 12:45:45 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sgkic-000m7E-AD for pgsql-hackers@postgresql.org; Wed, 21 Aug 2024 12:45:45 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-201d5af11a4so61325515ad.3 for ; Wed, 21 Aug 2024 05:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724244341; x=1724849141; 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=dtsEz615STX3VdsTK0xtkN0gb/WCsvVAdBTVZlYYmcM=; b=UNKBKiI97wjMwndcMCzxIiFJNXgKJcTFt+GRs94WDXtL5pJ5skPGLYbXEJSFe5Lh4b MMrFh0Jq29iCLHMvt6ISl6zV/AAnOx3M0K1PGKiIMKb9T4QCjddq4Ikj63N5vyh4PUcZ 8C2wYr87F8Jfb9zyfWHYILuKWc/eF8ZHTxeZNOtsIqMofA1MKeIBMKjhCfECTudSDQ0Z 1L4mJbZ4L4TNBQEjf7dkvnEp458VHzHpmK/hPWcJVn8wTJrv9IqBDc1l+CGxHFs1Pcrd CSuAFQ/tkeqZsFiDmAYVhPPeDrJM57NXmffQl9Y0yHFcqwLOxpgMDQC2oKhg9UhMv02g jufQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724244341; x=1724849141; 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=dtsEz615STX3VdsTK0xtkN0gb/WCsvVAdBTVZlYYmcM=; b=o7cglwrVZy9AhJrBB4HFIR/zP1A6paZ0IZ5Fg66L8qb0yQXffLqdTerfLtO0B8aIVR kDVblkjLMtGs0ayrX/+xtJKWeV5JSy/zRDbVx6NoQePTwAnpU/MVx6sLX55ZdV4GLqqR L0kS9KorFXS3DmJwDByYdN4dF8n6aC0DgD+XcXASKwF7GEJVe2ZuXLCfHAyRIoph+pdu 60KAirEodreI0ITLPYYCdITPETuoNdDsa2Z17d1+VsnU2C5vOPPp0T6IoDb8s8dhaQM1 9Uim9d60mEttHlP1nFwxj/6iAqnQUCfJojcX8pyRfElqkDNqJVZSNqecIPeC7PpQ3X2k IzWg== X-Forwarded-Encrypted: i=1; AJvYcCXrbqwDXGvU8PbmbW6NQHCH91NqkLePRohPrR/4lZGrosT3WursLtX39uTXupBZ6V7HrmHMvIgPFsCX5cKH@postgresql.org X-Gm-Message-State: AOJu0YzWJ875Raup3KXnl3pcv4J2Q9Ns2wGCE5FCZocHeJmZ+SWQLk81 /tSgNgD8GI6XistKHLXgiYLBritCsQd5NFDbNpffK3yPqWUt08a7nlk6+uORkVjvYKre8CPhGi3 YgrPoL/VZgFTUFsLMg+1WYUBEwPo= X-Google-Smtp-Source: AGHT+IHOWZEgfhM8HYwyBuPl3WgrzbaVbNMQa14x4SLGy0vF21ukf5UoSAP7vSYflVI43o7A1WF5vN5TMXIIZ1KzDhY= X-Received: by 2002:a17:90a:6803:b0:2d3:c3e5:b51a with SMTP id 98e67ed59e1d1-2d5e99c66a4mr2351398a91.9.1724244341356; Wed, 21 Aug 2024 05:45:41 -0700 (PDT) MIME-Version: 1.0 References: <202406191709.jbvpf7d7hl6g@alvherre.pgsql> In-Reply-To: From: Amit Langote Date: Wed, 21 Aug 2024 21:45:24 +0900 Message-ID: Subject: Re: generic plans and "initial" pruning To: Robert Haas Cc: Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown , Tom Lane 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 11:53=E2=80=AFPM Robert Haas wrote: > On Tue, Aug 20, 2024 at 9:00=E2=80=AFAM Amit Langote wrote: > > I think we'd modify plancache.c to postpone the locking of only > > prunable relations (i.e., partitions), so we're looking at only a > > handful of concurrent modifications that are going to cause execution > > errors. That's because we disallow many DDL modifications of > > partitions unless they are done via recursion from the parent, so the > > space of errors in practice would be smaller compared to if we were to > > postpone *all* cached plan locks to ExecInitNode() time. DROP INDEX > > a_partion_only_index comes to mind as something that might cause an > > error. I've not tested if other partition-only constraints can cause > > unsafe behaviors. > > This seems like a valid point to some extent, but in other contexts > we've had discussions about how we don't actually guarantee all that > much uniformity between a partitioned table and its partitions, and > it's been questioned whether we made the right decisions there. So I'm > not entirely sure that the surface area for problems here will be as > narrow as you're hoping -- I think we'd need to go through all of the > ALTER TABLE variants and think it through. But maybe the problems > aren't that bad. Many changeable properties that are reflected in the RelationData of a partition after getting the lock on it seem to cause no issues as long as the executor code only looks at RelationData, which is true for most Scan nodes. It also seems true for ModifyTable which looks into RelationData for relation properties relevant to insert/deletes. The two things that don't cope are: * Index Scan nodes with concurrent DROP INDEX of partition-only indexes. * Concurrent DROP CONSTRAINT of partition-only CHECK and NOT NULL constraints can lead to incorrect result as I write below. > It does seem like constraints can change the plan. Imagine the > partition had a CHECK(false) constraint before and now doesn't, or > something. Yeah, if the CHECK constraint gets dropped concurrently, any new rows that got added after that will not be returned by executing a stale cached plan, because the plan would have been created based on the assumption that such rows shouldn't be there due to the CHECK constraint. We currently don't explicitly check that the constraints that were used during planning still exist before executing the plan. Overall, I'm starting to feel less enthused by the idea throwing an error in the executor due to known and unknown hazards of trying to execute a stale plan. Even if we made a note in the docs of such hazards, any users who run into these rare errors are likely to head to -bugs or -hackers anyway. Tom said we should perhaps look at the hazards caused by intra-session locking, but we'd still be left with the hazards of missing index and constraints, AFAICS, due to DROP from other sessions. So, the options: * The replanning aspect of the lock-in-the-executor design would be simpler if a CachedPlan contained the plan for a single query rather than a list of queries, as previously mentioned. This is particularly due to the requirements of the PORTAL_MULTI_QUERY case. However, this option might be impractical. * Polish the patch for the old design of doing the initial pruning before AcquireExecutorLocks() and focus on hashing out any bugs and issues of that design. --=20 Thanks, Amit Langote