List: Internals « Previous MessageNext Message » From: Sergei Golubchik Date: February 1 2010 6:28pm Subject: Re: Finding the start of a statement View as plain text
```Hi, Paul!

On Feb 01, Paul McCullagh wrote:
>
> 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.

but the first start_stmt() corresponds to the top-level select * from t1,
doesn't it ?

Regards,
Sergei
```
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