Multi-table query slower than using array?

From: Date: Thu, 30 May 2002 17:51:54 +0000
Subject: Multi-table query slower than using array?
Groups: php.db 
Request: Send a blank email to php-db+get-19529@lists.php.net to get a copy of this message
I have a website where users can adopt virtual "pets". On this page, there is a page with some statistics. One of the statistics listed on that page is most popular pet species. It was taking over 3 seconds to load, so I'm trying to optimize it. I store the pet species in a seperate table from pets, an id from the species table is stored in the species table. I used to be putting all of the species in an array by looping through the species table, then I would use that array to process the id numbers. In my attempts to optimize, I changed it to a multi-table query that looked something like "select count(*) as cnt,species.name,pets.species from pets,species where species.id=pets.species group by pets.species order by cnt desc limit 1". Now, the speed of the page loading is up to 10 seconds! Was the array method the better way?

« previous php.db (#19529) next »