In SQL, what’s the difference between count(*) and count('x')? -


this question has answer here:

i have following code:

select <column>, count(*) <table> group <column> having count(*) > 1; 

is there difference results or performance if replace count(*) count('x')?

(this question related previous one)

to select count(*) vs count(1) results in dbms returning "columns" pure bunk. may have been case long, long ago self-respecting query optimizer choose fast method count rows in table - there no performance difference between select count(*), count(1), count('this silly conversation')

moreover, select(1) vs select(*) not have difference in index usage -- dbms optimize select( n ) select(*) anyway. see ask tom: oracle has been optimizing select(n) select(*) better part of decade, if not longer: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::p11_question_id:1156151916789

problem in count(col) count() conversion **03/23/00 05:46 pm *** 1 workaround set event 10122 turn off count(col) ->count() optimization. work around change count(col) count(), means same, when col has not null constraint. bug number 1215372.

one thing note - if using count(col) (don't!) , col marked null, have count number of occurrences in table (either via index scan, histogram, etc. if exist, or full table scan otherwise).

bottom line: if want count of rows in table, use count(*)


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -