Feature Request: Allow for libpq pipeline mode

Aperta
#649 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
cpp, postgresql
Ambito
backend, database

Direzione di ricerca

Start by tracing how postgres_execute handles query parameters and why its prepare=FALSE path throws, then compare that with libpq pipeline mode. The issue proposes a new postgres_execute_pipeline function for batches of parameterized statements, but leaves API design and implementation scope open. Done would mean agreeing on the approach and supporting statement-level results or errors.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 https://github.com/duckdb/duckdb-postgres/pull/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 🙃

Lingua principale
C++
Stelle
380
Fork
122
Merge medio
2h 17m
PR unite (30g)
18

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di duckdb/duckdb-postgres

Tutte le issue di duckdb/duckdb-postgres

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.