Skip to content

Feature Request: Allow for libpq pipeline mode #649

Open

Description

@wergstatt

Hi 👋 I've been reading through the roadmap of the ducklake project where the reduction of the number of round trips is showing up.

Originally, I've contributed #647 before, with the intention to suggest to hide encryption keys in query parameters to the ducklake project, but it seems that those cause four round trips instead of one, which would oppose a central goal of the project.

This brought me to the existing pipeline mode in libpq, its idea to simply send multiple statements with or without query parameters. However, in order to use it most efficiently, I think we'd need to open a statement with prepare=FALSE to have query parameters.

I'm sure you've had multiple sessions already about those round trips, thus I want to highlight that my thoughts here might be premature and at risk of hitting glass ceilings quickly, that are hidden to me, but obvious to you. I mean, I've already noticed that the prepare=FALSE path was equipped with a throw, thus there was some decision in the past against this combination.

Suggestion

Introduce a new function postgres_execute_pipeline which allows to send batches of statements with parameters that are sent without preparing them beforehand instead of joining query literals into a single string as done in ducklake:

FROM postgres_execute_pipeline('pg', [
  {'query': 'SET LOCAL extra_float_digits = 3', 'params': []},
  {'query': 'INSERT INTO "lake".ducklake_snapshot VALUES ($1, clock_timestamp(), $2, $3, $4)', 'params': ['2', '1', '2', '1']},
  ... -- cut off for simplicity
]);

instead of a single string inside a CALL postgres_execute('__ducklake_metadata_lake', '<the string below>', prepare=FALSE);

SET LOCAL extra_float_digits = 3;
INSERT INTO "lake".ducklake_snapshot VALUES (2, clock_timestamp(), 1, 2, 1);
...

I see that this is not improving on the round trip problem per se, but I feel like it enables a way forward in some other dimensions:

  1. efficient: keep the minimal network interaction
  2. elegant: enable query parameters
  3. observable: results/errors/metrics per statement

I guess my punchline being that we could gain something here without losing out on your existing ambitions of using stored procedures in postgres in general and might widen the use-cases the postgres extension can serve.


I'd be happy to learn about your thoughts about any kind of optimization in that regard or in general. The example here is tied to the ducklake project, but I'd argue it would apply in general. Of course, I'd feel more than happy to get my hands dirty or trying to compile some more evidence 🙃

