I am running the following MySQL query:
select * from combinations where family_type= f597 ;
On a table that has about 90,000 lines. If I run the query via phpMyAdmin, it takes 0.3 seconds to run, but in my PHP page on the same host it consistently takes about 8 seconds.
To test the amount of time it takes in my page, I run it like this:
$secs = microtime(true); $q = "select * from combinations where family_type= f597 ;"; $r = mysql_query($q); $secs = round(microtime(true)-$secs, 3); exit("$secs seconds");
The table structure is as follows:
CREATE TABLE `combinations` ( `part_no` char(7) collate latin1_general_ci NOT NULL, `key_type` smallint(4) unsigned NOT NULL, `family_type` char(5) collate latin1_general_ci NOT NULL, `year_start` varchar(6) collate latin1_general_ci NOT NULL, `year_end` varchar(6) collate latin1_general_ci NOT NULL, `visual` varchar(31) collate latin1_general_ci NOT NULL , `info_veh_0` varchar(255) collate latin1_general_ci NOT NULL, `info_veh_1` varchar(255) collate latin1_general_ci NOT NULL, `info_veh_2` varchar(255) collate latin1_general_ci NOT NULL, `key` mediumint(8) unsigned NOT NULL auto_increment, PRIMARY KEY (`key`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=2349584 ;
Can anyone explain why my program runs the same query so much slower than phpMyAdmin?
[update 1] I tested the query outside of any other programming -- I created a simple test.php page that contained only the mysql connect info and the query in question. So a priori it s not some other aspect of the site programming that s causing the delay.
[update 2] The actual time that it takes to load the page is the same for phpMyAdmin and for my test page. The difference may be due to the way that phpMyAdmin calculates the query time.
In any case, if the query takes only 0.3 seconds to process, where does the rest of the delay come from?