X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 4E5DE11F8BF3 for ; Mon, 24 Apr 2006 15:17:28 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 54366-01-5 for ; Mon, 24 Apr 2006 15:17:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from xproxy.gmail.com (xproxy.gmail.com [66.249.82.205]) by postgresql.org (Postfix) with ESMTP id CD8C411F8B7A for ; Mon, 24 Apr 2006 07:53:29 -0300 (ADT) Received: by xproxy.gmail.com with SMTP id h31so623071wxd for ; Mon, 24 Apr 2006 03:53:30 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=CvPunHi8iH9qgwwUrOQyprOHACCYyNF34/rwR5XmyPZm05G1wZ24qSOPZ8q19WsoKWzRZyavROmGL8N1KINN0DTK3QE/YiWFiyZUObQZC/dNzoIRuyBJd1fyH1yY9AIabRYIM6aiFEk3BQianLOt7tHG7Qkq4B+BbBMRLysL3fI= Received: by 10.70.43.8 with SMTP id q8mr3791011wxq; Mon, 24 Apr 2006 03:53:30 -0700 (PDT) Received: by 10.70.37.12 with HTTP; Mon, 24 Apr 2006 03:53:29 -0700 (PDT) Message-ID: <786c2f6d0604240353n7853ef1fn148611ed2674044c@mail.gmail.com> Date: Mon, 24 Apr 2006 12:53:29 +0200 From: "Paul Mackay" To: pgsql-performance@postgresql.org Subject: Index on function less well cached than "regular" index ? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_23912_14956547.1145876009963" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/525 X-Sequence-Number: 18609 ------=_Part_23912_14956547.1145876009963 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I have a table of ~ 41 000 rows with an index on the result of a function applied to a certain text column (the function basically removes "neutral" or common words like "the","on","a", etc. from the string). I then execute a query with a where clause on this function result with an order by on the function result also and a limit of 200. Logically the EXPLAIN shows that an index scan is used by the planner. A query returning the maximum 200 number of records takes around 20 ms. What is surprising is that the same query executed several times takes practically the same time, as if the result was not cached. To test this, I then added a new text column to the same table, populating it with the function result mentioned above. Now, I create an index on this new column and execute the same query as described above (order by on the new column and limit 200). The execution plan is exactly the same, except that the new index is used of course. The first execution time is similar, i.e. 20 ms approx., but the next executions of the same query take about 2 ms (i.e to say a 10 to 1 difference). So this time, it seems that the resul= t is properly cached. Could the problem be that an index on a function result is not cached or less well cached ? Thanks, Paul ------=_Part_23912_14956547.1145876009963 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I have a table of ~ 41 000 rows with an index on the result of a function a= pplied to a certain text column (the function basically removes "neutr= al" or common words like "the","on","a",= etc. from the string).

I then execute a query with a where clause on this function result = with an order by on the function result also and a limit of 200. Logically = the EXPLAIN shows that an index scan is used by the planner. A query return= ing the maximum 200 number of records takes around 20 ms. What is surprisin= g is that the same query executed several times takes practically the same = time, as if the result was not cached.

To test this, I then added a new text column to the same table, pop= ulating it with the function result mentioned above. Now, I create an index= on this new column and execute the same query as described above (order by= on the new column and limit 200). The execution plan is exactly the same, = except that the new index is used of course. The first execution time is si= milar,=20 i.e. 20 ms approx., but the next executions of the same query take about 2 = ms (i.e to say a 10 to 1 difference). So this time, it seems that the resul= t is properly cached.

Could the problem be that an index on a functi= on result is not cached or less well cached ?=20

Thanks,
Paul
------=_Part_23912_14956547.1145876009963--