Closed AmoebaProtozoa closed 3 years ago
it should update dcparser firstly to understand pg transaction syntax. https://github.com/DigitalChinaOpenSource/DCParser
The corresponding issue can be find under DCParser https://github.com/DigitalChinaOpenSource/DCParser/issues/20
Development Task
Description
The SQL standard syntax for starting a transaction is
START TRANSACTION
, which both MySQL and PostgreSQL supports. They also support syntax likeSTART TRANSACTION + [modifier]
, where modifier can beREAD WRITE
,READ ONLY
, etc. For the ease of use, they also support useBEGIN
instead ofSTART TRANSACTION
However, they treatBEGIN + [modifier]
differently. (likeBEGIN READ WRITE
)In Postgres this is completely fine,
BEGIN
/BEGIN WORK
/BEGIN TRANSACTION
are all treated as aliases forSTART TRANSACTION
MySQL, on the other hand, does not allow modifier after
BEGIN
, a limitation which TiDB inherits.In TiDB, the standard way to start new transaction via go code is
which calls underlying
go-mysql-driver
via go'sdatabase
module, and return a transaction handle (thetxn
above). After we switch the driver fromlib/pq
, becausepq
starts transaction byBEGIN READ WRITE
when no modifier provided, it will cause parser to complain.Previously in unit tests fixing, we have been solving the problem by skipping
Begin()
method and execute SQL statementSTART TRANSACTION;
and executeCOMMIT;
at the end of query block. But since we are not usingBegin()
, we can't gettxn
handle. It will cause problem when multiple transactions are nested or intersected.The ideal solution is for parser to support
begin + modifier
syntax.References
PostgreSQL: Documentation: 9.1: BEGIN MySQL :: MySQL 8.0 Reference Manual :: 13.3.1 START TRANSACTION, COMMIT, and ROLLBACK Statements MySQL Difference between BEGIN and START TRANSACTION - Database Administrators Stack Exchange