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 1sS3Xp-003SRo-AU for pgsql-performance@arkaria.postgresql.org; Thu, 11 Jul 2024 23:49:49 +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 1sS3Xn-001lYa-Ir for pgsql-performance@arkaria.postgresql.org; Thu, 11 Jul 2024 23:49:47 +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 1sS3Xn-001lYR-7N for pgsql-performance@lists.postgresql.org; Thu, 11 Jul 2024 23:49:47 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sS3Xg-001cBh-BM for pgsql-performance@lists.postgresql.org; Thu, 11 Jul 2024 23:49:45 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70b703eda27so18362b3a.3 for ; Thu, 11 Jul 2024 16:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720741779; x=1721346579; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=jz/UTDG2xvu0mwcvIVjdD1u+k5vgsuLKnTAapsuAxqo=; b=Fhoz4uc3O+B/A1I4j70bLG53t2B+WliAo/OKZd9HYAxZ8mkAUc90OepX4CJWfnhKE+ Bu9zCOYCV0JuwUB84OKLWZVKOBPfRsGqnMIKbLOadn/fa21vCijpa3Rt5FCsSiiDSfpL ClRnR1+8ubqu83+r8GjBWWQTclFejkr/ZyCxCMlO16KamdVwZbK5l3mPRTS8/Vk7/n5y Rdd1txmDTzmQ6kcT/NB7x+fh2xmERtawId56eVr+KoFfr7Xpcw+gtQFeRiaXieccpR2S qlNCcT2pREdtFD+CS9RmWzpYfYLv2YBkmJwNKyGOnMdzcLMg87z70fnzZtcwgtkau0Eu 3h+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720741779; x=1721346579; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jz/UTDG2xvu0mwcvIVjdD1u+k5vgsuLKnTAapsuAxqo=; b=ZIi5roUL5heHYR+dHVGeVk6PayznxtVcIGwFcEGOlSzRSXQMCUcuviHO1IHpXoXW14 XuDCM7qD5qiyogRBTd1SwwWsT7VcovbhMFWTtRf3bLtvVfKTteQ/1UDjOnPrEmVgXSx6 PfjXUeNI0sMGtfNRx/uQ0pgfGuUkJPjMiBQ57saOrXyuquUpPNod8CZQOyfVy/Vr5M5q le5r4l9oYqiWTITi0P6k7kthAaGdIoA6fHhUGYD0IYxjWA+mxJ5nei6y/WDs4v64UQQc +7DhDF+4SybVDOvZFyhp/EsBtiD5jPQrYJKcRSu57+we7Yh8rBYp35O7wCTI0FsmM8KE MhgQ== X-Forwarded-Encrypted: i=1; AJvYcCVhMWO1//fztTkDwEtQrfXIU+J2AIFuwVZCGTEYGgZrERzYv5PXYM5+SXo6awwGCDOJkzFH+HeTHQVYPH5Xkja5FLCvxR1KZBh15ptpqLjV8UClEJ8KUw== X-Gm-Message-State: AOJu0Yy4aRnGT9syIBXKuxyXfaF9tDrZtu4xXJ6obKFcu7vqC6AuiOSg 3DDOWtIb+c830cn7FjGyaOpNxpa7j6eWjbgdp+Hts/uK+0s26AFB X-Google-Smtp-Source: AGHT+IFTkkKdG3eNm+RdS+F2675btRbd/3yyn1UlptjQoUSWphII41ucKVkHnUjRQ+fx2v0IFKyO7g== X-Received: by 2002:a05:6a20:729f:b0:1c2:9320:758a with SMTP id adf61e73a8af0-1c298221cf1mr11177743637.15.1720741778563; Thu, 11 Jul 2024 16:49:38 -0700 (PDT) Received: from [192.168.1.40] (cm-27-145-179-239.revip12.asianet.co.th. [27.145.179.239]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cacd657fa5sm159881a91.38.2024.07.11.16.49.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jul 2024 16:49:37 -0700 (PDT) Message-ID: Date: Fri, 12 Jul 2024 06:49:34 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: inequality predicate not pushed down in JOIN? To: Paul George , pgsql-performance@lists.postgresql.org References: Content-Language: en-US From: Andrei Lepikhov In-Reply-To: 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 12/7/2024 06:31, Paul George wrote: > In the example below, I noticed that the JOIN predicate "t1.a<1" is not > pushed down to the scan over "t2", though it superficially seems like it > should be. It has already discussed at least couple of years ago, see [1]. Summarising, it is more complicated when equivalences and wastes CPU cycles more probably than helps. > > create table t as (select 1 a); > analyze t; > explain (costs off) select * from t t1 join t t2 on t1.a=t2.a and t1.a<1; >           QUERY PLAN > ------------------------------- >  Hash Join >    Hash Cond: (t2.a = t1.a) >    ->  Seq Scan on t t2 >    ->  Hash >          ->  Seq Scan on t t1 >                Filter: (a < 1) > (6 rows) > > The same is true for the predicate "t1.a in (0, 1)". For comparison, the > predicate "t1.a=1" does get pushed down to both scans. > > explain (costs off) select * from t t1 join t t2 on t1.a=t2.a and t1.a=1; >        QUERY PLAN > ------------------------- >  Nested Loop >    ->  Seq Scan on t t1 >          Filter: (a = 1) >    ->  Seq Scan on t t2 >          Filter: (a = 1) > (5 rows) [1] Condition pushdown: why (=) is pushed down into join, but BETWEEN or >= is not? https://www.postgresql.org/message-id/flat/CAFQUnFhqkWuPCwQ1NmHYrisHJhYx4DoJak-dV%2BFcjyY6scooYA%40mail.gmail.com -- regards, Andrei Lepikhov