Skip to content
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

Serialization refactor: obtain information about column types when doing Session::execute #800

Closed
Tracked by #463
piodul opened this issue Aug 25, 2023 · 1 comment · Fixed by #812
Closed
Tracked by #463
Assignees
Milestone

Comments

@piodul
Copy link
Collaborator

piodul commented Aug 25, 2023

Sub-task of #463.

Information about the types of the bind markers is necessary to make the serialization API safe (i.e. so that the user data won't be misinterpreted when sending it to the database). The problem with unprepared statements is that the driver doesn't have a good way to determine column names and types of the bind markers - the QUERY request only contains the query string and serialized, untypes values for the bind markers. There is no good way to obtain the types for the bind markers or let the database validate the types when it receives the request.

In the case of prepared statements, information about the bind marker types is available because it is computed by the DB and returned in the response to the prepare request.

I see two ways out:

  1. Before sending an unprepared statement, quietly prepare it first to obtain the information about the bind markers (it's only necessary to prepare on one node). This increases latency of unprepared queries twofold, but using unprepared queries is a performance anti-pattern anyway. We could provide an optimization: if the list of values to be bound is empty, we just send it as an unprepared query. This API will also introduce less breakage in the user code.
  2. Remove the values argument from the Session::query and only allow for queries without bind markers. This is simpler to implement than 1. If the user wanted to send an unprepared query with some bind markers, now they will have to prepare it beforehand - latency-wise it will be the same as for 1., though 1. does not have to prepare the statement on every node which would be a win if somebody wants to execute the query only once.

The task doesn't make the API safer by itself, but it is a necessary element of #463 that can be done in parallel from the others sub-tasks.

@piodul
Copy link
Collaborator Author

piodul commented Aug 25, 2023

IMO the first option looks better to me at the moment. The empty list optimization can be done as a follow-up.

@piodul piodul changed the title Serialization refactor: add new serialization traits Serialization refactor: obtain information about column types when doing Session::execute Aug 25, 2023
@piodul piodul added this to the 0.10.0 milestone Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants