我有一个非常大的表(8gb),其中包含有关文件的信息,我需要针对它运行一个看起来像这样的报告:
(select * from fs_walk_scan where file_path like '\\\\server1\\groot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server1\\hroot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server1\\iroot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server2\\froot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server2\\groot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server3\\hroot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server4\\iroot$\\%' order by file_size desc limit 0,30)
UNION ALL
(select * from fs_walk_scan where file_path like '\\\\server5\\iroot$\\%' order by file_size desc limit 0,30)
[...]
order by substring_index(file_path,'\\',4), file_size desc
此方法完成了我需要做的事情:获取每个卷的 30 个最大文件的列表。但是,这非常慢,并且“喜欢”搜索是硬编码的,即使它们位于另一个表中并且可以通过这种方式获得。
我正在寻找的是一种无需多次通过巨大桌子即可做到这一点的方法。有人有想法么?
谢谢。
PS我不能以任何方式改变巨大源表的结构。
更新:file_path 和 file_size 上有索引,但是这些子(?)查询中的每一个仍然需要大约 10 分钟,我必须至少做 22 分钟。