Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WpdxO-0007ut-N7 for pgsql-performance@arkaria.postgresql.org; Wed, 28 May 2014 13:31:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WpdxO-0007uf-2J for pgsql-performance@arkaria.postgresql.org; Wed, 28 May 2014 13:31:50 +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 1WpdxM-0007uX-NJ for pgsql-performance@postgresql.org; Wed, 28 May 2014 13:31:48 +0000 Received: from smtp.peak6.com ([38.98.137.6]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WpdxI-0000WW-49 for pgsql-performance@postgresql.org; Wed, 28 May 2014 13:31:46 +0000 X-AuditID: 0a64cb20-f79426d000005a0a-1d-5385e53cbb6e Message-ID: <5385E53A.4000406@optionshouse.com> Date: Wed, 28 May 2014 08:31:38 -0500 From: Shaun Thomas User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Grzegorz Olszewski , AI Rumman CC: "pgsql-performance@postgresql.org" Subject: Re: Planner doesn't take indexes into account References: , In-Reply-To: Content-Type: text/plain; charset="ISO-8859-2"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.220.56] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRmVeSWpSXmKPExsXClcIrpmv7tDXY4MsOFou1d36yW1yfeY7Z 4kNvgAOzx85Zd9k9Nr9+wexxYd809gDmqAZGm8S8vPySxJJUhZTU4mRbJf+Cksz8vGKP/NLi VAWXzOLknMTM3NQiJYXMFFslYyWFgpzE5NTc1LwSW6XEgoLUvBQlOy4FDGADVJaZp5Cal5yf kpmXbqvkGeyva2FhaqlrqGQXjwwSOlkyJnTvYylo56pY1nCTsYGxnaOLkZNDQsBE4uvUqewQ tpjEhXvr2UBsXgF9iZN905lAbBYBVYnG10vBatgEdCUm9a8AqxEVCJP4eHQdVL2gxMmZT1hA bBGBKIkrG6+xgtjMAp4SHadWMYLYwgIOEu/mfQCaycUhJLCGUeLt38vMIAlOASuJjjtPmCEa bCUuztvHBGHLS2x/OwcsLgR0xIrmiUDLOIAOVQA6NHUCo8AsJKtnIemehaR7ASPzKkbx4rLE 5IxM04Li3JICI72C1MRsM7281JJNjODYPK2wg/F7p9UhRgEORiUe3oIVLcFCrIllxZW5hxgl OJiVRHj3XGkNFuJNSaysSi3Kjy8qzUktPsToAwybicxSosn5wLSRVxJvaGxqYGppamhqbmpo hENYSZz3SEtcsJBAOjA1ZKemFqQWwYxj4uCUamCcYL3m78/Osh0zinJmqzSe74maU5VZHCkW uzLxnEyyYbfe7exrrj6hHNM+CUjw7dnSp6LN1G4vIdkr5cdi76zi9+NopNdH9pCCB8L59t2v 7mdJbmXYa1SU06n956XoO/M3X+W9tz0V/HRl5dsuxjLDc/PWacyRuvbxLt/LudZzgkKy9+Ry RSmxFGckGmoxFxUnAgDmkbX/+gIAAA== 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 05/28/2014 04:59 AM, Grzegorz Olszewski wrote: > There is about 500,000 rows and about 500 new rows each business day. > > About 96% of rows meet given conditions, that is, count shoud be about > 480,000. Heikki is right on this. Indexes are not a magic secret sauce that are always used simply because they exist. Think of it like this... If the table really matches about 480,000 rows, by forcing it to use the index, it has to perform *at least* 480,000 random seeks. Even if you have a high-performance SSD array that can do 100,000 random reads per second, you will need about five seconds just to read the data. A sequence scan can perform that same operation in a fraction of a second because it's faster to read the entire table and filter out the *non* matching rows. Indexes are really only used, or useful, when the number of matches is much lower than the row count of the table. I highly recommend reading up on cardinality and selectivity before creating more indexes. This page in the documentation does a really good job: http://www.postgresql.org/docs/9.3/static/row-estimation-examples.html -- Shaun Thomas OptionsHouse, LLC | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@optionshouse.com ______________________________________________ See http://www.peak6.com/email_disclaimer/ for terms and conditions related to this email -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance