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.