Skip to main content
Question

Which query is faster, select count(*) or count(pk)?

  • November 4, 2021
  • 1 reply
  • 2 views

HyeontaeJu
Forum|alt.badge.img+2

Which query is faster, select count(*) or count(pk)?

1 reply

verban
Forum|alt.badge.img+1
  • Participating Frequently
  • November 8, 2021

Definitely select count(1) is too much faster,
The count(pk) is equal to select count(1) where pk is not null,
In my case select count(1) takes 200ms but the select count(id) takes more than 20 seconds (the table has more than 10B records)!
Also i think select count(1) and select count(*) are same