Re: Emitting JSON to file using COPY TO
Andrew Dunstan <andrew@dunslane.net>
From: Andrew Dunstan <andrew@dunslane.net>
To: Joe Conway <mail@joeconway.com>, Davin Shearer <davin@apache.org>,
PostgreSQL-development <pgsql-hackers@postgreSQL.org>
Date: 2023-12-03T19:52:29Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Add option force_array for COPY JSON FORMAT
- 4c0390ac53b7 19 (unreleased) landed
-
json format for COPY TO
- 7dadd38cda95 19 (unreleased) landed
-
introduce CopyFormat, refactor CopyFormatOptions
- a2145605ee3d 19 (unreleased) landed
-
Doc: add IDs to copy.sgml's <varlistentry> and <refsect1>
- e4018f891dec 19 (unreleased) cited
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