We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Count many rows

If I were to count let's say, maybe millions of rows how would you do it?

Let's say i have 10 million rows and 1 million of them is the country "Germany"

And i would run a query "Count(*) as count group by country = Germany"

Would that be bad or can the server handle it?

Thanks!

edited Sep '15

From the documentation you can use count as a prefix in a model query: https://docs.phalcon.io/en/latest/reference/models.html

<?php

// How many employees are in the Testing area?
$rowcount = Employees::count(
    "area = 'Testing'"
);

You would just need to modify for your model. Model::count("country = 'Germany'");

But my question was, can my server handle that request if there is a million rows with country "Germany" ?

It can, but you can better add an index to speed up the query: https://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

Thank you! :-)