Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f4RZY-0003LY-1Y for pgsql-general@arkaria.postgresql.org; Fri, 06 Apr 2018 13:38:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f4RZX-0007az-6G for pgsql-general@arkaria.postgresql.org; Fri, 06 Apr 2018 13:38:31 +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 1f4RX9-0007ZB-Ji for pgsql-general@lists.postgresql.org; Fri, 06 Apr 2018 13:36:03 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f4RX6-00065q-3A for pgsql-general@postgresql.org; Fri, 06 Apr 2018 13:36:02 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id CB7DDC28051E for ; Fri, 6 Apr 2018 06:35:56 -0700 (MST) Date: Fri, 6 Apr 2018 06:35:56 -0700 (MST) From: pinker To: pgsql-general@postgresql.org Message-ID: <1523021756830-0.post@n3.nabble.com> In-Reply-To: <40cd1824-1dd0-1aad-2c8d-c34ee510b5c5@simkorp.com.br> References: <40cd1824-1dd0-1aad-2c8d-c34ee510b5c5@simkorp.com.br> Subject: Re: decompose big queries MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Edson Carlos Ericksson Richter wrote > I don't know if there are best practices (each scenario requires its own > solution), but for plain complex SELECT queries, I do use "WITH" > queries... They work really well. Be cautious with CTE's. They weren't meant to be an alternative to subqueries and will probably change the way your query is executed, because they are optimisation fences: https://blog.2ndquadrant.com/postgresql-ctes-are-optimization-fences/ -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html