MySQL 可以并行 UNION 子查询(或任何其他查询)吗?

发布于 2024-11-26 19:53:00 字数 353 浏览 1 评论 0原文

我使用包含大量数据的分区表。根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

儭儭莪哋寶赑 2024-12-03 19:53:00

据我所知,目前使用多个线程/核心在应用程序中运行查询的唯一方法是使用多个连接。这当然使得不可能运行作为单个事务一部分的并行查询。

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.

尽揽少女心 2024-12-03 19:53:00

严格来说,在一个较大查询中联合在一起的不同查询并不是真正的子查询。

  • 查询按顺序运行
  • 列的数据类型由第一个查询确定
  • 默认情况下,相同的行将被删除(UNION 默认为 DISTINCT)
  • 直到所有查询都运行后,结果集才完成构建

...没有办法并行化不同的查询,因为它们实际上都是同一查询的一部分。

您可能想要尝试从代码中并行运行不同的查询,然后在查询全部完成后将结果混合在代码中。

有关 UNION 的文档可以在此处找到。

The different queries that are UNIONed together in one larger query aren't really subqueries, strictly speaking.

  • The queries are run in order
  • The data type of the columns is determined by the first query
  • By default, identical rows are dropped (UNION defaults to DISTINCT)
  • The result set is not finished building until all queries are run

...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.

骷髅 2024-12-03 19:53:00

我想这里已经回答了类似的问题。
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.)

笑饮青盏花 2024-12-03 19:53:00

抱歉,你运气不好。

然而,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文