Replies: 1 comment 8 replies
-
Could you go in a bit more detail here? It seems like we're not taking the global lock in enough places then, if that's possible. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, DuckDB may execute in parallel with the Postgres main thread, meaning DuckDB result chunks are returned and converted to Postgres in a stream. This approach works well for SELECT queries.
However, when experimenting with WRITE in
pg_duckdb
(e.g., CTAS and #688), I found there were race conditions on Postgres resources like the shared buffer, leading to backend crashes. These races occur bwteen the backend main thread and DuckDB's execution threads. For instance, when the main thread writes to a heap table while DuckDB threads execute a SELECT query (e.g., reading the heap table).Supporting WRITE would significantly enahce
pg_duckdb
's usecase, and it already allows CTAS to create new tables with DuckDB-generated data.Potential solutions to address the issue:
Single-Threaded Execution for WRITE operations
Limit DuckDB to one thread during WRITE, restricting execution to the main thread. While simple, this reduces performance gain, especially for complex ETL jobs.
Always Parallel Workers for Reading PG tables
Use parallel workers (running in separate backend processes) to avoid heap table resource conflicts. However, not all SELECT queries support parallel execution, and other Postgres resources might still be affected.
Execution Barrier Between DuckDB and Postgres:
Introduce a hard barrier where DuckDB completes execution first, then materializes results for Postgres. This resembles the stage-by-stage execution model used in engines like Spark. The implementation would be straightforward, as DuckDB already supports materialization APIs and memory management through spilling.
Beta Was this translation helpful? Give feedback.
All reactions