Skip to content

Commit

Permalink
doc: correct subquery optimization examples for clarity (#19825) (#19826
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ti-chi-bot authored Feb 13, 2025
1 parent c607541 commit 6d83478
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subquery-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ summary: 了解子查询相关的优化。
对于这种情况,可以将 `ALL` 或者 `ANY``MAX` 以及 `MIN` 来代替。不过由于在表为空时,`MAX(EXPR)` 以及 `MIN(EXPR)` 的结果会为 `NULL`,其表现形式和 `EXPR` 是有 `NULL` 值的结果一样。以及外部表达式结果为 `NULL` 时也会影响表达式的最终结果,因此这里完整的改写会是如下的形式:

- `t.id < all(select s.id from s)` 会被改写为 `t.id < min(s.id) and if(sum(s.id is null) != 0, null, true)`
- `t.id < any (select s.id from s)` 会被改写为 `t.id < max(s.id) or if(sum(s.id is null) != 0, null, false)`
- `t.id > any (select s.id from s)` 会被改写为 `t.id > max(s.id) or if(sum(s.id is null) != 0, null, false)`

## `... != ANY (SELECT ... FROM ...)`

Expand Down

0 comments on commit 6d83478

Please sign in to comment.