Ajax mysql查询部分工作


Ajax mysql query working partially

一个PHP网页正在调用一个AJAX脚本(查询DB)。我不得不停止它,因为它在2小时前被称为。然而,我在另一个DigitalOcean服务器上测试了它,它在2分钟内响应。

服务器是相似的(16GB RAM, 8CPU等)

而且交通也不多。

我真的不明白。我注意到的唯一区别是服务器是:MySQL版本和Ubuntu版本。

第一个服务器:MySQL服务器版本:5.5.52-0ubuntu0.14.04.1 (Ubuntu 14.04.2 LTS).

第二个:MySQL Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu 16.04 LTS).

被查询的表在相同的表上得到相同的索引。

我还是不明白问题出在哪里

可能来自SQL查询:

SELECT COUNT(*) as max_tok FROM dest WHERE b_id = 1 and statut < 3 and id IN (SELECT dest_id from ouv where created_at > '2016-07-13 00:00:00' and created_at < '2016-10-13 00:00:00')

MySQL Server 1:

+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table         | Non_unique | Key_name                         | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dest |          0 | PRIMARY                          |            1 | id          | A         |     5994930 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          0 | dest_b_id_mail_index |            1 | b_id     | A         |          16 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          0 | dest_b_id_mail_index |            2 | mail        | A         |     5994930 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          1 | dest_statut_index       |            1 | statut      | A         |          16 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          1 | dest_base_id_hash_index |            1 | b_id     | A         |          16 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          1 | dest_base_id_hash_index |            2 | hash        | A         |     5994930 |     NULL | NULL   |      | BTREE      |         |               |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
MySQL Server 2:
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table         | Non_unique | Key_name                         | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dest |          0 | PRIMARY                          |            1 | id          | A         |     4320721 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          0 | dest_b_id_mail_index |            1 | b_id     | A         |        1156 |     NULL | NULL   |      | BTREE      |         |               |
| dest|          0 | dest_b_id_mail_index |            2 | mail        | A         |     4320721 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          1 | dest_statut_index       |            1 | statut      | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          1 | dest_b_id_hash_index |            1 | b_id     | A         |         942 |     NULL | NULL   |      | BTREE      |         |               |
| dest |          1 | dest_b_id_hash_index |            2 | hash        | A         |     4320721 |     NULL | NULL   |      | BTREE      |         |               |
+---------------+------------+----------------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
(注:

: SQL查询工作在我们的第二个服务器)

在这种特殊情况下,我已经迁移到一个新的DO服务器(MySQL 5.7.15和PHP 7.0.12)。我已经备份了我的数据库和文件,并将其导入到新的服务器中。