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 1tvLur-003nbX-S9 for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Mar 2025 19:50:57 +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 1tvLuq-007id3-KB for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Mar 2025 19:50:56 +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 1tvLuq-007icu-Bw for pgsql-bugs@lists.postgresql.org; Thu, 20 Mar 2025 19:50:56 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tvLuo-000CCy-0c for pgsql-bugs@lists.postgresql.org; Thu, 20 Mar 2025 19:50:56 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3914aba1ce4so1004346f8f.2 for ; Thu, 20 Mar 2025 12:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742500253; x=1743105053; darn=lists.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=Ku6YPJkiJnUv3kQERpRmCyPPhfwKw5TZZlTd7KmICPM=; b=W/yIVEjKeeQypUFC4e6g0lNE77FhCj2nSSDCZC41/jss97mSbBKaoNbaChQl7SZc33 lxfXNkd4QMJYRo3jEHb1pZpqq+kJjylW9B5SSiS6dzuAQRTbMEX2faonoGHD/S4fLsOu qoZNMAHyKYrOe6DDKJ05NUzRWjIRGhBbSKq85iWJVDbow00WOolrO4v7nwHEhaEvnWDH oVSZcUf9KOc9rNfryMGVwWGGMhEZoqg4G0EfWroE2GN2aACA7tn0s3w+UmzTG9G5q60M Gv/086QYZok25ZeIWWnTbv6gJwI2wFnIgYTRIClMF7Rv1i2IzjyW3gCfRpw/q65efHxG +i5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742500253; x=1743105053; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ku6YPJkiJnUv3kQERpRmCyPPhfwKw5TZZlTd7KmICPM=; b=cx0vD8zzeu6QiNIX6loa1OLCeH1E+IWkuRcWHKDs25yPqXz7Xlb3s/nt2i9s70AL1a q8H2LvdaVrk9aJBSDK6NiUClroZNltIK7CZ/BCs1bDFe5ceg81oBXeQisMVSzWc0ZD7C ymEbv124oNRFN5LRd4LHF/TUzcapfert3W/2nAo/tyi3GH9Y6ZSebcLZRDduf+O8bSwu FMoPmIszD+k0cGv/l8fHw+XsHRyOzy+7qngwW8iY2clgRyXKCsu3SLWP89ftcofNwODx B77l3BpvijPdf/X4WINXOKvgfF/cC1B5xdFXzYnk5d7DGG7H/Jv2ufbVEWOrwGsooBCv +Hwg== X-Gm-Message-State: AOJu0YxQaM0SyuTWHeWF9v4BomSsottNBDSJfPfA3XUc5kiOSfx5ZP5T ZuoIe6L9Z5+E6bJJQuIO2GZJsZ7/c6KStjvZEO+sHDOeEhSYG6XR X-Gm-Gg: ASbGncv29ahCkbG3zu5wJzg5Qq5YNriFiNlcyJyFOSok3//w1MFl4WwatNek/uCQOPZ EPhNTJEOA7wKdyKo+q0BG07C1QC++vMXPnBtMRiauZCDnT3kTP0AvmWiGtMyMZejtrIP9ahOznb JQvFtWR6U9vCqqkVSFDHS54W0dyLNx4vmOSAXwddlkG1czQ/hsTQj+U+W0AuPx1vwASvJdJrp6e oCClAUj3W9mv1JiLZaR1miKsKX+YvzkExo/TJPE8mTaq+h78ozElkXOmhybZ9NGJ/nwR2wMzBdf qiTqLdeQsj27twc7Mb1jgAee53kkZiSMYw7z8BS6Jf0UTU7JSXj5 X-Google-Smtp-Source: AGHT+IGTgBywr42KXTSLaoUYyuVT0vFnsW246E7JVKn68oOICxhyKtWiowzqnw/DE8hRaHwvA7PP0Q== X-Received: by 2002:a05:6000:4027:b0:391:241d:a13e with SMTP id ffacd0b85a97d-3997f9405famr798943f8f.48.1742500253007; Thu, 20 Mar 2025 12:50:53 -0700 (PDT) Received: from [10.59.3.23] ([90.121.90.131]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3997f995423sm431378f8f.20.2025.03.20.12.50.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Mar 2025 12:50:52 -0700 (PDT) Message-ID: <31635fee-f260-49a4-81d3-8f684efdabd3@gmail.com> Date: Thu, 20 Mar 2025 20:50:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18854: PostgreSQL chooses a suboptimal execution plan when using a specific WHERE filter To: Yoni Sade Cc: pgsql-bugs@lists.postgresql.org References: <18854-f5bc660117569bdf@postgresql.org> <91d297ae-71ca-4406-a404-f8daa0b0c4a5@gmail.com> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 19/3/2025 14:34, Yoni Sade wrote: > I would like to add that commenting out that WHERE clause doesn't work > for all of this query variations so I've found another workaround for > now ("LIMIT 1000000" in *bold*) > > to make the optimizer better estimate the cardinality of the subquery > and change the plan to a better one:* I wouldn't say it is the ultimate root of the problem, but using generate_series, especially with non-constant parameters, seems harmful for the query planning: we can't predict the number of tuples and don't have any statistics on that set. So, your LIMIT works like a hint that helps decide how massive a set of tuples it will generate and seems to be the only option possible. -- regards, Andrei Lepikhov