Re: How to represent a bi-directional list in db?

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: Pankaj Jangid <pankaj(dot)jangid(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to represent a bi-directional list in db?
Date: 2019-09-24 07:29:54
Message-ID: CA+bJJbxeEXYMOczyxF5Hv7Bf5byLSO7DcRaEM3aoN5inEBBYHQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Pankaj:

On Mon, Sep 23, 2019 at 4:07 PM Pankaj Jangid <pankaj(dot)jangid(at)gmail(dot)com> wrote:
...
> My stages are stages of processes. So yes processes are also stored in a
> table. I got the idea. I'll add another column in the processes table
> which points to the first stage (first_stage_id). And quries
> Forward pass:
...
> Backward pass:
..
> This is assuming I also create a circular list. I can also store
> last_stage_id in the process table if we don't want to create circular
> list in db.

That's exactly the idea. A pointer in C becomes a pair of fields with
corresponding value, and it can be traversed in any direction, slowly
by table scan or fastly with indexes. In fact a pair of values becomes
equivalent to two pointers, as it can be traversed either way ( but
the indexing acceleration has to be applied to each direction ).

That being said, linked lists are procedural data structures, SQL is
declarative, so they are not a great match, that's one of the reasons
why they are rarely seen. Things like master-detail have less
impedance mismatch.

Francisco Olarte.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daulat Ram 2019-09-24 09:17:49 Monitor Postgres database status on Docker
Previous Message Laurenz Albe 2019-09-24 05:06:42 Re: Autovacuum lock conflict