开发者

Same MySQL query takes 0.3 sec in phpMyAdmin, 7.9 sec in PHP -- Why?

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开发者_StackOverflow中文版` 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?


This could be because phpMyAdmin adds a limit clause behind the screen due to the fact that it's paginating the results.


When you run your sql query you get all the records which suits you criteria. But if you don't show all all of them in your page get records how many you want to show at your web page. I mean page them.


If it is on a linux box, you can try to query the serveur using the tool "mysql" if you want to check.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