我在 MySQL 中有一个特定的查询,它使用 collate 比较来自两个不同表(索引)的值,但这不会执行几个小时。查询如下:
create temporary table elig_temp
select id from table_elig;
create index elig_temp on elig_temp(id);
create temporary table med_temp
select id from table_med;
create index med_temp on med_temp(id);
select COUNT(1) as result
from med_temp a
where exists
(
select 1
from elig_temp b
where a.id collate latin1_general_cs = b.id collate latin1_general_cs
)
仅供参考 elig_temp 表有 70k 条记录,而 med_temp 有 100 万条记录。
此外,table_elig 和 table_med 表的 id 字段是同一个表中另一个字段的哈希加密值。因此,我也尝试使用二进制排序规则技术,例如 udf8_bin 和 latin1_bin 来使查询运行,但我又被卡住了。
我什至尝试使用与查询一起使用的相同排序技术来定义 table_med 和 table_elig 的每个字段(varchar 和 char),但没有运气。
请向我建议任何可能的解决方案,以有效地执行此查询时间。