473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

count (1) and count (*)

I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.
Jul 19 '05 #1
6 34425

"Geetha" <ge******@hotmail.com> wrote in message
news:4b**************************@posting.google.c om...
I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.

There is a myth out there that count(1) is faster than count(*). It isn't
true. Use count(*).(You can look it up on asktom.oracle.com)
Jim
Jul 19 '05 #2
it used to be true prior to somewhere in v7 -- should not be true anymore,
but it's always good to do an EXPLAIN PLAN or SET AUTOTRACE ON to make sure

-- mcs

"Jim Kennedy" <ke****************************@attbi.net> wrote in message
news:H1Rnb.40108$mZ5.224243@attbi_s54...

"Geetha" <ge******@hotmail.com> wrote in message
news:4b**************************@posting.google.c om...
I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.

There is a myth out there that count(1) is faster than count(*). It isn't
true. Use count(*).(You can look it up on asktom.oracle.com)
Jim

Jul 19 '05 #3
Jim Kennedy wrote:
"Geetha" <ge******@hotmail.com> wrote in message
news:4b**************************@posting.google.c om...
I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.


There is a myth out there that count(1) is faster than count(*). It isn't
true. Use count(*).(You can look it up on asktom.oracle.com)
Jim

Well, as it is a myth, you might just as well count(1) ;-)
As long as you do not expect (or -even worse- explain!) it
to be faster

--
Regards, Frank van Bortel

Jul 19 '05 #4
I read somewhere (asktom?) that "select count(1) from table" is
internally rewritten as "select count(*) from (select 1 from table)",
and therefore just adds some overhead.

Daniel

ge******@hotmail.com (Geetha) wrote in message news:<4b**************************@posting.google. com>...
I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.

Jul 19 '05 #5
Daniel Roy wrote:
I read somewhere (asktom?) that "select count(1) from table" is
internally rewritten as "select count(*) from (select 1 from table)",
and therefore just adds some overhead.

Daniel

ge******@hotmail.com (Geetha) wrote in message news:<4b**************************@posting.google. com>...
I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.


NO!
Actually Tom wrote:
"Prove it, give me that test case. You are wrong.
COUNT(*) and COUNT(1) are the *same* -- the same -- the same -- no
different, the same.
count(1) is internally optimized to count(*) "

And he posted the explain plans for count(*) and count(1).

--
Regards, Frank van Bortel

Jul 19 '05 #6
Thanx Frank for the correction. I now remember that it was in a Google
thread that I saw this. But as Tom Kyte mentioned on the thread you
quote, it used to be that select count(*) and select count(1) were
treated differently, in versions 7 and lower. That's probably why I
saw that comment on an old Google thread about how differently they're
treated.

Daniel

Daniel Roy wrote:
I read somewhere (asktom?) that "select count(1) from table" is
internally rewritten as "select count(*) from (select 1 from table)",
and therefore just adds some overhead.

Daniel

ge******@hotmail.com (Geetha) wrote in message news:<4b**************************@posting.google. com>...
I searched in the Oracle documents what count (1) meant and I could
not find an answer. Can some one explain what Oracle does internally
when use count (1) VS count (*). Thank you very much in advance! We
use Oracle 9i.


NO!
Actually Tom wrote:
"Prove it, give me that test case. You are wrong.
COUNT(*) and COUNT(1) are the *same* -- the same -- the same -- no
different, the same.
count(1) is internally optimized to count(*) "

And he posted the explain plans for count(*) and count(1).

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
1
by: JD | last post by:
Hi guys I'm trying to write a program that counts the occurrences of HTML tags in a text file. This is what I have so far: #include <stdio.h> #include <stdlib.h> #include <string.h> ...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
23
by: Gary Wessle | last post by:
Hi I have a vector<charwhich looks like this (a d d d a d s g e d d d d d k) I need to get the biggest count of consecutive 'd'. 5 in this example I am toying with this method but not sure if...
1
by: heckstein | last post by:
I am working in Access 2002 and trying to create a report from our company's learming management system. I am not a DBA and most of my SQL knowledge has been self taught through trial and error. I...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
7
by: Chris | last post by:
I am trying to increase/decrease the value of $_SESSION by 1 after clicking on a link e.g index.php?gotoWk=nxtWk and index.php? gotoWk=lstWk. I'm sure you will get the drift if you look at the code...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.