Subject Re: Tree Sql query
Author johnsparrowuk
How about this one? Assumes a table like:

create table wtreestore (id integer not null, something varchar(30)
not null, parentnode integer);

id is the PK, parentnode should be a FK pointing to id.

/**********/
SET TERM !! ;
CREATE PROCEDURE OLDVIEW (
IDNEEDED INTEGER,
IND INTEGER)
RETURNS (
ID INTEGER,
INDENT INTEGER,
SOMETHING VARCHAR(30))
AS
declare a integer;
begin
select :idneeded,:ind,something from wtreestore where id
= :idneeded into :id,:indent,:something;
suspend;
ind = ind + 1;
for select id from wtreestore where parentnode = :idneeded
into :a do
begin
for select id,indent,something from oldview(:a,:ind)
into :id,:indent,:something do
suspend;
end
end!!
set term ; !!
/**********/

Hope this helps,

John

--- In firebird-support@yahoogroups.com, "Jerome Bouvattier"
<JBouvattier@I...> wrote:
> John,
>
> > I'm less impressed after running some tests:
>
> > 2) Inserting a new node involved updating all parent records -
which
> > is quite blocking. (those transactions had better be very quick
> > indeed!)
>
> I agree. I read the article a while back, but I remember the side
effect of
> an insert could be even worse. It's not only parents that must be
updated,
> but all what is on "right" of the inserted node. So no matter how
deep the
> tree, inserting near the "left" of the tree won't cost the same as
inserting
> near the "right".
>
> > After testing, I'll stick with the old technique. With Firebird's
> > fast stored procedure language, it performs very well.
>
> John, would you be so kind as to post one of those SPs for the
example ?
> I'll need such code very soon, and I'll be happy to start with
something
> tested.
>
> Best regards.
>
> --
> Jerome