CPU Cost of a Query without executing it?

Is there any mathematical formula to find CPU cost of a query without executing it? Thanks

902181 wrote:
Is there any mathematical formula to find CPU cost of a query without executing it? ThanksAny why do you want the cost? What do you expect it to tell you? How are you planning to apply this in your code? Make sure you understand what cost tells you and what it does not tell you. And use that value in a sane fashion.
As for an alternative to using EXPLAIN PLAN, you can simply parse a SQL into a cursor without executing it. Then determine the SQL cursor id and address and use DBMS_XPLAN to display its execution plan.
E.g.
SQL> create or replace procedure ParseSQL( sqlStatement varchar2 ) is
  2          c       integer;
  3  begin
  4          c := DBMS_SQL.open_cursor;
  5 
  6          DBMS_SQL.parse(
  7                  c,
  8                  sqlStatement,
  9                  DBMS_SQL.native
10          );
11 
12          DBMS_SQL.close_cursor( c );
13  end;
14  /
Procedure created.
SQL>
SQL> var sqlID varchar2(100)
SQL> var childNumber number
SQL> var sqlText varchar2(4000)
SQL> begin
  2          ParseSQL( 'select /* TEST1 */  * from emp' );
  3 
  4          select
  5                  sql_text, sql_id, child_number into :sqlText, :sqlID, :childNumber
  6          from    v$sql
  7          where   sql_text like 'select /* TEST1 */%';
  8  end;
  9  /
PL/SQL procedure successfully completed.
SQL>
SQL> col PLAN_TABLE_OUTPUT format a50
SQL> select
  2          rownum, p.plan_table_output
  3  from       TABLE( DBMS_XPLAN.Display_Cursor( :sqlID, :childNumber, 'BASIC,COST' ) ) p;
    ROWNUM PLAN_TABLE_OUTPUT
         1 EXPLAINED SQL STATEMENT:
         2 ------------------------
         3 select /* TEST1 */  * from emp
         4
         5 Plan hash value: 3956160932
         6
         7 -----------------------------------------------
         8 | Id  | Operation         | Name | Cost (%CPU)|
         9 -----------------------------------------------
        10 |   0 | SELECT STATEMENT  |      |     3 (100)|
        11 |   1 |  TABLE ACCESS FULL| EMP  |     3   (0)|
        12 -----------------------------------------------
        13
13 rows selected.
SQL> The problem is extracting intelligence from the output as it is raw text. Perhaps not that complex as a where clause can be added to only display line id 0 and then extract the cost value from that line. Regular expressions (not my forte) will likely do this easily.

