Skip to content

Conversation

@tatchi
Copy link
Contributor

@tatchi tatchi commented Oct 2, 2024

add start_txn cc @jorisgio

@tatchi tatchi requested a review from ygrek as a code owner October 2, 2024 07:48
@paurkedal
Copy link
Collaborator

I am not so sure about this PR. Although parsing overhead is likely limited, it seems wrong to use a non-prepared query for every transaction, when the rest runs by prepared queries. Is it not better to leave it to the use to create a prepared query for the purpose? There is also a different way of doing this in MariaDB, using SET autocommit = 0, and I'm wondering what is the preferred way for MariaDB users, given the C API has commit but start-transaction.

(On the other hand, I think exposing the binding for mysql_real_query could we very useful, though handling parameters and result rows would take some work.)

@jorisgio
Copy link
Contributor

I am not so sure about this PR. Although parsing overhead is likely limited, it seems wrong to use a non-prepared query for every transaction, when the rest runs by prepared queries. Is it not better to leave it to the use to create a prepared query for the purpose?

What do you mean ? we added this, because you can't prepare START TRANSACTION statement. Or are you talking about some other way to prepare transactions ?

There is also a different way of doing this in MariaDB, using SET autocommit = 0, and I'm wondering what is the preferred way for MariaDB users, given the C API has commit but start-transaction.

that is what we were using. But it is a bit finicky when you have connections pool and proxy like proxysql. Means that this becomes stateful, and just to be safe, each time you reuse a connection, you have to ensure that autocomit is 1. This is fine, but for us this ended up beging hundred of thousands of queries per second just to set autocommit, while most queries are not inside transactions, which ended up having a high cost in term of cpu usage.
So this is why we added excliplit transaction support.

@paurkedal
Copy link
Collaborator

Aha, I recall now there is restriction with prepared queries. In that case, I think this is an acceptable solution given the lack of a full mysql_real_query binding. Thanks, I'll merge in a moment.

@paurkedal paurkedal merged commit c442287 into ocaml-community:master Oct 11, 2024
@paurkedal paurkedal mentioned this pull request Oct 17, 2024
paurkedal added a commit to paurkedal/opam-repository that referenced this pull request Nov 28, 2024
CHANGES:

  - Added `Stmt.start_txn` (ocaml-community/ocaml-mariadb#59 by Corentin Leruth).
  - Added `Res.insert_id` as binding for `mysql_stmt_insert_id` (ocaml-community/ocaml-mariadb#58 by
    Corentin Leruth).
  - Updated to support recent OCaml versions (ocaml-community/ocaml-mariadb#45 by @kit-ty-kate).
  - Fixed too-early retrieval of statement metadata (ocaml-community/ocaml-mariadb#41 by Albert Peschar).
  - Fixed decoding bug for the integer type (ocaml-community/ocaml-mariadb#54 by Raman Varabets, tested
    by ocaml-community/ocaml-mariadb#61 by Corentin Leruth).
  - Fixed a memory leaks related to result metadata (ocaml-community/ocaml-mariadb#39 by Albert Peschar).
  - The build system is now dune and dune-configurator (ocaml-community/ocaml-mariadb#52 by Petter A.
    Urkedal) and some of the examples have been converted to a test suite
    (ocaml-community/ocaml-mariadb#60 by Petter A. Urkedal).
  - The project has been transferred to ocaml-community with Petter A.
    Urkedal as the new maintainer.
paurkedal added a commit to paurkedal/opam-repository that referenced this pull request Nov 28, 2024
CHANGES:

  - Added `Stmt.start_txn` (ocaml-community/ocaml-mariadb#59 by Corentin Leruth).
  - Added `Res.insert_id` as binding for `mysql_stmt_insert_id` (ocaml-community/ocaml-mariadb#58 by
    Corentin Leruth).
  - Updated to support recent OCaml versions (ocaml-community/ocaml-mariadb#45 by @kit-ty-kate).
  - Fixed too-early retrieval of statement metadata (ocaml-community/ocaml-mariadb#41 by Albert Peschar).
  - Fixed decoding bug for the integer type (ocaml-community/ocaml-mariadb#54 by Raman Varabets, tested
    by ocaml-community/ocaml-mariadb#61 by Corentin Leruth).
  - Fixed a memory leaks related to result metadata (ocaml-community/ocaml-mariadb#39 by Albert Peschar).
  - The build system is now dune and dune-configurator (ocaml-community/ocaml-mariadb#52 by Petter A.
    Urkedal) and some of the examples have been converted to a test suite
    (ocaml-community/ocaml-mariadb#60 by Petter A. Urkedal).
  - The project has been transferred to ocaml-community with Petter A.
    Urkedal as the new maintainer.
paurkedal added a commit to paurkedal/opam-repository that referenced this pull request Nov 29, 2024
CHANGES:

  - Added `Stmt.start_txn` (ocaml-community/ocaml-mariadb#59 by Corentin Leruth).
  - Added `Res.insert_id` as binding for `mysql_stmt_insert_id` (ocaml-community/ocaml-mariadb#58 by
    Corentin Leruth).
  - Updated to support recent OCaml versions (ocaml-community/ocaml-mariadb#45 by @kit-ty-kate).
  - Fixed too-early retrieval of statement metadata (ocaml-community/ocaml-mariadb#41 by Albert Peschar).
  - Fixed decoding bug for the integer type (ocaml-community/ocaml-mariadb#54 by Raman Varabets, tested
    by ocaml-community/ocaml-mariadb#61 by Corentin Leruth).
  - Fixed a memory leaks related to result metadata (ocaml-community/ocaml-mariadb#39 by Albert Peschar).
  - The build system is now dune and dune-configurator (ocaml-community/ocaml-mariadb#52 by Petter A.
    Urkedal) and some of the examples have been converted to a test suite
    (ocaml-community/ocaml-mariadb#60 by Petter A. Urkedal).
  - The project has been transferred to ocaml-community with Petter A.
    Urkedal as the new maintainer.
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 this pull request may close these issues.

4 participants