Hi Sergei,
> but the first start_stmt() corresponds to the top-level select *
> from t1,
> doesn't it ?
Yes, but I don't think that helps me.
For example if the SELECT is as follows:
select * from t1, t2 where data = getcount("bar") and t1.data = t2.c1;
Then the first 2 start_stmt() calls correspond to the top-level SELECT.
So I have to know how may tables are in the top-level SELECT in order
to know where the nested statement starts.
On Feb 1, 2010, at 7:28 PM, Sergei Golubchik wrote:
> 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.
>
> --
> 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