SELECT
sum(toDecimal64(a.inBytesTotal, 2)) AS inBytesTotal
FROM
biz_monitor_trace_detail a
RIGHT JOIN biz_monitor_trace b ON
a.traceId = b.id
AND b.alarmId = ‘2023022419154300120001’
AND b.dstIp = ‘223.99.7.182’
AND b.sourceType = ‘1’
AND b.ondemand = ‘1’
where
a.type = ‘Total’
如果这个B表数据很大,过滤结果很少,把他单独插入到一个临时表C,然后,用这个C表的结果再去和a表关联
biz_monitor_trace b
AND b.alarmId = ‘2023022419154300120001’
AND b.dstIp = ‘223.99.7.182’
AND b.sourceType = ‘1’
AND b.ondemand = ‘1’
你可以试试,我也不确定效率会不会提升:
insert into table_c as select * from biz_monitor_trace b
where b.alarmId = ‘2023022419154300120001’
AND b.dstIp = ‘223.99.7.182’
AND b.sourceType = ‘1’
AND b.ondemand = ‘1’
create index idx_001 on table_c(id);
a.traceId = b.id 这个b表id对应的a表的traceid是一对多还是一对一。如果1对一,那估计比较快。如果一对多,或者A表全表都是那可能不会很快
traceId 有索引吗?没有就搞一个
然后
SELECT
sum(toDecimal64(a.inBytesTotal, 2)) AS inBytesTotal
FROM
biz_monitor_trace_detail a
RIGHT JOIN table_c b ON
a.traceId = b.id
where
a.type = ‘Total’