Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A322C65060E for ; Tue, 9 Dec 2008 19:36:48 -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 96890-01-6 for ; Tue, 9 Dec 2008 19:36:45 -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 4D782650558 for ; Tue, 9 Dec 2008 19:27:25 -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 mB9NRNIR022938; Tue, 9 Dec 2008 18:27:24 -0500 (EST) To: Richard Yen cc: pgsql-performance@postgresql.org Subject: Re: query plan with index having a btrim is different for strings of different length In-reply-to: <751F49DC-1142-4E9C-95C8-BC3C229B3F0B@richyen.com> References: <751F49DC-1142-4E9C-95C8-BC3C229B3F0B@richyen.com> Comments: In-reply-to Richard Yen message dated "Tue, 09 Dec 2008 11:56:45 -0800" Date: Tue, 09 Dec 2008 18:27:23 -0500 Message-ID: <22937.1228865243@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/99 X-Sequence-Number: 32135 Richard Yen writes: > I've discovered a peculiarity with using btrim in an index and was > wondering if anyone has any input. What PG version is this? In particular, I'm wondering if it's one of the early 8.2.x releases, which had some bugs in and around choose_bitmap_and() that caused them to sometimes make weird choices of indexes in a BitmapAnd plan structure ... Like David, I'm pretty dubious that the behavior has anything to do with strings being 5 characters long exactly; but it could very much depend on whether the string you choose is a common last name or not. That would change the estimated number of matching rows and hence affect the apparent relative attractiveness of different indexes. regards, tom lane