difference between count(*) and count(1)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ratnababunarne
    New Member
    • May 2007
    • 4

    difference between count(*) and count(1)

    difference between count(*) and count(1)
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Please dont post questions in Article section

    I am moving it to Oracle Forum

    Comment

    • frozenmist
      Recognized Expert New Member
      • May 2007
      • 179

      #3
      Hi,

      Both perform the same function, to get the number of rows returned by the query.
      But performance wise count(1) is better as count(*) retrieves all columns and counts the rows, where as count(1) retrieves 1's whenever a row is there.

      Cheers

      Comment

      • Medhatithi
        New Member
        • Mar 2007
        • 33

        #4
        Originally posted by frozenmist
        Hi,

        Both perform the same function, to get the number of rows returned by the query.
        But performance wise count(1) is better as count(*) retrieves all columns and counts the rows, where as count(1) retrieves 1's whenever a row is there.

        Cheers
        Tom Kyte said about it correctly, there was a version where it did make a difference (6, early 7 maybe) and thus a myth was born. According to Tom, the parser is now coded so that count(1) and count(*) use exactly the same code path so any differences you see between the two would occur on multiple runs of the same statement, i.e. they are caused by external events.

        Comment

        Working...