本文介绍并行查询能力支持的语句场景和受限场景。
兼容语句场景
兼容语句场景
TDSQL-C MySQL 版已经实现了具备如下特征的 SQL 语句的并行查询处理,并在逐渐完善更多的功能场景。
对于单表扫描:支持全表扫描、索引扫描、索引范围扫描、索引 REF 查询等扫描类型的正序、逆序扫描。
对于多表连接:支持 Nested Loop Join 算法以及 Semi Join、Anti Join、Outer Join 等连接类型。
对于子查询:支持 derived table 的并行。
对于数据类型:支持带多种数据类型的查询,包括整型数据、字符型数据、浮点型数据、时间类型数据、以及(有运行时大小限制的)溢出类型数据。
普通运算符和函数原则上不限。
聚合函数支持 COUNT/SUM/AVG/MIN/MAX。
支持 UNION/UNION ALL 查询。
支持 traditional(默认格式)、json 和 tree 三种 EXPLAIN 格式。
对应语句的性能提升
SF=100,Dop=16设置下,加速比如下。
SUM/AVG/COUNT 等聚合函数。
SELECT l_returnflag, l_linestatus,Sum(l_quantity) AS sum_qty,Sum(l_extendedprice) AS sum_base_price,Sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,Sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,Avg(l_quantity) AS avg_qty,Avg(l_extendedprice) AS avg_price,Avg(l_discount) AS avg_disc,Count(*) AS count_order FROMlineitem WHERE l_shipdate <= date '1998-12-01' - INTERVAL '93' dayGROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus ;
未开启并行查询执行时间为1376.96秒,开启并行查询执行时间为107.25秒,加速倍数可以达到12.84倍。
order by/group by 分组/排序语句。
SELECT l_returnflag, l_linestatus,Sum(l_quantity) AS sum_qty,Sum(l_extendedprice) AS sum_base_price,Sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,Sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,Avg(l_quantity) AS avg_qty,Avg(l_extendedprice) AS avg_price,Avg(l_discount) AS avg_disc,Count(*) AS count_order FROMlineitem WHERE l_shipdate <= date '1998-12-01' - INTERVAL '93' dayGROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus ;
未开启并行查询执行时间为1376.96秒,开启并行查询执行时间为107.25秒,加速倍数可以达到12.84倍。
Join/Between/In 语句
selectsum(l_extendedprice* (1 - l_discount)) as revenuefromlineitem,partwhere(p_partkey = l_partkeyand p_brand = 'Brand#12'and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')and l_quantity >= 6and l_quantity <= 6 + 10and p_size between 1 and 5and l_shipmode in ('AIR', 'AIR REG')and l_shipinstruct = 'DELIVER IN PERSON')or(p_partkey = l_partkeyand p_brand = 'Brand#13'and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')and l_quantity >= 10 and l_quantity <= 10 + 10and p_size between 1 and 10and l_shipmode in ('AIR', 'AIR REG')and l_shipinstruct = 'DELIVER IN PERSON')or(p_partkey = l_partkeyand p_brand = 'Brand#24'and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')and l_quantity >= 21and l_quantity <= 21 + 10and p_size between 1 and 15and l_shipmode in ('AIR', 'AIR REG')and l_shipinstruct = 'DELIVER IN PERSON');
未开启并行时查询时间为20.55秒,开启并行查询后加速时间为1.87秒,加速倍数可以达到11倍。
受限场景
TDSQL-C MySQL 版并行查询能力不支持的场景如下。
限制项 | 限制说明 |
语句兼容性限制 | 非查询语句不支持并行查询,包括 INSERT ... SELECT 和 REPLACE ... SELECT。 |
| stored program 中的查询语句无法并行。 |
| prepared statement 中的查询语句无法并行。 |
| 串行化隔离级别事务内的查询语句无法并行。 |
| 加锁读语句无法并行,如 select for update/share lock。 |
| CTE 无法并行。 |
表/索引兼容性限制 | 查询表为系统表/临时表/非 Innodb 表时无法并行。 |
| 空间索引无法并行。 |
| 全文索引无法并行。 |
| 分区表无法并行。 |
| 扫描方式为 index_merge 的表无法并行。 |
表达式/Field 兼容性限制 | 包含 Generated Column 、BLOB、TEXT、JSON、BIT 和 GEOMETRY 字段的表无法并行。 |
| BIT_AND、BIT_OR、BIT_XOR 类型的聚合函数无法并行。 |
| aggregation(distinct),如 SUM(DISTINCT)、COUNT(DISTINCT) 等聚合函数无法并行。 |
| GIS 相关函数(如 SP_WITHIN_FUNC、ST_DISTANCE 等)无法并行。 |
| 用户自定义函数无法并行。 |
| json 相关的函数无法并行(如 json_length,json_type,JSON_ARRAYAGG 等)。 |
| XML 相关函数无法并行(xml_str)。 |
| 用户锁相关的函数无法并行(is_free_lock,is_used_lock,release_lock, release_all_locks,get_lock)。 |
| sleep 函数、random 函数、GROUP_CONCAT 函数、set_user_var 函数、weight_string 函数无法并行。 |
| 部分统计相关函数(STD/STDDEV/STDDEV_POP,VARIANCE/VAR_POP/VAR_SAMP)无法并行。 |
| 子查询无法并行。 |
| 窗口函数无法并行。 |
| rollup 无法并行。 |