Which query is efficient?

Hi all,
I have 2 queries which produce same output on test data. But i am not confident which is a better one or efficient one.
How can I measure the efficiency of these programs?
Query1:
SELECT TAB1.A, TAB1.B
FROM TAB1
LEFT OUTER JOIN (SELECT * FROM TAB2 WHERE d=-1) t2
ON TAB1.a = T2.c;
Query2:
SELECT TAB1.A, TAB1.B, TAB2.e
FROM TAB1
LEFT OUTER JOIN TAB2 ON TAB1.a = TAB2.c AND TAB2.d=-1;
Thanks
Edited by: KinsaKaUy? on 10-Oct-2011 02:00

But there should be at least a difference?
I am worried if I cut n paste the same program?
ok I will try again. brb
| Id  | Operation                         | Name         | Rows  | Bytes | Cost  |
|   0 | SELECT STATEMENT                  |              |    15 |  2640 |     6 |
|   1 |  NESTED LOOPS                     |              |       |       |       |
|   2 |   NESTED LOOPS                    |              |    15 |  2640 |     6 |
|   3 |    NESTED LOOPS OUTER             |              |     6 |   942 |     5 |
|   4 |     NESTED LOOPS OUTER            |              |     6 |   822 |     4 |
|   5 |      NESTED LOOPS                 |              |     6 |   654 |     3 |
|   6 |       NESTED LOOPS                |              |     6 |   444 |     2 |
|   7 |        TABLE ACCESS BY INDEX ROWID| CI_CASE_CHAR |     7 |   259 |     1 |
|   8 |         INDEX SKIP SCAN           | XT222P0      |     7 |       |     1 |
|   9 |        TABLE ACCESS BY INDEX ROWID| CI_CASE_CHAR |     1 |    37 |     1 |
|  10 |         INDEX RANGE SCAN          | XT222P0      |     1 |       |     1 |
|  11 |       TABLE ACCESS BY INDEX ROWID | CI_CASE      |     1 |    35 |     1 |
|  12 |        INDEX UNIQUE SCAN          | XT220P0      |     1 |       |     1 |
|  13 |      TABLE ACCESS BY INDEX ROWID  | CI_CASE_CHAR |     1 |    28 |     1 |
|  14 |       INDEX RANGE SCAN            | XT222P0      |     1 |       |     1 |
|  15 |     TABLE ACCESS BY INDEX ROWID   | CI_SP        |     1 |    20 |     1 |
|  16 |      INDEX UNIQUE SCAN            | XM226P0      |     1 |       |     1 |
|  17 |    INDEX RANGE SCAN               | XT221P0      |     3 |       |     1 |
|  18 |   TABLE ACCESS BY INDEX ROWID     | CI_CASE_LOG  |     3 |    57 |     1 |
| Id  | Operation                         | Name         | Rows  | Bytes | Cost  |
|   0 | SELECT STATEMENT                  |              |    15 |  2640 |     6 |
|   1 |  NESTED LOOPS                     |              |       |       |       |
|   2 |   NESTED LOOPS                    |              |    15 |  2640 |     6 |
|   3 |    NESTED LOOPS OUTER             |              |     6 |   942 |     5 |
|   4 |     NESTED LOOPS OUTER            |              |     6 |   822 |     4 |
|   5 |      NESTED LOOPS                 |              |     6 |   654 |     3 |
|   6 |       NESTED LOOPS                |              |     6 |   444 |     2 |
|   7 |        TABLE ACCESS BY INDEX ROWID| CI_CASE_CHAR |     7 |   259 |     1 |
|   8 |         INDEX SKIP SCAN           | XT222P0      |     7 |       |     1 |
|   9 |        TABLE ACCESS BY INDEX ROWID| CI_CASE_CHAR |     1 |    37 |     1 |
|  10 |         INDEX RANGE SCAN          | XT222P0      |     1 |       |     1 |
|  11 |       TABLE ACCESS BY INDEX ROWID | CI_CASE      |     1 |    35 |     1 |
|  12 |        INDEX UNIQUE SCAN          | XT220P0      |     1 |       |     1 |
|  13 |      TABLE ACCESS BY INDEX ROWID  | CI_CASE_CHAR |     1 |    28 |     1 |
|  14 |       INDEX RANGE SCAN            | XT222P0      |     1 |       |     1 |
|  15 |     TABLE ACCESS BY INDEX ROWID   | CI_SP        |     1 |    20 |     1 |
|  16 |      INDEX UNIQUE SCAN            | XM226P0      |     1 |       |     1 |
|  17 |    INDEX RANGE SCAN               | XT221P0      |     3 |       |     1 |
|  18 |   TABLE ACCESS BY INDEX ROWID     | CI_CASE_LOG  |     3 |    57 |     1 |
I guess they are identical :)
Edited by: KinsaKaUy? on Oct 10, 2011 2:40 AM

