X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 715EBDAD64 for ; Thu, 24 Nov 2005 07:16:04 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93528-09 for ; Thu, 24 Nov 2005 11:16:06 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail46.e.nsc.no (mail46.e.nsc.no [193.213.115.46]) by svr1.postgresql.org (Postfix) with ESMTP id 59578DAD33 for ; Thu, 24 Nov 2005 07:16:00 -0400 (AST) Received: from [192.168.0.57] (062016183238.customer.alfanett.no [62.16.183.238]) (authenticated bits=0) by mail46.nsc.no (8.13.5/8.13.5) with ESMTP id jAOBG10k018262 for ; Thu, 24 Nov 2005 12:16:02 +0100 (CET) From: "Leif B. Kristensen" To: "PostgreSQL pg-sql list" Subject: Index wonder Date: Thu, 24 Nov 2005 12:16:00 +0100 User-Agent: KMail/1.8.1 X-Face: %iea8o"[SI'kMDS.`hz7lU=?\^lC9J-]CVjo; f{4-C:$?uVUEjyN~uYFn%*aH_c3d09U>=?utf-8?q?x=0A=09TXtaoj=7EMV=2E8PgG7hik9=3BcCT2N6+u?=@Y{wH\p3*_f~FH9k,Wi74e[_l%.7b^'zJ)8S'^G<(=?utf-8?q?=3D=0A=09zw8=5CPMC3=27=7BKl9=2EzL*ks!b6wA?=,c~'F`k&Vq|ELDGa|4 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[AWL=0.000] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/230 X-Sequence-Number: 23481 I just wanted to share my revelation on how an index can do wonders for a query: pgslekt=> explain select child_fk, get_coparent(570,child_fk), get_pbdate(child_fk) as pbd from relations where parent_fk = 570 order by pbd; QUERY PLAN ----------------------------------------------------------------- Sort (cost=378.26..378.27 rows=5 width=4) Sort Key: get_pbdate(child_fk) -> Seq Scan on relations (cost=0.00..378.20 rows=5 width=4) Filter: (parent_fk = 570) (4 rows) pgslekt=> create index parent_key on relations(parent_fk); CREATE INDEX pgslekt=> create index child_key on relations(child_fk); CREATE INDEX pgslekt=> explain select child_fk, get_coparent(570,child_fk), get_pbdate(child_fk) as pbd from relations where parent_fk = 570 order by pbd; QUERY PLAN ----------------------------------------------------------------- Sort (cost=13.81..13.83 rows=5 width=4) Sort Key: get_pbdate(child_fk) -> Index Scan using parent_key on relations (cost=0.00..13.76 rows=5 width=4) Index Cond: (parent_fk = 570) (4 rows) As a consequence, the time for generating a page listing the descendants and their spouses for a singularly prodigius and well-researched family - in total about 1100 persons - went down from 30 seconds to 3. I am thoroughly amazed. -- Leif Biberg Kristensen | Registered Linux User #338009 http://solumslekt.org/ | Cruising with Gentoo/KDE