Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9sW5-002w9C-DE for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Dec 2023 19:52:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r9sW4-00DIcc-18 for pgsql-hackers@arkaria.postgresql.org; Sun, 03 Dec 2023 19:52:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r9sW3-00DIcU-Nl for pgsql-hackers@lists.postgresql.org; Sun, 03 Dec 2023 19:52:35 +0000 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r9sW1-009vnl-0d for pgsql-hackers@postgresql.org; Sun, 03 Dec 2023 19:52:35 +0000 Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-77f035e4dabso78860785a.0 for ; Sun, 03 Dec 2023 11:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1701633151; x=1702237951; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=NAdzjselIFNXfkFm0GzkhXGcLP6NMG3IyVRma6VwNCw=; b=sc9sbSiU49m/t6KvW/TCQS+kQ+B6loTrR486Mg7p8IvGwESqYjxnXeN/VSyrQZnKfO cTazjw0/vSuzBabUCTlSBpOfGtV4DFmLTKEz/aVBOf5H+qzbMludkLnV6yxInSevzVnG HfJazvVpK30KSK8Y/CoC97YP1+AMA/8GI7zGdCMcWYdVSzeJf8crZxm+iF+YHqPgG6Kh vYMV1hc3rtHpdRRz/jgtvS4zyiRet29GfWU/YTFMfMXoy5PmHf365uQibqii3HOpcftz 0s+7fupupIjevslY83/XUqEANarqRHGidlZAp61vi9C19yKzsb+CKACIRdjbaTBaDCFO xwrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701633151; x=1702237951; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NAdzjselIFNXfkFm0GzkhXGcLP6NMG3IyVRma6VwNCw=; b=iHEhe6oqQqNyVMwFv4PEmZuUBbD70wVa+yWe928JZvA+x8JLRp+kizxc+E6EQMnG9F vsXktEQaymEGCaM5yolMY5YvY40xhg8z6PpGAMtI4TJYqbDD7qnMl4b2ecXK8M1hyQBf uAoOyrGqjPpGe8lg7A/miU05CpLD+N18bsQFGf9kh8wGkYoa2T/lxUYgLLMmIcxwLvm9 aEdFQVLmnnqKX3b7hFxHxcFBZmjTsc8agrsYMl2kJ4db4KC5aSG/KdAuXpD3o0PI0Lun k8eGAuZtx3ESBsM8421i6PS9v861zw58KENFpLHoECAFxa9mjNtI37ccJ4UsuKsQOk/K KqdA== X-Gm-Message-State: AOJu0Yx2oASVHyc5lC+5ZGOdexcJU1+J3AUGpf/PTk6LgG6VJE85X2dg Qn5Xfb+Y5PgDJBF6mMIoIvNb9w== X-Google-Smtp-Source: AGHT+IG5Rjm/jWZqppQWmGPjjcJ+Tys3FeZFvvvavdlyJoelfUR+Uopi8uK2felmNVac99n6p5rLUw== X-Received: by 2002:a05:620a:108f:b0:77e:fba3:4f00 with SMTP id g15-20020a05620a108f00b0077efba34f00mr3689138qkk.86.1701633150873; Sun, 03 Dec 2023 11:52:30 -0800 (PST) Received: from ?IPV6:2605:a601:91bc:f600::2bb? ([2605:a601:91bc:f600::2bb]) by smtp.googlemail.com with ESMTPSA id z9-20020ae9c109000000b0077d84f46d65sm3593555qki.37.2023.12.03.11.52.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 03 Dec 2023 11:52:30 -0800 (PST) Message-ID: <6603ea04-8ec3-67b2-e9f6-e00fd0e46858@dunslane.net> Date: Sun, 3 Dec 2023 14:52:29 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Emitting JSON to file using COPY TO Content-Language: en-US To: Joe Conway , Davin Shearer , PostgreSQL-development References: <3853387.1701096982@sss.pgh.pa.us> <3a98decf-3fe3-4b49-9b68-fda01338872c@sedlakovi.org> <24e3ee88-ec1e-421b-89ae-8a47ee0d2df1@joeconway.com> <8c88da85-c197-4765-96f8-a9a1c78305a6@joeconway.com> From: Andrew Dunstan In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-12-03 Su 14:24, Joe Conway wrote: > On 12/3/23 11:03, Joe Conway wrote: >> On 12/3/23 10:10, Andrew Dunstan wrote: >>> I  realize this is just a POC, but I'd prefer to see >>> composite_to_json() >>> not exposed. You could use the already public datum_to_json() instead, >>> passing JSONTYPE_COMPOSITE and F_RECORD_OUT as the second and third >>> arguments. >> >> Ok, thanks, will do > > Just FYI, this change does loose some performance in my not massively > scientific A/B/A test: > > 8<--------------------------- > -- with datum_to_json() > test=# \timing > Timing is on. > test=# copy foo to '/tmp/buf' (format json, force_array); > COPY 10000000 > Time: 37196.898 ms (00:37.197) > Time: 37408.161 ms (00:37.408) > Time: 38393.309 ms (00:38.393) > Time: 36855.438 ms (00:36.855) > Time: 37806.280 ms (00:37.806) > > Avg = 37532 > > -- original patch > test=# \timing > Timing is on. > test=# copy foo to '/tmp/buf' (format json, force_array); > COPY 10000000 > Time: 37426.207 ms (00:37.426) > Time: 36068.187 ms (00:36.068) > Time: 38285.252 ms (00:38.285) > Time: 36971.042 ms (00:36.971) > Time: 35690.822 ms (00:35.691) > > Avg = 36888 > > -- with datum_to_json() > test=# \timing > Timing is on. > test=# copy foo to '/tmp/buf' (format json, force_array); > COPY 10000000 > Time: 39083.467 ms (00:39.083) > Time: 37249.326 ms (00:37.249) > Time: 38529.721 ms (00:38.530) > Time: 38704.920 ms (00:38.705) > Time: 39001.326 ms (00:39.001) > > Avg = 38513 > 8<--------------------------- > > That is somewhere in the 3% range. I assume it's because datum_to_json() constructs a text value from which you then need to extract the cstring, whereas composite_to_json(), just gives you back the stringinfo. I guess that's a good enough reason to go with exposing composite_to_json(). cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com