Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/14-reference/01-components/01-taosd.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ The effective value of charset is UTF-8.
| curRange | | Supported, effective after restart | Internal parameter, used for setting lossy compression |
| compressor | | Supported, effective after restart | Internal parameter, used for setting lossy compression |
| compareAsStrInGreatest | After 3.4.0.0 | Supported, effective immediately | Whether to compare values as strings in GREATEST function; default value true |
| ignoreNullInGreatest | After 3.4.2.0 | Supported, effective immediately | Whether GREATEST and LEAST skip NULL arguments; 0 (default): MySQL-compatible, any NULL makes the result NULL; 1: skip NULL arguments and compare only non-NULL values |
| showFullCreateTableColumn | After 3.4.0.0 | Supported, effective immediately | Whether SHOW CREATE TABLE displays full column information; 0: only table name and database name, 1: full create statement; default value 0 |
| multiResultFunctionStarReturnTags | After 3.4.0.0 | Supported, effective immediately | Whether multi-result functions return tag columns when using *; default value false |

Expand Down
1 change: 1 addition & 0 deletions docs/en/14-reference/01-components/02-taosc.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The following configuration parameters only take effect for Native connections.
|minSlidingTime | |Supported, effective immediately |Internal parameter, minimum allowable value for sliding|
|minIntervalTime | |Supported, effective immediately |Internal parameter, minimum allowable value for interval|
|compareAsStrInGreatest | v3.3.6.0 |Supported, effective immediately |When the greatest and least functions have both numeric and string types as parameters, the comparison type conversion rules are as follows: Integer; 1: uniformly converted to string comparison, 0: uniformly converted to numeric type comparison.|
|ignoreNullInGreatest | v3.4.2.0 |Supported, effective immediately |Whether the GREATEST and LEAST functions skip NULL arguments. Integer; 0 (default): MySQL-compatible — any NULL argument makes the result NULL; 1: skip NULL arguments and compare only non-NULL values, returning NULL only when every argument is NULL. Orthogonal to compareAsStrInGreatest.|
|showFullCreateTableColumn | Added in 3.3.7.1 | Supported | Whether show column compress info while execute `show create table tablname`, range 0/1, default: 0.|

### Writing Related
Expand Down
1 change: 1 addition & 0 deletions docs/en/14-reference/01-components/08-config-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ This document compares the configuration parameters of taosd (server-side) and t
| minSlidingTime | taosc | Minimum allowable value for sliding |
| minIntervalTime | taosc | Minimum allowable value for interval |
| compareAsStrInGreatest | taosc | Comparison type conversion rules for greatest and least functions |
| ignoreNullInGreatest | taosc | Whether greatest and least functions skip NULL arguments |
| showFullCreateTableColumn | taosc | Whether show create table returns column compression information |
| rpcRecvLogThreshold| taosd| The threshold for warning logs in the RPC module |
| **Region Related** | | |
Expand Down
7 changes: 5 additions & 2 deletions docs/en/14-reference/03-taos-sql/22-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ GREATEST(expr1, expr2[, expr]...)

**Comparison rules**: The following rules describe the conversion method of the comparison operation:

- If any parameter is NULL, the comparison result is NULL.
- If any parameter is NULL, the comparison result is NULL. (See `ignoreNullInGreatest` below to skip NULL arguments instead.)
- If all parameters in the comparison operation are string types, compare them as string types
- If all parameters are numeric types, compare them as numeric types.
- If there are both string types and numeric types in the parameters, according to the `compareAsStrInGreatest` configuration item, they are uniformly compared as strings or numeric values. By default, they are compared as strings.
- In all cases, when different types are compared, the comparison type will choose the type with a larger range for comparison. For example, when comparing integer types, if there is a BIGINT type, BIGINT will definitely be selected as the comparison type.

**Related configuration items**: Client configuration, compareAsStrInGreatest is 1, which means that both string types and numeric types are converted to string comparisons, and 0 means that they are converted to numeric types. The default is 1.
**Related configuration items**:

- `compareAsStrInGreatest` (client configuration): `1` means that when both string types and numeric types are present they are uniformly compared as strings; `0` means they are uniformly compared as numeric values. The default is `1`.
- `ignoreNullInGreatest` (client configuration, available since ver-3.4.2.0): `0` (default) keeps the MySQL-compatible behavior — any NULL argument makes the result NULL. `1` skips NULL arguments and compares only the non-NULL values; if every argument is NULL, the result is still NULL. This option is orthogonal to `compareAsStrInGreatest`: it only controls NULL handling, the comparison rules above for non-NULL values are unchanged.

#### LEAST