Similar Messages

  • Implicit Join or Explicit Join...which is more efficient???

    Which is more efficient?
    An IMPLICIT JOIN
    SELECT TableA.ColumnA1,
    TableB.ColumnB2
    FROM TableA,
    TableB
    WHERE TableA.ColumnA1 = TableB.ColumnB1
    Or....An EXPLICIT JOIN
    SELECT TableA.ColumnA1,
    TableB.ColumnB2
    FROM TableA
    INNER JOIN TableB
    ON TableA.ColumnA1 = TableB.ColumnB1
    I have to write a pretty extensive query and there will be many parts and I just want to try and make sure it is efficient as possible. Can I EXPLAIN this in SQL Navigator as well to find out???
    Thanks in advance for your review and hopeful for a reply.
    PSULionRP

    Alex Nuijten wrote:
    The Partition Outer Join is very handy, but it's an Oracle-ism - Not ANSI ...Ooh, "New thing learnt today" - check.
    but then again who cares? ;)Oracle roolz! *{;-D                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Which one is efficient???

    I have a text file with huge data. I need to generate Oracle report from this file.
    I have two options...
    1. Creating External table and query the data from external table
    2. Directly accessing data from text file.
    Which one is efficient?
    Thank you,
    Prasad

    hello,
    i guess that depends on
    a) how often your data changes
    b) how often your report is run
    c) how often the format of the data changes
    d) is creating the report the only use for that file
    if you have one single file that does not change and you want to use the data from other applications, i would load it intot he database. also if you generate a lot of reports off that data, going the database route would possibly be the best one.
    on the other hand if creating a report off this data is more of an one-off thing and you might create a new version once in a while but don't need the data for anything else, you might want to access the data directly.
    overall it's a performance vs. work issue. you will have to invest a bit of work to load the data into the database, but will have a much better performance if you use the data heavily, but if you only use it once in a while you might not want to invest in creating loader scripts or setting up a warehousebuilder mapping.
    regards,
    philipp

  • ADF: How to find out which query has taken what time?

    Hi,
    I have an ADF application which has many SQL queried running on each button click/page load, so how to find out which query is taking what amount of time? So that i can identify the long running queries and modify them to improve the application performance.
    Thanks in advance.

    Hi,
    As suggested by Timo,you need to start tracing on oracle.jbo package for getting the SQL queries.But I think the second option suggested by him would be better.You will have to override executeQueryForCollection method in VO Impl class .Pseudo code would be
    @Override
    Take start time
    super.executeQueryForCollection
    Take end time

  • How to identify what customer exit variables are used in which query?

    Hi all,
    When i happened to check the CMOD transaction code i can find a list of customer exits are used. But i want to know what are those customer exist are used in which query? can anyone let me know the procedure of identifying it.
    Thanks a lot
    Pooja

    hii pooja
    check the foll links
    Very Urgent: Customer Exit Variable
    customer exit variable
    MIssing Authorisation for customer exit variable query
    Authorization variable or customer exit variables
    if it is helpful assign points
    thanks.

  • Which query is running in package

    Hi,
    I created one package and run this package in toad
    like
    select reports_package.func_reports('ABC') from dual;
    I have 10 delete and 10 insert statement on this .
    How I will check which query is running iin database.

    799301 wrote:
    I have 10 delete and 10 insert statement on this .
    How I will check which query is running iin database.V$SESSION_LONGOPS holds information on SQL taking > 6 seconds to run but its not always possible to find expected entries in the V$ views
    If you're trying to figure out what is slow a better bet would be to perform trace or use DBMS_PROFILER to analyze the PL/SQL

  • How to check which query is consuming most resources....

    Hi guys how can i check which query is consuming most resources , run by which user and how to kill that....
    Khurana

    1)     At the first stage, login to the server and at the OS level I run commands like TOP and see the overall performance of the Server. From this one can know the Total CPU Memory, CPU Usage, Memory Available, and Swap Memory Available and how busy the CPU is.
    2)     Once you identify the top processes in the CPU, relate them to ORACLE using V$PROCESS.SPID = OS Process ID to get the V$PROCESS.ADDR and join this with the V$SESSION.PADDR to get the V$SESSION.SID and SERIAL# columns.
    3)     Then enable the Session Trace using DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION.
    4)     look on the Trace File using the TKPROF. During this sort the Trace File using various options like EXEELA/DSK, PRSELA/DSK, FCHELA /DSK.
    5)     Once you identify the expensive SQL statements, inform the user about it and KILL the respective job.

  • Ho do i check bcz of which query's the dead locks happend in 11g

    Hi,
    I am working on 11g database and recently dead locks happend and it's released it's fine. But i need to know becz of which query's the dead locks happend and who fired those query's.
    i hope we can get these info from trace file i opend trace file but am fully confusing how do i know all these details. Can any one help me on this...
    Thanks in advance
    Regards

    Check
    How to find where is deadlock?

  • How to find which query taking more cpu

    Hi,
    How to find which query taking more CPU
    at a particular point of time .
    Chhers,

    Take a look at Server Standard Reports. It has a few CPU usage oriented reports.
    You can also track CPU usage by server-side tracing:
    http://www.sqlusa.com/bestpractices/createtrace/
    Glenn Berry's CPU usage query:
    SELECT TOP(25) p.name AS [SP Name], qs.total_worker_time AS [TotalWorkerTime],
    qs.total_worker_time/qs.execution_count AS [AvgWorkerTime], qs.execution_count,
    ISNULL(qs.execution_count/DATEDIFF(Second, qs.cached_time, GETDATE()), 0) AS [Calls/Second],
    qs.total_elapsed_time, qs.total_elapsed_time/qs.execution_count
    AS [avg_elapsed_time], qs.cached_time
    FROM sys.procedures AS p WITH (NOLOCK)
    INNER JOIN sys.dm_exec_procedure_stats AS qs WITH (NOLOCK)
    ON p.[object_id] = qs.[object_id]
    WHERE qs.database_id = DB_ID()
    ORDER BY qs.total_worker_time DESC OPTION (RECOMPILE);
    LINK:
    http://dba.stackexchange.com/questions/52216/sql-server-2008-high-cpu-historical-queries
    Query optimization:
    http://www.sqlusa.com/articles/query-optimization/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Which is more efficient for includes/imports?

    Which is more efficient?
    1) <jsp:include
    2) <%@ include file
    3) <c:import
    4) Custom tag version (tomcat 5)
    <me:header/>
    header.tag
    navigation html stuff
    Thanks,
    Karmen

    Depends...
    1) <jsp:include -- this is a runtime include. It will embed the included file at runtime.
    2) <%@ include -- this is a compile-time include. It will copy the file's contents into the JSP page when it compiles it into a servlet. Also, typcially it will not recompile the main page if the include file changes, where as #1 above will.
    3) <c:import -- ...well, I don't honestly know what this does.
    4) Custom tag -- what this does clearly depends on what the tag is written to do. But most of the time, this is just going to write some simple HTML stuff out. You could do it that way, but using 1 or 2 to include some HTML or JSP fragment files would probably be better, since it would be easier to maintain.

  • Which query is using which Hierarchy?

    Hello All,
    Where can i get the information like which query is using which hierarchy!?
    I tried to make it happen by combining lot of tables like
    RSRREPDIR
    RSZELTPROP
    RSZELTXREF
    RSHIEDIR
    RSZCOMPDIR
    but couldn't arrive at a solution. Did u guys come across such a situation!?
    If so please brief me how?
    Thanks
    Karthik

    Please see this link for a solution:
    Queries that use a hierarchy
    Hope this helps.
    Regards
    PS: assign points is the way to say thanks

  • How to find which query need to tuned

    Hi ,
    How can i find , which query need to tuned . Is there any mechanism behind it?

    The mechanisms behind it are depending on your database version.
    For example:
    Oracle 9i has STATSPACK that helps you to identify possible problem queries.
    Oracle 10g has AWR - Automatic Workload Repository
    Oracle 11g has SPA - Database Replay SQL Performance Analyzer
    but there are many more tools/mechanisms...trace/tkprof for example.
    Go to http://tahiti.oracle.com and do a search on 'performance tuning guide', and pick the one that matches your (sofar unknown) database version, read a bit every now and then and see what tools are at your disposal and fit your requirement and situation.
    Besides the links that Blu already posted, searches on http://asktom.oracle.com also give lots of pointers and explanations regarding the (neverending) tuning process (at least: helped me tremendously in understanding the tuning process, the do's and dont's).
    Make sure you don't get CTD (Compulsive Tuning Disorder) from all this... ;)

  • Which query is the job running ?

    Dear all,
    Normally when you want to see the currently running query by a session, you can just query the V$Session table and get the SQL_ID of a particular session. Then use SQL_ID to query V$SQL.
    However when a PL/SQL procedure is submitted via a job. You can see in the V$Session that the job runs as a dedicated server session and the SQL_ID is always null. Although I do see always that the session waits for "DB sequential file read". So it means that some query might be getting executed.
    How can I see which query is being run by the job (dedicated server session)?
    Version : 10.1.0.5
    Thanks in advance

    You can try :-
    SELECT sql_id,sql_text FROM v$open_cursor WHERE sid = :1
    http://www.ContractOracle.com

  • Which query is best

    Hi,
    Which query is best interms of performance.
    SELECT NAME
    COUNT(ID) AS CNT,
         RANK() OVER (ORDER BY COUNT(ID) DESC) AS RANK
    FROM TABLE_1
    GROUP BY NAME
    SELECT NAME
    --- COUNT(ID) AS CNT,
         RANK() OVER (ORDER BY COUNT(ID) DESC) AS RANK
    FROM TABLE_1
    GROUP BY NAME

    Which query is best interms of performance. They dont look similar, i.e., in the second query, you have commented out --COUNT.  This will avoid sorting, by the way.
    Do you think both queries gives you the same output?
    you have said in your last reply that you hate full table scans.
    Let me tell you, FTS are always not evils and INDEX scan is not always FASTER.
    it all depends on many factors why optimizer chooses FTS over INDEX scan.
    Jaffar

  • How to find which query ORA-1652: unable to extend temp segment by 128 in

    How can i find which query caused the below error,the query is not running currently
    ORACLE ERRORS IN ALERTS LOG dnb2stg3 - lnx300 on Thu Jun 17 12:10:01 EDT 2010
    1 ORA-1652: unable to extend temp segment by 128 in tablespace TEMP_SCHED
    SQL> select inst_id, tablespace_name, total_blocks, used_blocks, free_blocks from gv$sort_segment;
    INST_ID TABLESPACE_NAME TOTAL_BLOCKS USED_BLOCKS FREE_BLOCKS
    1 TEMP 638336 0 638336
    4 TEMP 565760 0 565760
    4 TEMP_SCHED 16776704 0 16776704
    3 TEMP 484864 0 484864
    3 TEMP_SCHED 0 0 0
    2 TEMP 455808 0 455808
    6 rows selected.
    SQL> SQL> SELECT S.sid || ',' || S.serial# sid_serial, S.username,
    2 T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
    3 T.sqladdr address, Q.hash_value, Q.sql_text
    FROM v$sort_usage T, gv$session S, gv$sqlarea Q, dba_tablespaces TBS
    4 5 WHERE T.session_addr = S.saddr
    6 AND T.sqladdr = Q.address (+)
    7 AND T.tablespace = TBS.tablespace_name
    8 ORDER BY S.sid;
    no rows selected

    Hello,
    You may try to catch the SQL with a Servererror Trigger.
    This link will give you an interesting example:
    http://oratips-ddf.blogspot.com/2008/09/to-err-is-human.html
    Hope this help.
    Best regards,
    Jean-Valentin

