Re: Add LIMIT option to COPY FROM - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Add LIMIT option to COPY FROM
Date
Msg-id aYLlaaGexTGyUtLS@paquier.xyz
Whole thread Raw
In response to Re: Add LIMIT option to COPY FROM  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Feb 03, 2026 at 09:41:54AM -0500, Tom Lane wrote:
> Do we really need this?  Each random feature we load onto COPY
> slows it down for everybody.

[ ...reads the patch... ]
@@ -1122,6 +1122,32 @@ CopyFrom(CopyFromState cstate)
          */
         ResetPerTupleExprContext(estate);

+        /*
+         * Stop early when LIMIT would be exceeded.  In multi-insert mode,
+         * include already buffered tuples so we don't overshoot.
+         */
+        if (cstate->opts.limit > 0)

This is an extra check in the per-row processing of COPY FROM, that
can never be skipped as the limit needs to be checked all the time,
once per row.  This is not going to be entirely free, more noticeable
when processing many rows with few attributes.
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Corey Huinker
Date:
Subject: Re: Add expressions to pg_restore_extended_stats()
Next
From: Michael Paquier
Date:
Subject: Re: Add expressions to pg_restore_extended_stats()