Activity

  1. wergstatt commented on Nov 8, 2026

    @wergstatt
    ContributorAuthor

    [...] existing ambitions of using stored procedures [...]

    Oh damn, my remark aged like milk... I've just spotted duckdb/ducklake#1930 and must admit that I had missed it before. I guess this answers my question about your current plans. At the same time, I feel that query pipelines might still be a viable way forward for ducklake on a postgres catalog, even now that the round trips to it get short.

    To me, pipelining could complement the REST API for deployments that live fully inside a data center (or are self-hosted). The REST API brings what pipelining can't, such as clients without direct database access and no tie to postgres. Pipelining attempts to shrink the collision window of snapshot_id values by removing round trips between the client and the postgres catalog. For writes with a Parquet file upload, I see that the upload likely dominates. With inlined writes, however, there is no upload, so the catalog round trips become a major part of the write's cost.

    My claims above are based on a benchmark I've asked the genie to do. It compares the current ducklake main, #1930 as it is today (unmerged at the time of writing), and a branch that removes and batches statements in libpq pipelines. It illustrates that even in the "one zone" case, the branch can reduce the duration of, say, one inlined MERGE:

    added latency main REST (#1930) pipeline
    0 ms (one zone) 15 ms 31 ms 6 ms
    1 ms (one region) 82 ms 38 ms 10 ms
    10 ms 464 ms 128 ms 45 ms
    40 ms 1516 ms 274 ms 137 ms

    On the duckdb-postgres side, this needs a way to send several statements as one pipeline; my branch adds it as postgres_execute_pipeline. If this direction is of interest, I'm happy to share those branches, but would rather split them into reasonable smaller PRs. Alternatively, I'm also perfectly fine with just proposing the pipeline batch idea here, in case it doesn't fit your plans, as it's also quite postgres-centric.



    🪄 Genie territory below


    Naturally, I've asked the genie to check whether this holds up for a MERGE, which covers insert, update and delete in one statement. It traced every statement ducklake sends to the postgres catalog for two builds, and counted each round trip twice: inside duckdb-postgres, where libpq talks to the server, and with a TCP proxy between DuckDB and postgres. Both counts agree.

    • main: upstream ducklake and duckdb-postgres
    • pipeline: all statements sent with postgres_execute_pipeline, grouped into libpq pipelines, with $n parameters. The writes are main's statements. The reads are plain SELECTs too, but changed: catalog reads return rows only if the catalog changed, the file list is read once, and one pg_tables listing replaces main's probe for one table. No functions, DO blocks or locks.
    -- once: a table with six data files
    CREATE TABLE lake.merged (id INTEGER, name VARCHAR);
    BEGIN;
    INSERT INTO lake.merged SELECT i, 'seed' FROM range(0, 100) r(i);
    -- … five more of these, 100 rows each, up to range(500, 600)
    COMMIT;
    INSERT INTO lake.merged VALUES (-1, 'prime');  -- creates the inlined tables up front
    DELETE FROM lake.merged WHERE id = 99;
    
    -- traced: update 3 rows, insert 2 (up to 10 rows are inlined into the catalog: no Parquet file)
    MERGE INTO lake.merged t
    USING (SELECT i AS id, 'merged' AS name FROM range(200, 203) r(i)
           UNION ALL SELECT i, 'merged' FROM range(1010, 1012) r(i)) s
    ON t.id = s.id
    WHEN MATCHED THEN UPDATE SET name = s.name
    WHEN NOT MATCHED THEN INSERT VALUES (s.id, s.name);
    main: 31 round trips pipeline: 3
    1: pool health check SELECT 1 1: BEGIN, the latest snapshot and 18 guarded catalog reads (rows only if the catalog changed)
    2: BEGIN 2: the file list with stats, the inlined deletions, the inlined rows
    3–6: the latest snapshot 3: SET LOCAL, the 7 writes, COMMIT
    7–10: the file list, to plan the update
    11–14: the file list with stats, for the scan
    15–18: does the inlined deletion table exist (pg_tables)
    19: the inlined deletions
    20–23: the inlined rows
    24–27: the list of inlined-data tables
    28: SET LOCAL and the 7 writes (inlined rows and deletions), in one string
    29: COMMIT
    30–31: pool health check, DISCARD ALL

    Each read on main costs four round trips: prepare, describe, close, COPY. The 3 round trips are not from pipelining alone. They also include changes to which statements are emitted: no pool health checks, one file list instead of two, and the pg_tables lookup and the list of inlined-data tables read along with the catalog. The pipeline then removes the waits between the statements that remain. The workflow was the same on both builds: same SQL, same setup, same catalog state.

    • Collision window. snapshot_id is taken at commit, so a concurrent commit between reading the snapshot and COMMIT forces a retry or a failure. That window is 23 round trips on main and 2 with the pipeline.
    • Other MERGEs. Insert-only, update-only and delete-only MERGEs, inlined or with data files, take 27–31 round trips on main and 3 with the pipeline.
    • Results. Both builds return the same results.

    Time (the table at the top). The same MERGE in a loop, median of 9 runs, with Toxiproxy adding latency between DuckDB and postgres: 0 ms is a 0.29 ms round trip, 1 ms a 1.49 ms one. For #1930, the latency sits between DuckDB and the REST server, which runs next to postgres. In a loop, main takes 35 round trips per MERGE, because it re-reads the stats the previous commit changed; REST takes 5 from DuckDB, and its server 67 to postgres; the pipeline stays at 3. The rows are inlined, so object storage plays no part. All runs were on one machine (macOS, postgres 17 in a container, Release builds), with #1930 at its head a0d2ead5.

    The pipeline costs postgres 0.6–1.6 ms more server time per MERGE, mostly planning, which is less than one round trip at 1 ms.

    pipeline: 3 round trips
    # rework-23-merge-mixed-inlined
    # 3 round trips (trace), 3 turns at the proxy, matched turn by turn, 32 statements
    # round trips by category: 2 metadata read, 1 metadata write
    # statements by category: 3 transaction, 22 metadata read, 7 metadata write
    # how this is counted: README.md
    
    ──── round trip 1 (metadata read) · connection 1 · pipeline, results kept · 20 statements: 1 transaction, 19 metadata read ────
    [1] BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ
    [2] -- reads ducklake_metadata, ducklake_snapshot
        SELECT snapshot_id, schema_version, next_catalog_id, next_file_id,
        (SELECT MAX(value) FROM "log_rework".ducklake_metadata WHERE key = 'version')
        FROM "log_rework".ducklake_snapshot
        WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
        -- result kept: 1 row, read with postgres_pipeline_result
    [3] -- reads ducklake_schema, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_schema
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [4] -- reads ducklake_table, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_table
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [5] -- reads ducklake_tag, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_tag
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [6] -- reads ducklake_column, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_column
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [7] -- reads ducklake_column_tag, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_column_tag
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [8] -- reads ducklake_view, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_view
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [9] -- reads ducklake_macro, ducklake_snapshot
        SELECT *
        FROM "log_rework".ducklake_macro
        WHERE end_snapshot IS NULL
          AND $1 <> (
            SELECT schema_version
            FROM "log_rework".ducklake_snapshot
            WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
          )
        -- 1 parameter ($1), values not logged
        -- result kept: 0 rows, read with postgres_pipeline_result
    [10] -- reads ducklake_partition_info, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_partition_info
         WHERE end_snapshot IS NULL
           AND $1 <> (
             SELECT schema_version
             FROM "log_rework".ducklake_snapshot
             WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
           )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [11] -- reads ducklake_sort_info, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_sort_info
         WHERE end_snapshot IS NULL
           AND $1 <> (
             SELECT schema_version
             FROM "log_rework".ducklake_snapshot
             WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
           )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [12] -- reads ducklake_view_column_tag, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_view_column_tag
         WHERE end_snapshot IS NULL
           AND $1 <> (
             SELECT schema_version
             FROM "log_rework".ducklake_snapshot
             WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
           )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [13] -- reads ducklake_inlined_data_tables, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_inlined_data_tables
         WHERE $1 <> (
           SELECT schema_version
           FROM "log_rework".ducklake_snapshot
           WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [14] -- reads ducklake_macro_impl, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_macro_impl
         WHERE $1 <> (
           SELECT schema_version
           FROM "log_rework".ducklake_snapshot
           WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [15] -- reads ducklake_macro_parameters, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_macro_parameters
         WHERE $1 <> (
           SELECT schema_version
           FROM "log_rework".ducklake_snapshot
           WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [16] -- reads ducklake_partition_column, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_partition_column
         WHERE $1 <> (
           SELECT schema_version
           FROM "log_rework".ducklake_snapshot
           WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [17] -- reads ducklake_sort_expression, ducklake_snapshot
         SELECT *
         FROM "log_rework".ducklake_sort_expression
         WHERE $1 <> (
           SELECT schema_version
           FROM "log_rework".ducklake_snapshot
           WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [18] -- reads ducklake_schema_versions, ducklake_snapshot
         SELECT table_id, schema_version, begin_snapshot
         FROM "log_rework".ducklake_schema_versions
         WHERE $1 <> (
           SELECT schema_version
           FROM "log_rework".ducklake_snapshot
           WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         )
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [19] -- reads pg_tables, ducklake_snapshot
         SELECT CAST(tablename AS TEXT)
         FROM pg_catalog.pg_tables
         WHERE schemaname = 'log_rework' AND tablename LIKE 'ducklake_inlined_delete_%'
           AND $1 <> (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    [20] -- reads ducklake_table_stats, ducklake_table_column_stats, ducklake_snapshot
         SELECT table_id, column_id, record_count, next_row_id, file_size_bytes, contains_null, contains_nan,
           min_value, max_value, extra_stats, min_is_exact, max_is_exact
         FROM "log_rework".ducklake_table_stats
         LEFT JOIN "log_rework".ducklake_table_column_stats USING (table_id)
         WHERE $1 <> (SELECT MAX(snapshot_id) FROM "log_rework".ducklake_snapshot)
         ORDER BY table_id ASC ;
         -- 1 parameter ($1), values not logged
         -- result kept: 0 rows, read with postgres_pipeline_result
    ════ end of pipeline: 20 statements in 1 round trip ════
    
    ──── round trip 2 (metadata read) · connection 1 · pipeline, results kept · 3 statements: 3 metadata read ────
    [1] -- reads ducklake_file_column_stats, ducklake_data_file, ducklake_delete_file
        WITH col_1_stats AS (
          SELECT data_file_id,
            CASE WHEN value_count = 0 AND null_count = 0 THEN NULL ELSE value_count END AS value_count,
            max_value, contains_nan, min_value
          FROM "log_rework".ducklake_file_column_stats
          WHERE column_id = 1 AND table_id = 3
        )
        SELECT data.data_file_id, del.delete_file_id, data.record_count, data.path AS data_path,
          data.path_is_relative AS data_path_is_relative, data.file_size_bytes AS data_file_size_bytes,
          data.footer_size AS data_footer_size,
          CASE
            WHEN data.file_format = 'parquet' THEN NULL
            ELSE data.file_format
          END AS data_unsupported_format,
          data.row_id_start, data.begin_snapshot, data.partial_max, data.mapping_id, del.path AS del_path,
          del.path_is_relative AS del_path_is_relative, del.file_size_bytes AS del_file_size_bytes,
          del.footer_size AS del_footer_size, del.format AS del_format, del.begin_snapshot,
          col_1_stats.min_value AS col_1_stats_min_value, col_1_stats.max_value AS col_1_stats_max_value,
          col_1_stats.contains_nan AS col_1_stats_contains_nan
        FROM "log_rework".ducklake_data_file data
        LEFT JOIN col_1_stats ON col_1_stats.data_file_id = data.data_file_id
        LEFT JOIN (
          SELECT *
          FROM "log_rework".ducklake_delete_file
          WHERE table_id=3 AND 20 >= begin_snapshot AND (20 < end_snapshot OR end_snapshot IS NULL)
        ) del ON del.data_file_id = data.data_file_id
        WHERE data.table_id=3 AND 20 >= data.begin_snapshot
          AND (20 < data.end_snapshot OR data.end_snapshot IS NULL)
          AND (
            col_1_stats.data_file_id IS NULL
              OR (
                (col_1_stats.value_count IS NULL OR col_1_stats.value_count > 0)
                  AND (
                    col_1_stats.max_value IS NULL OR col_1_stats.min_value IS NULL
                      OR (
                        (
                          (200 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER)
                            OR (
                              201 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                            )
                            OR (
                              202 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                            )
                            OR (
                              1010 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                            )
                            OR (
                              1011 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                            )
                        )
                      )
                  )
              )
          )
        -- result kept: 1 row, read with postgres_pipeline_result
    [2] -- reads ducklake_inlined_delete_3
        SELECT file_id, row_id FROM "log_rework"."ducklake_inlined_delete_3" WHERE begin_snapshot <= 20
        -- result kept: 11 rows, read with postgres_pipeline_result
    [3] -- reads ducklake_inlined_data_3_5
        SELECT *
        FROM "log_rework"."ducklake_inlined_data_3_5" inlined_data
        WHERE 20 >= "_ducklake_begin_snapshot"
          AND (20 < "_ducklake_end_snapshot" OR "_ducklake_end_snapshot" IS NULL)
        ORDER BY "_ducklake_row_id" ASC;
        -- result kept: 11 rows, read with postgres_pipeline_result
    ════ end of pipeline: 3 statements in 1 round trip ════
    
    ──── round trip 3 (metadata write) · connection 1 · pipeline · 9 statements: 2 transaction, 7 metadata write ────
    [1] SET LOCAL extra_float_digits = 3
    [2] -- writes INSERT ducklake_snapshot
        INSERT INTO "log_rework".ducklake_snapshot VALUES ($1, clock_timestamp(), $2, $3, $4)
        -- 4 parameters ($1 … $4), values not logged
    [3] -- writes UPDATE ducklake_table_stats
        UPDATE "log_rework".ducklake_table_stats
        SET record_count=$1, file_size_bytes=$2, next_row_id=$3
        WHERE table_id=$4
        -- 4 parameters ($1 … $4), values not logged
    [4] -- writes UPDATE ducklake_table_column_stats
        WITH new_values(cid, new_contains_null, new_contains_nan, new_min, new_max, new_extra_stats,
                        new_min_is_exact, new_max_is_exact) AS (
          VALUES (CAST($1 AS BIGINT), CAST($2 AS BOOLEAN), CAST($3 AS BOOLEAN), CAST($4 AS VARCHAR),
                  CAST($5 AS VARCHAR), CAST($6 AS VARCHAR), CAST($7 AS BOOLEAN), CAST($8 AS BOOLEAN)),
            (CAST($9 AS BIGINT), CAST($10 AS BOOLEAN), CAST($11 AS BOOLEAN), CAST($12 AS VARCHAR),
             CAST($13 AS VARCHAR), CAST($14 AS VARCHAR), CAST($15 AS BOOLEAN), CAST($16 AS BOOLEAN))
        )
        UPDATE "log_rework".ducklake_table_column_stats
        SET contains_null=new_contains_null, contains_nan=new_contains_nan, min_value=new_min,
          max_value=new_max, extra_stats=new_extra_stats, min_is_exact=new_min_is_exact,
          max_is_exact=new_max_is_exact
        FROM new_values
        WHERE table_id=$17 AND column_id=cid
        -- 17 parameters ($1 … $17), values not logged
    [5] -- writes INSERT ducklake_inlined_data_3_5
        INSERT INTO "log_rework".ducklake_inlined_data_3_5
        VALUES ($1, $2, NULL, $3, $4), ($5, $6, NULL, $7, $8) /* … 3 more rows */
        -- 20 parameters ($1 … $20), values not logged
    [6] -- writes CREATE ducklake_inlined_delete_3
        CREATE TABLE IF NOT EXISTS "log_rework"."ducklake_inlined_delete_3"(file_id BIGINT, row_id BIGINT,
            begin_snapshot BIGINT)
    [7] -- writes INSERT ducklake_inlined_delete_3
        INSERT INTO "log_rework".ducklake_inlined_delete_3
        VALUES ($1, $2, $3), ($4, $5, $6) /* … 1 more row */
        -- 9 parameters ($1 … $9), values not logged
    [8] -- writes INSERT ducklake_snapshot_changes
        INSERT INTO "log_rework".ducklake_snapshot_changes VALUES ($1, $2, $3, $4, $5)
        -- 5 parameters ($1 … $5), values not logged
    [9] COMMIT
    ════ end of pipeline: 9 statements in 1 round trip ════
    
    main: 31 round trips
    # main-23-merge-mixed-inlined
    # 31 round trips (trace), 31 turns at the proxy, matched turn by turn, 20 statements
    # round trips by category: 3 connection, 2 transaction, 18 protocol, 1 catalog lookup, 6 metadata read, 1 metadata
    #   write
    # statements by category: 3 connection, 3 transaction, 1 catalog lookup, 6 metadata read, 7 metadata write
    # how this is counted: README.md
    
    ──── round trip 1 (connection) · connection 2 · pool health check · 1 statement: connection ────
    SELECT 1
    
    ──── round trip 2 (transaction) · connection 2 · query · 1 statement: transaction ────
    BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ
    
    ──── round trip 3 (protocol) · connection 2 · prepare statement duckdb_stmt_222 · no statement executed (protocol step) ────
    -- reads ducklake_metadata, ducklake_snapshot
    SELECT snapshot_id, schema_version, next_catalog_id, next_file_id,
    (SELECT MAX(value) FROM "log_main".ducklake_metadata WHERE key = 'version')
    FROM "log_main".ducklake_snapshot
    WHERE snapshot_id = (SELECT MAX(snapshot_id) FROM "log_main".ducklake_snapshot)
    
    ──── round trip 4 (protocol) · connection 2 · describe prepared statement duckdb_stmt_222 · no statement executed (protocol step) ────
    -- the statement prepared in round trip 3
    
    ──── round trip 5 (protocol) · connection 2 · close prepared statement duckdb_stmt_222 · no statement executed (protocol step) ────
    
    ──── round trip 6 (metadata read) · connection 2 · query · 1 statement: metadata read ────
    COPY (/* the query of duckdb_stmt_222, prepared in round trip 3 */) TO STDOUT (FORMAT "binary")
    
    ──── round trip 7 (protocol) · connection 2 · prepare statement duckdb_stmt_223 · no statement executed (protocol step) ────
    -- reads ducklake_data_file, ducklake_delete_file
    SELECT data.data_file_id, del.delete_file_id, data.record_count, data.path AS data_path,
      data.path_is_relative AS data_path_is_relative, data.file_size_bytes AS data_file_size_bytes,
      data.footer_size AS data_footer_size,
      CASE
        WHEN data.file_format = 'parquet' THEN NULL
        ELSE data.file_format
      END AS data_unsupported_format,
      data.row_id_start, data.mapping_id, del.path AS del_path,
      del.path_is_relative AS del_path_is_relative, del.file_size_bytes AS del_file_size_bytes,
      del.footer_size AS del_footer_size, del.format AS del_format, del.begin_snapshot
    FROM "log_main".ducklake_data_file data
    LEFT JOIN (
      SELECT *
      FROM "log_main".ducklake_delete_file
      WHERE table_id=3 AND 20 >= begin_snapshot AND (20 < end_snapshot OR end_snapshot IS NULL)
    ) del ON del.data_file_id = data.data_file_id
    WHERE data.table_id=3 AND 20 >= data.begin_snapshot
      AND (20 < data.end_snapshot OR data.end_snapshot IS NULL)
    
    ──── round trip 8 (protocol) · connection 2 · describe prepared statement duckdb_stmt_223 · no statement executed (protocol step) ────
    -- the statement prepared in round trip 7
    
    ──── round trip 9 (protocol) · connection 2 · close prepared statement duckdb_stmt_223 · no statement executed (protocol step) ────
    
    ──── round trip 10 (metadata read) · connection 2 · query · 1 statement: metadata read ────
    COPY (/* the query of duckdb_stmt_223, prepared in round trip 7 */) TO STDOUT (FORMAT "binary")
    
    ──── round trip 11 (protocol) · connection 2 · prepare statement duckdb_stmt_224 · no statement executed (protocol step) ────
    -- reads ducklake_file_column_stats, ducklake_data_file, ducklake_delete_file
    WITH col_1_stats AS (
      SELECT data_file_id,
        CASE WHEN value_count = 0 AND null_count = 0 THEN NULL ELSE value_count END AS value_count,
        max_value, contains_nan, min_value
      FROM "log_main".ducklake_file_column_stats
      WHERE column_id = 1 AND table_id = 3
    )
    SELECT data.data_file_id, data.path AS data_path, data.path_is_relative AS data_path_is_relative,
      data.file_size_bytes AS data_file_size_bytes, data.footer_size AS data_footer_size,
      CASE
        WHEN data.file_format = 'parquet' THEN NULL
        ELSE data.file_format
      END AS data_unsupported_format,
      data.row_id_start, data.begin_snapshot, data.partial_max, data.mapping_id, del.path AS del_path,
      del.path_is_relative AS del_path_is_relative, del.file_size_bytes AS del_file_size_bytes,
      del.footer_size AS del_footer_size, del.format AS del_format,
      col_1_stats.min_value AS col_1_stats_min_value, col_1_stats.max_value AS col_1_stats_max_value,
      col_1_stats.contains_nan AS col_1_stats_contains_nan
    FROM "log_main".ducklake_data_file data
    LEFT JOIN col_1_stats ON col_1_stats.data_file_id = data.data_file_id
    LEFT JOIN (
      SELECT *
      FROM "log_main".ducklake_delete_file
      WHERE table_id=3 AND 20 >= begin_snapshot AND (20 < end_snapshot OR end_snapshot IS NULL)
    ) del ON del.data_file_id = data.data_file_id
    WHERE data.table_id=3 AND 20 >= data.begin_snapshot
      AND (20 < data.end_snapshot OR data.end_snapshot IS NULL)
      AND (
        col_1_stats.data_file_id IS NULL
          OR (
            (col_1_stats.value_count IS NULL OR col_1_stats.value_count > 0)
              AND (
                col_1_stats.max_value IS NULL OR col_1_stats.min_value IS NULL
                  OR (
                    (
                      (200 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER)
                        OR (
                          201 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                        )
                        OR (
                          202 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                        )
                        OR (
                          1010 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                        )
                        OR (
                          1011 BETWEEN col_1_stats.min_value::INTEGER AND col_1_stats.max_value::INTEGER
                        )
                    )
                  )
              )
          )
      )
    
    ──── round trip 12 (protocol) · connection 2 · describe prepared statement duckdb_stmt_224 · no statement executed (protocol step) ────
    -- the statement prepared in round trip 11
    
    ──── round trip 13 (protocol) · connection 2 · close prepared statement duckdb_stmt_224 · no statement executed (protocol step) ────
    
    ──── round trip 14 (metadata read) · connection 2 · query · 1 statement: metadata read ────
    COPY (/* the query of duckdb_stmt_224, prepared in round trip 11 */) TO STDOUT (FORMAT "binary")
    
    ──── round trip 15 (protocol) · connection 2 · prepare statement duckdb_stmt_225 · no statement executed (protocol step) ────
    -- reads pg_tables
    SELECT 1
    FROM pg_catalog.pg_tables
    WHERE schemaname = 'log_main' AND tablename = 'ducklake_inlined_delete_3'
    LIMIT 1
    
    ──── round trip 16 (protocol) · connection 2 · describe prepared statement duckdb_stmt_225 · no statement executed (protocol step) ────
    -- the statement prepared in round trip 15
    
    ──── round trip 17 (protocol) · connection 2 · close prepared statement duckdb_stmt_225 · no statement executed (protocol step) ────
    
    ──── round trip 18 (catalog lookup) · connection 2 · query · 1 statement: catalog lookup ────
    COPY (/* the query of duckdb_stmt_225, prepared in round trip 15 */) TO STDOUT (FORMAT "binary")
    
    ──── round trip 19 (metadata read) · connection 2 · query · 1 statement: metadata read ────
    -- reads ducklake_inlined_delete_3
    COPY (
      SELECT "begin_snapshot", "file_id", "row_id"
      FROM "log_main"."ducklake_inlined_delete_3"
      WHERE "begin_snapshot" <= 20
    ) TO STDOUT (FORMAT "binary");
    
    ──── round trip 20 (protocol) · connection 2 · prepare statement duckdb_stmt_226 · no statement executed (protocol step) ────
    -- reads ducklake_inlined_data_3_5
    SELECT "id" AS "col1", "_ducklake_row_id" AS "col2", "_ducklake_row_id" AS "col3"
    FROM "log_main"."ducklake_inlined_data_3_5" AS "inlined_data"
    WHERE (
      (20 >= "_ducklake_begin_snapshot")
        AND ((20 < "_ducklake_end_snapshot") OR ("_ducklake_end_snapshot" IS NULL))
    )
    ORDER BY "_ducklake_row_id" ASC NULLS LAST
    
    ──── round trip 21 (protocol) · connection 2 · describe prepared statement duckdb_stmt_226 · no statement executed (protocol step) ────
    -- the statement prepared in round trip 20
    
    ──── round trip 22 (protocol) · connection 2 · close prepared statement duckdb_stmt_226 · no statement executed (protocol step) ────
    
    ──── round trip 23 (metadata read) · connection 2 · query · 1 statement: metadata read ────
    COPY (/* the query of duckdb_stmt_226, prepared in round trip 20 */) TO STDOUT (FORMAT "binary")
    
    ──── round trip 24 (protocol) · connection 2 · prepare statement duckdb_stmt_227 · no statement executed (protocol step) ────
    -- reads ducklake_inlined_data_tables
    SELECT "table_name", "schema_version"
    FROM "log_main"."ducklake_inlined_data_tables"
    WHERE (
      ("table_id" = 3)
        AND (
          "schema_version" = (
            SELECT max("schema_version") AS "max(schema_version)"
            FROM "log_main"."ducklake_inlined_data_tables"
            WHERE ("table_id" = 3)
          )
        )
    )
    
    ──── round trip 25 (protocol) · connection 2 · describe prepared statement duckdb_stmt_227 · no statement executed (protocol step) ────
    -- the statement prepared in round trip 24
    
    ──── round trip 26 (protocol) · connection 2 · close prepared statement duckdb_stmt_227 · no statement executed (protocol step) ────
    
    ──── round trip 27 (metadata read) · connection 2 · query · 1 statement: metadata read ────
    COPY (/* the query of duckdb_stmt_227, prepared in round trip 24 */) TO STDOUT (FORMAT "binary")
    
    ──── round trip 28 (metadata write) · connection 2 · query · 8 statements in one text: 1 transaction, 7 metadata write ────
    SET LOCAL extra_float_digits = 3;
    -- writes INSERT ducklake_snapshot
    INSERT INTO "log_main".ducklake_snapshot VALUES (21, clock_timestamp(), 5, 4, 18);
    -- writes UPDATE ducklake_table_stats
    UPDATE "log_main".ducklake_table_stats
    SET record_count=616, file_size_bytes=4912, next_row_id=608
    WHERE table_id=3;
    -- writes UPDATE ducklake_table_column_stats
    WITH new_values(cid, new_contains_null, new_contains_nan, new_min, new_max, new_extra_stats,
                    new_min_is_exact, new_max_is_exact) AS (
      VALUES (1, CAST(false AS BOOLEAN), CAST(NULL AS BOOLEAN), '-1', '1011', NULL,
              CAST(true AS BOOLEAN), CAST(true AS BOOLEAN)),
        (2, CAST(false AS BOOLEAN), CAST(NULL AS BOOLEAN), 'merged', 'seed', NULL,
         CAST(true AS BOOLEAN), CAST(true AS BOOLEAN))
    )
    UPDATE "log_main".ducklake_table_column_stats
    SET contains_null=new_contains_null, contains_nan=new_contains_nan, min_value=new_min,
      max_value=new_max, extra_stats=new_extra_stats, min_is_exact=new_min_is_exact,
      max_is_exact=new_max_is_exact
    FROM new_values
    WHERE table_id=3 AND column_id=cid;
    -- writes INSERT ducklake_inlined_data_3_5
    INSERT INTO "log_main".ducklake_inlined_data_3_5
    VALUES (606, 21, NULL, 1010, '\x6d6572676564'),
      (607, 21, NULL, 1011, '\x6d6572676564') /* … 3 more rows */;
    -- writes CREATE ducklake_inlined_delete_3
    CREATE TABLE IF NOT EXISTS "log_main"."ducklake_inlined_delete_3"(file_id BIGINT, row_id BIGINT,
        begin_snapshot BIGINT);
    -- writes INSERT ducklake_inlined_delete_3
    INSERT INTO "log_main".ducklake_inlined_delete_3 VALUES (10, 0, 21), (10, 1, 21) /* … 1 more row */;
    -- writes INSERT ducklake_snapshot_changes
    INSERT INTO "log_main".ducklake_snapshot_changes
    VALUES (21, 'inlined_insert:3,inlined_delete:3', NULL, NULL, NULL)
    
    ──── round trip 29 (transaction) · connection 2 · query · 1 statement: transaction ────
    COMMIT
    
    ──── round trip 30 (connection) · connection 2 · pool health check · 1 statement: connection ────
    SELECT 1
    
    ──── round trip 31 (connection) · connection 2 · pool reset · 1 statement: connection ────
    DISCARD ALL
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions