Algorithm to make tree of DB tables that can be processed in parallel [DISCUSSION]

4 views
Skip to first unread message

Tommi Prami

unread,
2:46 AM (4 hours ago) 2:46 AM
to firebird-support

Hey,

I was just pondering.

With foreign keys and all, you could basically build a tree of tables that can be processed independently and in parallel.

Of course, some database structures would parallelize better than others, depending on how your tables and dependencies are set up.

That could be really helpful for bulk inserts, updates, deletes, or general housekeeping tasks.

-tee-

Dimitry Sibiryakov

unread,
3:30 AM (3 hours ago) 3:30 AM
to firebird...@googlegroups.com
Tommi Prami wrote 14.10.2025 8:46:
> With foreign keys and all, you could basically build a tree of tables that can
> be processed independently and in parallel.

It is actually trivial:

1. Get list of tables and list of foreign keys (except self-references).
2. Add tables that has no references into the sorted list in any order.
3. For each table from the rest, if all referenced tables are already in list,
add the table into the list.
4. Repeat 3) until no tables left (success) or no tables was added in current
iteration (failure).
5. In the case of failure the rest of tables forms loop so this database cannot
be parallelised automatically and you must solve it somehow depending of your
task. For example, by adding them into the sorted list staring from the table
with smallest number of "unresolved" reference.

The resulting list can be processed in parallel up to tables referencing to
still unprocessed tables.

--
WBR, SD.
Reply all
Reply to author
Forward
0 new messages