You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
The text was updated successfully, but these errors were encountered:
IMO the first option looks better to me at the moment. The empty list optimization can be done as a follow-up.
piodul
changed the title
Serialization refactor: add new serialization traits
Serialization refactor: obtain information about column types when doing Session::executeAug 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:
values
argument from theSession::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.
The text was updated successfully, but these errors were encountered: