Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CD7D96501D1 for ; Wed, 10 Dec 2008 20:08:34 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 53140-04 for ; Wed, 10 Dec 2008 20:08:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 865A865032E for ; Wed, 10 Dec 2008 20:08:31 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id mBB08S2X009071; Wed, 10 Dec 2008 19:08:28 -0500 (EST) To: Richard Yen cc: Robert Haas , pgsql-performance@postgresql.org Subject: Re: query plan with index having a btrim is different for strings of different length In-reply-to: <129E8D79-341B-411A-83B7-E2B509A7B6E2@richyen.com> References: <751F49DC-1142-4E9C-95C8-BC3C229B3F0B@richyen.com> <22937.1228865243@sss.pgh.pa.us> <603c8f070812101139p189cc828hef8702f37f952b6d@mail.gmail.com> <129E8D79-341B-411A-83B7-E2B509A7B6E2@richyen.com> Comments: In-reply-to Richard Yen message dated "Wed, 10 Dec 2008 14:04:57 -0800" Date: Wed, 10 Dec 2008 19:08:28 -0500 Message-ID: <9070.1228954108@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200812/132 X-Sequence-Number: 32168 Richard Yen writes: > Is there any way to tune this so that for the common last names, the query > run time doesn't jump from <1s to >300s? Well, as near as I can tell there's factor of a couple hundred difference between the frequencies of 'smith' and 'smithers', so you shouldn't really expect similar runtimes for the two cases. Having said that, I still think you should try to index both first and last name. Also I wonder whether the index on owner is worth having at all. It definitely doesn't seem worthwhile to index the entries with owner = -1, since there are so many; so maybe you could make it a partial index that excludes those entries, in order to prevent the planner from trying to use it for this case. regards, tom lane