Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jGQ1L-0000be-I5 for pgsql-performance@arkaria.postgresql.org; Mon, 23 Mar 2020 16:33:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGQ1K-0005z8-37 for pgsql-performance@arkaria.postgresql.org; Mon, 23 Mar 2020 16:33:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jGQ1J-0005z1-Ll for pgsql-performance@lists.postgresql.org; Mon, 23 Mar 2020 16:33:45 +0000 Received: from mout.gmx.net ([212.227.15.15]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jGQ1G-0002Xq-9f for pgsql-performance@lists.postgresql.org; Mon, 23 Mar 2020 16:33:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1584981217; bh=WBmsoUJpqiYz7eQhDf9JNY5TebFBo3HbOjP4xCtPcDs=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=K1ML0E9exT3EdXX7eU48jTXMuAdOCNsGlzsDa19tJwUmPHGtSWs0XOl/rKXksruAa mWe1MFhnIsPIt3Nttdch+1EX/A6LKu70j/wV0o2ohxDF27JodQO6CsLBQrN9Sbr5hX PvzCh8wmuxYITSeONPkfElgycLAHpK9zlbtAmkbg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.20] ([188.174.166.124]) by mail.gmx.com (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M42jK-1jGQ1B0WAK-0007wF for ; Mon, 23 Mar 2020 17:33:37 +0100 Subject: Re: JOIN on partitions is very slow To: pgsql-performance@lists.postgresql.org References: From: Thomas Kellerer Message-ID: <7cdfd0d6-e4d3-7351-f13c-696460853657@gmx.net> Date: Mon, 23 Mar 2020 17:33:34 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:YYTPIIv8wQf3nNx/mKO3omrEaGj5+0OlCgkNMrCwDDmp46AyR07 3y4STjnQtUezZJU5WvLJRmTs50W+gsFWWxfnzJYzSqM01u3D+0QL4xhd2OaO0SWuieWIRrp 63IOHQrJkLHgfkLc/vx2vp1ZEnTlbauT7IGuiKV8MfXgvAPbB/Uxr2zmuBmHGfYp8dgq/3F Tb1nq595gA9WEeUEtiKxg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:DkS8d9WFC0c=:wNhapkKa7y/iAbTijFdvZR 1xVcjECdISKqupKZgfO/zwiktPdr1M05DfJ+g47+HgJxNJuZ5KGfaGdgps1epmiUqXBsTVxe5 1aHpuOQA3ixMtsTsxW6O1EUZ2Mxm82Fg8ZFiRvk5OlQNw38J/bln+quclThwUUw1s23KppWHm +OeLqxxS58muJd3I7K2H+uu5dsprFd8u7XbSW40PmlsQWZoSufhc8UBjUcdN/hh9bzxG7nk4r 859QxQ29dDXwlP/1i8hGZW8QNrCrwaMIyxDo9V7gxPwOLTNAtK4jdKilXxBZUwwIoh7urRjZv Mm+Hi920TJyZmkh6RsIY907yLQ4OXn6VbhlP1gUiGZBpR4QGeiK744COFQ2QSvAnmE0aq7axI m5LIPxtCfaSiZD9+1oM0NLlnK0JkFc+fj5Jhrp4wxeH/tLXt9JMmFs+bhnXphN46NwFm+KVa0 redQJvtJMvEuLCkJ+ysvLHw3cDEBRb48L1KyR+jUjtqyhAFYWp7HjEBJlpTJeqirH2kD95bIF cX65Xgtvrj01JlEclH1jhkOmmJb28jipK+QFZbZL866pV5qiefgFCpc5ghGz+nk4msNBPUHvh IdG9KfqLr5kA0Tn5qrK7/wvXWu+vA74b9kVKt41wtcI4Haip8YPUbDsjdZikBDPJIqbjP8CMe 1xFzDtRgRvCwgB/gGj7bBTTMQ1VTWHylmiCvfphBfRaZj9bdMc8Ut6/7r1sVymCyFwOVBWEgR WDApHgrzbzWpR4nYyvcIFDCiYXCZuo+KUgeTdafv1rAhnUONmUT8FRaqR6Hy0gr3m6t1xQuVg BM1V7afMi37+6/tzvQVRJlVNZkEdIykYAbtyVAbaNktS6X7YBSew9FUqcoSchQtfhk6mhSYox 594RNYJCt6AYuW+Y6/EVO61B8FodShZ/hmtLAygqD7Ip+uJYdhoRbUEJFX6fO9keN5G3J6zj8 YDODppWMU5GOniZQqwfq4KeLv5uHnRRfo6F4uRNemf/HBbYM7goMJA/qMgNcvmO/7nRNPlnu/ +HmYi20072XynzMuK+LWTbMAfoJyFrDPHvEJbXn2TsdgIrSy+Mr89LZpf1AFU1LqwXbcD4M/a kQatsYM1etwPPnDZgUN5XUzeumeTHqTNnDKe9NY1EJLp1Q+KHKsUAcXS4S8gE88rKNnaNhycQ T1u3BDOtQnB801ineB/eS5v/sUbKQ90NNEL4ybZCuZE0fbRFTpVm+eMVanaXjis5A4aFutc3H i0Yd73sj27MGi2mWd List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Lewis schrieb am 23.03.2020 um 17:16: > Yes. I can tweak the query. Version of postgres is 9.5.15. I have > about 20 partitions for company_sale_account table. I do have an > index on company name. > > I need to use DISTINCT as i need to remove the duplicates. > > > DISTINCT is a sign of improper joins most of the time in my > experience. Often, just changing to group by is faster As none of the columns of the joined table are used, most probably this should be re-written as an EXISTS condition. Then neither GROUP BY nor DISTINCT is needed.