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