Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaPEF-0004nM-Nq for pgsql-general@arkaria.postgresql.org; Sun, 17 May 2020 19:45:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jaPEE-0007ch-Bj for pgsql-general@arkaria.postgresql.org; Sun, 17 May 2020 19:45:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jaPEE-0007cZ-1s for pgsql-general@lists.postgresql.org; Sun, 17 May 2020 19:45:42 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jaPE9-0001mG-NJ for pgsql-general@lists.postgresql.org; Sun, 17 May 2020 19:45:40 +0000 Received: by mail-wr1-x434.google.com with SMTP id l18so9373313wrn.6 for ; Sun, 17 May 2020 12:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=nxfVzMfeWjYkbw8k/TDftefcP13NVA3DfyZYv3JUA/s=; b=uFrLNOqZh3GxQUP62kXVIxMJAsbV8J9/ZaBKh75ZF7vGHKDD4lYIHKGqbyaBPn/E+C pRGt4KmKhctatMnLG7JzuS4ydTbbkcnBKwjDTO/Lt9n+CSnTLMlcXFoJKw8aOVoIVAze LNjZLn/kJLZWr5+7cONInJILJrThVFRJih+bIojQIZjuUXZ8MOl1Z34P7SmlQZae5ic4 nzjJa1jvXhaXCg+wP9pEGs9NcsAKVqRBLT6wWu+dOJFWmzkjfXR0MDKNoVMIOZllbh3V lXK7T574qV+WS8ID538iVBYplDLrUO1Oo5wx+zF4S22UiSWFMZzbqBCuZ/cFmHTWbB2m IuPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=nxfVzMfeWjYkbw8k/TDftefcP13NVA3DfyZYv3JUA/s=; b=CzXw1YWpotKww0FKUmoYll/3G2L2RTbRdkiRiGaW2uTIbWdptYvGvbxewRpcKArQly 7gMXameUZ7ewjMBzxNqrVfmiC9DmYcOijxCuPbID+DJUsQFwO50/od4hFMy725X/JP5m 1HQ6w8DzpELkhb3AmXNCBBcBfktpF479wdWVh9CMciqJzBlv2CAtRs3aW1LeQI/3Xz4F uN9tFMsHtaDlk2+yiyMm641FC/f+t6ibwHdox5KvHtCQVTu1XZlEaoq5y5SDCUqhzOxG ARRSlbKamEMFDWxqiuZYqatYqg43F9LZmDaaTJo0y0XbYkRzed49nefF5UKpDsP/gPD4 vIzA== X-Gm-Message-State: AOAM533+mv/CI8dK4zj5LZDFmOdh3ojIj5GemHx00Mh9B2oKN+M31h9g WD6xH1o9bLxTSxfE2yloLBjnJiODBa4= X-Google-Smtp-Source: ABdhPJy/+1UkUD8qrsxepdrNb5k4/ZJyo1/u6XBqiDTdrS7rS3hkY82DebTWMM8FMJEbc6B8sX6GrA== X-Received: by 2002:a5d:522d:: with SMTP id i13mr16082572wra.306.1589744735016; Sun, 17 May 2020 12:45:35 -0700 (PDT) Received: from [192.168.1.127] ([5.151.70.165]) by smtp.gmail.com with ESMTPSA id f5sm13579142wro.18.2020.05.17.12.45.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 May 2020 12:45:34 -0700 (PDT) Subject: Re: Using b-tree index for >= condition when joining To: Tom Lane Cc: pgsql-general@lists.postgresql.org References: <31575.1589685738@sss.pgh.pa.us> From: =?UTF-8?B?xYF1a2FzeiBExIViZWs=?= Message-ID: Date: Sun, 17 May 2020 20:45:33 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <31575.1589685738@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 17/05/2020 at 04:22, Tom Lane wrote:> Note that you're not really getting the same plan that way: it's not > a left join anymore, because you put a strict constraint on the join's > inner relation, so the planner realizes it doesn't have to produce any > null-extended rows. You could make it work with the desired semantics > with something along the lines of > > SELECT * FROM tbl1 t1 > LEFT JOIN (select * from tbl2 where tbl2.date >= '2019-04-21') t2 > USING (date) > WHERE t1.date >= '2019-04-21'; > > but of course that's even less easy :-( Thanks, I didn't realise my version of the query was incorrect. It seems like there isn't much hope of creating a view equivalent to the query which would behave reasonably with "date >= CONST" constraint, or am I missing something? I think I can create a workaround using functions but would love to know if there's something simpler I could do. Thanks, Lukasz