-
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
-
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.
-
Junior Member
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.
-
Junior Member
-
Junior Member
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
-
Forum Rules