This is an automated email from the ASF dual-hosted git repository.
zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 35b1c8176a0 [feature](function) Support interval function (#3176)
35b1c8176a0 is described below
commit 35b1c8176a0c4cf340a8f844362f65f7749a387a
Author: linrrarity <[email protected]>
AuthorDate: Thu Jan 8 01:45:24 2026 +0800
[feature](function) Support interval function (#3176)
## Versions
- [x] dev
- [x] 4.x
- [ ] 3.x
- [ ] 2.1
## Languages
- [x] Chinese
- [x] English
## Docs Checklist
- [ ] Checked by AI
- [ ] Test Cases Built
---
.../scalar-functions/numeric-functions/interval.md | 107 +++++++++++++++++++++
.../scalar-functions/numeric-functions/interval.md | 107 +++++++++++++++++++++
.../scalar-functions/numeric-functions/interval.md | 107 +++++++++++++++++++++
sidebars.ts | 1 +
.../scalar-functions/numeric-functions/interval.md | 107 +++++++++++++++++++++
versioned_sidebars/version-4.x-sidebars.json | 1 +
6 files changed, 430 insertions(+)
diff --git
a/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
new file mode 100644
index 00000000000..63b634fd35c
--- /dev/null
+++
b/docs/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
@@ -0,0 +1,107 @@
+---
+{
+ "title": "INTERVAL",
+ "language": "en"
+}
+---
+
+## Description
+
+The INTERVAL function uses binary search to return the index of the first
threshold strictly greater than N. This function requires the threshold
parameters to be sorted in ascending order (N1 ≤ N2 ≤ N3 ≤ ... ≤ Nn) to
correctly use the binary search algorithm and achieve optimal performance.
+
+- All parameters are treated as integers.
+- Uses binary search algorithm with time complexity O(log n), providing
excellent performance.
+
+This function behaves consistently with the [interval
function](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_interval)
in MySQL.
+
+## Syntax
+
+```sql
+INTERVAL(N, N1, N2, N3, ...)
+```
+
+## Parameters
+
+| Parameter | Description
|
+| ----------------- |
--------------------------------------------------------------------------------------------------------------------------------------------
|
+| `N` | The value to search for, integer type.
|
+| `N1, N2, N3, ...` | List of thresholds, integer type, must be sorted in
ascending order (N1 ≤ N2 ≤ N3 ≤ ... ≤ Nn). At least one threshold parameter is
required. |
+
+## Return Value
+
+Returns the index (0-based) of the first threshold strictly greater than N.
The return type is integer.
+
+Returns -1 if N is NULL.
+
+If threshold parameters (N1, N2, ...) are NULL, they are treated as 0.
+
+## Examples
+
+```sql
+-- Basic usage
+SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200);
++-----------------------------------------+
+| INTERVAL(23, 1, 15, 17, 30, 44, 200) |
++-----------------------------------------+
+| 3 |
++-----------------------------------------+
+
+SELECT INTERVAL(10, 1, 10, 100, 1000);
++-----------------------------------+
+| INTERVAL(10, 1, 10, 100, 1000) |
++-----------------------------------+
+| 2 |
++-----------------------------------+
+
+-- Boundary case: less than the first threshold
+SELECT INTERVAL(0, 1, 10, 100);
++--------------------------+
+| INTERVAL(0, 1, 10, 100) |
++--------------------------+
+| 0 |
++--------------------------+
+
+-- Boundary case: greater than all thresholds
+SELECT INTERVAL(200, 1, 10, 100);
++----------------------------+
+| INTERVAL(200, 1, 10, 100) |
++----------------------------+
+| 3 |
++----------------------------+
+
+-- Boundary case: equal to a threshold
+SELECT INTERVAL(33, 1, 10, 32, 33, 102, 200);
++-------------------------------------------+
+| INTERVAL(33, 1, 10, 32, 33, 102, 200) |
++-------------------------------------------+
+| 4 |
++-------------------------------------------+
+
+-- First parameter is NULL
+SELECT INTERVAL(NULL, 1, 10, 100);
++----------------------------+
+| INTERVAL(NULL, 1, 10, 100) |
++----------------------------+
+| -1 |
++----------------------------+
+
+-- Subsequent parameters are NULL, treated as 0
+SELECT INTERVAL(3, -1, NULL, 2, 3, 4);
++--------------------------------+
+| INTERVAL(3, -1, NULL, 2, 3, 4) |
++--------------------------------+
+| 4 |
++--------------------------------+
+
+-- NULL values causing unsorted sequence, resulting in incorrect binary search
result
+SELECT INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50);
++-----------------------------------------------+
+| INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50) |
++-----------------------------------------------+
+| 6 |
++-----------------------------------------------+
+
+-- Input single parameter, error
+SELECT INTERVAL(33);
+ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the
compatibility function signature: interval(TINYINT)
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
new file mode 100644
index 00000000000..d78f254e81c
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
@@ -0,0 +1,107 @@
+---
+{
+ "title": "INTERVAL",
+ "language": "zh-CN"
+}
+---
+
+## 描述
+
+INTERVAL 函数使用二分查找返回第一个严格大于 N 的阈值位置索引。该函数要求阈值参数按升序排列(N1 ≤ N2 ≤ N3 ≤ ... ≤
Nn)才能正确使用二分查找算法,从而获得最佳性能。
+
+- 所有参数都被视为整数类型。
+- 使用二分查找算法,时间复杂度为 O(log n),性能优异。
+
+该函数与 MySQL 中的 [interval
函数](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_interval)
行为一致。
+
+## 语法
+
+```sql
+INTERVAL(N, N1, N2, N3, ...)
+```
+
+## 参数
+
+| 参数 | 说明 |
+| -- | -- |
+| `N` | 待查找的值,整数类型。 |
+| `N1, N2, N3, ...` | 阈值列表,整数类型,且要求按升序排列(N1 ≤ N2 ≤ N3 ≤ ... ≤ Nn)。至少需要一个阈值参数 |
+
+## 返回值
+
+返回第一个严格大于 N 的阈值位置索引(从 0 开始计数),为整数类型。
+
+若 N 为 NULL 则返回-1。
+
+若阈值参数(N1, N2, ...) 为 NULL,则将其视为 0。
+
+## 举例
+
+```sql
+-- 基本用法
+SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200);
++-----------------------------------------+
+| INTERVAL(23, 1, 15, 17, 30, 44, 200) |
++-----------------------------------------+
+| 3 |
++-----------------------------------------+
+
+SELECT INTERVAL(10, 1, 10, 100, 1000);
++-----------------------------------+
+| INTERVAL(10, 1, 10, 100, 1000) |
++-----------------------------------+
+| 2 |
++-----------------------------------+
+
+-- 边界情况:小于第一个阈值
+SELECT INTERVAL(0, 1, 10, 100);
++--------------------------+
+| INTERVAL(0, 1, 10, 100) |
++--------------------------+
+| 0 |
++--------------------------+
+
+-- 边界情况:大于所有阈值
+SELECT INTERVAL(200, 1, 10, 100);
++----------------------------+
+| INTERVAL(200, 1, 10, 100) |
++----------------------------+
+| 3 |
++----------------------------+
+
+-- 边界情况:等于某个阈值
+SELECT INTERVAL(33, 1, 10, 32, 33, 102, 200);
++-------------------------------------------+
+| INTERVAL(33, 1, 10, 32, 33, 102, 200) |
++-------------------------------------------+
+| 4 |
++-------------------------------------------+
+
+-- 首个参数为 NULL 值
+SELECT INTERVAL(NULL, 1, 10, 100);
++----------------------------+
+| INTERVAL(NULL, 1, 10, 100) |
++----------------------------+
+| -1 |
++----------------------------+
+
+-- 后续参数为 NULL 值会将其替换为整数`0`
+SELECT INTERVAL(3, -1, NULL, 2, 3, 4);
++--------------------------------+
+| INTERVAL(3, -1, NULL, 2, 3, 4) |
++--------------------------------+
+| 4 |
++--------------------------------+
+
+-- 由 NULL 值导致的序列未按升序排序 从而导致二分结果错误
+SELECT INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50);
++-----------------------------------------------+
+| INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50) |
++-----------------------------------------------+
+| 6 |
++-----------------------------------------------+
+
+-- 输入单个参数,报错
+SELECT INTERVAL(33);
+ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the
compatibility function signature: interval(TINYINT)
+```
\ No newline at end of file
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
new file mode 100644
index 00000000000..d78f254e81c
--- /dev/null
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
@@ -0,0 +1,107 @@
+---
+{
+ "title": "INTERVAL",
+ "language": "zh-CN"
+}
+---
+
+## 描述
+
+INTERVAL 函数使用二分查找返回第一个严格大于 N 的阈值位置索引。该函数要求阈值参数按升序排列(N1 ≤ N2 ≤ N3 ≤ ... ≤
Nn)才能正确使用二分查找算法,从而获得最佳性能。
+
+- 所有参数都被视为整数类型。
+- 使用二分查找算法,时间复杂度为 O(log n),性能优异。
+
+该函数与 MySQL 中的 [interval
函数](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_interval)
行为一致。
+
+## 语法
+
+```sql
+INTERVAL(N, N1, N2, N3, ...)
+```
+
+## 参数
+
+| 参数 | 说明 |
+| -- | -- |
+| `N` | 待查找的值,整数类型。 |
+| `N1, N2, N3, ...` | 阈值列表,整数类型,且要求按升序排列(N1 ≤ N2 ≤ N3 ≤ ... ≤ Nn)。至少需要一个阈值参数 |
+
+## 返回值
+
+返回第一个严格大于 N 的阈值位置索引(从 0 开始计数),为整数类型。
+
+若 N 为 NULL 则返回-1。
+
+若阈值参数(N1, N2, ...) 为 NULL,则将其视为 0。
+
+## 举例
+
+```sql
+-- 基本用法
+SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200);
++-----------------------------------------+
+| INTERVAL(23, 1, 15, 17, 30, 44, 200) |
++-----------------------------------------+
+| 3 |
++-----------------------------------------+
+
+SELECT INTERVAL(10, 1, 10, 100, 1000);
++-----------------------------------+
+| INTERVAL(10, 1, 10, 100, 1000) |
++-----------------------------------+
+| 2 |
++-----------------------------------+
+
+-- 边界情况:小于第一个阈值
+SELECT INTERVAL(0, 1, 10, 100);
++--------------------------+
+| INTERVAL(0, 1, 10, 100) |
++--------------------------+
+| 0 |
++--------------------------+
+
+-- 边界情况:大于所有阈值
+SELECT INTERVAL(200, 1, 10, 100);
++----------------------------+
+| INTERVAL(200, 1, 10, 100) |
++----------------------------+
+| 3 |
++----------------------------+
+
+-- 边界情况:等于某个阈值
+SELECT INTERVAL(33, 1, 10, 32, 33, 102, 200);
++-------------------------------------------+
+| INTERVAL(33, 1, 10, 32, 33, 102, 200) |
++-------------------------------------------+
+| 4 |
++-------------------------------------------+
+
+-- 首个参数为 NULL 值
+SELECT INTERVAL(NULL, 1, 10, 100);
++----------------------------+
+| INTERVAL(NULL, 1, 10, 100) |
++----------------------------+
+| -1 |
++----------------------------+
+
+-- 后续参数为 NULL 值会将其替换为整数`0`
+SELECT INTERVAL(3, -1, NULL, 2, 3, 4);
++--------------------------------+
+| INTERVAL(3, -1, NULL, 2, 3, 4) |
++--------------------------------+
+| 4 |
++--------------------------------+
+
+-- 由 NULL 值导致的序列未按升序排序 从而导致二分结果错误
+SELECT INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50);
++-----------------------------------------------+
+| INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50) |
++-----------------------------------------------+
+| 6 |
++-----------------------------------------------+
+
+-- 输入单个参数,报错
+SELECT INTERVAL(33);
+ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the
compatibility function signature: interval(TINYINT)
+```
\ No newline at end of file
diff --git a/sidebars.ts b/sidebars.ts
index 3294f4e744f..b9128d7f86a 100644
--- a/sidebars.ts
+++ b/sidebars.ts
@@ -1240,6 +1240,7 @@ const sidebars: SidebarsConfig = {
'sql-manual/sql-functions/scalar-functions/numeric-functions/floor',
'sql-manual/sql-functions/scalar-functions/numeric-functions/fmod',
'sql-manual/sql-functions/scalar-functions/numeric-functions/format-round',
+
"sql-manual/sql-functions/scalar-functions/numeric-functions/interval",
'sql-manual/sql-functions/scalar-functions/numeric-functions/isinf',
'sql-manual/sql-functions/scalar-functions/numeric-functions/isnan',
'sql-manual/sql-functions/scalar-functions/numeric-functions/ln',
diff --git
a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
new file mode 100644
index 00000000000..63b634fd35c
--- /dev/null
+++
b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/numeric-functions/interval.md
@@ -0,0 +1,107 @@
+---
+{
+ "title": "INTERVAL",
+ "language": "en"
+}
+---
+
+## Description
+
+The INTERVAL function uses binary search to return the index of the first
threshold strictly greater than N. This function requires the threshold
parameters to be sorted in ascending order (N1 ≤ N2 ≤ N3 ≤ ... ≤ Nn) to
correctly use the binary search algorithm and achieve optimal performance.
+
+- All parameters are treated as integers.
+- Uses binary search algorithm with time complexity O(log n), providing
excellent performance.
+
+This function behaves consistently with the [interval
function](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function_interval)
in MySQL.
+
+## Syntax
+
+```sql
+INTERVAL(N, N1, N2, N3, ...)
+```
+
+## Parameters
+
+| Parameter | Description
|
+| ----------------- |
--------------------------------------------------------------------------------------------------------------------------------------------
|
+| `N` | The value to search for, integer type.
|
+| `N1, N2, N3, ...` | List of thresholds, integer type, must be sorted in
ascending order (N1 ≤ N2 ≤ N3 ≤ ... ≤ Nn). At least one threshold parameter is
required. |
+
+## Return Value
+
+Returns the index (0-based) of the first threshold strictly greater than N.
The return type is integer.
+
+Returns -1 if N is NULL.
+
+If threshold parameters (N1, N2, ...) are NULL, they are treated as 0.
+
+## Examples
+
+```sql
+-- Basic usage
+SELECT INTERVAL(23, 1, 15, 17, 30, 44, 200);
++-----------------------------------------+
+| INTERVAL(23, 1, 15, 17, 30, 44, 200) |
++-----------------------------------------+
+| 3 |
++-----------------------------------------+
+
+SELECT INTERVAL(10, 1, 10, 100, 1000);
++-----------------------------------+
+| INTERVAL(10, 1, 10, 100, 1000) |
++-----------------------------------+
+| 2 |
++-----------------------------------+
+
+-- Boundary case: less than the first threshold
+SELECT INTERVAL(0, 1, 10, 100);
++--------------------------+
+| INTERVAL(0, 1, 10, 100) |
++--------------------------+
+| 0 |
++--------------------------+
+
+-- Boundary case: greater than all thresholds
+SELECT INTERVAL(200, 1, 10, 100);
++----------------------------+
+| INTERVAL(200, 1, 10, 100) |
++----------------------------+
+| 3 |
++----------------------------+
+
+-- Boundary case: equal to a threshold
+SELECT INTERVAL(33, 1, 10, 32, 33, 102, 200);
++-------------------------------------------+
+| INTERVAL(33, 1, 10, 32, 33, 102, 200) |
++-------------------------------------------+
+| 4 |
++-------------------------------------------+
+
+-- First parameter is NULL
+SELECT INTERVAL(NULL, 1, 10, 100);
++----------------------------+
+| INTERVAL(NULL, 1, 10, 100) |
++----------------------------+
+| -1 |
++----------------------------+
+
+-- Subsequent parameters are NULL, treated as 0
+SELECT INTERVAL(3, -1, NULL, 2, 3, 4);
++--------------------------------+
+| INTERVAL(3, -1, NULL, 2, 3, 4) |
++--------------------------------+
+| 4 |
++--------------------------------+
+
+-- NULL values causing unsorted sequence, resulting in incorrect binary search
result
+SELECT INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50);
++-----------------------------------------------+
+| INTERVAL(20, 7, NULL, 14, NULL, 25, NULL, 50) |
++-----------------------------------------------+
+| 6 |
++-----------------------------------------------+
+
+-- Input single parameter, error
+SELECT INTERVAL(33);
+ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the
compatibility function signature: interval(TINYINT)
+```
diff --git a/versioned_sidebars/version-4.x-sidebars.json
b/versioned_sidebars/version-4.x-sidebars.json
index dc5d220ff95..23d51774d0e 100644
--- a/versioned_sidebars/version-4.x-sidebars.json
+++ b/versioned_sidebars/version-4.x-sidebars.json
@@ -1260,6 +1260,7 @@
"sql-manual/sql-functions/scalar-functions/numeric-functions/floor",
"sql-manual/sql-functions/scalar-functions/numeric-functions/fmod",
"sql-manual/sql-functions/scalar-functions/numeric-functions/format-round",
+
"sql-manual/sql-functions/scalar-functions/numeric-functions/interval",
"sql-manual/sql-functions/scalar-functions/numeric-functions/isinf",
"sql-manual/sql-functions/scalar-functions/numeric-functions/isnan",
"sql-manual/sql-functions/scalar-functions/numeric-functions/ln",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]