Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To say that <code>SELECT COUNT(*) vs COUNT(1)</code> results in your DBMS returning "columns" is pure bunk. That <em>may</em> have been the case long, long ago but any self-respecting query optimizer will choose some fast method to count the rows in the table - there is <strong>NO</strong> performance difference between <code>SELECT COUNT(*), COUNT(1), COUNT('this is a silly conversation')</code></p> <p>Moreover, <code>SELECT(1) vs SELECT(*)</code> will NOT have any difference in INDEX usage -- most DBMS will actually optimize <code>SELECT( n ) into SELECT(*)</code> anyway. See the ASK TOM: Oracle has been optimizing <code>SELECT(n) into SELECT(*)</code> for the better part of a decade, if not longer: <a href="http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156151916789" rel="noreferrer">http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156151916789</a></p> <blockquote> <p>problem is in count(col) to count(<em>) conversion <strong></em> **03/23/00</strong> 05:46 pm *** one workaround is to set event 10122 to turn off count(col) ->count(<em>) optimization. Another work around is to change the count(col) to count(</em>), it means the same, when the col has a NOT NULL constraint. The bug number is 1215372.</p> </blockquote> <p>One thing to note - if you are using COUNT(col) (don't!) and col is marked NULL, then it will actually have to count the number of occurrences in the table (either via index scan, histogram, etc. if they exist, or a full table scan otherwise). </p> <p>Bottom line: if what you want is the count of rows in a table, use COUNT(*)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload