Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 6D6AE9FA154 for ; Fri, 20 Oct 2006 23:39:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 73467-07 for ; Sat, 21 Oct 2006 02:39:33 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.187]) by postgresql.org (Postfix) with ESMTP id 8507A9FA469 for ; Fri, 20 Oct 2006 23:39:33 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id i2so1750400nfe for ; Fri, 20 Oct 2006 19:39:31 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fjoY9PQLvlj8hQBHU22lZf8xfjtO/AgK9i1dGcAHQTXY+OXTxN5cvu25QCWCrDTgdqyT9ekvejRJY6c2VUef931top0NbgoOKobK8dEondblphIowK9a6Uc/o3AsC1+ATHRjAIa85aK57oo41dD9MPEZw+GhvJokTbLj+ZVyiA4= Received: by 10.78.117.10 with SMTP id p10mr3121435huc; Fri, 20 Oct 2006 19:39:31 -0700 (PDT) Received: by 10.78.45.3 with HTTP; Fri, 20 Oct 2006 19:39:31 -0700 (PDT) Message-ID: Date: Sat, 21 Oct 2006 08:09:31 +0530 From: "Merlin Moncure" To: "Stuart Bishop" Subject: Re: Slow functional indexes? Cc: pgsql-performance@postgresql.org In-Reply-To: <45387666.204@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45387666.204@canonical.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.199 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/450 X-Sequence-Number: 21579 On 10/20/06, Stuart Bishop wrote: > I would like to understand what causes some of my indexes to be slower to > use than others with PostgreSQL 8.1. On a particular table, I have an int4 > primary key, an indexed unique text 'name' column and a functional index of > type text. The function (person_sort_key()) is declared IMMUTABLE and > RETURNS NULL ON NULL INPUT. database will not allow you to create index if the function is not immutable. > A simple query ordering by each of these columns generates nearly identical > query plans, however runtime differences are significantly slower using the > functional index. If I add a new column to the table containing the result > of the function, index it and query ordering by this new column then the > runtime is nearly an order of magnitude faster than using the functional > index (and again, query plans are nearly identical). > demo=# explain analyze select * from person order by id offset 527000 limit 50; > QUERY PLAN it looks you just turned up a bad interaction between a functional index and 'offset' probably your function is getting executed extra times or there is a sort going on. however, I'd suggest not using 'offset', because its bad design. merlin