我可以强制MySQL在查询完成之前输出结果吗?
我有一个大型 MySQL 表(大约 7.5 亿行),我只想提取几列。
SELECT id, delid FROM tbl_name;
没有加入或选择标准或任何东西。两个字段(分别)都有一个索引。
原则上,它可以开始读取表格并立即吐出值,但实际上整个系统只会消耗内存并基本上停止运行。
似乎整个查询正在执行,并且输出在生成任何输出之前存储在某处......
我已经搜索了取消缓冲、关闭缓存等,但找不到答案。
(mysqldump几乎是我想要的,除了它转储整个表 - 但至少它立即开始生成输出)
I have a large MySQL table (about 750 million rows) and I just want to extract a couple of columns.
SELECT id, delid FROM tbl_name;
No joins or selection criteria or anything. There is an index on both fields (separately).
In principle, it could just start reading the table and spitting out the values immediately, but in practice the whole system just chews up memory and basically grinds to a halt.
It seems like the entire query is being executed and the output stored somewhere before ANY output is produced...
I've searched on unbuffering, turning off caches etc, but just cannot find the answer.
(mysqldump is almost what I want except it dumps the whole table - but at least it just starts producing output immediately)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否看过加载数据文件和选择进入?
我认为以下内容接近您想要做的事情:
Have you looked at load data infile and select into?
I think the following is close to what you want to do:
我唯一能想到的就是手动执行此操作,但有限制。我不知道你总共会得到多少速度提升,但至少你的结果集会更小。另一方面,您将不得不处理多个查询,这可能使这成为一个糟糕的解决方案。
您可以使用 无缓冲查询,但是当您在运行时无法“潜入”其他查询,我不知道这是否是您的情况的解决方案
The only thing I can think of is manually doing this with a LIMIT. I don't know how much of a speed improvement you will get in total, but at least your resultset will be smaller. You will, on the other hand, have to deal with several queries, which might make this a bad sollution.
You could use an unbuffered query, but as you cannot "sneak in" other queries while this is running, I don't know if that is a sollution in your case