storing intermediate results from recursive plpgsql

Поиск
Список
Период
Сортировка
От Fran Fabrizio
Тема storing intermediate results from recursive plpgsql
Дата
Msg-id 3C192106.D2651F1E@mmrd.com
обсуждение исходный текст
Ответы Re: storing intermediate results from recursive plpgsql  (Philip Hallstrom <philip@adhesivemedia.com>)
Список pgsql-general
Hello,

I've got a plpgsql function that is recursive.  Basically, it traverses
a table that represents a tree, which in turn represents parent-child
relationships.  So, I have a function, get_descendants.  For each pass,
it gets the children of some id.  Then it recurses and looks for the
children of all of those children, etc...So, along the way, I'm building
a list of ids that represent the whole family.

For lack of a better idea, I'm storing the id's into a table on each
pass.  So, if I recurse three levels, I'm doing three inserts.  When the
recursion exits, I simply select the entire table and then I delete all
rows from it.  The performance hit I take is unacceptable, something
like .02 - .03 seconds per insert, and it's adding up due to the amount
of times I have to run this function.  The end result is that the web
page that displays this data takes many seconds to run.

Is there some sort of data structure in plpgsql (an array) that I can
use instead of the hack of inserting into a table on each pass and
selecting back out at the end?  I have to find a way to optimize this
process further.

Thanks,
Fran


В списке pgsql-general по дате отправления:

Предыдущее
От: Vince Vielhaber
Дата:
Сообщение: Re: Can I call unix/linux commands within plsql?
Следующее
От: GB Clark II
Дата:
Сообщение: Re: How to increase shared mem for PostgreSQL on FreeBSD