Implementing pg_dump_sort.c topological sorting in sql/plpgsql/plperl? - Mailing list pgsql-hackers

From Joel Jacobson
Subject Implementing pg_dump_sort.c topological sorting in sql/plpgsql/plperl?
Date
Msg-id AANLkTik=_OZi0NShedfGHoUOrY6RAdQT3GWgLcjnVyhO@mail.gmail.com
Whole thread Raw
Responses Re: Implementing pg_dump_sort.c topological sorting in sql/plpgsql/plperl?  (Dimitri Fontaine <dimitri@2ndQuadrant.fr>)
Re: Implementing pg_dump_sort.c topological sorting in sql/plpgsql/plperl?  (David Fetter <david@fetter.org>)
List pgsql-hackers
Hi hackers,

The project I'm currently working with fsnapshot[1], is written in
plain plpgsql and I need to sort all the oids in their
creatable/droppable order.
This has already been properly implemented in pg_dump_sort.c using
Knuth's algorithm for topological sorting, with some special magic to
find and break dependency loops.

It's not possible to use a plain recursive query to do the trick (due
to 'i' bidirectional dependencies and dependency loops).

I need a general approach, only making use of pg_depend.

The function should take no input arguments and the output argument
should be oid[], containing a list of the oids in a
creatable/droppable or order.
It doesn't matter if it is left-to-right, least number of edges first.
Any valid topological sort will do.

I'm sure it's possible to implement it in plpgsql or plperl, but I
wanted to check first if anyone has already made such a function to
hopefully save some time?

Thanks a lot!

[1] https://github.com/gluefinance/fsnapshot

-- 
Best regards,

Joel Jacobson
Glue Finance


pgsql-hackers by date:

Previous
From: Jeff Davis
Date:
Subject: WIP: Range Types
Next
From: Dimitri Fontaine
Date:
Subject: Re: Extension upgrade, patch v0: debug help needed