English 中文(简体)
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` 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.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签