RE: php / mysql performance resources

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'll throw in my suggestion here as to how I implement this.

Generally I evaluate how big are the tables and what do I intend to do
with them. 

Sorting is usually a "problem". Using the PHP multi_sort seems
cumbersome and never seems to be as simple as letting the DB do it.

I too use LEFT JOINs frequently.

If I have to join more than say 4 or 5 tables, I start to break it up.

My favorite little trick is to load a PHP array with smaller tables.

[Pseudocoded:]

$employeeType = array( "SELECT id, name FROM employee_type_table" );

And I might do this for several tables.

(you can also store these in a $_SESSION if you're using these
key/values frequently on different pages)

Then this can effectively eliminate one whole join (per), as most tables
key off of ID's (duh).

Then do my real SELECT/JOIN query, and during my while/$row loop I just
substitute the array value back in like this

<?= $employeeType[ $row['employee_type_id'] ] ?>

I actually use this little optimizing trick as an interview question for
new hires. You'd be amazed at how many people don't think of this, as
obvious as it seems to me...

D.Vin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux