Ticket #824 (closed enhancement: duplicate)
Specify needed fields on demand in ActiveRecord
| Reported by: | rogerjose81 | Owned by: | xue |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1.3 |
| Component: | Prado Framework v3 | Version: | 3.1 |
| Severity: | minor | Keywords: | TActiveRecordCriteria |
| Cc: |
Description
"Would be very useful to extend TActiveRecordCriteria with a (get|set) SelectFields? method, so we can specify the needed fields on demand, getting as a result, better performance in cases where the table of the database has many fields, and we only need to read only one, or some of these fields.
By example:
Code:
$selectFields = array('id', 'name');
$criteria = new TActiveRecordCriteria();
$criteria->SelectFields = $selectFields;
This would give us the possibility to very easily manipulate the select fields and also it would be quite easy to generate the proper field select string for the query using the PHP implode function. If no SelectFields? are specified we just use the asterisk as selector and we'd be 100% compatible to any existing code.
I also see two advantages here which i forgot to mention in my previous posts on this topic:
The first (and IMHO most important) advantage would be the saving of a lot of memory on the database. Think about working on a table with lets say 30 fields and a few million records. If we just request two of these fields, the resultset (which every database server stores in memory before transmitting it to the database client) would shrink by about 93% which directly translates into reduced memory consumption by 93% compared to requesting all 30 fields. It also would increase the performance by a pretty huge factor as we would transfer far less data from the database server to the database client and the latter would have to handle far less data aswell.
The second advantage would be the possibility to do things like this: Code:
$criteria->SelectFields = array('count(*) as sum');
This functionality should be pretty easy to implement, but unfortunately i am very busy at the moment with a Typo3 project which consumes almost all my time."
Submit by rojaro on post http://www.pradosoft.com/forum/index.php/topic,9786.msg43599.html#msg43599
