| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Shinya Kato <shinya11(dot)kato(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Add LIMIT option to COPY FROM |
| Date: | 2026-02-04 06:21:29 |
| Message-ID: | aYLlaaGexTGyUtLS@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-02-04 06:23:59 | Re: Add expressions to pg_restore_extended_stats() |
| Previous Message | Corey Huinker | 2026-02-04 06:13:05 | Re: Add expressions to pg_restore_extended_stats() |