-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extended protocol and prepared statements #147
Conversation
3bdc96b
to
98376a1
Compare
24c63d4
to
0a41720
Compare
src/pgduckdb_types.cpp
Outdated
case FLOAT8OID: { | ||
return duckdb::Value::DOUBLE(DatumGetFloat8(value)); | ||
} | ||
// case duckdb::LogicalTypeId::DECIMAL: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see there's a few types that we support in other places that I didn't implement here yet. Also if you look at the added tests you'll see that there are a bunch of issues with floats and string arguments for some reason not working as expected in comparisons.
In my opinion it's important to support them and fix those errors, but I don't think it necessarily needs to be part of this PR. This PR is already a bit larger than I'd like it to be. So I'd rather merge this soonish if we're happy with the general design, and then fix the remaining issues in follow up PRs. Especially since making DuckDB a singleton is a significant change in architecture that I feel would benefit from early use by developers to find bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only used for binding? Maybe rename it, also we don't need to have commented out what is not supported (probably ticket should be created at this point).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the function a bit and removed the commented out code. After we merge this I'll create a ticket to track support for the other types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally i would like to see this PR split int two parts. One is which enabled singleton duckdb object and another that deals with binding.
src/pgduckdb_types.cpp
Outdated
case FLOAT8OID: { | ||
return duckdb::Value::DOUBLE(DatumGetFloat8(value)); | ||
} | ||
// case duckdb::LogicalTypeId::DECIMAL: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only used for binding? Maybe rename it, also we don't need to have commented out what is not supported (probably ticket should be created at this point).
2136ffe
to
7a5087a
Compare
7a5087a
to
829bcfb
Compare
Based on work by @Y-- and PR #102 and #147. This basically extracts the work from there into a separate PR, so it can be merged before some of the open TODOs related to prepared statements/extended protocol are resolved. Co-authored-by: Y. <[email protected]>
829bcfb
to
bbf508e
Compare
@@ -2,7 +2,7 @@ | |||
|
|||
|
|||
def test_explain(cur: Cursor): | |||
cur.sql("CREATE TABLE test_table (id int primary key, name text)") | |||
cur.sql("CREATE TABLE test_table (id int, name text)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to change this definition to not create an index because index scans are currently broken, see #183 for details.
42c8794
to
b50d061
Compare
a0d3df5
to
ee6865f
Compare
618277c
to
7303512
Compare
28d333c
to
9985939
Compare
7303512
to
689cec9
Compare
9985939
to
6f028f2
Compare
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 thisQuery
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