Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cIO3K-0001ie-JK for pgsql-performance@arkaria.postgresql.org; Sat, 17 Dec 2016 23:06:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cIO3J-00072v-Vq for pgsql-performance@arkaria.postgresql.org; Sat, 17 Dec 2016 23:06:06 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cIO1e-00057L-7l for pgsql-performance@postgresql.org; Sat, 17 Dec 2016 23:04:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cIO1b-00024j-Q0 for pgsql-performance@postgresql.org; Sat, 17 Dec 2016 23:04:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id uBHN4IsT023586; Sat, 17 Dec 2016 18:04:18 -0500 From: Tom Lane To: Gabliver Faluker cc: pgsql-performance@postgresql.org Subject: Re: bad performance In-reply-to: References: Comments: In-reply-to Gabliver Faluker message dated "Sat, 17 Dec 2016 23:25:53 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <23584.1482015858.1@sss.pgh.pa.us> Date: Sat, 17 Dec 2016 18:04:18 -0500 Message-ID: <23585.1482015858@sss.pgh.pa.us> X-Pg-Spam-Score: -5.0 (-----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Gabliver Faluker writes: > It runs for ~5 seconds . I'm a little skeptical that a 12-way join producing 340K rows and executing in 5 seconds should be considered "bad performance". It looks like it'd help some if you increased work_mem enough to let both sorts happen in-memory rather than externally. But really, this is going to take awhile no matter what. Do you really need all 340K rows of the result? Can you improve your data representation so that you don't need to join quite so many tables to get the answer, and (probably even more importantly) so that you don't need to use SELECT DISTINCT? The sort/unique steps needed to do DISTINCT are eating a large part of the runtime, and they also form an optimization fence IIRC. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance