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 1vvt0e-008Aah-06 for pgsql-performance@arkaria.postgresql.org; Fri, 27 Feb 2026 08:15:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vvt0c-001qlx-3D for pgsql-performance@arkaria.postgresql.org; Fri, 27 Feb 2026 08:15:39 +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.96) (envelope-from ) id 1vvt0c-001qlp-2F for pgsql-performance@lists.postgresql.org; Fri, 27 Feb 2026 08:15:38 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vvt0Z-00000001XEO-3sjC for pgsql-performance@postgresql.org; Fri, 27 Feb 2026 08:15:38 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-48379a42f76so13189035e9.0 for ; Fri, 27 Feb 2026 00:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772180135; x=1772784935; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=wmacTLUe8f+6j0aeQ+UDrzF+TsfDgiEaR7FvgynnA8A=; b=QwJQwVKwpO+SnxVutkXlJF2kWxKA8sjp091dGI3Otodxm2LDiy3ziVsBcbMS+lR3cM N2XXRxPd5f1uoo9sQC4IMbPMkJOczWKWoCQXiD6UL9R08YsStbYxPDfi4hffmX9tgdpV bYJx57QKCc9FqInuzfPN7a1yOiTsVmJgUbUbub1sOlVWQ1zrvzf58rLb53DK9iOd+k2o khnR2gK6nfH4I586tGDBnEiEP6kDiq/7NWmRZIZQbVA+Zgi4z5zrqzjiRGyZP+ay5LWN Gl24RzyfNmXp3d9kC8wsMj/gLvEtd+qBsg5qEMTi5mRCuxJp9ZpoUFvi5AlJw9z1hzGi hCKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772180135; x=1772784935; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wmacTLUe8f+6j0aeQ+UDrzF+TsfDgiEaR7FvgynnA8A=; b=FBJxpQ04/7upnCtE/DXm5rgi8dsPE++m6mV3VuOzspBn8ajRr9B4FJnIAi4xe0gMH1 PCtlA5Zx7rXjk/qa6OmHBJZQZ8+YCo/kcSm2oym6RYmFGEM+ZwXLKs4Cqne5Qa3oDs+P 0oBU1gYjDvoVTjR3lD/VZlYX/4ZI2hK5LlH1DmM3uL5CQkrBKgTBNxgYVSQR1dBha9uf iW1YgNw0b4gP0KmhMdhbeRrMM5C4LlVRbDmxxwthNS03oI0yMD6aMQRL504LB0lR7Pjs Wjve+s6gsAX5KByK80sBrYdhgPgJ98vD6YOMBv0G3ZvoplinqT1UwpDUfxZpiTGTdhHt 3+UQ== X-Gm-Message-State: AOJu0Yx2G5a4HF5/GyPKLTzBKrpF1IkbdORuF3KJihdlUHF1pCB3Unty m5cU/K2Jl25nPfj8UmSh6pmYXxokrqdB5T+6molpCCz0g5WpMV4luyJf X-Gm-Gg: ATEYQzyFhXxra1MR+z6zyTE7E5Zk5m1gegEqsmkxp17TkGDew5DUYJE003HyEkCJk/I JxuldYxBKgj/AY1ryRIoWSPxc7+0AggWmj44awp08K6Zk8lQi6IVfoWZ3B26L023A5AtNwrDvXn yrnt2adhsAmO8/gd0IuwYXQ3RUZrG+Zka9o/SZqgr3OzRPdTog+UDak6p/b3Gbkai3sAbNGdeEs I75U0HM+GXVpDEoGHMWc8NzFXjuuYEmCSpUJoKDxFYyFWxCyPv9jkqFrXWoBl+y2uTYR0YzzDvE 6tulghlPjZg5iz2dJqrn97q/iduuMgj3mT2TzdkhNsjX4IkJjXKE3kMP5nK7v5YmXDRYZuIE3iv y/bLctNDWxWMmhcs1RHmUhahGdsGFaubF/K5FT+nt5sOEdHYan8T0hqKhWthRipNFm3x9qNhWS4 wI+RArZtseprj6AAkSGWMOyoQ57+Ipq0jRK30eeQ== X-Received: by 2002:a05:600c:3e86:b0:480:6941:d38b with SMTP id 5b1f17b1804b1-483c9c1bc0bmr26010985e9.30.1772180135299; Fri, 27 Feb 2026 00:15:35 -0800 (PST) Received: from [192.168.15.167] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483c3b3ce8fsm91643785e9.4.2026.02.27.00.15.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Feb 2026 00:15:34 -0800 (PST) Message-ID: <6199d929-711e-4657-bcf9-7d285cbafca6@gmail.com> Date: Fri, 27 Feb 2026 09:15:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: unstable query plan on pg 16,17,18 To: Attila Soki Cc: pgsql-performance@postgresql.org, Laurenz Albe References: <64ddfe83-317c-4cf1-b04f-cb74d9f40629@gmail.com> <529E2365-6C3F-4BDA-9625-312F3A023C5B@gmx.net> <5bace3e5-3d6b-4f81-92a9-9ff4e9e5de53@gmail.com> <1C445A2F-3256-4F04-B55D-9850581FF39A@gmx.net> <0dd76506-053e-4a30-9f95-9dc324e8e1fb@gmail.com> <1388B912-7E9A-475A-93AA-67FB99A084BC@gmx.net> <0c8b9845-a2ac-4613-8075-45dc55911143@gmail.com> <45AA83DB-A6B4-43A2-879B-290E4A7845AE@gmx.net> <4FEE2E28-5A05-4423-B49E-CA23E2B78420@gmx.net> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: <4FEE2E28-5A05-4423-B49E-CA23E2B78420@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 26/2/26 17:22, Attila Soki wrote: > On 24 Feb 2026, at 20:20, Andrei Lepikhov wrote: >> >> On 24/2/26 17:48, Attila Soki wrote: >>>> On 24 Feb 2026, at 16:57, Andrei Lepikhov wrote: >>>> On 24/2/26 16:50, Attila Soki wrote: >>> I can provide more details on other parts of the query too, if that helps. >> >> Only query and reproduction make sense for me to discover more deeply at >> the moment. >> It looks like we have managed to reproduce the potential 'Hash over >> parameterised subtree' issue. Please check the attachment: there are two >> plans. One plan has a longer execution time and more blocks hit, but its >> cost estimate is four times lower. The EXPLAIN output does not show any >> obvious estimation errors. This suggests there may be a bug in the cost >> model. >> > > I looked your repro, and I tried to find the corresponding part in my query. > If that not the right place is, please point me to the part in explain, so I can compare your repro and that part of my query. No problem. Issues with your query plan starts in exactly the following line: -> Hash Right Join (cost=210369.25..210370.30 rows=8 width=99) (actual time=150.790..150.853 rows=44.56 loops=21798) Schema of this part of the query tree is as the following: Hash Right Join (loops=21798) │ ├─ [Left/Probe] GroupAggregate (loops=14426) │ └─ Merge Right Anti Join │ └─ Merge Join │ └─ Index Only Scan on table_k gkal_2 (loops=14426) │ └─ [Right/Build = Hash] Nested Loop (loops=21798) ├─ Index Scan on table_o goftr_1 (loops=21798) │ Index Cond: goftr_1.au_id = gauf_1.id └─ Index Scan on table_k gkal_1 Index Cond: gkal_1.oo_id = goftr_1.id So, the hash table is rebuilt each rescan based on the changed 'gauf_1.id' external parameter. Without the query, it is hard to say exactly what the trigger of this problem is. Having a reproduction, we could use planner advising extensions and see how additional knowledge of true cardinalities rebuilds the query plan. Sometimes, additional LATERAL restriction, added by the planner to pull-up subplan, restricts the join search scope badly, but I doubt if we have this type of problem here. -- regards, Andrei Lepikhov, pgEdge