Maybe you are looking for

  • Can't create a new SQL Azure Standard Tier db

    I'm having an issue creating a new sql azure standard tier db. Here's the basic steps I've done to migrate a web tier db. Register for the sql preview programme https://account.windowsazure.com/PreviewFeatures Perform a db export to blob storage use

  • How to trace the flow of plsql procedures/functions in oracle 10g

    Hi All, Recently I came to know that there is dbms_hprof PL/SQL built-in package in Oracle 11g which can be used to trace PL/SQL calls in a Hierarchical way. (acts as a PL/SQL Hierarchical Profiler). Steps are given in - http://www.oracle-base.com/ar

  • Service method of servlet is called repeatedly by 9ias

    Problem: when we try to retrieve data for a particular input, then the retrieve query takes longer time which is as expected i.e more than five minutes as our data ware house is large and the where clause is very complex. After 5 mins what happens is

  • Problem in understanding Axis client-side artifacts

    Hi, I created a web service using complex type - Industry & Product as shown below - package com.server; public class Industry {      public int industryID;      public String industryName;      public Product[ ] products; package com.server; public

  • Smart objects generate huge ( 10 GB) temp files ??

    Hi folks. I think there's a bug in CS3's smart object handling. Everytime I move (not resize!) a smart object, the temp file's size increases by some 100-200 MB. I easily get over 10 GB just by moving around a single object repeatedly. I find that qu