- 论坛徽章:
- 0
|
楼上的各位朋友 不好意思 星期天没有上网 所以没有回复
mysql> show create table p1;
+-------+------------------------------------------------------------------
---------------------------------------------------------------------------
----------------------------+
| Table | Create Table
|
+-------+------------------------------------------------------------------
---------------------------------------------------------------------------
----------------------------+
| p1 | CREATE TABLE `p1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11167266 DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------
---------------------------------------------------------------------------
----------------------------+
1 row in set (0.00 sec)
mysql> show create table p1gl;
+-------+------------------------------------------------------------------
---------------------------------------------------------------------------
-------------------------------+
| Table | Create Table
|
+-------+------------------------------------------------------------------
---------------------------------------------------------------------------
-------------------------------+
| p1gl | CREATE TABLE `p1gl` (
`pid` int(11) NOT NULL,
`tid` int(11) NOT NULL,
KEY `pid` (`pid`),
KEY `tid` (`tid`),
KEY `pid_2` (`pid`,`tid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+------------------------------------------------------------------
---------------------------------------------------------------------------
-------------------------------+
1 row in set (0.00 sec)
mysql> explain select count(*) from `p1`,`p1gl` where `p1`.`id`=`p1gl`.`pid` and
`p1gl`.tid in(1,2,3);
+----+-------------+-------+--------+---------------+---------+---------+-------
--------+----------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref
| rows | Extra |
+----+-------------+-------+--------+---------------+---------+---------+-------
--------+----------+--------------------------+
| 1 | SIMPLE | p1gl | index | pid,tid,pid_2 | pid_2 | 8 | NULL
| 11167260 | Using where; Using index |
| 1 | SIMPLE | p1 | eq_ref | PRIMARY | PRIMARY | 4 | test.p
1gl.pid | 1 | Using index |
+----+-------------+-------+--------+---------------+---------+---------+-------
--------+----------+--------------------------+
2 rows in set (0.00 sec)
mysql> explain select count(*) from `p1`,`p1gl` where `p1`.`id`=`p1gl`.`pid` and
`p1gl`.tid in(1,2,3)\G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: p1gl
type: index
possible_keys: pid,tid,pid_2
key: pid_2
key_len: 8
ref: NULL
rows: 11167260
Extra: Using where; Using index
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: p1
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: test.p1gl.pid
rows: 1
Extra: Using index
2 rows in set (0.00 sec)
mysql> select count(*) from `p1`,`p1gl` where `p1`.`id`=`p1gl`.`pid` and `p1gl`.
tid in(1,2,3);
+----------+
| count(*) |
+----------+
| 3350466 |
+----------+
1 row in set (15.14 sec)
Server version: 5.1.40-community MySQL Community Server (GPL)
这个就是我的大概情况 请问各位朋友 这个该怎么优化啊 执行个查询要几十秒 |
|