#26268·duckdb

Partitioned COPY to S3 sends two blocking existence HEADs per output file (2.0-alpha is ~2× slower than 1.5.4)

Author: RamitGoolryCreated Sep 29, 2026Updated Sep 29, 2026
Labelsneeds triage

What happens?

In the 2.0 alpha, a partitioned COPY ... TO 's3://...' sends two blocking HEAD requests per output file before writing it. They run one at a time, so the cost grows with the number of partitions. In my experiments, a 180-partition Parquet COPY takes 33.1 s on v2.0.0-alpha43586, against 17.4 s on 1.5.4.

Request logging shows, per output file: 2 HEAD calls (both 404), then 1 PUT. The HEAD calls never overlap, whatever threads, async_threads or the connection pool size is set to.

The two existence checks come from:

  • CopyOutputLifecycle::GetOwnership (copy_output_lifecycle.cpp:22) calls FileExists before DirectoryExists. On S3, DirectoryExists always returns true without a request, so the result is always PRESERVE and the HEAD is wasted.
  • ParquetWriteInitializeGlobal (parquet_extension.cpp:420) calls FileExists to decide whether to set FILE_FLAGS_EXCLUSIVE_CREATE, which httpfs doesn't read.

I measured a change with both removed as an experiment: 33.1 s → 0.4 s for the plain COPY. Opens stop blocking, and the async executor overlaps the uploads, up to 128 in flight. I added a small proxy to simulate lag (toxiproxy, 45ms lag each way)

I would be happy to contribute PRs for both these changes

To Reproduce

sql
-- any S3-compatible endpoint; MinIO is enough
CREATE SECRET (TYPE s3, KEY_ID '...', SECRET '...', ENDPOINT '...', URL_STYLE 'path', USE_SSL false);
SET enable_logging = true;
SET logging_level = 'debug';
SET logging_storage = 'stdout';
COPY (SELECT i % 180 AS p, i FROM range(2340) t(i))
TO 's3://bucket/prefix' (FORMAT parquet, PARTITION_BY (p));

OS:

Linux x86_64 (Ubuntu 24.04.3 LTS)

DuckDB Version:

v2.0.0-alpha43586

DuckDB Client:

CLI

Hardware:

AMD Ryzen 9 9950X , 128 GB RAM

Full Name:

Ramit Goolry

Affiliation:

Arbium

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • Yes, I have

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set