Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xarmi-00070S-8d for pgsql-performance@arkaria.postgresql.org; Sun, 05 Oct 2014 19:48:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xarmh-0007sY-05 for pgsql-performance@arkaria.postgresql.org; Sun, 05 Oct 2014 19:47:59 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xarmf-0007sR-P3 for pgsql-performance@postgresql.org; Sun, 05 Oct 2014 19:47:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xarmc-0007dD-OQ for pgsql-performance@postgresql.org; Sun, 05 Oct 2014 19:47:55 +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 s95JlqrW024855; Sun, 5 Oct 2014 15:47:52 -0400 From: Tom Lane To: Andrey Lizenko cc: pgsql-performance@postgresql.org Subject: Re: query plan question, nested loop vs hash join In-reply-to: References: Comments: In-reply-to Andrey Lizenko message dated "Sun, 05 Oct 2014 22:57:18 +0400" Date: Sun, 05 Oct 2014 15:47:52 -0400 Message-ID: <24854.1412538472@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Andrey Lizenko writes: > What is the reason of "Seq Scan on activities_example" in the first case? > Is it possible to force optimizer choose the second plan without doing > "set enable_hashjoin = off;" ? Disabling hashjoins altogether would be a pretty dangerous "fix". I think the real issue here is that you have an entirely cached-in-memory database and therefore you ought to reduce random_page_cost. The planner's estimates for the first query seem to more or less match reality (on the assumption that 1 msec equals about 100 cost units on your machine). The cost estimates for the second one are way off though, mainly in that the repeated indexscans are far cheaper than the planner thinks. Getting that cost estimate down requires reducing random_page_cost or increasing effective_cache_size or some combination. You can find the conventional wisdow about this sort of thing at https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server 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