Skip to content

Commit

Permalink
Use the unnamed prepared statement for Pgx.execute
Browse files Browse the repository at this point in the history
The unnamed prepared statement is optimized differently, assuming the
query will only be executed once (which is what Pgx.execute does):

https://www.postgresql.org/docs/current/static/protocol-overview.html#PROTOCOL-QUERY-CONCEPTS

> In addition, an “unnamed” prepared statement and portal exist.
> Although these behave largely the same as named objects, operations
> on them are optimized for the case of executing a query only once
> and then discarding it, whereas operations on named objects are
> optimized on the expectation of multiple uses.
  • Loading branch information
brendanlong committed Jul 4, 2018
1 parent 55ed2e4 commit 77d0a82
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pgx/src/pgx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1345,15 +1345,15 @@ module Make (Thread : IO) = struct
fail_msg "Pgx.execute: Query returned multiple result sets but \
execute should only ever return one. Query was: %s" query)
| Some params ->
Prepared.(with_prepare db ~query ~f:(fun s ->
Prepared.(with_prepare db ~name:"" ~query ~f:(fun s ->
execute s ~params))

let execute_iter ?(params=[]) db query ~f =
Prepared.(with_prepare db ~query ~f:(fun s ->
Prepared.(with_prepare db ~name:"" ~query ~f:(fun s ->
execute_iter s ~params ~f))

let execute_fold ?(params=[]) db query ~init ~f =
Prepared.(with_prepare db ~query ~f:(fun s ->
Prepared.(with_prepare db ~name:"" ~query ~f:(fun s ->
execute_fold s ~params ~init ~f))

let begin_work ?isolation ?access ?deferrable seq =
Expand Down

0 comments on commit 77d0a82

Please sign in to comment.