Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqyRR-0006Pp-Uf for pgsql-general@arkaria.postgresql.org; Sat, 18 Aug 2018 10:26:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fqyRP-0003PC-EV for pgsql-general@arkaria.postgresql.org; Sat, 18 Aug 2018 10:26:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqyRP-0003P5-6W for pgsql-general@lists.postgresql.org; Sat, 18 Aug 2018 10:26:43 +0000 Received: from mail.i-mark.de ([188.138.104.222]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fqyRF-0001he-3I for pgsql-general@lists.postgresql.org; Sat, 18 Aug 2018 10:26:40 +0000 Received: from [192.168.178.20] (unknown [185.38.49.16]) by mail.i-mark.de (Postfix) with ESMTPSA id 485DF158119C for ; Sat, 18 Aug 2018 12:26:28 +0200 (CEST) Authentication-Results: loft7616.startdedicated.de; spf=pass (sender IP is 185.38.49.16) smtp.mailfrom=andreas@a-kretschmer.de smtp.helo=[192.168.178.20] Received-SPF: pass (loft7616.startdedicated.de: connection is authenticated) Subject: Re: CTE with JOIN of two tables is much faster than a regular query To: pgsql-general@lists.postgresql.org References: <004b01d436d6$ff96c840$fec458c0$@gmail.com> From: Andreas Kretschmer Message-ID: <42ce9b74-0671-ecba-3deb-dc8bc8d5e9b3@a-kretschmer.de> Date: Sat, 18 Aug 2018 12:26:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <004b01d436d6$ff96c840$fec458c0$@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Am 18.08.2018 um 11:36 schrieb kpi6288@gmail.com: > What can I do to improve the performance of the regular query without > using a CTE? try to rewrite it to a subselect: select ... from ... join (selec ... from ... where ...) x on ... Regards, Andreas -- 2ndQuadrant - The PostgreSQL Support Company. www.2ndQuadrant.com