Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tqyy5-0006r7-Q1 for pgsql-performance@arkaria.postgresql.org; Fri, 04 Jan 2013 04:33:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Tqyy4-0002v6-Ux for pgsql-performance@arkaria.postgresql.org; Fri, 04 Jan 2013 04:33:16 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tqyy4-0002uy-3w for pgsql-performance@postgresql.org; Fri, 04 Jan 2013 04:33:16 +0000 Received: from mail.synedra.com ([81.223.55.196]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Tqyy2-0001Ku-Cy for pgsql-performance@postgresql.org; Fri, 04 Jan 2013 04:33:15 +0000 Received: by mail.synedra.com (Postfix, from userid 99) id 42A8E104787; Fri, 4 Jan 2013 05:33:12 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on web X-Spam-Level: X-Spam-Status: No, score=-6.8 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED, RDNS_NONE autolearn=ham version=3.2.4 Received: from [192.168.180.26] (unknown [83.175.89.110]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.synedra.com (Postfix) with ESMTP id 3CC1A104782 for ; Fri, 4 Jan 2013 05:33:10 +0100 (CET) Message-ID: <50E65B85.9000001@synedra.com> Date: Fri, 04 Jan 2013 05:33:09 +0100 From: Stefan Andreatta Organization: synedra IT User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Simple join doesn't use index References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 On 01/03/2013 11:54 PM, Alex Vinnik wrote: > Don't understand why PG doesn't use views_visit_id_index in that query > but rather scans whole table. One explanation I have found that when > resulting dataset constitutes ~15% of total number of rows in the table > then seq scan is used. In this case resulting dataset is just 1.5% of > total number of rows. So it must be something different. Any reason why > it happens and how to fix it? But does the query planner know the same? If you added the EXPLAIN ANALYZE output of the query and something like: SELECT tablename AS table_name, attname AS column_name, null_frac, avg_width, n_distinct, correlation FROM pg_stats WHERE tablename in ('views', 'visits'); .. one could possibly tell a bit more. > Postgres 9.2 > Ubuntu 12.04.1 LTS > shared_buffers = 4GB the rest of the settings are default ones There are more than just this one memory related value, that need to be changed for optimal performance. E.g. effective_cache_size can have a direct effect on use of nested loops. See: http://www.postgresql.org/docs/9.2/static/runtime-config-query.html Regards, Stefan -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance