Subject | Re: Tree Sql query |
---|---|
Author | johnsparrowuk |
Post date | 2004-03-25T09:17:25Z |
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:
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,which
>
> > I'm less impressed after running some tests:
>
> > 2) Inserting a new node involved updating all parent records -
> > is quite blocking. (those transactions had better be very quickeffect of
> > indeed!)
>
> I agree. I read the article a while back, but I remember the side
> an insert could be even worse. It's not only parents that must beupdated,
> but all what is on "right" of the inserted node. So no matter howdeep the
> tree, inserting near the "left" of the tree won't cost the same asinserting
> near the "right".example ?
>
> > 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
> I'll need such code very soon, and I'll be happy to start withsomething
> tested.
>
> Best regards.
>
> --
> Jerome