Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Count(*) Vs Count(1)

RE: Count(*) Vs Count(1)

From: Kimberly Smith <kimberly.smith_at_gmd.fujitsu.com>
Date: Mon, 18 Dec 2000 09:24:52 -0800
Message-Id: <10714.124851@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------_=_NextPart_001_01C06917.6E668270
Content-Type: text/plain;

        charset="iso-8859-1"

I went though a whole discussion on this a while back and between myself and the list it came down to it depends on which version of Oracle you are using but they have indeed optimized for count(*). This was determined by many of us actually running tests with timing. -----Original Message-----
From: Abdul Aleem [mailto:abchaudhary-ho_at_beaconhouse.edu.pk] Sent: Sunday, December 17, 2000 11:46 PM To: Multiple recipients of list ORACLE-L Subject: RE: Count(*) Vs Count(1)

Some where in Oracle Documentation I remember reading that Oracle encouraged using Count(1) over Count(*).
HTH!
Aleem  

-----Original Message-----
From: Sanjay Kumar [mailto:ora_user_at_hotmail.com] Sent: Saturday, December 16, 2000 12:51 AM To: Multiple recipients of list ORACLE-L Subject: Count(*) Vs Count(1)  

Hi,  

I issed the following two statements and generated a plan using Explain Plan. The table on which I tried this query was v$cache.  

Select Count(*) from v$cache  

Select Count(1) from v$cache  

I found that the explain plan generated the same plan for both the statements. Does that mean that both the statements are equally efficient.  

In my opinion, I feel that Count(1) is better than Count(*).  

Kindly explain.  

Thanks
Rgds
Sanjay

------_=_NextPart_001_01C06917.6E668270
Content-Type: text/html;

        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML xmlns=3D"http://www.w3.org/TR/REC-html40" xmlns:v =3D=20

"urn:schemas-microsoft-com:vml" xmlns:o =3D=20
"urn:schemas-microsoft-com:office:office" xmlns:w =3D=20
"urn:schemas-microsoft-com:office:word"><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Diso-8859-1">
<META content=3DWord.Document name=3DProgId>
<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR>
<META content=3D"Microsoft Word 9" name=3DOriginator><LINK=20
href=3D"cid:filelist.xml_at_01C068C9.C60B04E0" rel=3DFile-List><!--[if gte = mso 9]><xml>
 <o:OfficeDocumentSettings>
<o:DoNotRelyOnCSS/>

 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>  <w:WordDocument>
<w:Zoom>0</w:Zoom>
<w:DocumentKind>DocumentEmail</w:DocumentKind>
<w:EnvelopeVis/>

 </w:WordDocument>
</xml><![endif]-->
<STYLE>@font-face {

        font-family: Tahoma;
}
P.MsoNormal {

        FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; = mso-style-parent: ""; mso-pagination: widow-orphan; = mso-fareast-font-family: "Times New Roman" }
LI.MsoNormal {

        FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; = mso-style-parent: ""; mso-pagination: widow-orphan; = mso-fareast-font-family: "Times New Roman" }
DIV.MsoNormal {

        FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; = mso-style-parent: ""; mso-pagination: widow-orphan; = mso-fareast-font-family: "Times New Roman" }
