cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

I have been profiling a number of functions and procedures and this has highlighted a big difference (in the wrong direction, unfortunately) in performance of some individual statements within a number of functions after moving from v10.0.1 to 12.0.1.

Some of these statements are not straight selects or updates, but are in the form of a Watcom IF connstruct eg:

if VacID is not null and(exists(select 1 from Progress where Progress.VacancyID = VacID and Progress.PersonID = persid and Progress.status = '.')
or exists(select 1 from Progress where Progress.VacancyID = VacID and Progress.PersonID = persid and Progress.noreemploy = 1)) then
return 'V' end if;

This is just one of half a dozen similarly constructed statements in the function.

The application profiling / tracing viewer treats everything between the initial BEGIN and the final END as a single statement, so no plan is available. Obviously I could rewrite the statement as something like

select if VacID is not null and(exists(select 1 from Progress where Progress.VacancyID = VacID and Progress.PersonID = persid and Progress.status = '.')
or exists(select 1 from Progress where Progress.VacancyID = VacID and Progress.PersonID = persid and Progress.noreemploy = 1)) then 1 else 0 endif

then run that from isql and get a plan, but the query isn't quite the same and the context is quite different.

Is there some way of getting the plans for such statements as the are actually executed, in the context of the function / procedure?


UPDATE

Screen shot showing how the whole procedure is treated as a single statement, with no plan tab


Getting plans for statements inside a function or procedure

View Entire Topic
Former Member

There is some functionality to obtain these plans, Breck walks through it fairly well here:

LogExpensiveQueries: A Little Bit Of Jasper In 9.0.2


Edit: You won't be able to diagnose exactly as in 9.0.2. In later versions, you'll be able to specify plan logging with -zr ALL or -zr ...+PLAN and direct the output with -zo


Of course, you can always wrap a query in a GRAPHICAL_PLAN call to get the necessary plan details from within the stored procedure or function:

(i.e.)

CALL xp_write_file('my_plan.saplan', // write plan to a file
    GRAPHICAL_PLAN('SELECT * FROM my_table',2) // 2 for detailed statistics
);

Documentation for GRAPHICAL_PLAN is at:

GRAPHICAL_PLAN function

justin_willey
Participant
0 Likes

Thanks Tyson, I've been able to get plans for individual queries like the one in your example OK, but the problem comes with functions and procedures.

What seems to happen there is that the whole procedure is treated as a unit, you can get statistics on how long it took to run and so on, and in the profile of the function you can get execution times of the individual statements that make up the procedure, but not plans for those statements.

Former Member

This can be used to get the graphical plan from within a stored procedure. Although, if the statement is executed multiple times, you may want to insert the graphical plan into a temporary table before writing to disk.

But, with the LogExpensiveQueries feature, you should be able to get by without modifying the stored procedure or function. You can specify a minimum cost for queries as well as RememberLastPlan and the database server will output the plans accordingly.

justin_willey
Participant
0 Likes

Thanks - I'll give that a go

VolkerBarth
Contributor
0 Likes

FWIW, how does that 9.0.2 feature "LogExpensiveQueries" apply to current versions?

With 10.0.1.4181 and 12.0.1.3389, both dbsrvX -zx and sa_server_option( 'LogExpensiveQueries', '1000'); are rejected as unknown options...

Former Member

Good point! I've updated my answer.