未验证 提交 56fd29e8 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #10790 from taosdata/fix/TD-14070

Fix/td 14070  fix compare error if value is NULL with nchar and binary type
......@@ -1094,7 +1094,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
应用字段:适合于除时间主列外的任何类型字段。
适用于:**表**
说明:由于返回数据量未知,考虑到内存因素,为了函数可以正常返回结果,建议不重复的数据量在10万级别,否则会报错
示例:
```mysql
......@@ -1118,7 +1118,9 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
```mysql
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
功能说明:采用hyperloglog算法,返回某列的基数。该算法在数据量很大的情况下,可以明显降低内存的占用,但是求出来的基数是个估算值,标准误差为0.81%。
功能说明:
- 采用hyperloglog算法,返回某列的基数。该算法在数据量很大的情况下,可以明显降低内存的占用,但是求出来的基数是个估算值,标准误差(标准误差是多次实验,每次的平均数的标准差,不是与真实结果的误差)为0.81%。
- 在数据量较少的时候该算法不是很准确,可以使用select count(data) from (select unique(col) as data from table) 的方法。
返回结果类型:整形。
......@@ -1596,7 +1598,9 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数
支持版本:2.6.0.x 之后的版本。
说明:该函数可以应用在普通表和超级表上。不能和窗口操作一起使用,例如 interval/state_window/session_window 。
说明:
- 该函数可以应用在普通表和超级表上。不能和窗口操作一起使用,例如 interval/state_window/session_window 。
- 由于返回数据量未知,考虑到内存因素,为了函数可以正常返回结果,建议不重复的数据量在10万级别,否则会报错。
示例:
```mysql
......
......@@ -863,7 +863,9 @@ TDengine supports aggregations over data, they are listed below:
Applicable Fields: All types except timestamp.
Supported version: Version after 2.6.0 .
Note: Since the amount of returned data is unknown, considering the memory factor, in order to return the result normally, it is recommended that the amount of non repeated data is 100000, otherwise an error will be reported.
Example:
```mysql
taos> select voltage from d002;
......@@ -886,7 +888,9 @@ TDengine supports aggregations over data, they are listed below:
```mysql
SELECT HYPERLOGLOG(field_name) FROM { tb_name | stb_name } [WHERE clause];
```
Function: The hyperloglog algorithm is used to return the cardinality of a column. In the case of large amount of data, the algorithm can significantly reduce the occupation of memory, but the cardinality is an estimated value, and the standard error is 0.81%.
Function:
- The hyperloglog algorithm is used to return the cardinality of a column. In the case of large amount of data, the algorithm can significantly reduce the occupation of memory, but the cardinality is an estimated value, and the standard error(the standard error is the standard deviation of the average of multiple experiments, not the error with the real result) is 0.81%.
- When the amount of data is small, the algorithm is not very accurate. You can use the method like this: select count(data) from (select unique(col) as data from table).
Return Data Type:Integer.
......@@ -1215,8 +1219,10 @@ TDengine supports aggregations over data, they are listed below:
Supported version: Version after 2.6.0 .
Note: This function can be applied to ordinary tables and super tables. Cannot be used with window operations,such as interval/state_window/session_window.
Note:
- This function can be applied to ordinary tables and super tables. Cannot be used with window operations,such as interval/state_window/session_window.
- Since the amount of returned data is unknown, considering the memory factor, in order to return the result normally, it is recommended that the amount of non repeated data is 100000, otherwise an error will be reported.
Example:
```mysql
taos> select ts,voltage from unique1;
......
......@@ -7054,7 +7054,7 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
return invalidOperationMsg(pMsgBuf, msg1);
}
if (index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX && !isTopBottomUniqueQuery(pQueryInfo)) {
if (index.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX && !isTopBottomUniqueQuery(pQueryInfo)){
bool validOrder = false;
SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo;
if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) {
......@@ -7065,15 +7065,8 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
if (!validOrder) {
return invalidOperationMsg(pMsgBuf, msg7);
}
if (udf) {
return invalidOperationMsg(pMsgBuf, msg11);
}
pQueryInfo->groupbyExpr.orderType = pItem->sortOrder;
}
if (isTopBottomUniqueQuery(pQueryInfo)) {
}else if (isTopBottomUniqueQuery(pQueryInfo)) {
SArray *columnInfo = pQueryInfo->groupbyExpr.columnInfo;
if (columnInfo != NULL && taosArrayGetSize(columnInfo) > 0) {
SColIndex* pColIndex = taosArrayGet(columnInfo, 0);
......@@ -7093,14 +7086,16 @@ int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSq
return invalidOperationMsg(pMsgBuf, msg5);
}
}
pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
}else{
pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
}
if (udf) {
return invalidOperationMsg(pMsgBuf, msg11);
}
pQueryInfo->order.order = pItem->sortOrder;
pQueryInfo->order.orderColId = pSchema[index.columnIndex].colId;
} else {
// handle the temp table order by clause. You can order by any single column in case of the temp table, created by
// inner subquery.
......
......@@ -385,6 +385,11 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t
case TSDB_DATA_TYPE_TINYINT: DEFAULT_COMP(GET_INT8_VAL(f1), GET_INT8_VAL(f2));
case TSDB_DATA_TYPE_BINARY: {
bool leftIsNull = isNull(f1, TSDB_DATA_TYPE_BINARY);
bool rightIsNull = isNull(f2, TSDB_DATA_TYPE_BINARY);
if(leftIsNull && rightIsNull) return 0;
else if(leftIsNull) return -1;
else if(rightIsNull) return 1;
int32_t len1 = varDataLen(f1);
int32_t len2 = varDataLen(f2);
......@@ -408,6 +413,12 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t
return (ret < 0) ? -1 : 1;
};
case TSDB_DATA_TYPE_NCHAR: { // todo handle the var string compare
bool leftIsNull = isNull(f1, TSDB_DATA_TYPE_NCHAR);
bool rightIsNull = isNull(f2, TSDB_DATA_TYPE_NCHAR);
if(leftIsNull && rightIsNull) return 0;
else if(leftIsNull) return -1;
else if(rightIsNull) return 1;
int32_t len1 = varDataLen(f1);
int32_t len2 = varDataLen(f2);
......
......@@ -180,6 +180,12 @@ int32_t compareDoubleValDesc(const void* pLeft, const void* pRight) {
}
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {
bool leftIsNull = isNull(pLeft, TSDB_DATA_TYPE_BINARY);
bool rightIsNull = isNull(pRight, TSDB_DATA_TYPE_BINARY);
if(leftIsNull && rightIsNull) return 0;
else if(leftIsNull) return -1;
else if(rightIsNull) return 1;
int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight);
......@@ -200,6 +206,12 @@ int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight) {
}
int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
bool leftIsNull = isNull(pLeft, TSDB_DATA_TYPE_NCHAR);
bool rightIsNull = isNull(pRight, TSDB_DATA_TYPE_NCHAR);
if(leftIsNull && rightIsNull) return 0;
else if(leftIsNull) return -1;
else if(rightIsNull) return 1;
int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册