【发布时间】:2009-10-14 12:58:17
【问题描述】:
我运行这个查询:
SELECT u.user_id, u.fname, u.lname, n.title, n.news_id, n.post,
n.zip, z.city,z.state_abbr
FROM yc_users u, yc_news n, yc_zipcodes z
WHERE u.user_id = n.user_id AND n.zip = z.zip
ORDER BY n.stamp
LIMIT 10
并得到这个错误:
The SELECT would examine more than MAX_JOIN_SIZE rows;
check your WHERE and use SET SQL_BIG_SELECTS=1 or
SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
yc_zipcodes 下有超过 42,000 行。目前其他表的行数不足 10 行。
编辑:按要求提供数据样本:
yc_zipcodes
zip city state_abbr
00210 Portsmouth NH
00211 Portsmouth NH
00212 Portsmouth NH
00213 Portsmouth NH
yc_users
user_id username password fname lname email zip active_bln
1 fission1 e09dc84a23fd6cd68ce1fff1ff95713a Hayden Ferguson xxxxxx@gmail.com 92831 1
2 jason c2d0d212936c4bfd7f587607e6c72808 jason stevenson xxxxxx@gmail.com 93710 1
yc_news
news_id user_id title post zip stamp active_bln
2 1 Gummy bear falls into manhole OMG! A drunk man dressed as gummy bear... 93740 2009-10-12 09:49:04 1
3 1 Guy robbed Some dude got robbed last night at corner of... 93740 2009-10-12 09:50:19 1
上面的数据是无效的。在制作这个应用程序的过程中没有小熊软糖=D
【问题讨论】:
-
您应该根据需要指定 LEFT JOIN 或其他特定的连接类型。
-
设置“SQL_BIG_SELECTS=1”后它工作正常,但我不喜欢这样做。它告诉我我的查询过于臃肿。
标签: mysql