Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 847FB64FE39 for ; Tue, 9 Dec 2008 18:41:38 -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 84112-02 for ; Tue, 9 Dec 2008 18:41:35 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.29]) by mail.postgresql.org (Postfix) with ESMTP id E998164FE1D for ; Tue, 9 Dec 2008 18:41:34 -0400 (AST) Received: by yw-out-2324.google.com with SMTP id 3so99561ywj.73 for ; Tue, 09 Dec 2008 14:41:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=DDufn/6A5jdblgiz1WfE5nLUawGw/uaAPLlenMV1A84=; b=dGsnqjMcloL80pV4sLlaDr0UitTto94gNJu+nj1jUbU6LnXTXYhtR5iZut0+NrwaH6 jU0/tT5xGHyDrlnlTfEJrClDhjvjGdOyVd7dYf5oSa49U+ZEiiv12IgkwDmlfkScvIcS FfcOUChTvRyJ8IdQ8S0WiIweMDIf2oy19ivf4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=QIXhJCdAlMI22s+Ew47GE1TQyhR86b7MvYWHWw0hRWgxV29SZ799ZqSk7IOeDxmlTA gU2BLMQ61EetnuNXRQskw3yfCKRQewOSPER2J2Q0IsGkiRyJihobp+Io6gO21PveMMwh 1boH3LVe2ZTIBwnNpAAr0XBeSfUPJeXOnLJQA= Received: by 10.151.111.1 with SMTP id o1mr838554ybm.88.1228862493669; Tue, 09 Dec 2008 14:41:33 -0800 (PST) Received: by 10.150.226.11 with HTTP; Tue, 9 Dec 2008 14:41:33 -0800 (PST) Message-ID: Date: Tue, 9 Dec 2008 17:41:33 -0500 From: "David Wilson" To: "Richard Yen" Subject: Re: query plan with index having a btrim is different for strings of different length Cc: pgsql-performance@postgresql.org In-Reply-To: <751F49DC-1142-4E9C-95C8-BC3C229B3F0B@richyen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <751F49DC-1142-4E9C-95C8-BC3C229B3F0B@richyen.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3 tagged_above=0 required=5 tests=SARE_RAND_OTHER_H=3 X-Spam-Level: *** X-Archive-Number: 200812/94 X-Sequence-Number: 32130 On Tue, Dec 9, 2008 at 2:56 PM, Richard Yen wrote: > In practice, the difference is 300+ seconds when $LASTNAME == 5 chars and <1 > second when $LASTNAME != 5 chars. > > Would anyone know what's going on here? Is there something about the way > btrim works, or perhaps with the way indexes are created? It's strange that > the query plan would change for just one case ("Jones," "Smith," "Brown," > etc., all cause the query plan to use that extra heap scan). Those are likely common names, and may be showing up in the table stats as common values, causing the planner to change things around. Does this hold even for non-existent 5-character lastname strings? Speaking of table statistics, might be worth upping the statistics target on that table/column, analyzing, and seeing if you get different results. -- - David T. Wilson david.t.wilson@gmail.com