我的 SQL 查询有问题,它运行得非常快,除非它不返回任何结果。
我有 4 个表:世界(2 项)、玩家(约 2000 项)、world_chunk(约 16000 项)和 world_block(约 100 万项)
SELECT bid,playername FROM worlds
JOIN world_chunks ON worlds.id = world_chunks.mainid
JOIN world_blocks ON world_chunks.cid = world_blocks.cid
JOIN players ON world_blocks.player = players.pid
WHERE worldname='world' AND x='-684' AND y='63' AND z='-2234' AND cx ='-43' AND cz='-140'
x,y,z 保存在 world_blocks 中,cx,cz 保存在 world_chunks 中,worlds 中的 worldname 所有索引都已设置,除了空结果之外的所有内容都非常快。
无论如何我可以加快空结果?
非常感谢你们的帮助。
编辑:这是数据库结构: http: //pastebin.com/rxQQ5mzp
它的 MySQL InnoDB
EXPLAIN on Emtpy Query:
1 SIMPLE worlds ALL PRIMARY,idx_mainid NULL NULL NULL 2 Using where
1 SIMPLE world_blocks ALL NULL NULL NULL NULL 766845 Using where; Using join buffer
1 SIMPLE world_chunks eq_ref PRIMARY,idx_cid PRIMARY 4 WatchBlock.world_blocks.cid 1 Using where
1 SIMPLE players eq_ref PRIMARY,idx_pid PRIMARY 4 WatchBlock.world_blocks.player 1
EXPLAIN on Found Query:
1 SIMPLE worlds ALL PRIMARY,idx_mainid NULL NULL NULL 2 Using where
1 SIMPLE world_blocks ALL NULL NULL NULL NULL 766845 Using where; Using join buffer
1 SIMPLE world_chunks eq_ref PRIMARY,idx_cid PRIMARY 4 WatchBlock.world_blocks.cid 1 Using where
1 SIMPLE players eq_ref PRIMARY,idx_pid PRIMARY 4 WatchBlock.world_blocks.player 1
结果可以为空,因为 x,y,z 和 cx,cz 不匹配(因此,如果其中一个不在 db 中,则 player 的结果应该为空)