【发布时间】:2013-10-18 15:54:24
【问题描述】:
我有 80k 多个客户和 4 个组。现在我想在 mysql 中找到 2 组用户进行查询。我的查询如下:
select c.customers_firstname as recipient_firstname,
c.customers_lastname as recipient_lastname,
c.customers_id as recipient_id,
c.customers_email_address as recipient_email_address
from customers c
where customers_group_id = '1' OR customers_group_id = '3'
当我在 phpmyadmin 中运行此查询时,我得到了结果:显示第 0 - 29 行(总共 59,815 行,查询耗时 0.0034 秒)
但是当我在这个查询中添加ORDER BY recipient_firstname ASC 的顺序时,结果时间是:显示第 0 - 29 行(总共 59,815 行,查询耗时 0.2607 秒)
按查询排序需要太多时间才能得到结果。
我想减少查询下单的时间。
如果有其他方法可以在更短的时间内获得相同的结果,请提供帮助。
【问题讨论】:
-
在
recipient_firstname字段上创建索引。另外,请尝试:where customers_group_id IN (1, 3) -
好吧,当遇到针对 mysql 的特定查询的性能问题时,一如既往:尝试 mysql 中出色的“解释”功能!它告诉你问题出在哪里!