【 TiDB 版本】
tidb 5.3.0
【概述】 场景 + 问题概述
由于部分sql需要下推至tiflash,在数据库连接中新增sessionVariables=tidb_opt_agg_push_down=1配置,导致其他sql报错
sql如下:
set @@tidb_opt_agg_push_down=1;
EXPLAIN ANALYZE SELECT
count( 0 )
FROM
(
SELECT
grid_display_plan_id,
grid_code AS grid,
grid_display_type,
display_owner,
grid_display_name,
max( edit_flag ) AS edit_flag,
max( delete_flag ) AS delete_flag,
share_flag,
max( share_flag2 ) AS share_flag2,
default_flag,
creation_date,
object_version_number
FROM
(
SELECT
hgdp.grid_display_plan_id,
hgdp.grid_code,
hgdp.grid_display_type,
hgdp.display_owner,
hgdpt.grid_display_name,
‘0’ AS edit_flag,
‘0’ AS delete_flag,
hgdp.share_flag,
‘0’ AS share_flag2,
hgdp.default_flag,
hgdp.creation_date,
hgdp.object_version_number
FROM
hgl_grid_display_plan hgdp
LEFT JOIN hgl_grid_display_plan_tl hgdpt ON hgdp.grid_display_plan_id = hgdpt.grid_display_plan_id
AND hgdpt.lang = ‘zh_CN’
LEFT JOIN hgl_grid_plan_permission hgdpp ON hgdpp.grid_display_plan_id = hgdp.grid_display_plan_id
WHERE
hgdp.grid_display_type = ‘GLOBAL’ UNION ALL
SELECT
hgdp.grid_display_plan_id,
hgdp.grid_code,
hgdp.grid_display_type,
hgdp.display_owner,
hgdpt.grid_display_name,
‘1’ AS edit_flag,
‘1’ AS delete_flag,
hgdp.share_flag,
‘0’ AS share_flag2,
hgdp.default_flag,
hgdp.creation_date,
hgdp.object_version_number
FROM
hgl_grid_display_plan hgdp
LEFT JOIN hgl_grid_display_plan_tl hgdpt ON hgdp.grid_display_plan_id = hgdpt.grid_display_plan_id
AND hgdpt.lang = ‘zh_CN’
LEFT JOIN hgl_grid_plan_permission hgdpp ON hgdpp.grid_display_plan_id = hgdp.grid_display_plan_id
WHERE
hgdp.grid_display_type = ‘TENANT’
AND hgdp.tenant_id = 0 UNION ALL
SELECT
hgdp.grid_display_plan_id,
hgdp.grid_code,
hgdp.grid_display_type,
hgdp.display_owner,
hgdpt.grid_display_name,
‘1’ AS edit_flag,
‘1’ AS delete_flag,
hgdp.share_flag,
‘1’ AS share_flag2,
hgdp.default_flag,
hgdp.creation_date,
hgdp.object_version_number
FROM
hgl_grid_display_plan hgdp
LEFT JOIN hgl_grid_display_plan_tl hgdpt ON hgdp.grid_display_plan_id = hgdpt.grid_display_plan_id
AND hgdpt.lang = ‘zh_CN’
LEFT JOIN hgl_grid_plan_permission hgdpp ON hgdpp.grid_display_plan_id = hgdp.grid_display_plan_id
WHERE
hgdp.grid_display_type = ‘USER’
AND hgdp.tenant_id = 0) a
WHERE
1 = 1
GROUP BY
grid_display_plan_id,
grid_code,
grid_display_type,
display_owner,
grid_display_name,
share_flag,
default_flag,
creation_date,
object_version_number
) table_count
执行计划如下: