317316abcd 发表于 2015-07-31 04:29

mysql数据查询很少,但耗时过长不合理,什么原因?


EXPLAIN一下的结果:
+----+-------------+-------+-------+--------------------------------+------------+---------+--------------------+------+--------------------------+
| id | select_type | table | type| possible_keys                  | key      | key_len | ref                | rows | Extra                  |
+----+-------------+-------+-------+--------------------------------+------------+---------+--------------------+------+--------------------------+
|1 | SIMPLE      | br    | range | PRIMARY,ntime                  | ntime      | 9       | NULL               |135 | Using where; Using index |
|1 | SIMPLE      | cc    | ref   | x_cc_block                     | x_cc_block | 7       | abenew.br.block_id |    1 | Using where            |
|1 | SIMPLE      | bt    | ref   | PRIMARY,block_id,x_block_tx_tx | PRIMARY    | 7       | abenew.br.block_id |    4 | Using where; Using index |
|1 | SIMPLE      | txout | ref   | tx_id,x_txout_pubkey         | tx_id      | 12      | abenew.bt.tx_id    |    1 | Using where            |
+----+-------------+-------+-------+--------------------------------+------------+---------+--------------------+------+--------------------------+


几乎都耗时在sending data过程中, 查询都采用了index, 这一般会是什么问题。
mysql> show profile for query 1;
+--------------------------------+----------+
| Status                         | Duration |
+--------------------------------+----------+
| starting                     | 0.000043 |
| checking query cache for query | 0.000113 |
| Opening tables               | 0.000031 |
| System lock                  | 0.000010 |
| Table lock                     | 0.000073 |
| init                           | 0.000045 |
| optimizing                     | 0.000023 |
| statistics                     | 0.000806 |
| preparing                      | 0.000030 |
| executing                      | 0.000011 |
| Sending data                   | 1.973856 |
| end                            | 0.000016 |
| query end                      | 0.000007 |
| freeing items                  | 0.000045 |
| storing result in query cache| 0.000010 |
| logging slow query             | 0.000004 |
| cleaning up                  | 0.000007 |
+--------------------------------+----------+
17 rows in set (0.00 sec)

317316abcd 发表于 2015-07-31 04:30


mysql> SELECT
    -> COALESCE (SUM(txout.txout_value), 0)
    -> FROM
    -> txout
    -> JOIN block_tx bt ON (bt.tx_id = txout.tx_id)
    -> JOIN chain_candidate cc ON (cc.block_id = bt.block_id)
    -> JOIN block_relay br ON (br.block_id = cc.block_id)
    -> WHERE
    -> pubkey_id = 47609754
    -> AND cc.in_longest = 1
    -> AND br.ntime BETWEEN 1438198897
    -> AND 1438285297
    -> ;

这是查询语句

linuxforlive 发表于 2015-07-31 10:54

还不知道这个呢留名学习一下

kylin3278 发表于 2015-07-31 11:46

网络耗时?

swenzhao 发表于 2015-08-01 11:31

最后的AND 1438285297 是干嘛用的?

renxiao2003 发表于 2015-08-13 20:32

优化一下啊。
页: [1]
查看完整版本: mysql数据查询很少,但耗时过长不合理,什么原因?