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 1rjxrM-009HX7-Uz for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 08:51:45 +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 1rjxrL-008hEM-CR for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 08:51:43 +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 1rjxrK-008h6B-Ny for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 08:51:43 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rjxrH-0045ht-4w for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 08:51:41 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id DAFC75F7B7; Tue, 12 Mar 2024 04:51:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=snowman.net; s=dkim; t=1710233494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bmEeaNDTBJNSUa1Y3uHirRHNLc3dTXi+5ElRgxtMit0=; b=I3dS/JgS5l950xsP/X+I8xLbhy6/j/iqU7MUi1LZg7QpHSZqEiy//PPZF0lPUVaOxIHyiJ out+tWcE9dnTPd0cCsMInVQr6Vlfl+sK1sTmyD5+/wIIqGuCV6n3Xq+0SJ8HWCp5bhycuO fivRozfA00vLknexi+EObapNTZk8IrI= Date: Tue, 12 Mar 2024 04:51:34 -0400 From: Stephen Frost To: Corey Huinker Cc: Matthias van de Meent , Ashutosh Bapat , Peter Smith , PostgreSQL Hackers , Tomas Vondra Subject: Re: Statistics Import and Export Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wcRNTwCrQUoGUxVf" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.4 (2021-12-11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --wcRNTwCrQUoGUxVf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Corey Huinker (corey.huinker@gmail.com) wrote: > > > One persistent problem is that there is no _safe equivalent to ARRAY_= IN, > > so > > > that can always fail on us, though it should only do so if the string > > > passed in wasn't a valid array input format, or the values in the arr= ay > > > can't coerce to the attribute's basetype. > > > > That would happen before we even get to being called and there's not > > much to do about it anyway. >=20 > Not sure I follow you here. the ARRAY_IN function calls happen once for > every non-null stavaluesN parameter, and it's done inside the function > because the result type could be the base type for a domain/array type, or > could be the type itself. I suppose we could move that determination to t= he > caller, but then we'd need to call get_base_element_type() inside a clien= t, > and that seems wrong if it's even possible. Ah, yeah, ok, I see what you're saying here and sure, there's a risk those might ERROR too, but that's outright invalid data then as opposed to a NULL getting passed in. > > > Or one compound command > > > > > > SELECT pg_set_relation_stats(t.oid, ...) > > > pg_set_attribute_stats(t.oid, 'id'::name, ...), > > > pg_set_attribute_stats(t.oid, 'last_name'::name, ...), > > > ... > > > FROM (VALUES('foo.bar'::regclass)) AS t(oid); > > > > > > The second one has the feature that if any one attribute fails, then = the > > > whole update fails, except, of course, for the in-place update of > > pg_class. > > > This avoids having an explicit transaction block, but we could get th= at > > > back by having restore wrap the list of commands in a transaction blo= ck > > > (and adding the explicit lock commands) when it is safe to do so. > > > > Hm, I like this approach as it should essentially give us the > > transaction block we had been talking about wanting but without needing > > to explicitly do a begin/commit, which would add in some annoying > > complications. This would hopefully also reduce the locking concern > > mentioned previously, since we'd get the lock needed in the first > > function call and then the others would be able to just see that we've > > already got the lock pretty quickly. >=20 > True, we'd get the lock needed in the first function call, but wouldn't we > also release that very lock before the subsequent call? Obviously we'd be > shrinking the window in which another process could get in line and take a > superior lock, and the universe of other processes that would even want a > lock that blocks us is nil in the case of an upgrade, identical to existi= ng > behavior in the case of an FDW ANALYZE, and perfectly fine in the case of > someone tinkering with stats. No, we should be keeping the lock until the end of the transaction (which in this case would be just the one statement, but it would be the whole statement and all of the calls in it). See analyze.c:268 or so, where we call relation_close(onerel, NoLock); meaning we're closing the relation but we're *not* releasing the lock on it- it'll get released at the end of the transaction. Thanks! Stephen --wcRNTwCrQUoGUxVf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEwf6gbxKhD863zrx/7WyKOINHZFUFAmXwF5QACgkQ7WyKOINH ZFXJDBAAluRUwbnFoK61vcCEztLNElzy6/KMVhiZ8nhA16yOro4Ac346q18uKMdG LuL32doNxlR1RPH4OzKZbyx2qFN2oDpzDt17wapqL9qWMrFPz04DQhwpC6mO/Gho pC14CRyyGSOoJwF3wFihfwo2Y1ge22SkSmwPR3l1StvT/gfWP/dp85ME0R4m0FsR iHW5zKwCXz7rPCTKTKtPk7w4Fn0Jx7yjp4OT73kq5mKUWyyPqwa9iY+zjoLaNJCi I2ICFKtq/BGBq+j+phjc1wOdtxCj49sGYNLXuJi4431rvsElxUerH5Qt4sKKbxVE RXc9BblJoDFU7/vRnTVACxRG0FWbNC9/p97gt9UKIxt/bMJs3ITDBxqREnWdaMjU r52PsdE2rRXCOrr92bA8SiimnX3ISlYRuI6FOWvQ2hRr/37cAkE+TTFa9MzdKPAx qDzefQYRbl3wczJGGeZocafS456lnYkXidR6AUSz+OCM7Uy7sPcpD6n0dxIs4MsC jsEB1iOIR/yVsxWiWG3mCPU0E8qKvos3laZUtQ67DmN9h60iU7e9lzKWpozPMnee VwWhmBcFTgLykTYrKqigA0N1fIi6qnjLoevelHeeGBzwGw16j3GHiC5Qz98SADjB dbIHp3zNZAFKMDVdYqgY5KvKCdnzRmjZXRQBjzuzpTOa18FX6Lg= =oJd1 -----END PGP SIGNATURE----- --wcRNTwCrQUoGUxVf--