Results 1 to 5 of 5

Thread: Which is faster

  1. #1
    Geek_Guest
    Guest

    Which is faster

    Which is faster and why among below;

    select count(*) from T1
    select count(1) from T1
    select count(PK) from T1

    Question asked by visitor sant


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Which is faster

    All the three will give you same performance. But there will be difference if you are using oracle version 8 or before.
    In that case 2nd wil be faster than 1st. and 3rd will be the fastest.

    Find the details here.


  3. #3

    Re: Which is faster

    it actually depends upon whether your table is having any primary key ? if there is any primary key ,then an associated index would be there . if there is an primary key in a table oracle only counts nodes in the index

    my answer is

    if the first column is primary key then all the three queries performance would be the same.

    if the first column is not a primary key then query 1 and query 3 will result in same performance (using index). But query 2 will lag.


  4. #4
    Junior Member
    Join Date
    Sep 2008
    Answers
    18

    Re: Which is faster

    its a good ans


  5. #5
    Junior Member
    Join Date
    Sep 2008
    Answers
    7

    Re: Which is faster

    I dont think so I would like to explain with example
    suppose that I have written following qyuery for the emp table
    select count(*) from emp;
    this will always take more time.....just because it will have to
    retrive all the fields of the emp table.........

    But Instead you have written the query as
    select count(1) from emp;
    it will only retirve the data about the first column so it woould
    surely be faste compared to the prevoius one.........

    as far as primary key is concerned it will always be faster cause
    by deafult the oracle assign the index to the primary key......
    so it will again be faster than previous one........

    but for this particular query there is no condition specified so
    again it will have the same performance as the first query

    but I think second one will be faster


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact