on 2012 Jan 23 7:27 PM
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
I really don't understand, why only SA still don't has convenient mechanism for getting plans of any sql statements, without voodoo. Using Tracing/LogExpensiveQueries is not that thing that all wants today. For some statement 1min is very fast, for another -1ms - very slow. So how to use LogExpensiveQueries in that case? Please, just give us simple mechanism getting any plans without voodoo, like any other RDBMS has.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"A simple mechanism for getting plans without voodoo" is a good description of a much needed improvement... too bad it lacks management appeal.
Let's see... paradigm shift... adaptive server... unwired enterprise...
...got it! cloud computing!
How about "A simple mechanism for getting plans to improve cloud performance"?
...what's the current value of the brandnew BUZZWORD_LEVEL option...?
I'm sure it's essential for implementing IP6 🙂 or even better BIG DATA - the last one is even has the advantage of being true
And now is the time to give the slight pointer that in German (or my particular region), "Fuji" sounds similar to the colloquial "futsch" or its "italized" version "futschikato" - both meaning
lost, gone, broken
Some may claim that's a very fitting association with a cloud-based database, others may not...
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
Good point! I've updated my answer.
I see the[/an] issue now.
The database server is not tracing the value of the expression tested in the IF statement. It's hard to say exactly why this is, but it could be that the EXISTS keyword is usually treated as a predicate for a query which creates a subquery. Since the IF statement isn't quite a query, the EXISTS subquery is not easily tied to the IF statement.
But, there is in fact request logging for these statements (in my test using "dbsrv12 -zr ALL -zp -zo rll.log ...").
For example, the following code:
CREATE OR REPLACE PROCEDURE myProc() RESULT ( ret LONG VARCHAR ) BEGIN DECLARE ret LONG VARCHAR; IF EXISTS(SELECT * FROM SYS.SYSTAB WHERE table_id = 3408) THEN SET ret = '1'; END IF; IF EXISTS(SELECT * FROM SYS.SYSTAB WHERE table_name = 'Robert') THEN SET ret = '2'; END IF; IF EXISTS(SELECT * FROM SYS.SYSPROCEDURE WHERE proc_name = 'myProc') THEN SELECT COUNT(*) INTO ret FROM SYS.SYSPROCEDURE WHERE proc_name = 'myProc'; END IF; SET ret = '0'; SELECT ret; END; CALL myProc();
Produces the following plan information in the request log:
+1,P,1,[R][0]tab<ISYSTAB(IO)> =,P,1,[R][1]tab<table_name(IO)> +1,P,1,[R][1]b<procedure_name(IO)> =,[,1,myProc,15,select COUNT() into ret from SYS.SYSPROCEDURE where proc_name = 'myProc' +12,P,1,[R][1]GrByS[ b<procedure_name(IO)> ]
As you can see, the output is fairly obscure. Also, the SELECT COUNT(*)... plan is pretty clearly tied to its query. This output can get better if the query can be executed apart from the if statement (although not ideal) as in:
DECLARE test INTEGER; SELECT 1 INTO test FROM SYS.DUMMY WHERE EXISTS(...); // or SELECT TOP 1 1 INTO test FROM ... IF test = 1 THEN //it exists! END IF;
Again, not ideal, but I hope this can provide some more ammo to tackle the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is that "request log" the result of request level logging? If so, it will only show requests coming into the server from the outside world; i.e., the CREATE PROCEDURE coming from dbisql, not the statements executed inside the procedure.
That statement is somewhat correct... However, if you look at the fifth line for my request output, you'll notice that the query
=,[,1,myProc,15,select COUNT() into ret from SYS.SYSPROCEDURE where proc_name = 'myProc'
is the rewritten statement being executed by the stored procedure on line 15. (Although it's not actually line 15, I modified the procedure a couple of times in my test, but I digress...)
For a more recent execution I have:
+147,P,1,[R][0]tab<ISYSTAB(IO)> +1,P,1,[R][1]tab<table_name(IO)> +2,P,1,[R][1]b<procedure_name(IO)> =,[,1,myProc,12,select COUNT() into ret from SYS.SYSPROCEDURE where proc_name = 'myProc' +1,P,1,[R][1]GrByS[ b<procedure_name(IO)> ] =,],1,myProc,12 =,[,1,myProc,14,set ret = '0' =,],1,myProc,14 =,[,1,myProc,15,select ret =,P,1,[S]DUMMY<seq> =,],1,myProc,15
User | Count |
---|---|
62 | |
10 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.