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

From Francisco Olarte
Subject Re: How to represent a bi-directional list in db?
Date
Msg-id CA+bJJbxeEXYMOczyxF5Hv7Bf5byLSO7DcRaEM3aoN5inEBBYHQ@mail.gmail.com
Whole thread Raw
In response to Re: How to represent a bi-directional list in db?  (Pankaj Jangid <pankaj.jangid@gmail.com>)
Responses Re: How to represent a bi-directional list in db?
List pgsql-general
Pankaj:

On Mon, Sep 23, 2019 at 4:07 PM Pankaj Jangid <pankaj.jangid@gmail.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.



pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Autovacuum lock conflict
Next
From: Daulat Ram
Date:
Subject: Monitor Postgres database status on Docker