Expand Down
11 changes: 11 additions & 0 deletions docs/zh/14-reference/01-components/01-taosd.md
Original file line number Diff line number Diff line change
Expand Up @@ -2630,6 +2630,17 @@ charset 的有效值是 UTF-8。
- 动态修改:支持通过 SQL 修改,立即生效。
- 支持版本:从 v3.4.0.0 版本开始引入

#### ignoreNullInGreatest

- 说明:GREATEST、LEAST 函数是否跳过 NULL 参数
- 类型:整数;0:与 MySQL 一致,任一参数为 NULL 则返回 NULL;1:跳过 NULL 参数,仅在非 NULL 值之间比较,所有参数均为 NULL 时仍返回 NULL。与 compareAsStrInGreatest 正交。
- 默认值:0
- 最小值:0
- 最大值:1
- 参数类型:局部配置参数
- 动态修改:支持通过 SQL 修改,立即生效。
- 支持版本:从 v3.4.2.0 版本开始引入

#### showFullCreateTableColumn

- 说明:SHOW CREATE TABLE 是否显示完整的列信息
Expand Down
7 changes: 7 additions & 0 deletions docs/zh/14-reference/01-components/02-taosc.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ taosc 和 taosd 存在许多同名参数,虽然名称相同但作用范围可
- 动态修改:支持通过 SQL 修改,立即生效
- 支持版本:从 v3.3.6.0 版本开始引入

#### ignoreNullInGreatest

- 说明:用于决定 greatest、least 函数是否跳过 NULL 参数。
- 类型:整数;0(默认):与 MySQL 一致,任一参数为 NULL 则返回 NULL;1:跳过 NULL 参数,仅在非 NULL 值之间比较,所有参数均为 NULL 时仍返回 NULL。与 compareAsStrInGreatest 正交。
- 动态修改:支持通过 SQL 修改,立即生效
- 支持版本:从 v3.4.2.0 版本开始引入

#### showFullCreateTableColumn

- 说明:`show create table` 的返回值是否带 `column` 的压缩信息
Expand Down
1 change: 1 addition & 0 deletions docs/zh/14-reference/01-components/08-config-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ toc_max_heading_level: 4
| minSlidingTime | taosc | sliding 的最小允许值 |
| minIntervalTime | taosc | interval 的最小允许值 |
| compareAsStrInGreatest | taosc | 用于决定 greatest、least 函数的参数既有数值类型又有字符串类型时,比较类型的转换规则 |
| ignoreNullInGreatest | taosc | 用于决定 greatest、least 函数是否跳过 NULL 参数 |
| showFullCreateTableColumn | taosc | show create table 的返回值是否带 column 的压缩信息 |
| **区域相关** | | |
| timezone | both | 时区 |
Expand Down
7 changes: 5 additions & 2 deletions docs/zh/14-reference/03-taos-sql/22-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,16 @@ GREATEST(expr1, expr2[, expr]...)

**比较规则**:以下规则描述了比较操作的转换方式:

- 如果有任何一个参数为 NULL,则比较结果为 NULL。
- 如果有任何一个参数为 NULL,则比较结果为 NULL。(如需跳过 NULL 参数,参见下方 `ignoreNullInGreatest` 配置项。)
- 如果比较操作中的所有参数都是字符串类型,按照字符串类型比较
- 如果所有参数都是数值类型,则将它们作为数值类型进行比较。
- 如果参数中既有字符串类型,也有数值类型,根据 compareAsStrInGreatest 配置项,统一作为字符串或者数值进行比较。默认按照字符串比较。
- 在所有情况下,不同类型比较,比较类型会选择范围更大的类型进行比较,例如作为整数类型比较时,如果存在 BIGINT 类型,必定会选择 BIGINT 作为比较类型。

**相关配置项**:客户端配置,compareAsStrInGreatest 为 1 表示同时存在字符串类型和数值类型统一转为字符串比较,为 0 表示统一转为数值类型比较。默认为 1。
**相关配置项**:

- `compareAsStrInGreatest`(客户端配置):为 `1` 表示同时存在字符串类型和数值类型时统一转为字符串比较,为 `0` 表示统一转为数值类型比较。默认为 `1`。
- `ignoreNullInGreatest`(客户端配置,自 ver-3.4.2.0 起支持):为 `0`(默认)时保持与 MySQL 一致的行为,任一参数为 NULL 则结果为 NULL;为 `1` 时跳过 NULL 参数,仅在非 NULL 值之间进行比较,若所有参数均为 NULL 仍返回 NULL。该项与 `compareAsStrInGreatest` 正交,仅影响 NULL 参数的处理,非 NULL 值之间的比较规则不变。

#### LEAST

