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 1nG1xl-0001Lg-FN for pgsql-general@arkaria.postgresql.org; Fri, 04 Feb 2022 17:01:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nG1xk-0008I1-6o for pgsql-general@arkaria.postgresql.org; Fri, 04 Feb 2022 17:01:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nG1xj-0008Hr-HE for pgsql-general@lists.postgresql.org; Fri, 04 Feb 2022 17:01:31 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nG1xc-0006we-9j for pgsql-general@lists.postgresql.org; Fri, 04 Feb 2022 17:01:30 +0000 Received: by mail-wr1-x42d.google.com with SMTP id e8so12594627wrc.0 for ; Fri, 04 Feb 2022 09:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=fSo68//5GYmEf0px7geAsT96IbKqXNs/d9MMMf90uHI=; b=D9MFlfbMkZ5teelGzDawtgj0d+9VLMioQ8Cd9D2Ur84N9XnBsNuPyCikMK7JyX3aMd VGCgkWwpmWwfNmbHTLlXFiM141LWIljz5+QrPpepnadhvBo2xbMoAaHhLDB3m7G5M25d biMqxdRcR512FGSzE4vK/xWXgm0sSbU1vIL2i3mA1S1sh4yFGQULurfDkZ0RwOlgSdAz DtsU1tdf8JTU2gQoWlQgomN3PeB9z8VSqW7tn8FMtLPGv12LiRDfEAMWc0ucVH28qxsW NB7BxccOHvy7iQr9TvQ+f0EpW1bwoSR8KrcBI1Mx0s/hq3vFIWOvYPhJaSzswmuN+g90 0Cdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=fSo68//5GYmEf0px7geAsT96IbKqXNs/d9MMMf90uHI=; b=UREZut4igLNxkqG/1i0WxHskuKdkybcM7mxzuZKWnS1a6AXcfehznkDOUmhtoNFehl Qo9LtOTALepJliIwQMEGsnT/7aZT5LiVptdmw0AzcPDyF39WiMg4+THD5u8jHX5Hs8Kx zb+TlVlNzJsFhrYT1ar6v3y1rfoD/mSb3x2Q/qaDaN4eE/yTm3LsAC8Mi1hft71yACI1 IKv51Sk7NwYMt8lDwOGpbj291ZXpw6bytQIe6+4/U4jwa87oCn9bzjc0wt9OMmWu/+Qu I+1PnIWgUDvfZI7PNNrsJR9iPBJniLhufRTLguuXdFPSmgE1T3x2LMugEfsGgqD4e5qq LO5A== X-Gm-Message-State: AOAM530iK6AbfpNh3fkcWtjb01qmQO6WJEu81fTuuAP/FDXZHRxSrz9k B0UEbT48dt0S2WGo24Ftmx80KZDQyPuB3xnLXHDY2iMvJJxiIDMvSbPlQ3MXxF+53y7sQR/j28t jx3Zj4ShaYI6swAgfzRSAnUe4yCmKvjhxJrFNh2xNZj5W6QYXYfK2z4P48uWZZHiOasSfQgJV4f QQEJKPu3Hadj7wMw7Ngw20tXMKEHwlaRtDIEUasK1xqQ1DbK0sQ9589HD3FCl1 X-Google-Smtp-Source: ABdhPJzjd2bBR6ediH9/0oBHFywN8W5P9smW9Jp1dJUAXTsLUwDWwgoUCXoBydI6L8Sa2nx7y7+yCQ== X-Received: by 2002:a5d:5049:: with SMTP id h9mr3231017wrt.502.1643994083053; Fri, 04 Feb 2022 09:01:23 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id e16sm982541wrc.55.2022.02.04.09.01.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Feb 2022 09:01:22 -0800 (PST) Message-ID: Date: Fri, 4 Feb 2022 18:01:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: increasing effective_cache_size slows down join queries by a factor of 4000x Content-Language: en-US To: A Shaposhnikov , pgsql-general References: <747d822c-eae1-df4e-f4c3-099a5a00a721@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/4/22 05:21, A Shaposhnikov wrote: > Tomas, > > thank you! The query: > > select 1 from data as d, data_class as dc > where dc.data_id = d.id and d.id > 205284974 > and dc.data_id > 205284974 -- new condition > order by d.id > limit 1000; > > totally solved it - it is now fast under all conditions! I thought > that the optimizer would be able to infer it itself. > Unfortunately, the optimizer is not that smart - we can do that for equality conditions, but not for other operators. There was actually a thread [1] exploring a possibility to extend this to inequalities, but it went nowhere so far. It also explains why it's done only for equality operators. In short, it's fairly expensive, makes costing of joins more difficult, and most queries can't benefit from it (because conditions on join keys are not that common). BTW how does the final query plan look like? Is it using the merge sort of nested loop? I wonder if this might be formulated as a costing issue, pushing the planner to use the nested loop. [1] https://www.postgresql.org/message-id/flat/CAFQUnFhqkWuPCwQ1NmHYrisHJhYx4DoJak-dV%2BFcjyY6scooYA%40mail.gmail.com regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company