0
1. USER_PHONE
用户手机
AAA P-12345
BBB P-56454
2三个表.phone_a
ID PHONE_NUMBER
p-12345 887157481
p-16546 841461655
3.phone_b
ID PHONE_NUMBER
P-54847 48446165
P-56461 64964661
我用phone_a存储手机号码,并phone_b在家里的电话号码。
当用户输入一个电话号码,我想在两个表中搜索这个号码。
这里是我的查询:
select A.user
from
user_phone as A,phone_a as B,phone_b as C
where
(A.phone=B.id and B.phone_number ="+9878848") or
(A.phone=C.id and C.phone_number ="+9878848")
但此查询是很慢的,我不知道为什么。
user_phone和phone_a有60000行,而phone_b只有600.
我觉得这个数字对于MySql很小,所以我不知道为什么查询速度很慢。
我也知道使用JOIN可能会加快查询速度,但我想知道是否有一种方法不使用JOIN,并且为什么这个查询太慢?
你加了'phone_number'指数? – Volatil3 2014-11-05 06:00:50
http://dev.mysql.com/doc/refman/5.0/en/explain.html使用'Explain'来获取更多关于查询的信息。并做了正确的索引列也使用适当的数据类型? – gvgvgvijayan 2014-11-05 06:02:47