Hi softark. Thank you for the response. I read from the yii guide. It says:
[b][i]Do not overuse Active Record. Although Active Record is good at modelling data in an
OOP fashion, it actually degrades performance due to the fact that it needs to create one
or several objects to represent each row of query result. For data intensive applications,
using DAO or database APIs at lower level could be a better choice.
Last but not least, use LIMIT in your SELECT queries. This avoids fetching overwhelming
data from database and exhausting the memory allocated to PHP.[/i][/b]
This is the reason why i think i should use CArrayDataProvider over CActiveDataProvider for complex query. But i don’t know how to do it with CArrayDataProvider. Can you show me simple code that show the use of CArrayDataProvider and CGridView?
As I said, CArrayDataProvider is, well, far less efficient and convenient than CActiveDataProvider when you fetch data from database using SQL. You may consider using CSqlDataProvider if you are serious about the performance, but there’s no reason at all to stick to CArrayDataProvider.
The following is a very rough sketch about their pros and cons.
The worst thing about CArrayDataProvider is that you have to supply all the data that matches the given conditions (not only those for the current page). Otherwise the pagination and the sorting won’t work. It’s because CArrayDataProvider needs a raw data array as a whole on which it executes the sorting and the paginating.
On the other hand, CActiveDataProvider and CSqlDataProvider fetch only the data for the current page from database, because they construct OFFSET and LIMIT automatically according to the instruction of the pager. And the sorting is executed in SQL. So the fetched data is already sorted and paginated.
IMO, 80% or 90% of the database related jobs can be handled quite effectively and easily using CActiveRecord or CActiveDataProvider without any performance problem. I usually take this way.
Sometimes I use DAO for performance reason, but not very often.
And it’s true that sometimes you have to use CArrayDataProvider when the data set can’t be acquired solely by SQL. (For example, a scheduler for a group … X axis for dates and Y axis for persons … will be difficult for CActiveDataProvider or CSqlDataProvider)