gpt4 book ai didi

MySQL UNION 语句慢查询

转载 作者:行者123 更新时间:2023-11-29 22:26:56 26 4
gpt4 key购买 nike

是否可以进行任何优化来帮助以下语句更快地执行而不被标记为“慢”查询?

SELECT id FROM equipment_acc_1 WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_acc_2 WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_gloves WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_head WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_pants WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_shoes WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_top WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_donation_skins WHERE nick='Cutter29'
UNION ALL
SELECT id FROM equipment_weapon WHERE nick='Cutter29';

此查询中的所有表都完全相同,下面是一个示例:

mysql> describe equipment_acc_1;
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| nick | char(25) | NO | PRI | NULL | |
| id | int(11) | NO | MUL | NULL | |
| cooldown | datetime | NO | MUL | NULL | |
+----------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)

提前非常感谢!

最佳答案

使用联合没有太多用处 - 但如果保证所有表中都有数据,您可以尝试此操作(如果不能保证数据,请使用外连接)

select a.id, b.id, c.id, d.id, e.id, f.id, g.id, h.id
from equipment_acc_1 a,equipment_acc_2 b, equipment_gloves c, equipment_pants d, equipment_shoes e, equipment_top f, equipment_donation_skins g, equipment_weapon h
where a.nick='Cutter29'
and b.nick=a.nick
and c.nick=a.nick
and d.nick=a.nick
and e.nick=a.nick
and f.nick=a.nick
and g.nick=a.nick
and h.nick=a.nick

关于MySQL UNION 语句慢查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30199537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com