Home > Backend Development > PHP Tutorial > How to record the use of mysql performance query process_PHP tutorial

How to record the use of mysql performance query process_PHP tutorial

WBOY
Release: 2016-07-21 15:11:29
Original
999 people have browsed it

It all started from an experiment, please see the example below:

Table:

Copy code The code is as follows:

CREATE TABLE IF NOT EXISTS `foo` (
` a` int(10) unsigned NOT NULL AUTO_INCREMENT,
`b` int(10) unsigned NOT NULL,
`c` varchar(100) NOT NULL,
PRIMARY KEY (`a`),
KEY `bar` (`b`,`a`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `foo2` (
`a` int(10) unsigned NOT NULL AUTO_INCREMENT,
`b` int(10) unsigned NOT NULL,
`c` varchar(100) NOT NULL,
PRIMARY KEY (`a`),
KEY `bar` (` b`,`a`)

) ENGINE=MyISAM;

I inserted 300,000 data into two tables (the performance difference during insertion is that InnoDB is slower than MyISAM)

Copy the code The code is as follows:


$host = '192.168.100.166';

$dbName = 'test';

$user = 'root ';

$password = '';

$db = mysql_connect($host, $user, $password) or die('DB connect failed');

mysql_select_db($dbName, $db);

echo '===================InnoDB============= ==========' . "rn";

$start = microtime(true);

mysql_query("SELECT SQL_NO_CACHE SQL_CALC_FOUND_ROWS * FROM foo WHERE b = 1 LIMIT 1000, 10");

$end = microtime(true);

echo $end - $start . "rn";

echo '===== =============MyISAM=======================' . "rn";

$start = microtime(true);

mysql_query("SELECT SQL_NO_CACHE SQL_CALC_FOUND_ROWS * FROM foo2 WHERE b = 1 LIMIT 1000, 10");

$end = microtime(true);

echo $end - $start . "rn";

Return result:


One query can make so much difference! ! InnoDB and MyISAM, quickly analyze why.

First use explain to view

Make sure that no index is used on both sides. The rows queried in the second query, and the query rows of MyISAM are much less than those of InnoDB. On the contrary, the query is slower than InnoDB! ! This Y is a bit strange.

No problem, there is another awesome tool profile

For specific usage, please refer to: http://dev.mysql.com/doc/refman/5.0/en/show-profile.html

How to use it in simple terms:

Copy code The code is as follows:

Mysql > set profiling = 1;

Mysql>show profiles ;

Mysql>show profile for query 1;


You can see from this data that MyISAM’s Sending data is much more time-consuming than InnoDB’s Sending data . View mysql documentation

http://dev.mysql.com/doc/refman/5.0/en/general-thread-states.html

Sending data

The thread is reading and processing rows for a SELECT statement, and sending data to the client. Because operations occurring during this this state tend to perform large amounts of disk access (reads), it is often the longest-running state over the lifetime of a given query.

Sending data is to read the result of the selection from the disk, and then return the result to the client. This process will involve a large number of IO operations. You can use show profile cpu for query XX; to check and find that MyISAM's CPU_system is much larger than InnnoDB. At this point it can be concluded that MyISAM is slower than InnoDB for table queries (different from queries that can be completed using only indexes).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326869.htmlTechArticleEverything comes from an experiment, please see the example below: Table: Copy the code The code is as follows: CREATE TABLE IF NOT EXISTS `foo` ( `a` int(10) unsigned NOT NULL AUTO_INCREMENT, `b` int(10) u...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template