MySQL 可以并行 UNION 子查询(或任何其他查询)吗?
我使用包含大量数据的分区表。根据 MySQL 文档,ToDo 列表中有:
涉及聚合函数(例如 SUM() 和 COUNT())的查询可以 易于并行化。
...但是,我可以使用 UNION 子查询实现相同的功能吗?它们是并行的,还是我必须创建一个多线程客户端来使用所有可能的分区键运行并发查询?
编辑:
这个问题并不严格涉及 UNION 或子查询。我想利用尽可能多的核心来进行查询。有没有办法在不并行化我的应用程序的情况下执行此操作(并确保完成)?
关于 MySQL 目前的并行化功能有什么好的文档吗?
I use a partitioned table with a large amount of data. According to MySQL docs, it is on the ToDo list that:
Queries involving aggregate functions such as SUM() and COUNT() can
easily be parallelized.
... but, can I achieve the same functionality using UNION subqueries? Are they parallelized, or do I have to create a multithreaded client to run concurrent queries with all the possible partition keys?
Edit:
The question is not strictly about UNION or subqueries. I would like to utilize as many cores as possible for my queries. Is there any way to do this (and make sure it's done) without paralellizing my application?
Any good documentation about MySQL's current parallelizing capabilities?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
据我所知,目前使用多个线程/核心在应用程序中运行查询的唯一方法是使用多个连接。这当然使得不可能运行作为单个事务一部分的并行查询。
As far as I know, currently the only way to use more than one thread/core to run queries in your application, is to use more than one connection. This of course makes it impossible to run parallel queries that are part of a single transaction.
严格来说,在一个较大查询中联合在一起的不同查询并不是真正的子查询。
...没有办法并行化不同的查询,因为它们实际上都是同一查询的一部分。
您可能想要尝试从代码中并行运行不同的查询,然后在查询全部完成后将结果混合在代码中。
有关 UNION 的文档可以在此处找到。
The different queries that are UNIONed together in one larger query aren't really subqueries, strictly speaking.
...there is no way to parallelize the different queries, as they are all really part of the same query.
You may want to try runing the different queries in parallel from your code, and then mashing the results up together in your code once the queries all complete.
The documentation on UNIONs can be found here.
我想这里已经回答了类似的问题。
http://forums.mysql.com/read.php?115,84453,84453
(也许我应该将其作为评论发布,但老实说,我在这里找不到评论按钮。)
I think a similar question was answered here.
http://forums.mysql.com/read.php?115,84453,84453
(May be I should have posted this as a comment, but I honestly couldn't find a comment button anywhere around here.)
抱歉,你运气不好。
然而,MySQL 8.0 有少数少量优化器将使用多核的其他情况。
一般来说,当您需要并行性时,您需要的并行 I/O 多于多个 CPU。而这种情况很少见。
Sorry, you are out of luck.
However, MySQL 8.0 has a small number of other cases where the Optimizer will use multiple cores.
In general, when you need parallelism, you need parallel I/O more than multiple CPUs. And that is rarely available.