Which query is faster?

Hi everyone!
I have two query get the same number of records in a table below:
Query 1:
SELECT
FROM
SELECT
SUM(
CASE
WHEN TYPE = '1' THEN Amount
WHEN TYPE = '2' THEN Amount
ELSE 0
END
) Result
FROM
C_BPARTNER
WHERE Result > 0
Query 2:
SELECT
SUM(Amount)
FROM
SELECT
Amount
FROM
C_BPARTNER
WHERE
TYPE = '1'
UNION ALL
SELECT
Amount
FROM
C_BPARTNER
WHERE
TYPE = '2'
I have data in table C_BPARTNER like below:
TYPE Amount
1 100
2 200
3 300
4 400
Can you tell me know which is faster?
Thanks a lot!
Edited by: user12282721 on Nov 24, 2010 7:25 AM
Edited by: user12282721 on Nov 24, 2010 7:27 AM
Edited by: user12282721 on Nov 24, 2010 7:32 AM

user12282721 wrote:
Can you tell me know which is faster?
Sure, you just need to supply your table creation scripts and your data in the form of insert statements and the information requested in these threads -
HOW TO: Post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
When your query takes too long
When your query takes too long ...
Alternately you could just run them yourself.

Similar Messages

  • Which query is faster to run

    I want to use Oracle locator to find customers in a specified area. Which of the ideas on this page is a faster query? The idea where you add the SDO_Geometry column with long and lat to each address record or the index based function idea where no column needs to be added but a table with long and lats is used? thanks.

    user8602786 wrote:
    I want to use Oracle locator to find customers in a specified area. Which of the ideas on this page is a faster query? The idea where you add the SDO_Geometry column with long and lat to each address record or the index based function idea where no column needs to be added but a table with long and lats is used? thanks.Why don't you try them both out and let us know?

  • Which query will work fast

    Hi,
    Can anybody please suggest which query will work fast
    distinct role_cd is 1,2,3,4 and null in product table
    select * from product
    where nvl(role_cd,'4') not in '4'
    select * from product
    where role_cd in('1','2','3')
    I have 13 millions record in this table and there is no index on role_cd

    I tried this (11gR2) and get below, but still not sure if it is safe to say that the second one is better:
    create table product (role_cd char(2), id number);
    begin
    dbms_stats.set_table_stats( user, 'PRODUCT', numrows => 13000000 );
    end;
    explain plan for 
    select * from product where nvl(role_cd,'4') not in '4';
    Plan hash value: 427209646
    | Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |         |   650K|    10M|   319  (91)| 00:00:04 |
    |*  1 |  TABLE ACCESS FULL| PRODUCT |   650K|    10M|   319  (91)| 00:00:04 |
    Predicate Information (identified by operation id):
       1 - filter(NVL("ROLE_CD",'4')<>'4')
    explain plan for 
    select * from product where role_cd in('1','2','3');
    Plan hash value: 427209646
    | Id  | Operation         | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |         |   130K|  2158K|   287  (90)| 00:00:04 |
    |*  1 |  TABLE ACCESS FULL| PRODUCT |   130K|  2158K|   287  (90)| 00:00:04 |
    Predicate Information (identified by operation id):
       1 - filter("ROLE_CD"='1' OR "ROLE_CD"='2' OR "ROLE_CD"='3')

  • What are the ways to make Query run fast?

    Hi Experts,
    When a query runs slow, we generally go for creating an aggregate. My doubt is - what other things can be done to make a query run faster before creating an aggregate? What is the thumb rule to be carried out for creating an aggregate?
    Regards,
    Shreeem

    Hi Shreem,
    If you keep Query simple not complicate it with runtime calculations , it would be smooth. However as per business requirements we will have to go for it anyways mostly.
    regarding aggregates:
    Please do not use the standard proposal , it will give you hundreds based on std. rules , which consumes lots of space and adds up to load times. If you have users already using the Query and you are planning to tune it  then go for the statistics tables:
    1.RSDDSTAT_OLAP    find the query with long runtimes  get the Stepuid
    2. RSDDSTAT_DM
    3. RSDDSTATAGGRDEF  - use the stepuid above to see which aggregate is necessary for which cube.
    Another way to check ; check the users as in 1 to find the highest runtime users and find the last used bookmarks by user thru RSZWBOOKMARK for this query and check if the time matches and create the aggregates as in 3 above.
    You can also Use Transaction RSRT > execute & debug  (display stats ) - to create generic aggregates to support navigations for New queries and later refine as above.
    Hope it helps .
    Thnks
    Ram

  • Strange problem... Query runs faster, but report runs slow...

    Hi Gurus,
    We are using Report 10g on 10g Application server and solaris. we created a report on a table which has 10,000 rows. The report has 25 columns. when we run this query in Toad it took 12 sec for fetching all these 10,000 rows
    But when we run the report with Destype = 'FILE' and Desformat = 'DELIMITEDDDATA', it is taking 5 to 8 minutes
    to open in excel ( we concatenated mimetype=vnd-msexcel at the end of the url if the Destype=FILE). We removed the layout in the report as it is taking 10 to 15 mins to run to Screen with Desformat=HTML/PDF(formating pages taking more time). We are wondering why DELIMITEDDATA format is taking long time as it runs only query.
    Does RWSERVLET take more time of writing the data to the Physical file in the cache dir? Our cache size is 1 GB. we have 2 report servers clustered. Tracing is off.
    Please advise me if there are any report server settings to boost the performance.
    Thanks alot,
    Ram.

    Duplicate of Strange problem... Query runs faster, but report runs slow... in the Reports forum.
    [Thread closed]

  • 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

  • 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.

  • Query on fast moving items

    Hi Experts,
    Do you have any query on fast moving items based on A/R Reserve Invoice? Also this should have date parameters.
    Thanks,
    Don

    Hi Gordon,
    The condition is quite vague. But can we generate a query on the no. of transactions of the items based on A/R Invoices and based on a from/to date parameters?
    Thanks.
    Don

  • 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?

  • Does SQL Query run faster with/without Conditions....

    Hi All, forgive my novice question.
    Was just wondering" In general if we run a SQL query on a single table; does my query run faster if there are multiple where conditions? or without. What happens if the conditions increase? My table is a big one with 5 million rows and some bitmap indexes defined on it.
    Thanks,
    Kon

    I think it's difficult to give general rule because there are too much dependencies on the fact that the columns are indexed or not, on the way tables and indexes statistics are computed or not, on the possible session or instance parameters that the optimizer may use, on the Oracle version, etc.
    Message was edited by:
    Pierre Forstmann

  • 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

  • Updated to LR 5.4, images now importing extremely slow. After importing and rendering images are still very slow to go through and develop. No issues in LR 5.3 which was very fast.

    After importing and rendering images are still very slow to go through and develop. No issues in LR 5.3 which was very fast. Canon,Nikon, Leica and Fuji files all rendering slow. iMac 2.9 ghz 16gb RAM OSX 10.8.5. Catalogs and images are kept on external drives. Drives running fine. Really need a fix on this since I'm norally imported and processing at least 4,000 images per LR Catalog. Is there way to revert back to 5.3? I can't use 5.4 is its current state. Thanks.

    Download LR 5.3 and install it
    By the way, lots of people have this complaint about LR 5.4, and the advice I give is to use LR 5.3 unless you need one of the new camera models supported by LR 5.4

Maybe you are looking for