P.MsoAutoSig {

        FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; = mso-pagination: widow-orphan; mso-fareast-font-family: "Times New = Roman"
}
LI.MsoAutoSig {

        FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; = mso-pagination: widow-orphan; mso-fareast-font-family: "Times New = Roman"
}
DIV.MsoAutoSig {

        FONT-FAMILY: "Times New Roman"; FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; = mso-pagination: widow-orphan; mso-fareast-font-family: "Times New = Roman"
}
SPAN.EmailStyle15 {

        COLOR: navy; mso-style-type: personal-reply; mso-ansi-font-size: = 10.0pt; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; = mso-bidi-font-family: Arial
}
DIV.Section1 {

        page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext=3D"edit" spidmax=3D"1027"/> </xml><![endif]--><!--[if gte mso 9]><xml>  <o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1"/>

 </o:shapelayout></xml><![endif]--></HEAD> <BODY bgColor=3Dwhite lang=3DEN-US style=3D"tab-interval: .5in"> <DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN = class=3D133222117-18122000>I went=20
though a whole discussion on this a while back and between=20 myself</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN = class=3D133222117-18122000>and=20
the list it came down to it depends on which version of Oracle you=20 </SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN = class=3D133222117-18122000>are=20
using but they have indeed optimized for count(*).&nbsp; This was=20 determined</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN = class=3D133222117-18122000>by=20
many of us actually running tests with timing.</SPAN></FONT></DIV> <BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
<DIV align=3Dleft class=3DOutlookMessageHeader dir=3Dltr><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B> Abdul Aleem=20   [mailto:abchaudhary-ho_at_beaconhouse.edu.pk]<BR><B>Sent:</B> Sunday, = December=20
  17, 2000 11:46 PM<BR><B>To:</B> Multiple recipients of list=20   ORACLE-L<BR><B>Subject:</B> RE: Count(*) Vs = Count(1)<BR><BR></DIV></FONT>
<DIV class=3DSection1>
<P class=3DMsoNormal><SPAN class=3DEmailStyle15><FONT color=3Dnavy =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-bidi-font-size: = 12.0pt">Some=20
  where in Oracle Documentation I remember reading that Oracle = encouraged using=20
  Count(1) over Count(*).<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal><SPAN class=3DEmailStyle15><FONT color=3Dnavy =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-bidi-font-size: = 12.0pt">HTH!<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal><SPAN class=3DEmailStyle15><FONT color=3Dnavy =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-bidi-font-size: = 12.0pt">Aleem<o:p></o:p></SPAN></FONT></SPAN></P>
<P class=3DMsoNormal><SPAN class=3DEmailStyle15><FONT color=3Dnavy =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-bidi-font-size: = 12.0pt"><![if =
!supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></SPAN></FONT></SPAN></P>=

<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DTahoma=20
  size=3D2><SPAN=20
  style=3D"COLOR: black; FONT-FAMILY: Tahoma; FONT-SIZE: = 10pt">-----Original=20
  Message-----<BR><B><SPAN style=3D"FONT-WEIGHT: bold">From:</SPAN></B> = Sanjay=20
  Kumar [mailto:ora_user_at_hotmail.com]<BR><B><SPAN=20   style=3D"FONT-WEIGHT: bold">Sent:</SPAN></B> Saturday, December 16, = 2000 12:51=20
  AM<BR><B><SPAN style=3D"FONT-WEIGHT: bold">To:</SPAN></B> Multiple = recipients of=20
  list ORACLE-L<BR><B><SPAN style=3D"FONT-WEIGHT: = bold">Subject:</SPAN></B>=20
  Count(*) Vs Count(1)</SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT face=3D"Times =
New Roman"=20
  size=3D3><SPAN style=3D"FONT-SIZE: 12pt"><![if = !supportEmptyParas]>&nbsp;<![endif]><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">Hi,</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">I issed=20
  the following two statements and generated a plan using Explain Plan. = The=20
  table on which I tried this query was v$cache.</SPAN></FONT><FONT=20   color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">Select=20
  Count(*) from v$cache</SPAN></FONT><FONT color=3Dblack><SPAN=20   style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">Select=20
  Count(1) from v$cache</SPAN></FONT><FONT color=3Dblack><SPAN=20   style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">I found=20
  that the explain plan generated the same plan for both the = statements. Does=20
  that mean that both the statements are equally = efficient.</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">In my=20
  opinion, I feel that Count(1) is better than = Count(*).</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">Kindly=20
  explain.</SPAN></FONT><FONT color=3Dblack><SPAN=20   style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =

  face=3D"Times New Roman" size=3D3><SPAN=20

  style=3D"COLOR: black; FONT-SIZE: 12pt">&nbsp;</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: =
windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">Thanks</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
face=3DArial=20
  size=3D2><SPAN=20
  style=3D"COLOR: black; FONT-FAMILY: Arial; FONT-SIZE: = 10pt">Rgds</SPAN></FONT><FONT=20
  color=3Dblack><SPAN=20
  style=3D"COLOR: black; mso-color-alt: = windowtext"><o:p></o:p></SPAN></FONT></P>
<P class=3DMsoNormal style=3D"MARGIN-LEFT: 0.5in"><FONT color=3Dblack =
Received on Mon Dec 18 2000 - 11:24:52 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US