Re: Guidance on INSERT RETURNING order

From: John Howroyd <jdhowroyd(at)googlemail(dot)com>
To: Federico <cfederico87(at)gmail(dot)com>
Cc: Thorsten Glaser <tg(at)evolvis(dot)org>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Guidance on INSERT RETURNING order
Date: 2023-04-12 10:50:21
Message-ID: CAAGaYBz6ZjkpNkJLpZUG2muwvjG0HLQhsGzBpop1NMRb9moV2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi All,

The fundamental question here is:
What does "insert into object(col1, ... , coln) select sel1, ... , seln
from ... order by ord1, ... ordm returning val1, ..., valk" mean?

In particular, what does the "order by" do in "insert ... select ... order
by"? Will this be honoured with parallel inserts? Is that really too much
to ask?

Is a DBMS just a black box archive of data (throw it in and forget about
it)? In my opinion, it's a system for the consistent and efficient storage
and *retrieval* of data, to be used in the context of other software
systems. Programmatically, that means matching up what's in the database
with what's stored in memory.

And yes, a DBMS needs to give guarantees! ACID compliance is one such
guarantee, but it is not the only one required.

Finally, please don't read this badly. It is meant purely to question
where we want to go, I strongly support PostgreSQL and believe it has made
many major contributions to the development of DBMS over the years.

Many thanks,
John.

On Wed, 12 Apr 2023 at 11:10, Federico <cfederico87(at)gmail(dot)com> wrote:

> On Wed, 12 Apr 2023 at 11:46, Thorsten Glaser <tg(at)evolvis(dot)org> wrote:
> >
> > On Tue, 11 Apr 2023, Federico wrote:
> >
> > >My understanding was that they are generated in select order
> >
> > But are they? (I don’t know, but I’d not assume that.)
>
> That's kind of the point for this question, to see if that's correct or
> not.
>
> > >If my understanding is incorrect, would this alternative guarantee the
> above
> >
> > > INSERT INTO t(id, data)
> > > SELECT nextval(pg_get_serial_sequence('t', 'id')) data
> > > FROM (VALUES ('a', 1), ('b', 2), ('c', 3)) as vv(data, num)
> > > ORDER BY num
> > > RETURNING id
> >
> > Wouldn’t, at that point, it be better to just send multiple
> > individual INSERT statements? The overhead (on both sides)
> > for all mentioned… workarounds… surely is larger than that?
>
> No, not by a long shot. Sending thousands of single inserts
> sequentially over the network requires a lot more time even when doing
> that on localhost.
> Using a single statement is many times faster.
>
> Federico
>
> > bye,
> > //mirabilos
> > --
> > 15:41⎜<Lo-lan-do:#fusionforge> Somebody write a testsuite for helloworld
> :-)
> >
> >
> >
> >
>
>
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Gustafsson 2023-04-12 10:59:46 Re: lippq client library and openssl initialization: PQinitOpenSSL()
Previous Message Achilleas Mantzios - cloud 2023-04-12 10:45:56 Re: pg_basebackup / recovery