pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedassignment vs SELECT INTO
4+ messages / 3 participants
[nested] [flat]
* assignment vs SELECT INTO
@ 2014-11-03 20:00 Andrew Dunstan <andrew@dunslane.net>
2014-11-03 20:24 ` Re: assignment vs SELECT INTO Tom Lane <tgl@sss.pgh.pa.us>
2014-11-03 20:27 ` Re: assignment vs SELECT INTO Matheus de Oliveira <matioli.matheus@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Dunstan @ 2014-11-03 20:00 UTC (permalink / raw)
To: pgsql-performance
I found out today that direct assignment to a composite type is (at
least in my test) about 70% faster than setting it via SELECT INTO. That
seems like an enormous difference in speed, which I haven't really been
able to account for.
Test case:
andrew=# \d abc
Table "public.abc"
Column | Type | Modifiers
--------+---------+-----------
x | text |
y | text |
z | integer |
andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop
select 'a','b',i into r.x,r.y,r.z; end loop; end; $x$;
DO
Time: 63731.434 ms
andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop r
:= ('a','b',i); end loop; end; $x$;
DO
Time: 18744.151 ms
Is it simply because the SELECT is in effect three assignments, so it
takes nearly 3 times as long?
cheers
andrew
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: assignment vs SELECT INTO
2014-11-03 20:00 assignment vs SELECT INTO Andrew Dunstan <andrew@dunslane.net>
@ 2014-11-03 20:24 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-11-03 20:31 ` Re: assignment vs SELECT INTO Andrew Dunstan <andrew@dunslane.net>
1 sibling, 1 reply; 4+ messages in thread
From: Tom Lane @ 2014-11-03 20:24 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: pgsql-performance
Andrew Dunstan <andrew@dunslane.net> writes:
> andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop
> select 'a','b',i into r.x,r.y,r.z; end loop; end; $x$;
> DO
> Time: 63731.434 ms
> andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop r
> := ('a','b',i); end loop; end; $x$;
> DO
> Time: 18744.151 ms
> Is it simply because the SELECT is in effect three assignments, so it
> takes nearly 3 times as long?
I think it's more likely that the second example is treated as a "simple
expression" so it has less overhead than a SELECT.
regards, tom lane
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: assignment vs SELECT INTO
2014-11-03 20:00 assignment vs SELECT INTO Andrew Dunstan <andrew@dunslane.net>
2014-11-03 20:24 ` Re: assignment vs SELECT INTO Tom Lane <tgl@sss.pgh.pa.us>
@ 2014-11-03 20:31 ` Andrew Dunstan <andrew@dunslane.net>
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Dunstan @ 2014-11-03 20:31 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-performance
On 11/03/2014 03:24 PM, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
>> andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop
>> select 'a','b',i into r.x,r.y,r.z; end loop; end; $x$;
>> DO
>> Time: 63731.434 ms
>> andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop r
>> := ('a','b',i); end loop; end; $x$;
>> DO
>> Time: 18744.151 ms
>> Is it simply because the SELECT is in effect three assignments, so it
>> takes nearly 3 times as long?
> I think it's more likely that the second example is treated as a "simple
> expression" so it has less overhead than a SELECT.
>
>
Well, I accidetally left out this case:
andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop
select row('a','b',i) into r; end loop; end; $x$;
DO
Time: 81919.721 ms
which is slower still.
cheers
andrew
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: assignment vs SELECT INTO
2014-11-03 20:00 assignment vs SELECT INTO Andrew Dunstan <andrew@dunslane.net>
@ 2014-11-03 20:27 ` Matheus de Oliveira <matioli.matheus@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: Matheus de Oliveira @ 2014-11-03 20:27 UTC (permalink / raw)
To: Andrew Dunstan <andrew@dunslane.net>; +Cc: pgsql-performance
On Mon, Nov 3, 2014 at 6:00 PM, Andrew Dunstan <andrew@dunslane.net> wrote:
> andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop
> select 'a','b',i into r.x,r.y,r.z; end loop; end; $x$;
> DO
> Time: 63731.434 ms
> andrew=# do $x$ declare r abc; begin for i in 1 .. 10000000 loop r
> := ('a','b',i); end loop; end; $x$;
> DO
> Time: 18744.151 ms
>
>
> Is it simply because the SELECT is in effect three assignments, so it
> takes nearly 3 times as long?
>
I don't think so, because this take pretty much the same time:
SELECT ('a','b',i) INTO r;
Regards,
--
Matheus de Oliveira
Analista de Banco de Dados
Dextra Sistemas - MPS.Br nĂvel F!
www.dextra.com.br/postgres
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2014-11-03 20:31 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-11-03 20:00 assignment vs SELECT INTO Andrew Dunstan <andrew@dunslane.net>
2014-11-03 20:24 ` Tom Lane <tgl@sss.pgh.pa.us>
2014-11-03 20:31 ` Andrew Dunstan <andrew@dunslane.net>
2014-11-03 20:27 ` Matheus de Oliveira <matioli.matheus@gmail.com>
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