sql - mysql select count(*) with where scan full table? -


i have innodb table 100m records this:

id    name   pid cid createdat int   char   int int timestamp 

id pk, , pid indexed: key

the query select count(*) table1 pid='pid'

my question query full table scanning?

count(*) want.

the count function counts rows not null, count(name) counts records name field not null example. if field being counted not indexed results in full table scan.

in case of count(*) database counts records have @ least 1 non null field, ie excludes records of fields null. might want, people incorrectly use form when want count of records regardless of content.

the efficient way of counting of records without database specific syntax count(1). works because value 1 not null every record, , not require data read database.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -