Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql,v diff -u -r1.10 -r1.11 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql 9 Dec 2001 04:21:58 -0000 1.10 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-relationships-create.sql 9 Dec 2001 04:49:30 -0000 1.11 @@ -363,8 +363,11 @@ actual_object_type_two acs_object_types.object_type%TYPE; begin - -- DRB: The obvious rewrite using exists kills Postgres!!! Argh!!! This is faster, so there ... - -- Get all the object type + -- DRB: The obvious rewrite to use Dan''s port of this to use tree_ancestor_keys kills + -- Postgres!!! Argh!!! This is fast, to, so there ... + + -- Get all the object type info from the relationship. + select rt.object_type_one, rt.object_type_two, o1.object_type, o2.object_type into target_object_type_one, target_object_type_two, @@ -374,17 +377,19 @@ and o1.object_id = new.object_id_one and o2.object_id = new.object_id_two; - select count(*) into dummy - from (select tree_ancestor_keys(acs_object_type_get_tree_sortkey(actual_object_type_one)) as tree_sortkey) parents1, - (select tree_ancestor_keys(acs_object_type_get_tree_sortkey(actual_object_type_two)) as tree_sortkey) parents2, - (select tree_sortkey from acs_object_types where object_type = target_object_type_one) root1, - (select tree_sortkey from acs_object_types where object_type = target_object_type_two) root2 - where tree_ancestor_p(root1.tree_sortkey, parents1.tree_sortkey) - and tree_ancestor_p(root2.tree_sortkey, parents2.tree_sortkey); + if not exists (select 1 + from + (select tree_ancestor_keys(acs_object_type_get_tree_sortkey(actual_object_type_one)) + as tree_sortkey) parents1, + (select tree_ancestor_keys(acs_object_type_get_tree_sortkey(actual_object_type_two)) + as tree_sortkey) parents2, + (select tree_sortkey from acs_object_types where object_type = target_object_type_one) + root1, + (select tree_sortkey from acs_object_types where object_type = target_object_type_two) + root2 + where root1.tree_sortkey = parents1.tree_sortkey + and root2.tree_sortkey = parents2.tree_sortkey) then - if NOT FOUND then - - raise EXCEPTION ''-20001: % violation: Invalid object types. Object % (%) must be of type % Object % (%) must be of type %'', new.rel_type, new.object_id_one, actual_object_type_one,