Index: openacs-4/packages/forums/sql/postgresql/upgrade-0.2d-0.3d.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/Attic/upgrade-0.2d-0.3d.sql,v
diff -u -N
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/forums/sql/postgresql/upgrade-0.2d-0.3d.sql	16 Jan 2003 13:49:10 -0000	1.2
@@ -0,0 +1,28 @@
+-- forums/sql/postgresql/upgrade-0.2d-0.3d.sql
+--
+-- Changes for scalability davis@xarg.net
+
+create unique index forums_mess_forum_sk_un on forums_messages(forum_id, tree_sortkey);
+
+create or replace function forums_message__root_message_id (integer)
+returns integer as '
+declare
+    p_message_id                    alias for $1;
+    v_message_id                    forums_messages.message_id%TYPE;
+    v_forum_id                      forums_messages.forum_id%TYPE;
+    v_sortkey                       forums_messages.tree_sortkey%TYPE;
+begin
+    select forum_id, tree_sortkey
+    into v_forum_id, v_sortkey
+    from forums_messages
+    where message_id = p_message_id;
+
+    select message_id
+    into v_message_id
+    from forums_messages
+    where forum_id = v_forum_id
+    and tree_sortkey = tree_ancestor_key(v_sortkey, 1);
+
+    return v_message_id;
+end;
+' language 'plpgsql' with(isstrict,iscachable);
