- 论坛徽章:
- 0
|
SELECT
COUNT(DISTINCT tblA.person) AS personNum -- VARCHAR(25)
FROM
tableA tblA
INNER JOIN tableB tblB USING (recType, year, num)
WHERE tblB.req_id = '';
说明:recType, year, num是tableA主键中的3个,还有个seqeunceID。这个表大概有450万条数据。
执行的时候,用到了由recType, year, num所组成的索引。
对于tableB,主键是req_id,用到了主键的索引。这个表大概会有3000条数据
上面这个语句花费如下
——# Query_time: 39 Lock_time: 0 Rows_sent: 1552 Rows_examined: 7927
请问这个语句应该优化!
谢谢gogo407 的提醒
explain的结果如下
id
| select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | 1
| SIMPLE
| tblB
| ref
| PRIMARY
| PRIMARY
| 150
| const
| 3621
| Using where
| 1 | SIMPLE | tblA | ref | PRIMARY,
ind_req_type_year | ind_req_type_year | 26 | tblB.recType,
tbleB.year,
tbleB.num
| 1 |
|
[ 本帖最后由 dynastyzhao 于 2007-12-21 10:25 编辑 ] |
|