473,378 Members | 1,421 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,378 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 34422

"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.