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 1w66vh-003xjR-0Y for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2026 13:08:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w66vf-009o55-1z for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Mar 2026 13:08:48 +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.96) (envelope-from ) id 1w66vf-009o4x-0f for pgsql-hackers@lists.postgresql.org; Fri, 27 Mar 2026 13:08:47 +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.98.2) (envelope-from ) id 1w66vd-00000001JuE-1fQB for pgsql-hackers@lists.postgresql.org; Fri, 27 Mar 2026 13:08:46 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b980785a0bfso290516666b.3 for ; Fri, 27 Mar 2026 06:08:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774616924; cv=none; d=google.com; s=arc-20240605; b=iPNcR+JR3HoqvE5t3JowCvmfrQDTir75EFxnbubi7Wj/n0Dy68nSnIDWi31TH274WC EHErI4aj5C8c97VIsT4sbhGz2G7hdx67ngmBbntRZv2Kza0VUAskwxkCoi+q3XlrnPwJ O2kbYpdNiWeE5xij9T37UUje2VrNv5yIvOSw/a6Chw688yIp7wGkaC1OjfTL7zSctEL3 8Z+1jt88cP54TA1AcnV9fHwXGOhGksSgGa+h0GXPRwPwhBRJNH5prV98mQZeE1Iso4XQ /0uVcb+AqQNoffctEHc4LHnJk/1I32GaNU/uxZUA80hdMSHue0oEC5a7/hRYAEQyhCN7 4axQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=efGVQuF5vwMHlAfa8an3CSyD4e4xpvXayVPfIq8LTz4=; fh=1S+pj64nMiaWoRaZS2yyPc5WpIEDEHJZH1b2KwcGUtQ=; b=UbM70gvsp1yhUbgIPzSw3WQg/1FYrc2qP3gGiujEucfZzG5eP8w9FbIXlSXwThwiy2 u0L0JZjniBuPPzpfGwA2Bvgk6MqbOx8XSiWMRNffYvYjAvAT5KxaVBXdgRDYXlsEy58f C9jaTJPbycuW4TPVd+7MsbHudBtyJnYH31uGl/+97UpG7yzbQBcWUfXc+fJOKbb2HPy1 gwUMgU5FhMOmdKOQVsSIiDo6n6KB9bDG3odJM0+IXnLlXEZWcSVn9ytp+wBBYDDaAK2m A8ert5nxBVb6ZPO7ocDm9H23HLgfqTdQhuLa0a0nscTabIRMWH6KjZxccBYTfj8RoU7n 03Lw==; 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=1774616924; x=1775221724; darn=lists.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=efGVQuF5vwMHlAfa8an3CSyD4e4xpvXayVPfIq8LTz4=; b=rR0gILqyVNXBHFA9b5PR709cMdEZxjj42mJIDDm1aFv7vxkoQsS/gxE4F0hQZVuZ0a w+yrc4uq+xcSplWeuAkgFSvr3F8+/6sOq9lYKjbKoq9lOC3urNP7u7JEZ7VfNgpnopOx fd96trE0X1Css803ibB2ITzfZ9d9rzhX8erqH6lLoYSbp7sMCP71OR6hdBsVMDS2oYtp AVP0OErCEEKYuOPZXZ6J3IIk+BE08y5IfafJg4S/DTQ3UMGSjE7DlGxS7JDRwTnngGqn QFZdt/hXxpJ0JF3m0wk22B7Q7VyAFCurv74qWd2yS2MiI8PdezA0vQbOOc9fQluU8TXA PWhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774616924; x=1775221724; h=content-transfer-encoding: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=efGVQuF5vwMHlAfa8an3CSyD4e4xpvXayVPfIq8LTz4=; b=G1+/zDC7zfamuzZQP32bwarv8eCCHyfBQ54ONs41/3vqvOoq6uBLORT49Zc4YCiJAv m/ionYd5GfCgPO0bEi0mfbn+XexBHz8AZ2Nm/EFTqq5pZQIff2EoSim5PJu8xZ2zuYxe hdGeSqHf036gUUwi+pPIdpZ3vC+pggM7JJmv+PjIYLmOg3rcw9DB2RZNAAFXI52qZ/Rj aI8ZeuiZAGy9doXpjj4enrtMrciaxhHbxwVpZZKlhDpKnNKm/ojCT/V82hpyB5E36Y8S WNzQb/R2wB6S0x0g8+fqbNR1jFdQu1yS6oxrAueaymp5+ws4n+GuHoWZIqJd9CM6XJPR r2sg== X-Forwarded-Encrypted: i=1; AJvYcCXLvi7yv/ovSScA0lVq9a7kC+MH+BruvuhJtIJwQxJYaiOO/zfnYFkj8nNqrrB8pxKOPrhPgupZX0kkZCWd@lists.postgresql.org X-Gm-Message-State: AOJu0Yz1FlgeVCqM1CFuUJMfZYkKlky7BJ4+/+Sr4RGNEbnyQHFfqfOV 1b7rRAzuoT6zcevOEX6mIiqTNDkkSMoQWjGPYAjB4x6haJ6invZwt1JBjmf5FyV8axlCgvkjVKU ABCMhzCa3FamVw1tbEu0I+K4V57ruiVc= X-Gm-Gg: ATEYQzzcjzcX/bRrjeVkKgfDZZejqBZnsatajT8GPKT8XzzbL5DMO30u4TZHd2bpPYP /OHK0Xhdu19qjR1URB1zvfykCzHPqE2AIwj8jNn4mBEzbR25Nv9ocSJrCZ38X/4QZBvH16VbGzU yeWd2oHgO5WJ06KQmmhf8L+vuUr1MWd/rD3Ybhi6vCRjVr0sJSWb4E5poTtCIOb2x0jeXfVPCDI sUPMmt/xBUvt8kJqWSMtYINsrpVl6TSCPAC97pNbAgDCQCgpG0ICxOiXTHsoh8NqjUgGBTzFKTn +A4RCcd6aX9GO6Wbube1RBScz+gvKxObEgBGFiE= X-Received: by 2002:a17:907:1b09:b0:b97:c719:14d4 with SMTP id a640c23a62f3a-b9b50908ff6mr179706066b.29.1774616923603; Fri, 27 Mar 2026 06:08:43 -0700 (PDT) MIME-Version: 1.0 References: <1136161.1769654478@sss.pgh.pa.us> <1299934.1773938807@sss.pgh.pa.us> In-Reply-To: From: Robert Haas Date: Fri, 27 Mar 2026 09:08:30 -0400 X-Gm-Features: AQROBzABgekzqlpLYSwuwDG42Cyh79yNXEByTjC8O-kunCV3_GeQ5vlicR2i-ow Message-ID: Subject: Re: pg_plan_advice To: Jakub Wartak Cc: Lukas Fittl , Tom Lane , PostgreSQL Hackers 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 Fri, Mar 27, 2026 at 4:00=E2=80=AFAM Jakub Wartak wrote: > there is visible collapse from 190k to 48k tps was due to constant flood > of artificial calls of: select count(*) from pg_get_collected_shared_advi= ce(); > > The code does LW_SHARED there over potentially lots of of tuplestore_putv= alues() > calls. However any other backend does pgca_planner_shutdown()-> > pg_collect_advice_save()->store_shared_advice() which is trying to grab > LW_EXCLUSIVE lock, so everything might be be blocked across whole cluster= ? (I > mean for the duration of tuplestore entry and that seems to even talk abo= ut > "tape"/"disk", so to me it looks like prolonged I/O operations for temp m= ight > impact CPU-only planning stuff?) Yeah ... I mean, I don't know what you want here. If you fetch very large quantities of data under a shared lock while concurrent activity is trying to add data under an exclusive lock, that's going to be slow. Now, as you say, there are ways to improve this. However, I don't feel like running pg_get_collected_shared_advice() in a tight loop is a normal use case. Normally you would turn it on, run a bunch of queries, and then run that once at the end. Even that could hit some issues because every session will be fighting to insert into the hash table, but here you've made it much worse in a way that I would say is artificial. > 0004: question, why in the pg_get_advice_stashes() the second call to > dshash_seq_init() nearby "Emit results" is done with exclusive=3Dtrue , b= ut > apparently only reads it? Good question. Actually, couldn't both of those loops use a shared lock onl= y? --=20 Robert Haas EDB: http://www.enterprisedb.com