Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XlNne-0005qC-Vn for pgsql-performance@arkaria.postgresql.org; Mon, 03 Nov 2014 20:00:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XlNne-0005JK-Fd for pgsql-performance@arkaria.postgresql.org; Mon, 03 Nov 2014 20:00:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XlNnd-0005H4-74 for pgsql-performance@postgresql.org; Mon, 03 Nov 2014 20:00:25 +0000 Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XlNnZ-0006I9-Pj for pgsql-performance@postgresql.org; Mon, 03 Nov 2014 20:00:23 +0000 Received: from mfilter27-d.gandi.net (mfilter27-d.gandi.net [217.70.178.155]) by relay6-d.mail.gandi.net (Postfix) with ESMTP id 2E547FB86B for ; Mon, 3 Nov 2014 21:00:17 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter27-d.gandi.net Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by mfilter27-d.gandi.net (mfilter27-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id e5+cKwzB6aA1 for ; Mon, 3 Nov 2014 21:00:15 +0100 (CET) X-Originating-IP: 98.27.58.255 Received: from [192.168.10.146] (cpe-098-027-058-255.nc.res.rr.com [98.27.58.255]) (Authenticated sender: adsend@dunslane.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 991E2FB88B for ; Mon, 3 Nov 2014 21:00:15 +0100 (CET) Message-ID: <5457DECE.3070302@dunslane.net> Date: Mon, 03 Nov 2014 15:00:14 -0500 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: pgsql-perform Subject: assignment vs SELECT INTO Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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