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.96) (envelope-from ) id 1wKYPb-00181A-24 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 May 2026 09:19:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKYPa-00G31d-20 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 May 2026 09:19:22 +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.96) (envelope-from ) id 1wKYPa-00G31U-17 for pgsql-hackers@lists.postgresql.org; Wed, 06 May 2026 09:19:22 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wKYPY-00000000nPW-0ndr for pgsql-hackers@lists.postgresql.org; Wed, 06 May 2026 09:19:22 +0000 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-b6ce6d1d3dcso2134575a12.3 for ; Wed, 06 May 2026 02:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778059158; x=1778663958; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QJoJ+gCErY3zUr+TVdZxM7FF/0Z02HgfVG9uHnqj5M4=; b=OIVYChWkA4To1EsugzmwRb81xqyVF49OuGQ83BRYy+qavxKK4mqrfxqMdtnilriaNU jQBr1XhWYr2SnbxItIZ4X6kEFc+tpu92NF5JbtloGBRGr0RO3WpfJXiyeyvw2bNY4D5Q oCmwJmdQ9Lc3fzCi3DvnUMDnCRSH6X2/PY/SUyr9JAjdfilO1vYPjnzWDeOfTRTBXpi1 BXOjYlXSTybI6irpf2G36zTXa7tAZHyIie9on8hR/2Dffd+0/tM5Q3sXF/+UQQ4XLrWs CjeRzbJMPx55biCYD2xtbTDbJiDTKD5xKKOvKtRcp3ND5TTwPGTUEGNb1n9izxgAcB+X 3bmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778059158; x=1778663958; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QJoJ+gCErY3zUr+TVdZxM7FF/0Z02HgfVG9uHnqj5M4=; b=iJax8XrPB3TI07Pwcrg3KEtQE4v+jHaahOpzXH+8VLSS42KN4IDAWxoDCHKaacgABG 98VW4PjiDLJEtEJv+lZAawR2kOi25GTlgC3POZvNZ9M09PGjn7LOUKWUQb55YU21PLrB 6EouN4Jc8s0Xfij3Acbog054Z0znDT+i0yodiZyjzpX5il4PT2m4slIgmlqPRnlIZ3KH gKoWTu8GrDZysxlVxM/nrf4iEMNHmAUdAp/ppXVLWjt91OkycymE5bFAv3WJyyNfUarh vujEo1XJHKTAttzAdgrUGKgagL9TGNz44r8rd6Qv8u9GHgA/0qQ5OcAmHu29vL/C8XSh 6L0g== X-Gm-Message-State: AOJu0YyuUyaT7C9FxL8fVlUPgcNfk5BAbOG8u6VTtxwgnWIdLtgsZLlk Du2pZMxtMUKentRdB0di0gbYjFrPV2aFdJO0gHR4HlrxgqCLCs+zHOMiRZJZTnxJ X-Gm-Gg: AeBDieuZlWK2Y4EFC6iANVyWOpaegZf4D7rbNoii5WwPZJq1vebEEZmZSm+IMf9KGGb 2VV1eeieggs8/rkDWdm3/8NWVbZfa/R/KfwabIQiacs8h8QviT9OO3jeHhPbKuXIu+ZLVH2/7fR 1cNJcez2kDQ0xOMHhuWg9FR6iTkjcCao53Pp5R+SyHJBxLo8xS3aq7gMwGuOpw2zKtfRfFYr20a BdwMP9LcVHJW42k49A13nAEIbI/6EnidYUvthOveeN/vvfL96CCpqGhQpWA2B6IhAzP2zUm6b+J W0d1NBkscaa/wdAZQxv47mA5nPkjGydkdBrMUt1yi6/Ylc1BRSTQc3DZQBydNm8Hsf0t3ggR03c IPTZ0G0hRhOpgheufJxrDObBWbxwymqI6L3ALkhWo3sFMpdKXFgwNqMhnRgs/I0uVf9ixCXm7zx 4kDbpixbZhIQCjEcKBRlWkfSLl9M0yLuZrWD2mfMEgLw== X-Received: by 2002:a17:90b:520b:b0:35d:ab26:5786 with SMTP id 98e67ed59e1d1-365ac4827c7mr2511687a91.19.1778059157865; Wed, 06 May 2026 02:19:17 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-365d8e3dad8sm169649a91.1.2026.05.06.02.19.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 May 2026 02:19:17 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: COPY JSON: use trailing commas in FORCE_ARRAY output From: Chao Li In-Reply-To: Date: Wed, 6 May 2026 17:18:38 +0800 Cc: PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Daniel Gustafsson X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 6, 2026, at 16:23, Daniel Gustafsson wrote: >=20 >> On 6 May 2026, at 08:40, Chao Li wrote: >=20 >> I was surprised by the comma placement. It is valid JSON, but it = looks quite uncommon. >=20 > It might look uncommon, but for very wide lines it's IMHO preferrable = to not > have to scroll all the way to the end of the line to know that the = line is part > of an array. >=20 >> For comparison, the existing json_agg() places commas at the end of = the line: >=20 > That's true, but json_agg() and COPY TO in ndjson format have = different use > cases. >=20 >> ..it should not have any performance impact. >=20 > It does add branches though, and in one branch use a non-inlined = function where > previously it would unconditionally use an inline function. ISTM it = would > still be valuable to do performance testing given that COPY is = commonly used in > performance sensitive settings. >=20 Make sense. I just did a test to compare the performance between master = and the patch: For the data setup, since the patch only changes where the comma is = emitted, I intentionally used a table with only one column, to minimize = the cost of formatting each row: ``` DROP TABLE IF EXISTS copy_json_force_array_perf; CREATE UNLOGGED TABLE copy_json_force_array_perf(id int); INSERT INTO copy_json_force_array_perf SELECT g FROM generate_series(1, 10000000) AS g; VACUUM ANALYZE copy_json_force_array_perf; \timing on ``` On master: ``` evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1208.694 ms (00:01.209) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1200.203 ms (00:01.200) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1238.639 ms (00:01.239) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1211.344 ms (00:01.211) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1252.197 ms (00:01.252) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1223.510 ms (00:01.224) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1212.378 ms (00:01.212) ``` Average: ~1221 ms With the patch: ``` evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1218.580 ms (00:01.219) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1212.913 ms (00:01.213) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1204.350 ms (00:01.204) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1205.276 ms (00:01.205) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1202.088 ms (00:01.202) evantest=3D# COPY copy_json_force_array_perf TO '/dev/null' WITH (FORMAT = json, FORCE_ARRAY); COPY 10000000 Time: 1222.390 ms (00:01.222) ``` Average: ~1211 ms The difference doesn't look quite meaningful from this test. I built = with debug and asserts disabled, and compiled with -O2. The output was = written to /dev/null to avoid client/network overhead. The tests ran on = my MacBook M4. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/