Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Which is faster

This is a discussion on Which is faster within the SQL forums, part of the Databases category; 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...

Go Back   Geeks Talk > Databases > SQL
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 10-23-2007
Expert Member
 
Join Date: Feb 2007
Posts: 1,279
Thanks: 0
Thanked 192 Times in 154 Posts
Geek_Guest has a spectacular aura aboutGeek_Guest has a spectacular aura aboutGeek_Guest has a spectacular aura about
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
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-24-2007
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,853
Thanks: 9
Thanked 168 Times in 142 Posts
debasisdas has a spectacular aura aboutdebasisdas has a spectacular aura about
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.
Reply With Quote
  #3 (permalink)  
Old 02-12-2008
Junior Member
 
Join Date: Feb 2008
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
expertsharingdotcom is on a distinguished road
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.
Reply With Quote
  #4 (permalink)  
Old 09-22-2008
Junior Member
 
Join Date: Sep 2008
Location: NOIDA
Posts: 12
Thanks: 1
Thanked 1 Time in 1 Post
aditi14 is on a distinguished road
Re: Which is faster

its a good ans
Reply With Quote
  #5 (permalink)  
Old 09-30-2008
Junior Member
 
Join Date: Sep 2008
Location: Pune
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
pacifier is on a distinguished road
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
Reply With Quote
Reply

  Geeks Talk > Databases > SQL

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Which frog is faster? jamesravid Aptitude Skills 13 01-29-2009 02:37 AM
Running 3 JCL is much more faster than one JCL with three steps altehexe74 MainFrame 1 06-11-2007 03:49 PM
How many minutes was his clock faster? jainbrijesh Brainteasers 5 05-10-2007 06:15 AM
Faster technique for Manual Software testing JobHelper Testing Issues 2 02-12-2007 06:53 AM


All times are GMT -4. The time now is 02:30 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved