-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support extended protocol and prepared statements (#147)
Previously prepared statements and the extended protocol were broken. We need to support this feature because pretty much every client library uses it. The reason that prepared statements did not work is that for prepared statements to work, a Postgres plan needs to be fully copyable using Postgres functionality. We were previously storing the DuckDB plan in the Postgres plan, but since Postgres did not know how to copy the DuckDB plan it would fail. To work around that problem we now store the full Postgres `Query` structure inside the DuckDB CustomScan node. Then during execution we use this `Query` structure to re-plan the query during execution. This works but it has the big downside that we're now planning the query twice in DuckDB, once during planning to get the the column types of the result and once during execution. For now that seems acceptable, so we can at least support prepared statements and the extended protocol. In the future we might want to do something smarter though, like serializing and deserializing the DuckDB plan that is created at planning time. Note: This does not support all our supported types as arguments to a prepared statement yet. After merging I'll open separate issue to track adding the rest of these types. Fixes #118
- Loading branch information
Showing
11 changed files
with
290 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
#pragma once | ||
|
||
#include "duckdb.hpp" | ||
|
||
extern "C" { | ||
#include "postgres.h" | ||
#include "optimizer/planner.h" | ||
} | ||
|
||
#include "pgduckdb/pgduckdb_duckdb.hpp" | ||
|
||
extern bool duckdb_explain_analyze; | ||
|
||
PlannedStmt *DuckdbPlanNode(Query *parse, int cursor_options, ParamListInfo bound_params); | ||
std::tuple<duckdb::unique_ptr<duckdb::PreparedStatement>, duckdb::unique_ptr<duckdb::Connection>> | ||
DuckdbPrepare(const Query *query, ParamListInfo bound_params); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.