pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sam Patterson <katoriasdev@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Varlena with recursive data structures?
Date: Wed, 16 Jan 2019 17:22:33 -0500
Message-ID: <26970.1547677353@sss.pgh.pa.us> (raw)
In-Reply-To: <CACA+8xiTtHyMrV-Y32dgXacLCJf3eRn+g-uhd4m_F4J5Rqt5AA@mail.gmail.com>
References: <CACA+8xiTtHyMrV-Y32dgXacLCJf3eRn+g-uhd4m_F4J5Rqt5AA@mail.gmail.com>

Sam Patterson <katoriasdev@gmail.com> writes:
> I presume the purpose for using this approach is because all the data in a
> varlena type has to be contiguous, and the moment you start using pointers
> this is no longer possible.

Yup.

> So my question is, given a structure that looks
> something like this,

> typedef struct Node
> {
>     char *data;
>     Node *left;
>     Node *right;
> } Node;

> am I right in saying that I wouldn't be able to store that representation
> on-disk, but instead I'd have to transform it into some binary
> representation and back again when writing/reading respectively, are there
> any alternatives?

Yes, yes, no.  Any elementary datatype has to be able to be flattened into
a "blob of bytes" to be stored on disk.

However, you might be able to avoid working with the flattened
representation all the time.  There's an API for "expanded datums"
whereby functions can pass around an in-memory data structure that
doesn't have to look like a blob of bytes, and only flatten it out
when it's due to be stored somewhere.  I'm not sure how much that'd
help you, but it's possibly worth looking at.  See

src/include/utils/expandeddatum.h
src/backend/utils/adt/expandeddatum.c

for the basic APIs and

src/backend/utils/adt/array_expanded.c
src/backend/utils/adt/expandedrecord.c

for two examples of use.

			regards, tom lane




view thread (4+ messages)  latest in thread

Message-ID: <26970.1547677353@sss.pgh.pa.us>
Permalink:  ../26970.1547677353@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/26970.1547677353@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, katoriasdev@gmail.com
  Subject: Re: Varlena with recursive data structures?
  In-Reply-To: <26970.1547677353@sss.pgh.pa.us>
  References: <CACA+8xiTtHyMrV-Y32dgXacLCJf3eRn+g-uhd4m_F4J5Rqt5AA@mail.gmail.com> <26970.1547677353@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox