Here's how the SQL Anywhere 16 Help describes the LastPlanText and LastStatement connection properties:
|
This Foxhound snapshot shows SELECT * FROM p() as the Last Statement value, but the Last Plan Text applies to a different statement, the SELECT COUNT_BIG(*) statement inside the stored procedure:
CREATE PROCEDURE p() BEGIN WAITFOR DELAY '00:00:01'; SELECT COUNT_BIG(*) FROM SYSTAB AS A CROSS JOIN SYSTABCOL AS B CROSS JOIN SYSUSER AS C; END; SELECT * FROM p();
That's the difference between these two connection properties:
- LastStatement shows what came from the client application,
- whereas LastPlanText applies to the last query run by the server whether it came from the client or (in this case) came from within a stored procedure.
Are you SURE about that?
Question: Is it possible the behavior of LastPlanText and LastStatement in the example above is related to peculiar symptoms described in Beware The Slow Result Set Query and Hunting The Slow Result Set Query where the SELECT statement used to return a result set didn't show up at all in the procedure profiler and was fairly well hidden in the database tracing output?Answer: Let's run a test with a stored procedure that contains time-consuming queries but doesn't return a result set at all:
When execution hit the first slow SELECT INTO @x statement, Foxhound showed that LastStatement contains the CALL statement but LastPlanText showed the plan for the SELECT:
CREATE PROCEDURE p ( OUT @x INTEGER ) BEGIN DECLARE @y INTEGER; SELECT COUNT_BIG(*) INTO @x FROM SYSUSER AS A CROSS JOIN SYSUSER AS B CROSS JOIN SYSUSER AS C CROSS JOIN SYSUSER AS D; SELECT COUNT_BIG(*) INTO @y FROM SYSTAB AS A CROSS JOIN SYSTABCOL AS B CROSS JOIN SYSUSER AS C; SET @x = @x + @y; END; CREATE OR REPLACE VARIABLE @x INTEGER; CALL p ( @x ); SELECT @x;
When the next slow SELECT INTO @y started executing, Foxhound still showed the CALL in LastStatement, but LastPlanText contained the plan for the next SELECT:
That pretty much confirms LastStatement is a client statement thing whereas LastPlanText follows the plans wherever they may be coming from, client or server.
|
No comments:
Post a Comment