限制在21.4.5.46版本中选择计数子查询工作,但无法在21.10.2.15中使用

发布于 2025-01-19 15:19:03 字数 799 浏览 2 评论 0原文

限制选择计数子查询在21.4.5.46版本中可以工作,但不能在21.10.2.15中工作

Sql is

select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);

该sql在21.4.5.46版本中可以很好地工作,但不能在21.10.2.15中工作。

Exception is : [1002] ClickHouse exception, message: Code: 440. DB::Exception: Illegal type Nullable(Int32) of LIMIT expression, must be numeric type. (INVALID_LIMIT_EXPRESSION) (version 21.10.2.15 (official build))

如何重现

1创建表sql:

create table mytable(cid String,create_time String,sid String)engine = MergeTree PARTITION BY sid ORDER BY cid SETTINGS index_granularity = 8192;

2执行sql

select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);

Limit select count subquery work in 21.4.5.46 version but can not work in 21.10.2.15

Sql is

select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);

The sql can work very well in in 21.4.5.46 version but can not work in 21.10.2.15.

Exception is : [1002] ClickHouse exception, message: Code: 440. DB::Exception: Illegal type Nullable(Int32) of LIMIT expression, must be numeric type. (INVALID_LIMIT_EXPRESSION) (version 21.10.2.15 (official build))

How to reproduce

1 create table sql:

create table mytable(cid String,create_time String,sid String)engine = MergeTree PARTITION BY sid ORDER BY cid SETTINGS index_granularity = 8192;

2 execute sql

select * from mytable order by sid limit (select toInt64(count(cid)*0.01) from mytable);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪梦之恋 2025-01-26 15:19:03

ClickHouse版本V21.9,2021-09-09

  • 向后不兼容更改
    • 现在,标量子查询(如果类型都可以无效)始终返回无效的结果。这是需要的,因为如果有空子查询,则结果应为无效。以前,可能会出现有关不兼容类型的错误(类型扣除不会执行标量副标,并且可以使用不可播放的类型)。现在无法转换为无效(例如数组或元组)的空结果的标量子查询现在会引发错误。修复#25411。 #26423(Nikolai Kochetov)。

现在您应该使用

SELECT *
FROM mytable
ORDER BY sid ASC
LIMIT assumeNotNull((
    SELECT toUInt64(count(cid) * 0.01)
    FROM mytable
))

Query id: e3ab56af-96e4-4e01-812d-39af945d7878

Ok.

0 rows in set. Elapsed: 0.004 sec.

ClickHouse release v21.9, 2021-09-09

  • Backward Incompatible Change
    • Now, scalar subquery always returns Nullable result if it's type can be Nullable. It is needed because in case of empty subquery it's result should be Null. Previously, it was possible to get error about incompatible types (type deduction does not execute scalar subquery, and it could use not-nullable type). Scalar subquery with empty result which can't be converted to Nullable (like Array or Tuple) now throws error. Fixes #25411. #26423 (Nikolai Kochetov).

Now you should use

SELECT *
FROM mytable
ORDER BY sid ASC
LIMIT assumeNotNull((
    SELECT toUInt64(count(cid) * 0.01)
    FROM mytable
))

Query id: e3ab56af-96e4-4e01-812d-39af945d7878

Ok.

0 rows in set. Elapsed: 0.004 sec.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文