You are here: Re: Aggregate/Scalar or via code? « All PHP « IT news, forums, messages
Re: Aggregate/Scalar or via code?

Posted by Juliette on 08/21/06 08:14

-Lost wrote:
> I hope that is not too vague of a question.
>
> I have begun taking a database class in school, which is where this question spawned from.
>
> If I were to use the aggregate or scalar functions for example, are they preferred over
> using code (such as PHP, VB/ASP et cetera)?
>
> An example of this is:
>
> SELECT AVG(column_name) FROM table_name
>
> ...whereas with PHP it would be:
>
> // retrieve the entire column via a query, then
>
> function average($_array_of_average_inputs)
> {
> return array_sum($_array_of_average_inputs) / count($_array_of_average_inputs);
> }
>
> $avg = average($average_array);
>
> ...and on and on. Or something like:
>
> SELECT UCASE(column_name) FROM table_name
>
> ...whereas with PHP it would be:
>
> // retrieve the entire column via a query, then
>
> $final_result = strtoupper($ascii_results_of_query);
>
> So, sorry if I rambled on a bit. As per the norm I am tired as hell and its 4AM. I just
> want to figure out (or learn) which is faster. Do the operation via SQL if possible and
> then store it, or issue vanilla queries and do everything myself with code.
>
> Thanks and sorry for the incoherence (if any exists)!
>
> -Lost
>
>


No one answer... it depends on numerous things, amongst which are:

1) sql query complexity - I presume you just gave the above as simple
examples
2) expected number of rows which may be returned
3) sql table setup - have indexes been defined and are they efficient ?
4) will you be doing other processing of the results within php ?
etc etc

Start by reading up on the SQL EXPLAIN syntax and meaning of the results
you get with that. DevShed has recently published some educational
tutorials about this.

Next start doing benchmarks on various implementations as everything
depends on how you implement it.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация