How to determine estimated cost of dynamic SQL queries before execution?
Hi Performance Gurus,
Does anybody need know of a function module or program which can give me an estimated cost for a given SQL query. SQL query is a dynamic query and we need to know the estimated cost before we execute it.
Cheers
Jiby
Moderator message: subject corrected, in the future please use one that describes your problem better.
Edited by: Thomas Zloch on Aug 24, 2010 12:56 PM
Hi,
The mentioned function module does not give you the cost but the plan.
On DB2 e.g.
U Explanation of query block number: 1 step: 1
D Query block type is SELECT
S Performance appears to be bad
S No index is used. Sequential tablespace scan
E Method:
D access new table.
D data pages are read in advance
D pure sequential prefetch is used
D new table:
D SAPD8M.DD02L
D table space locked in mode: N
D Accesstype: sequential tablespace scan.
I think there is some information that could be used as well (cost figure transformed to text)
S Performance appears to be bad
S No index is used. Sequential tablespace scan
But as already said: the whole requirement is quite strange...
I'm not aware of any other options, sorry.
Kind regards,
Hermann
Similar Messages
-
Can we capture SQL Queries before execution?
Hi Everyone,
I would like to know that is there any way to capture SQL queries before execution?
please advise.
thanks
kvHi!
You could capture the querys and use them as a payload for the "Database Engine Tuning Advisor".
Maybe it gives you some indexes which raise the performance.
But:
I only would add indexes to user tables.
Cheers,
Roland
PS.:
Indexes which are created directly through SQL could be lost after a B1 Upgrade. So saving the creation-statements in a warm and secure place is recommended
PPS.:
...and maybe such indexes are not supported by SAP...
Edited by: Roland Toschek on Dec 1, 2008 6:23 PM -
How to determine the cost center
Dear experts:
Could you give me some suggestions about how to determine the cost center depending on the different
storage location when we use the t-cdoe MI07
Thanks in advance.
RongHello experts!!!
how have you resolved this issue???
I have the same situation, and i dont know how to manage this.
Thank you very much in advance.
Best regards,
M. Cecilia Vacatello. -
How system determine target cost ?
Dear experts,
we use moving average price control for in-house production parts, when we finish one production order, I can not see any target cost from cost analysis.
Can you tell me how system determine target cost ? for moving average price control , is that mandatory for variance calculation ?
BR , ShubinHi
Target cost is calculated based on released Standard cost estimate
What you are doing is wrong.. Follow S for In House Made items and release standard cost estimate before GR
Maintain Target Cost Version 0 in IMG for variance Calculation
br, Ajay M -
Erratic Report Region Behavior with Dynamic SQL Queries
I'm running HTMLDB v 1.5.1.00.12 and I've noticed some odd behavior with report regions using dynamic SQL queries. Every so often, our testers will run a page containing a dynamic sql report region and get the following error, (despite the fact the query was working only moments ago and no other developer has touched it):
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
or sometimes
failed to parse SQL query:ORA-01403: no data found
The only solution I've found so far is to:
1) Make a copy of the failed report region.
2) Disable or delete the original failed report region.
The new copy of the report region runs without issue.
My search of the forums turned up the following two threads, but neither provided me with a clear explanation of the cause, and how to avoid it:
ORA-06502:PL/SQL: numeric or value error: character string buffer too small
Re: Import Export Error (ORA-06502)
The columns being returned are below the 4000 character limit, and the rows being returned are far less than 32k in size.
Could this have anything to do with the way HTMLDB is internally storing the PL/SQL used to generate the dynamic SQL Query? Is there any known issue related to this with that version of HTMLDB?
This problem occurs without any discernable pattern or consistency, making it hard to determine where I should focus my efforts in tracking down the cause.Hi all,
My report seems to be behaving correctly once i set it to "Use Generic Column Names (parse query at runtime only)" :)
Cheers,
Joel -
Dynamic SQL queries in HTMLDB application
How can i build a HTMLDB page only for dynamic sql queries like the features in the HTMLDB SQL-workshop.
I need a SQL interface for some power user running some ad-hoc queries.
Can i call this page directly from any other HTMLDB application?
Regards
MartinHello Martin,
I am a beginer in APEX but I have the same problem with you. What are your solution for dynamic sql query ? For report a solution is Pl Sql procedure which return a sql query. But for a form ? -
Size of SQL query before execution and after execution
hi all
I need help on how can i find out the size of SQL query before execution and after execution in java
The query can be any query select / insert / update
Can anyone help me if any system tables help to find out the required size i mentioned
Urgent help is required
Thanking in advanceI need the size in terms of bytes
like the rquirement is stated as below
select ................: 10 B , return 250 B
so i need size before and after execution in terms of bytes -
How to reduce Parse time in dynamic SQL
I'm using for a part of my code dynamic SQL with DBMS_SQL Package, this dynamic SQL code is located in a loop with say 1000 repeatations, if we trace the code we see that this sql statement is parsed 1000 times and this causes
a serios performance issue. If i convert this part of code into static PLSQL code , the statement is parsed only one time as expected. i would like
to know how i can resolve this problem in the dynamic SQL code.
Why in case of static SQL, despite it is inside the loop, it is parsed
only one time by ORACLE and in case of dynamic SQL as many as the upper limit of counter.
Why the ORACLE has different behaviour to parse them? Is there any way or trick
to force ORACLE to parse it only one time like static SQL?despite the open cursor is also inside the loop but oracle parse it only one time.That is because PL/SQL is caching your cursor and resuing it. With DBMS_SQL you are opening a new cursor area in the loop for each iteration (DBMS_SQL.OPEN_CURSOR).
what you need to do is open/parse once and bind the value each time through the loop:
DECLARE
expr VARCHAR2(1000);
check_cur PLS_INTEGER;
nDummy PLS_INTEGER;
nFetched PLS_INTEGER;
BEGIN
-- Open Cursor
check_cur := dbms_sql.open_cursor;
expr := 'select 1 from dual where ' || ':bindvar1 ' || '=' ||
' ''bindvar1'' ';
-- Parse Cursor
dbms_sql.parse(check_cur,
expr,
1);
FOR counter IN 1 .. 1000
LOOP
-- Define Column
DBMS_SQL.define_column(check_cur,
1,
1);
-- Do Binding
dbms_sql.bind_variable(check_cur,
':bindvar1',
'bindname1');
-- Execute Cursor
nDummy := DBMS_SQL.EXECUTE(check_cur);
-- Fetch Rows
nFetched := DBMS_SQL.fetch_rows(check_cur);
END LOOP;
-- Close Cursor
dbms_sql.close_cursor(check_cur);
END;
call count cpu elapsed disk query current rows
Parse 1 0.21 0.23 0 0 0 0
Execute 1000 0.11 0.10 0 0 0 0
Fetch 1000 0.03 0.01 0 0 0 0
total 2001 0.35 0.35 0 0 0 0 -
How to create a function with dynamic sql or any better way to achieve this?
Hello,
I have created below SQL query which works fine however when scalar function created ,it
throws an error "Only functions and extended stored procedures can be executed from within a
function.". In below code First cursor reads all client database names and second cursor
reads client locations.
DECLARE @clientLocation nvarchar(100),@locationClientPath nvarchar(Max);
DECLARE @ItemID int;
SET @locationClientPath = char(0);
SET @ItemID = 67480;
--building dynamic sql to replace database name at runtime
DECLARE @strSQL nvarchar(Max);
DECLARE @DatabaseName nvarchar(100);
DECLARE @localClientPath nvarchar(MAX) ;
Declare databaselist_cursor Cursor for select [DBName] from [DataBase].[dbo].
[tblOrganization]
OPEN databaselist_cursor
FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Processing DATABASE: ' + @DatabaseName;
SET @strSQL = 'DECLARE organizationlist_cursor CURSOR
FOR SELECT '+ @DatabaseName +'.[dbo].[usGetLocationPathByRID]
([LocationRID])
FROM '+ @DatabaseName +'.[dbo].[tblItemLocationDetailOrg] where
ItemId = '+ cast(@ItemID as nvarchar(20)) ;
EXEC sp_executesql @strSQL;
-- Open the cursor
OPEN organizationlist_cursor
SET @localClientPath = '';
-- go through each Location path and return the
FETCH NEXT FROM organizationlist_cursor into @clientLocation
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @localClientPath = @clientLocation;
SELECT @locationClientPath =
@locationClientPath + @clientLocation + ','
FETCH NEXT FROM organizationlist_cursor INTO
@clientLocation
END
PRINT 'current databse client location'+ @localClientPath;
-- Close the Cursor
CLOSE organizationlist_cursor;
DEALLOCATE organizationlist_cursor;
FETCH NEXT FROM databaselist_cursor INTO @DatabaseName
END
CLOSE databaselist_cursor;
DEALLOCATE databaselist_cursor;
-- Trim the last comma from the string
SELECT @locationClientPath = SUBSTRING(@locationClientPath,1,LEN(@locationClientPath)- 1);
PRINT @locationClientPath;
I would like to create above query in function so that return value would be used in
another query select statement and I am using SQL 2005.
I would like to know if there is a way to make this work as a function or any better way
to achieve this?
Thanks,This very simple: We cannot use dynamic SQL from used-defined functions written in T-SQL. This is because you are not permitted do anything in a UDF that could change the database state (as the UDF may be invoked as part of a query). Since you can
do anything from dynamic SQL, including updates, it is obvious why dynamic SQL is not permitted as per the microsoft..
In SQL 2005 and later, we could implement your function as a CLR function. Recall that all data access from the CLR is dynamic SQL. (here you are safe-guarded, so that if you perform an update operation from your function, you will get caught.) A word of warning
though: data access from scalar UDFs can often give performance problems and its not recommended too..
Raju Rasagounder Sr MSSQL DBA
Hi Raju,
Can you help me writing CLR for my above function? I am newbie to SQL CLR programming.
Thanks in advance!
Satya
-
How to determine a cost center based on a storage location
Hi all,
During material movement or stocked purchase, I need to determine different cost center by storage location. Therefore, i can't use OKB9 because the plant criteria is not enough.
Is there any user-exit or another solution i can implement to solve this problem?
Thank you for your answers.Hi
As i said earlier, you can use MSEG itself in your substitution rule.
For Ex:
Pre- requisite
BKPF-BUKRS = 'XXXX' AND BKPF-AWTYP = 'MKPF' (and anyother criteria that needs to be applied)
Substitute
Field - Material (MATNR)
is substituted by "EXIT"
Create your own exit here & give your logic like
If MSEG-LGORT = '0001'(your storage location values)
then BSEG-KOSTL = 'CCTR1'.
Let me know if you need any further details.
Thanks
Kalyan -
How to use database control to execute sql queries which change at run time
Hi all,
I need to execute sql queries using database controls , where the sql changes
at run time
based on some condition. For eg. based on the condition , I can add some where
condition.
Eg. sql = select id,name from emp where id = ?.
based on some condition , I can add the following condition .
and location = ?.
Have anybody had this kind of situation.
thanks,
sathishFrom the perspective of the database control, you've got two options:
1) use the sql: keyword to do parameter substitution. Your observation
about {foo} style sbustitution is correct -- this is like using a
PreparedStatement. To do substitution into the rest of the SQL
statement, you can use the {sql: foo} substitution syntax which was
undocumented in GA but is documented in SP2. Then, you can build up
the filter clause String yourself in a JPF / JWS / etc and pass it into
the DB control.
For example:
* @jc:sql statement="select * from product {sql: filter}"
public Product[] getProducts(String filter) throws SQLException;
This will substitute the String filter directly into the statement that
is executed. The filter string could be null, "", "WHERE ID=12345", etc.
2) you can use the DatabaseFilter object to build up a set of custom
sorts and filters and pass that object into the DB control method.
There have been other posts here about doing this, look for the subject
"DatabaseFilter example".
Hope that helps...
Eddie
Dan Hayes wrote:
"Sathish Venkatesan" <[email protected]> wrote:
Hi Maruthi,
The parameter substituion , I guess is used like setting the values for
prepared
statements.
What I'm trying to do , is change the sql at run time based on some condition.
For example ,
consider the following query :
select col1,col2 from table t where t.col3 > 1
At run time , based on some condition , I need to add one more and condition.
i.e. select col1,col2 from table t where t.col3 > 1 and t.col4 < 10.
This MAY not address your issue but if you are trying to add "optional" parameters
you may try including ALL the possible parameters in the SQL but send in null
for those params that you don't want to filter on in any particular case. Then,
if you word your query
as follows:
select col1, col2 from table t where t.col3 > 1 and (t.col4 = {col4param} or
{col4param} is null) and (t.col5 = {col5param} or {col5param} is null) ...
you will get "dynamic" filters. In other words, col4 and col5 will only be
filtered if you send in non-null parameters for those arguments.
I have not tried this in a WL Workshop database control but I've used
this strategy dozens of times in stored procedures or jdbc prepared statements.
Good luck,
Dan -
View the reports sql statement before execution
Hi
I am developing reports with dynamic sql statements.
How can I view the complete reports sql statement which is sent to the database?
Thanks
JuergYou can turn on the trace functionality. That will display the actual SQL statements sent to the database in the trace file.
-
How to determine ADF roles a user is in - before fully authenticated
[JDev/ADF v11.1.1.5.0]
I am trying to intercept a user's login to our ADF application (to log it to a database). I have written a custom login page and backing bean to handle the login using:
mySubject = login(this._username, this._password);
HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
ServletAuthentication.runAs(mySubject, request);
ServletAuthentication.generateNewSessionID(request);
// determine what ADF 'Application Roles' the user has
// log to database here
// ... [code removed] ...
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
RequestDispatcher dispatcher = request.getRequestDispatcher("/adfAuthentication");
dispatcher.forward(request, response);
What I need to do, however, is determine what roles a user has in the app, at the "???" point in the above code. If I interrogate the 'mySubject' object, it lists the groups from our authentication source that the user is a member of. In ADF Security, I've mapped these "Enterprise Roles" to "Application Roles", and need to get access to the Application Roles before redirecting them to the adfAuthentication servlet.
I've tried using ADFContext.getCurrent().getSecurityContext().getUserRoles() where the '// ???' is, but it returns the 'anonymous' user (and associated roles). It appears that even though I've switched to runAs the authenticated user (via ServletAuthentication.runAs), ADF still thinks I'm running as the initial (anonymous) user.
Is there a way to tell ADF to 'refresh' who it thinks I am now, so it will see me as the (now-authenticated) user, with their roles, etc.? Or, is there some other way to determine what (Application) roles a user has given their username?
Thanks!
Edited by: Karl C on Nov 27, 2012 12:28 PMJust checked code.
Sorry, in our code we test enterprise roles(and not application roles) because we are using ReadOnlySqlAuthenticator to retrieve db users/roles.
Set<Principal> allPrincipals = mySubject.getPrincipals();
for (Principal principal : allPrincipals) {
if(principal instanceof WLSGroupImpl ) {
roles.add(principal.getName());
}Dario -
How to pull history SQL queries before 18 day's
Hi,
I tried to pull the Awr report for the SQL history queries. Unfortunately it is saved only for 7 days. There is any way I can retrieve the history SQL from dictionary tables. I have access to all the DBA views. Please let me know if you need any further information.
Thanks,
Swagathswagath, as already stated as a general rule Oracle does not retain the information you are asking for. Even the AWR information consists of samples so it is not complete.
Keeping a record of all the queries ran would take a fair amount of space on any active system and really what practical use if this information.
If you need to know who accessed what then you need auditing configured and if you need to hold onto the data for more than a short period of time you likely need to be dumping the audit trail external to the database.
IMHO -- Mark D Powell -- -
How do I escape single quotes in SQL queries
Hi
I am using EclipseLink + EJB 3.0.
When single quote ( ' ) is entered as search criteria for JPA query, it throws exception.
As specified in the bolow link , its generic sql problem.
http://it.toolbox.com/wiki/index.php/How_do_I_escape_single_quotes_in_SQL_queries%3F
If single-quote is used to escape a single-quote, it might fail in mySQL (which use a backslash as the escape character).
Please suggest generic way to resolve this issue, so that it works across DBMS.
Thanks
TilakHello,
I'm not sure of the query you are trying to execute, or why you would link an article that is strongly suggestiong parameter binding when you state you are looking for escape characters. If you pass in the parameter, you do not need to use escape characters, and EclipseLink uses parameter binding by default.
What is the exception you are getting, and the SQL that is generated? Is this a native query or a JPQL query?
Best Regards,
Chris
Maybe you are looking for
-
Java extend client outside coherence grid or Java client inside grid ?
Hello, I'm quite new with Coherence and I'm wondering the best option to connect a JAVA client that will communicate with coherence cluster during few seconds. Around 30 clients may connect at the same time. Cluster stores around 4Gb of data. I consi
-
Hello, i have just built a custom component in multisim. All is well and good until i place the component then set it so i can see pin names. The pin names overlap the chip itself so i was wondering if there was a way to moves the pin name, or justif
-
How do i install and boot to DOS in NTFS format?
Hi every body. I have a PC setup winxp on the first partition,formatted NTFS,i setup DOS 7 on the next partition formatted FAT32,but i dont know how to add this partition to the boot choice so that when the PC boot up,there are 2 choices for me: 1.Wi
-
ZFS help - disk id has changed
Hi. I'm running Solaris 10 on x86 platform. I had 3 disks on my computer, 1 IDE (with solaris 10) and 2 SATA. Both SATA drives are (were) using zfs, though in two different pools. One of the drives crashed and I had to remove it, but I forgot to remo
-
How can I update my iPad one to new ios7? Thank you and please give me the answer ASAP.