只要我在 select 子句中包含“longtext”类型,查询时间就会从 8 秒变为 3 分钟(Amazon RDS t2.small)。where 子句中不使用长文本,结果集为空。见下文:
mysql> select id from mbp_process where errorAcknowledged='N' and (exitCode != 0 or exitCode is null);
Empty set (8.03 sec)
mysql> select id, stdoutContents from mbp_process where errorAcknowledged='N' and (exitCode != 0 or exitCode is null);
Empty set (3 min 43.36 sec)
Run Code Online (Sandbox Code Playgroud)
令我难以置信的是,通过主键请求 longtext 列很快:
select stdoutContents from mbp_process where id = 49213;
...
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
为什么是这样?在我的裸机服务器上效果不太明显:查询从 0.2s 减慢到 1:05m。
这是“select id from...”查询的解释:
+----+-------------+-------------+------+-----------------------------------------------------+----------------------------+---------+-------+-------+------------------------------------+
| id | …
Run Code Online (Sandbox Code Playgroud) mysql ×1