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 1wp8Ku-001Rus-0N for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2026 17:44:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wp8Kr-007Rzb-2x for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2026 17:44:53 +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 1wp8Kr-007RzT-28 for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 17:44:53 +0000 Received: from mail-vs1-xe2d.google.com ([2607:f8b0:4864:20::e2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wp8Kp-00000000xNP-1jZR for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 17:44:53 +0000 Received: by mail-vs1-xe2d.google.com with SMTP id ada2fe7eead31-738bcf9a573so429417137.2 for ; Wed, 29 Jul 2026 10:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785347090; x=1785951890; darn=lists.postgresql.org; h=in-reply-to:references:to:from:subject:message-id:date:content-type :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to:content-type; bh=R6AUH4GtpzBPNhBdGgkSgrPMOkBNnuwpN8+CmbjlEYE=; b=BfrkJxhtbWHE2dSUWhwd8kPaCC8apDEx4ZKHDmYZ9hHxf1Qu5W9KvDx2GODbR3GnH8 ZaDaT2oXhwRwUVYIbN4DLDcc9oWOrhQSWSN7TN6lzHGM8EJDfouK4w+E9XCcpwhJ3iTh PqMjf1a6MS+7ZLOk+HwAxuvlnVaMZ2K+mOdmYLF6A2VzLxfr5P01JTsPZL+24jxRa5N1 BdM26u6rCRnY77LgFNWEJ0GBPy/8bdyVCoi3XdpKMoDjVgOTwcTdDDendcw9A+NdIwJN ASOgynNACTM5oTWu5fRMluUloY9MeQxmlQvfsGedyt1hPmMYt8PwJgIkWQV9uFTV7q9d lR2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785347090; x=1785951890; h=in-reply-to:references:to:from:subject:message-id:date:content-type :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to:content-type; bh=R6AUH4GtpzBPNhBdGgkSgrPMOkBNnuwpN8+CmbjlEYE=; b=Bu/aBvb3tjILuPCqIXGrPCnr1HS5Kt9jPUbFTg3UXi4hH8Xt1sQb8GodSdx5dt+OQV 5GNN/XprBsUwIMqQXXl7cLReWRMEYP5T9YTv17j8moA/6K97YY5EnhFI5PfkKCbIneFS 6yOXiA5SzU04hoVfapOQd/sGjnfRKhPczfkxw6e4kZq0b3el5ZKmuffpZml6TwE9RhzN xmyAhayViLoza84Hz0jYHqQJyEPmRcLe3BLS4gbTOU6q8wEUQ/nmg1xIXwrevaxrnB/Z fhC9HlM56/l5Ctju759e+bXxlO1hwLm5tvqx/wMIbGPtyKgXLk9OYp6arbNquq4A7odS ZFCA== X-Forwarded-Encrypted: i=1; AHgh+RpbEpZVS8NKya2nbdwXNiLThhPmkC1ixL8QVz7grMcOFH87MmL6u5h2s3zzutWuBwVR6OMO0ydVfhcP@lists.postgresql.org X-Gm-Message-State: AOJu0YyVC11SEsB3FTQKpT+VkhCRyFLOvWCaE+MViRA5j6rd2tefFHht s1EDQgPoIvTZO1ttjs17sQsEdfpLZz+YoJBXCAfPUlNhISUh/MrKedAH X-Gm-Gg: AR+sD110VO06KID1AKiYHcHZ5wj2NB6q7XVjdIjOfURC6HCD+OWpC3ExmDcYDEvTqLF 7RgMnFVV5v5w0qsB56JwCOi1pSWEaFWlWp8p8YDtMKeaiwo1zFrfRBrTzHqJeBlte+IrTm0v1GB xQ9S3I+K41gY5KmHSNWIHq4c9tmJsp08Uj+aWceGHS8S+kQkcFzjkF3zi9+cKgTD7sCPHy7i4wb ICvLJ76nTRNIwXtbB5MV4peCgRBWPj4RsUDvcXpxPHhkdkJxDdbu6krDylmAvqnqAuEG4WWPWQL Tpm79zYDUknfmzNxuCqNmDBQ7c8uSj9VUwAX0CokSU3yuzl0wbgZfz2C2nLTWEBqMrG369VWad1 bn1WHCZ5l1m9borDnsZWzYF9c5afSahVh/VnfvAFcth72+O9sq0DNyAlzu+BAiYF4tMX1zxQV8Q jAQ1WMRKCFXfWAIjnQwRPi8me/jMjBh0hCrUM5QSl8QAs/V/bwGAl0hGrs4uoHg79QsnjX8Bs5k Eq+yQmhkvQ= X-Received: by 2002:a05:6102:4403:b0:6cb:d562:b96a with SMTP id ada2fe7eead31-754a1aafcf9mr3256698137.14.1785347089606; Wed, 29 Jul 2026 10:44:49 -0700 (PDT) Received: from localhost ([2804:14d:32a7:4273:c172:5997:87a2:4740]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-977b614787csm1984287241.13.2026.07.29.10.44.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2026 10:44:49 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 29 Jul 2026 14:44:45 -0300 Message-Id: Subject: Re: BUG #19572: Redundant predicate changes JIT decision and causes an 18x performance difference From: "Matheus Alcantara" To: <2320415112@qq.com>, X-Mailer: aerc 0.21.0 References: <19572-f770e89412629023@postgresql.org> In-Reply-To: <19572-f770e89412629023@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed Jul 22, 2026 at 4:34 AM -03, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 19572 > Logged by: cl hl > Email address: 2320415112@qq.com > PostgreSQL version: 17.10 > Operating system: Linux LAPTOP-2SQAVLB0 6.6.87.2-microsoft-standard- > Description: =20 > > ## Description > > This issue concerns a predicate that already applies to one side of an in= ner > join and is redundantly copied into the join condition. The transformatio= n > is semantics-preserving. PostgreSQL retains both copies and treats their > selectivities as independent, even though they are identical. The > underestimated row count lowers the total plan cost enough to change whet= her > expensive JIT inlining and optimization are enabled. > > ### Expected Behaviour > > PostgreSQL should recognize identical predicates or account for their > complete correlation. Adding a redundant copy should not change cardinali= ty > estimates, cross a JIT threshold, or produce a large execution-time > difference between equivalent queries. > AFAICT the planner treats each AND clause as an independent condition and multiplies their selectivities together. So in the duplicated case it estimates that the Seq Scan on redundant_join_fact returns fewer rows because there are "more" filters, even though the two are identical. Note the actual row counts are the same in both plans, only the estimate changes, so the results are correct. This is a cardinality-estimation that happens to cross the JIT cost threshold. So I think that this is an expected behavior rather than a bug, though I may be wrong. But I'm wondering whether the planner should detect duplicated quals and drop the redundant qual, or more generally recognize when one qual implies another (if qual1 is true, qual2 is always true) and remove qual2. We already have predicate_implied_by() in predtest.c, but IIUC it's currently only used for partial indexes, partition pruning, and constraint exclusion, but I'm not sure if it can be used for such case. I'm not sure it's worth doing for the general case given the possible added planning time, but exact duplicate detection might be cheap enough to be worthwhile, but also I'm not sure if it's a common pattern to make it worh implementing it. Any thoughts? -- Matheus Alcantara EDB: https://www.enterprisedb.com