[Solar-talk] select '*' vs. select $cols

Paul M Jones pmjones at ciaweb.net
Thu Feb 8 10:25:09 PST 2007


On Feb 8, 2007, at 12:08 PM, Rodrigo Moraes wrote:

> Hey,
>
> I made some benchmarks comparing selecting an entire row of data and
> some columns. I've been taking care of selecting only what is needed
> in a database, because it results in big performance improvements in
> most common cases. Here's the benchmark:
>
>     http://solarphp.org/wiki/SandBox
>     (needed to format it; didn't knew where to place it; well - it's
> on the sand box)
>
> In many cases you only need a partial row to display a list, or to get
> a simple data from a foreign table; normally I only need the entire
> row when it is being edited. Besides caching and having good indexes,
> this is the biggest performance improvement I'm aware of.
>
> This is of course just to reinforce my request to add the possibility
> to select columns is the new Solar_Model. Please let me know if I'm
> missing something and this is not necessary. :)

Good man for benching!  :-)

One point:  the speed issue is not '*'/14 cols vs only 3 cols; it  
makes sense that selecting fewer cols is going to be faster.  I'd be  
more interested to see the speed diff between '*' and a list of all  
14 cols.

Second point: in the new Model, the relation definition allows you to  
specify which cols are selected from the foreign model.  However, the  
fetchAll()/fetchOne() on the Model itself still returns all the table  
cols.

Are you suggesting that fetchAll(), fetchOne(), etc. should let you  
specify which columns are to be selected on a per-call basis?

If so, I think those methods will need to start using an array for  
their params.  For example, right now, fetchAll() looks like this:

     public function fetchAll($where, $order, $page)

To facilitate a more workable collection of params, maybe we should  
do something like this:

     public function fetchAll($params = array())

The $params would be an array keyed on 'where', 'order', 'page',  
'cols', etc.  The we don't have to worry about the order in which  
parameters appear.

Would that make sense at all?


--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.  <http://solarphp.com>

Join the Solar community wiki!  <http://solarphp.org>

Savant: The simple, elegant, and powerful solution for
templates in PHP.  <http://phpsavant.com>




More information about the solar-talk mailing list