Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

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

edited November 2021 in General Discussion

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


  • verbanverban
    edited November 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

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.