From: Michael Widenius Date: February 3 2010 11:17am Subject: Re: Finding the start of a statement List-Archive: http://lists.mysql.com/internals/37689 Message-Id: <19305.23374.940471.517011@narttu.askmonty.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi! >>>>> "MARK" =3D=3D MARK CALLAGHAN writes: MARK> On Fri, Jan 29, 2010 at 11:29 AM, Michael Widenius wrote: >>=20 >> Hi! >>=20 >>>>>>> "Paul" =3D=3D Paul McCullagh wri= tes: Paul> It would be easy to tell the start and end of statements if these= Paul> functions were only called ONCE for each statement. >>=20 Paul> However, if multiple tables are involved in a statement (which is= not Paul> the case in the example above), then start=5Fstmt() and reset() a= re Paul> called multiple times for each statement. >>=20 Paul> So how do I know where the actual boundaries of the statements ar= e=3F >>=20 >> Why not simply have a counter in your transaction object for how >> start=5Fstmt - reset(); =C2=A0When this is 0 then you know stmnt end= ed. >>=20 >> In Maria we count number of calls to external=5Flock() and when the = sum >> goes to 0 we know the transaction has ended. MARK> Why does the solution need to be so obscure=3F Historic reasons. MySQL never kept a count of which handlers are used by a transaction, only which tables. So the original logic was that external=5Flock(lock/unlock) is called for each usage of the table, which is normally more than enough information for a handler to know when a statement starts/ends. The one case this didn't work was in the case someone does lock tables as then external=5Flock is not called per statement. It was to satisfy this case that we added a call to start=5Fstmt() for each table. It's of course possible to change things so that start=5Fstmt() / end=5Fstmt() would be called once per used handler, but this would be yet another overhead for the upper level to do which the current handlers that tracks call to external=5Flock() doesn't need. Regards, Monty