此_TABLE_SUFFIX查询花费了 2.5秒:
SELECT COUNT(1)
FROM `projectid.datasetid.hospital_*`
如果我们添加以下WHERE语句:
WHERE _TABLE_SUFFIX LIKE '_2_' OR _TABLE_SUFFIX LIKE '_1_'
...查询需要 8分19秒!
第一个查询仅匹配三个表。这与我们正在考虑针对数千个表进行查询和过滤有关。
为什么_TABLE_SUFFIX查询这么慢,如何使其更快地执行(尤其是使用REGEX类型的操作)?
答案 0 :(得分:0)
如果您在'_1_'/'_2_'
中的下划线只能是数字,我只能建议尝试以下方法:
select sum(cnt) from (
SELECT COUNT(*) as cnt
FROM `projectid.datasetid.hospital_0*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_1*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_2*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_3*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_4*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_5*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_6*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_7*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_8*`
WHERE _TABLE_SUFFIX between '10' and '29'
union all
SELECT COUNT(*)
FROM `projectid.datasetid.hospital_9*`
WHERE _TABLE_SUFFIX between '10' and '29'
)