Similar Messages

  • How to validate a Query without executing it?

    How to validate a Query without executing it?
    For example if I have:
    ReadAllQuery myQuery = new ReadAllQuery(myClass);
    myQuery.setSelectionCriteria(myExpression);
    What can I do to have must validation as possible been done before executing the query?
    Validation that could be done are:
    - Expression reference fields that really exist in TopLink mapping
    - Literal provided to expression are of compatible type
    - Parameter setting set against the query are all compatible

    Your could prepare the query.
    query.prepareCall(session, record);
    This will do all query validation and generate the SQL for the query.

  • Can JDBS calculate the cost of a query ?

    In the past I worked with DB2 and I know that it has a feature that can calculate the cost of a query before executing it. Now I have to work with sybase.
    I would like to know if there is any way to get that cost in order to decide whether to execute the query or not. In the same way, I would prefer a standard method:
    Does JDBC provide a way? Is there any other standard way, using java? Is there any way possible way?, it may be not standard or not java.
    Thanks a lot.

    Most databases provide a way to do this. The most common verbage for this is "EXPLAIN".
    Some of them might expose it via SQL. But that depends on the database.
    I suspect there might also be problems with capturing the output.
    The most likely way that I can think is if you can encapsulate it in a stored procedure. At the very least you could just call the stored procedure. Or doing it that way might allow you to figure out how to do it via direct SQL calls.

  • Execute query without navigation

    hi all,
    My problem today that I want to execute query without navigation.
    I create a global variable
    (:global.usr := :block.username;)
    as you see the global variable takes the value of the current user accessing the system.
    I want the user to be able to change his password without any privilage to see the other users.
    when_new_form_instance
    execute_query;
    that what I did but what I want is to restrict his access only according to the value in the global variable

    I tryed to run the following code but I dont know why the condition in the else clause always execute.     
    if :global.usr = :global.usr = upper('ADMIN') or
         :global.usr = upper('SYS_ADMIN') then
         set_block_property('SYS_USER', DEFAULT_WHERE, '');
         execute_query;
         else
                   set_block_property('SYS_USER', DEFAULT_WHERE, 'USER_NAME = :global.usr');
                   execute_query;
         end if;

  • How to find the cpu cost and i/o cost  by a query

    I have a query that give the cpu utilization for a session.
    select s.name, m.value from v$statname s, v$mystat m
    where s.statistic# = m.statistic#
    and name = 'CPU used by this session';
    But how do you find the cpu cost and i/o cost by a query?

    Sounds like you want to use TRACE.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sqltrace.htm#PFGRF01020

  • Cpu costing is off (consider enabling it)

    Hi,
    I am using Oracle 10.2.0.3.
    Whenever I generate explain plan for any query, the very last line of explain plan is as below.
    cpu costing is off (consider enabling it)_
    It seems that optimizer didn't considerd CPU stats while generating plan for this.
    How to enable CPU statistics here?
    The parameter optimizer_mode value is "CHOOSE", and stats are being gathered at an interval of one week.
    When I use CPU_COSTING hint in the SQL, then this line went away, and the query plan also started giving CPU % in PLAN output. But how can I make this a default behaviour of optimizer ( Any parameter etc to be set in oracle 10g for this)?
    Thanks in advance.
    Best Regards,
    oratest

    oratest wrote:
    Hi,
    I am using Oracle 10.2.0.3.
    Whenever I generate explain plan for any query, the very last line of explain plan is as below.
    cpu costing is off (consider enabling it)_
    It seems that optimizer didn't considerd CPU stats while generating plan for this.
    How to enable CPU statistics here?
    The parameter optimizer_mode value is "CHOOSE", and stats are being gathered at an interval of one week.In your version of the database, the default value of optimizer_mode is ALL_ROWS. Is there any reason why you have changed it? You may want to post the output of following executed in SQL*Plus
    show parameter optimizer

  • What is the difference between est. cost, CPU cost, and IO cost

    When looking at and execution plan there is est. cost, CPU cost, and IO cost.
    Can someone explain these and more importantly explain which one is the most
    important to tune and the step to take to reduce these cost to a respect level.
    I have seen many program hit 10,000 cost and 1 Mio CPU cost and I need to get that down to improve performance.
    I am running on 10.2.
    Thanks
    Mikie

    Hi Olivier,
    sorry to disagree but:
    > They're both important and you'll have to balance
    > both. For instance a program accessing the database
    > too much (lots of I/O) may run for ages. You can tune
    > this program and lower your I/Os, therefore
    > increasing your CPU time; the quantity of work is
    > still the same!
    is just not right.
    The amount of work to do for the database to get the job done (that is to deliver the requested results) may vary A LOT!
    That is why there is a optimizer at all.
    It's true: I/O cost model the time required to perform necessary read/write operations and CPU cost do the same for handling the data in memory.
    With indexes, database features active and database versions the optimizer can choose from selecting different access, filter and sorting mechanisms to answer the db requests.
    Usually there's not much you can do to the CPU costs - the database has it's internal rating concerning how "expensive" a sort-merge-join will be or a hash-distinct function.
    What you can (and usually should) do, is to lower the main contributor to processing and I/O costs: the volume of data.
    Therefore one will try to reduce the number of rows to be processed early in the query process. That can either be done by changing the selection itself or via the indexing scheme. Furthermore physical I/O might be reduced by using specific db features (compression, datablock sizing, bitmap indexes, partitioning etc.).
    Anyhow, to come back to the original post: it's important to think of costs as time-to-execute modelled in CPU-activity and I/O-operations.
    The goal is to deliver the result at the fastest - so, nobody should bother about the absolute numbers when it comes to costs. The question has to be: what execution time is meant with this?
    KR Lars

  • Can I rewrite the following query without using Row_number() function ??!!

    Hello every one, can I rewrite the following query without using the 'ROW_NUMBER() OVER ' part.
    The query is supposed to pull out the records whose CODE is not NULL and has most
    recent date for UPDATE_DATE . The reason I wanted to do this is, When I embed this query
    in between many other queries along with JOINs, My oracle server is unable to execute. So, I thought
    its better to supplant 'ROW_NUMBER() OVER ' logic with something else and try it. .
    SELECT a.* FROM
    (SELECT b.*, ROW_NUMBER() OVER (PARTITION BY b.PIDM
    ORDER BY b.UPDATE_DATE DESC) AS Rno
    FROM
    SELECT *
    FROM SHYNCRO WHERE CODE IS NOT NULL
    )b
    )a
    WHERE a.Rno = 1

    Hi,
    You didn't write over 150 lines of code and then start testing it, did you?
    Don't.
    Take baby steps. Write as little as pssiblem test that. Debug and test again until you have something that does exactly what you want it to do.
    When you have somehting that works perfectly, take one baby step. Add a tiny amount of code, maybe 1 or 2 lines more, and test again.
    When you do get an error, or wrong results, you'll have a much better idea of where the problem is. also, you won't be building code on a flimsy foundation.
    If you need help, post the last working version and the new version with the error. Explain what you're trying to do in the new version.
    The error message indicates line 133. It looks like line 133 of your code is blank. Does your front end allow completely blank lines in the middle of a query? SQL*Plus doesn't by default; you have to say
    SET  SQLBLANKLINES  ONto have a completely blank line in SQL*Plus. (However, lines containing nothing but at commnet are always allowed.)
    You may have noticed that this site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as indented code) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The 4 people who posted small code fragments for you to read all did this.  It would be so much easier for people to read your humongeous query if it were formatted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • SQL server query without indicating server name

    I am writing a query  in SSIS and  utilize servername everytime  but it drags every time
    I am authorized to  work in Development area and can indicate deve  server
    But   Senior  officer ask me  not to use Server name  and when  package goes to  production   query  can execute without  indicate  server name any idea 
    thank you very much.
    Vijay
    Vijay Patel

    I think you're using linked server in your queries based on your description.
    While working in SSIS you dont need linked server. You'll just add connection manager to connect to your dev server and database and then use it for your tasks. Inside your query you will just reference objects using schemaname.objectname convention.
    You will make servername and database name configurable by adding them as configurations (parameters in SSIS 2012 if you use project deployment). Then you will be able to pass values for configurations from outside based on variety of options like through
    XML file, from SQLServer table, Environment variables etc
    see
    http://www.mssqltips.com/sqlservertip/1405/sql-server-integration-services-ssis-package-configuration/
    http://nexxtjump.com/2013/01/14/ssis-2012-configuration-guide-part-1-introduction/
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Looping a query without cursor

    Hi everybody
    i want to know that is there is any way by which we can loop through Resultset of a query without using cursor for loop in plsql
    vipul

    No. Reason:
    Any SQL statement in PL/SQL is a cursor. Any rows "obtained" from a cursor, is fetched via a read-cursor-loop mechanism.
    This can be an explicit cursor, where you open the cursor and manually code the loop with the FETCH statement.
    It can be an implicit cursor, where you simply code something like [SELECT col INTO var FROM table] - in which case PL/SQL still creates a cursor and still uses a cursor fetch to read the result of that cursor.
    PL/SQL is no different than Java or Delphi or C in this aspect. It takes a SQL statement and deliver that to the SQL Engine. The SQL Engine deals with SQL statements as cursors. It returns a cursor handle to the caller. The caller then has to fetch the rows from the cursor.
    What makes PL/SQL different is that the PL/SQL language and compiler integrates so tightly with SQL, that you can mix two different programming languages in the same source code. Unlike Java, Delpi and C, you can code native SQL inside your PL/SQL code. The PL/SQL compiler is clever enough to know what it can execute, and which source lines are SQL that need to be "wrapped and delivered" to the SQL Engine.
    Question though - why do you ask for another method? What do you view as a problem with using a cursor loop to fetch rows?

  • Query without using connect by

    Hi Guys,
    I need to rewrite the following query without a connect by command. Is there a way to do this?
    [code]
    SELECT DISTINCT *
      FROM serial_structure_table str,
           serial_catalog_table   psc,
           serial_table           sop,
           life_serials_table     lls,
           part_table             mp,
           serial_parts_table     vs,
           events_table           pe,
           task_table             lmt
    WHERE str.part_no       = psc.part_no
    AND   str.serial_no     = psc.serial_no
    AND   str.part_no       = sop.part_no(+)
    AND   str.serial_no     = sop.serial_no(+)
    AND   str.part_no       = lls.part_no(+)
    AND   str.serial_no     = lls.serial_no(+)
    AND   str.part_no       = vs.part_no
    AND   str.serial_no     = vs.serial_no
    AND   mp.maint_prog     = vs.maint_prog_id(+)
    AND   mp.maint_prog     = vs.maint_prog_rev(+)
    AND   mp.part_no        = vs.part_no(+)
    AND   mp.maint_group    = vs.maint_group(+)
    AND   str.part_no       = pe.part_no(+)
    AND   str.serial_no     = pe.serial_no(+)
    AND   str.serial_no     = lmt.serial_no(+)
    AND   str.part_no       = lmt.part_no(+)
    AND   mp.maint_code     = lmt.maint_code
    AND   str.parent_seq_no IS NOT NULL
    AND   str.seq_no IN (SELECT seq_no FROM serial_table
                          START WITH seq_no = (SELECT vss.seq_no
                                               FROM serial_structure_table vss, vehicle_serial_table vehicle
                                               WHERE vss.part_no      = vehicle.part_no
                                               AND vss.serial_no      = vehicle.serial_no
                                               AND vehicle.vehicle_id = '120')
                          CONNECT BY PRIOR seq_no = parent_seq_no)
    [/code]
    Many Thanks,
    Napster

    Hi Frank,
    This query which fetches a data set to a report... So when executing this query in the report I will need to have a sql expression something like below...
    select *
    from MY_VIEW
    where vehicle.vehicle_id = '&Vehicle_Id'
    When the above is run user will be asked to insert a vehicle id and that will be the user input for my sql statement... (I inserted the value 120 here just for the testing purpose). In here I will need to create a view (something like MY_VIEW which consist of the entire sql expression) as long sql expressions are not supported in our tool. So I have to compile a view with the results set without the connect by clause...
    Just let me know if it is still not clear..
    Thanks
    Napster

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • How to pull only column names from a SELECT query without running it

    How to pull only column names from a SELECT statement without executing it? It seems there is getMetaData() in Java to pull the column names while sql is being prepared and before it gets executed. I need to get the columns whether we run the sql or not.

    Maybe something like this is what you are looking for or at least will give you some ideas.
            public static DataSet MaterializeDataSet(string _connectionString, string _sqlSelect, bool _returnProviderSpecificTypes, bool _includeSchema, bool _fillTable)
                DataSet ds = null;
                using (OracleConnection _oraconn = new OracleConnection(_connectionString))
                    try
                        _oraconn.Open();
                        using (OracleCommand cmd = new OracleCommand(_sqlSelect, _oraconn))
                            cmd.CommandType = CommandType.Text;
                            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                                da.ReturnProviderSpecificTypes = _returnProviderSpecificTypes;
                                //da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                                if (_includeSchema == true)
                                    ds = new DataSet("SCHEMASUPPLIED");
                                    da.FillSchema(ds, SchemaType.Source);
                                    if (_fillTable == true)
                                        da.Fill(ds.Tables[0]);
                                else
                                    ds = new DataSet("SCHEMANOTSUPPLIED");
                                    if (_fillTable == true)
                                        da.Fill(ds);
                                ds.Tables[0].TableName = "Table";
                            }//using da
                        } //using cmd
                    catch (OracleException _oraEx)
                        throw (_oraEx); // Actually rethrow
                    catch (System.Exception _sysEx)
                        throw (_sysEx); // Actually rethrow
                    finally
                        if (_oraconn.State == ConnectionState.Broken || _oraconn.State == ConnectionState.Open)
                            _oraconn.Close();
                }//using oraconn
                if (ds != null)
                    if (ds.Tables != null && ds.Tables[0] != null)
                        return ds;
                    else
                        return null;
                else
                    return null;
            }r,
    dennis

  • How to delete confirmed schedule lines, without executing the ATP check?

    Sales and Distribution: Concerning ATP (product allocation)
    Situation:
    Step 1: An order is created with priority low. Quantities are confirmed for line items.
    Step 2: A second order is created with a higher priority. No confirmed quantities.
    Rescheduling program (SDV03V02) is then executed. This selects and sorts the orders in the correct order.
    The confirmed quantities for the first (low priority) order should now be freed up, to be able to allocate those quantities to the second (high priority) order.
    The problem I am facing is that the confirmed quantities are NOT released.
    We cannot use BAPI_SALESORDER_CHANGE or SD_SALESDOCUMENT_CHANGE to delete or modify the schedule lines, because these function modules execute the ATP check again. And when that happens, quantities are again confirmed and assigned.
    How can we get rid of the confirmed schedule lines, without executing the ATP check?
    Thanks,
    Edwin.

    Found a solution to the problem:
    In the Rescheduling program we export a parameter to the memory, to make it possible to delete schedule lines without executing the ATP check.
    Deleting of the schedule lines is done with a BAPI, which will call the ATP check automatically for ATP relevant materials. This we want to stop from happening (only when calling the BAPI).
    After the BAPI has been called we FREE the MEMORY ID.
    The parameter is imported again in Customer-Exit EXIT_SAPLATPC_001.
    Transaction.. SMOD
    Enhancement.. ATP00001
    Component.... EXIT_SAPLATPC_001,
    Include...... ZXATPU01.
    The customer exit is used in function AVAILABILITY_CHECK_CONTROLLER, just before calling function 'AVAILABILITY_CHECK'.
    Simply refreshing the ATP tables in the customer-exit, will prevent the ATP check from being executed (because we removed the list containing the materials for which the ATP check needs to be done). As a result, the function 'AVAILABILITY_CHECK' will not be processed.

  • Testing RFC without Executing RFC in SAP R/3

    Hi All,
    Is it possible to test a sender RFC adapter to invoke Web service in SAP XI without executing RFC in R/3. I am facing problems when executing RFC in R/3. So would like to confirm that the other portion ie, from XI to Webservice is working fine. Any help would be much appreciated.
    Thx
    Deno

    Hi Deno,
    Just go in a stepwise manner and you will know here the error is.
    1. First execute RFC and see if it reaches SAP XI.
    2. Check in Transaction SXMB_MONI as to which step is going into error.
    3. If it's not reaching XI ythen there is problem with RFC destination or the RFC adapter config check that.
    Regards
    Vijaya

Maybe you are looking for