MySQL可以并行化UNION子查询(或任何东西)吗?

时间:2022-09-20 14:46:04

I use a partitioned table with a large amount of data. According to MySQL docs, it is on the ToDo list that:

我使用带有大量数据的分区表。根据MySQL文档,它在待办事项列表中:

Queries involving aggregate functions such as SUM() and COUNT() can easily be parallelized.

涉及诸如SUM()和COUNT()之类的聚合函数的查询可以很容易地并行化。

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

...但是,我可以使用UNION子查询实现相同的功能吗?它们是并行化的,还是我必须创建一个多线程客户端来运行所有可能的分区键的并发查询?


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?

问题不是严格关于UNION或子查询。我想尽可能多地使用核心来查询。有没有办法做到这一点(并确保它完成)没有对我的应用程序进行并行化?

Any good documentation about MySQL's current parallelizing capabilities?

有关MySQL当前并行化功能的任何好文档?

3 个解决方案

#1


5  

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.

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

#2


1  

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

严格来说,在一个较大的查询中UNIONed的不同查询实际上不是子查询。

  • 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)
  • 默认情况下,删除相同的行(UNION默认为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.

有关UNION的文档可以在这里找到。

#3


1  

I think a similar question was answered here. http://forums.mysql.com/read.php?115,84453,84453

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

(可能我应该把它作为评论发布,但我老实说在这里找不到评论按钮。)

#1


5  

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.

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

#2


1  

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

严格来说,在一个较大的查询中UNIONed的不同查询实际上不是子查询。

  • 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)
  • 默认情况下,删除相同的行(UNION默认为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.

有关UNION的文档可以在这里找到。

#3


1  

I think a similar question was answered here. http://forums.mysql.com/read.php?115,84453,84453

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

(可能我应该把它作为评论发布,但我老实说在这里找不到评论按钮。)