List:Internals« Previous MessageNext Message »
From:Paul McCullagh Date:February 1 2010 10:59am
Subject:Re: Finding the start of a statement
View as plain text  
Yes, it is obscure, and as far as I can tell, this solution does not  
work when we are dealing with _nested_ statements.

Consider this example:

-------------------
create function getcount(s char(16)) returns int
begin
   declare x int;

   select count(*) into x from t3 where v = s;
   if x = 0 then
     insert into t3 values (s, 1);
   else
     update t3 set c = c+1 where v = s;
   end if;
   return x;
end

select * from t1 where data = getcount("bar");
------------------

This leads to the sequence:

ha_pbxt::start_stmt (./test/t1) lock_type=2

ha_pbxt::start_stmt (./test/t3) lock_type=2
SELECT t3
ha_pbxt::extra (./test/t3) operation=24
ha_pbxt::start_stmt (./test/t3) lock_type=2
INSERT t3
ha_pbxt::extra (./test/t3) operation=24
....
ha_pbxt::start_stmt (./test/t3) lock_type=2
SELECT t3
ha_pbxt::extra (./test/t3) operation=24
ha_pbxt::start_stmt (./test/t3) lock_type=2
UPDATE t3
ha_pbxt::extra (./test/t3) operation=24

ha_pbxt::extra (./test/t1) operation=24

So counting the number of start_stmt() and extra() in this case shows  
that statements within the getcount() begin at count == 1, because of  
the extra start_stmt (./test/t1) which has nothing to do with  
getcount(), but is not there if getcount() is not called.


On Jan 29, 2010, at 8:54 PM, MARK CALLAGHAN wrote:

> On Fri, Jan 29, 2010 at 11:29 AM, Michael Widenius  
> <monty@stripped> wrote:
>>
>> Hi!
>>
>>>>>>> "Paul" == Paul McCullagh <paul.mccullagh@stripped>
> writes:
>
>
>> Paul> It would be easy to tell the start and end of statements if  
>> these
>> Paul> functions were only called ONCE for each statement.
>>
>> Paul> However, if multiple tables are involved in a statement  
>> (which is not
>> Paul> the case in the example above), then start_stmt() and reset()  
>> are
>> Paul> called multiple times for each statement.
>>
>> Paul> So how do I know where the actual boundaries of the  
>> statements are?
>>
>> Why not simply have a counter in your transaction object for how
>> start_stmt - reset();  When this is 0 then you know stmnt ended.
>>
>> In Maria we count number of calls to external_lock() and when the sum
>> goes to 0 we know the transaction has ended.
>
> Why does the solution need to be so obscure?
>
> -- 
> Mark Callaghan
> mdcallag@stripped
>
> --
> MySQL Internals Mailing List
> For list archives: http://lists.mysql.com/internals
> To unsubscribe:    http://lists.mysql.com/internals?unsub=1
>



--
Paul McCullagh
PrimeBase Technologies
www.primebase.org
www.blobstreaming.org
pbxt.blogspot.com



Thread
Finding the start of a statementPaul McCullagh27 Jan
  • re: Finding the start of a statementMichael Widenius29 Jan
    • Re: Finding the start of a statementMARK CALLAGHAN29 Jan
      • Re: Finding the start of a statementPaul McCullagh1 Feb
        • Re: Finding the start of a statementKristian Nielsen1 Feb
          • Re: Finding the start of a statementPaul McCullagh1 Feb
          • Re: Finding the start of a statementKristian Nielsen11 Feb
        • Re: Finding the start of a statementSergei Golubchik1 Feb
          • Re: Finding the start of a statementPaul McCullagh2 Feb
      • Re: Finding the start of a statementMichael Widenius3 Feb
        • Re: Finding the start of a statementMARK CALLAGHAN18 Feb
          • Re: Finding the start of a statementMARK CALLAGHAN18 Feb
  • Re: Finding the start of a statementSergei Golubchik1 Feb
    • Re: Finding the start of a statementPaul McCullagh1 Feb