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

performance of Phalcon\Mvc\Model\Resultset\Simple

Hi,

I am studying the performance of ways of getting rows from database: 1. Phalcon\Mvc\Model\Resultset\Simple and 2. Phalcon\Db\Result\Pdo, and I would like to know the performance of each of the ways.

1. Phalcon\Mvc\Model\Resultset\Simple: The ways from https://docs.phalcon.io/en/latest/reference/models.html and https://docs.phalcon.io/en/latest/reference/phql.html will return the Phalcon\Mvc\Model\Resultset\Simple object, we may (thanks @Jurigag pointing it out) get object of model when we loop this Phalcon\Mvc\Model\Resultset\Simple object, then I suspect the performance of getting rows from database in such way because each object of model is huge.

2. Phalcon\Db\Result\Pdo: The ways from https://docs.phalcon.io/en/latest/api/Phalcon_Db_Result_Pdo.html return the Phalcon\Db\Result\Pdo object and we get object of stdClass from each fetch in the while loop; the object of stdClass is tremendously smaller than object of model. I guess we have already gotten all the rows from the database by the $connection->query("SELECT * FROM robots ORDER BY name") execution (please correct me if I am wrong) and the fetch is not connecting to the database in each loop.

Let's say there are a large number of rows to get, is doing 2 obviously quicker than doing 1? Or in general, when we are getting and using rows from database, what way would be the fastest?

Thanks in advance


update:

I guess I am just stupid. @Jurigag reminds me that there may be ways to avoid getting object of model when getting rows from database; with that consideration, I guess the raw PHQL method provided in https://docs.phalcon.io/en/latest/reference/phql.html#using-raw-sql is not intended for mere display purpose but to take advantage of the Phalcon model object.

Resultset\Simple is the resultset of simple objects(not full model object, like selecting columns). If you dont select columns then you have resultset of full models.



25.7k
edited Nov '15

Thank you for your reply.

Please allow me to add a note here to clarify that the result of method (selected column(s)) like $phql = "SELECT c.id, c.name FROM Cars AS c ORDER BY c.name"; $cars = $manager->executeQuery($phql); will give us Phalcon\Mvc\Model\Row object in each loop.

Resultset\Simple is the resultset of simple objects(not full model object, like selecting columns). If you dont select columns then you have resultset of full models.