子查询报错
● 目的:在子查询中使用not in过滤掉不想要的数据,使用代码
select
*
from
table1
where
report_time >= toUnixTimestamp(toDateTime('2023-12-25 10:00:00')) * 1000
AND report_time < toUnixTimestamp(toDateTime('2023-12-25 11:00:00')) * 1000
and id not in (
select
id
from
table2
)
● 发现报错:
PreparedStatementCallback; uncategorized SQLException; SQL state [null]; error code [288]; ClickHouse exception, code: 288,Exception: Double-distributed IN/JOIN subqueries is denied (distributed_product_mode = 'deny'). You may rewrite query to use local tables in subqueries, or use GLOBAL keyword, or set distributed_product_mode to suitable value
● 解决方式:
加GLOBAL关键字 (百度报错代码:ClickHouse exception, code: 288)
- 将where条件里,id not in ()
改为id GLOBAL not in () - 原因:是因为当查询分布式表时,不支持分布式子查询,会把查询发送到所有远程服务器,我们需要使用global,才能运行每个服务器的子查询