Expand Down
1 change: 1 addition & 0 deletions include/common/tglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ extern int32_t tsStreamNotifyMessageSize;
extern int32_t tsStreamNotifyFrameSize;
extern int32_t tsStreamBatchRequestWaitMs;
extern bool tsCompareAsStrInGreatest;
extern bool tsIgnoreNullInGreatest;
extern bool tsShowFullCreateTableColumn; // 0: show create table, and not include column compress info
extern int32_t tsRpcRecvLogThreshold; // in seconds, default 3

Expand Down
8 changes: 8 additions & 0 deletions source/common/src/tglobal.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ int8_t tsFlexDeploy = 0;
#endif

bool tsCompareAsStrInGreatest = true;
bool tsIgnoreNullInGreatest = false;

// monitor
#ifdef USE_MONITOR
Expand Down Expand Up @@ -808,6 +809,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
TAOS_CHECK_RETURN(cfgAddBool(pCfg, "compareAsStrInGreatest", tsCompareAsStrInGreatest, CFG_SCOPE_CLIENT,
CFG_DYN_CLIENT, CFG_CATEGORY_LOCAL, CFG_PRIV_SYSTEM));

TAOS_CHECK_RETURN(cfgAddBool(pCfg, "ignoreNullInGreatest", tsIgnoreNullInGreatest, CFG_SCOPE_CLIENT,
CFG_DYN_CLIENT, CFG_CATEGORY_LOCAL, CFG_PRIV_SYSTEM));

TAOS_CHECK_RETURN(cfgAddBool(pCfg, "showFullCreateTableColumn", tsShowFullCreateTableColumn, CFG_SCOPE_CLIENT,
CFG_DYN_CLIENT, CFG_CATEGORY_LOCAL, CFG_PRIV_SYSTEM));

Expand Down Expand Up @@ -1685,6 +1689,9 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "compareAsStrInGreatest");
tsCompareAsStrInGreatest = pItem->bval;

TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "ignoreNullInGreatest");
tsIgnoreNullInGreatest = pItem->bval;

TAOS_CHECK_GET_CFG_ITEM(pCfg, pItem, "showFullCreateTableColumn");
tsShowFullCreateTableColumn = pItem->bval;

Expand Down Expand Up @@ -3387,6 +3394,7 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
{"bypassFlag", &tsBypassFlag},
{"safetyCheckLevel", &tsSafetyCheckLevel},
{"compareAsStrInGreatest", &tsCompareAsStrInGreatest},
{"ignoreNullInGreatest", &tsIgnoreNullInGreatest},
{"showFullCreateTableColumn", &tsShowFullCreateTableColumn}};

if ((code = taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true)) != TSDB_CODE_SUCCESS) {
Expand Down
21 changes: 21 additions & 0 deletions source/libs/function/src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -2208,13 +2208,21 @@ static int32_t translateGreatestleast(SFunctionNode* pFunc, char* pErrBuf, int32
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));

bool mixTypeToStrings = tsCompareAsStrInGreatest;
bool ignoreNull = tsIgnoreNullInGreatest;

SDataType res = {.type = 0};
bool resInit = false;
int32_t nullLitCount = 0;
for (int32_t i = 0; i < LIST_LENGTH(pFunc->pParameterList); i++) {
SDataType* para = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, i));

if (IS_NULL_TYPE(para->type)) {
if (ignoreNull) {
// Skip NULL literal params from result-type derivation; they are also
// ignored at runtime in greatestLeastImpl/vectorCompareAndSelect.
nullLitCount++;
continue;
}
res.type = TSDB_DATA_TYPE_NULL;
res.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
break;
Expand Down Expand Up @@ -2255,7 +2263,20 @@ static int32_t translateGreatestleast(SFunctionNode* pFunc, char* pErrBuf, int32
}
}
}
// ignoreNullInGreatest=1: if every param was a NULL literal the output is
// still NULL type (matches default behavior; FS §4.5).
if (ignoreNull && !resInit && nullLitCount > 0) {
res.type = TSDB_DATA_TYPE_NULL;
res.bytes = tDataTypes[TSDB_DATA_TYPE_NULL].bytes;
}
pFunc->node.resType = res;

// tsIgnoreNullInGreatest is a CFG_SCOPE_CLIENT flag, so the runtime
// (which executes per-vnode) must receive its value via the param list.
// The flag is appended as a trailing TINYINT and stripped at runtime by
// greatestLeastImpl. Mirrors the addUint8Param pattern used by trim,
// translateDate, and similar builtins.
FUNC_ERR_RET(addUint8Param(&pFunc->pParameterList, ignoreNull ? 1 : 0));
return TSDB_CODE_SUCCESS;
}

Expand Down
Loading
Loading