views:

120

answers:

3

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 MyPHPAdmin, 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 MyPHPAdmin?

[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 MyPHPAdmin and for my test page. The difference may be due to the way that MyPHPAdmin 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?

+6  A: 

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

Nicky De Maeyer
This could be true, to test you could echo out your SQL from your PHP script and run it in the query tool on phpMyAdmin.
ILMV
You're right Nicky. I was so fixated on the query I was entering into the SQL pane that I didn't think about the "limit 30" that MyPHPAdmin adds to each query. My test page gives the same results as MyPHPAdmin when I add the limit clause.
Andrew Swift
A: 

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.

Erkan BALABAN
A: 

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

Aif