-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Move queries with variable number of args to a fixed number of args syntax #1114
Conversation
Replaced |
Queries in Batch are executed in the same order they were added to Batch, which is in turn the same as in unnest, so deadlock potential should be the same. As for efficiency, pgx uses prepared statement underndeath, so any request after first will be sending just args for the query, not the query itself. If string hashing becomes a problem, then explicit prepared statement can be used with Batch. |
The only other difference I see is tracking stats for every single query (Batch) vs the single bulk query (unnest) but I don't really prefer one or the other, wdyt? |
Queries with a variable number of arguments are treated as distinct queries from PostgreSQL perspective, and their statistics are tracked separately. This PR aims to improve query metrics' cardinality and, consequently, improve query stats monitoring. This is achieved by using a fixed syntax:
WHERE x in ($1,$2,$3, ...)
is replaced withWHERE x = ANY($1::type_of_x[])
, with all values passed as a single array argument.INSERT INTO t (a,b,c) VALUES ($1,$2,$3), ($4,$5,$6), ...
is replaced withpgx.Batch
, with a single row insert per query.