fix:[TS-5761] error for in operator

This commit is contained in:
wangmm0220 2024-12-18 11:01:23 +08:00
parent 2013a822f5
commit f71dfa40e5
7 changed files with 85 additions and 25 deletions

View File

@ -4848,7 +4848,6 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
}
SColumnNode *refNode = (SColumnNode *)node->pLeft;
int32_t type = refNode->node.resType.type;
SExprNode *exprNode = NULL;
if (OP_TYPE_IN != node->opType && OP_TYPE_NOT_IN != node->opType) {
SValueNode *valueNode = (SValueNode *)node->pRight;
@ -4857,29 +4856,34 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) {
valueNode->node.resType.type = TSDB_DATA_TYPE_BIGINT;
}
exprNode = &valueNode->node;
type = vectorGetConvertType(refNode->node.resType.type, exprNode->resType.type);
int32_t type = vectorGetConvertType(refNode->node.resType.type, exprNode->resType.type);
if (0 != type && type != refNode->node.resType.type) {
stat->scalarMode = true;
}
return DEAL_RES_CONTINUE;
} else {
SNodeListNode *listNode = (SNodeListNode *)node->pRight;
if (LIST_LENGTH(listNode->pNodeList) > 10) {
if (LIST_LENGTH(listNode->pNodeList) > 10 || OP_TYPE_NOT_IN == node->opType) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
}
int32_t type = -1;
exprNode = &listNode->node;
SListCell *cell = listNode->pNodeList->pHead;
for (int32_t i = 0; i < listNode->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode;
cell = cell->pNext;
int32_t tmp = vectorGetConvertType(type, valueNode->node.resType.type);
int32_t tmp = vectorGetConvertType(refNode->node.resType.type, valueNode->node.resType.type);
if (tmp != 0){
type = tmp;
stat->scalarMode = true;
if (IS_NUMERIC_TYPE(tmp) && tmp > type){
type = tmp;
}
}
}
if (IS_NUMERIC_TYPE(type)){
exprNode->resType.type = type;
}
}
if ((0 != type && type != refNode->node.resType.type) || OP_TYPE_NOT_IN == node->opType) {
stat->scalarMode = true;
return DEAL_RES_CONTINUE;
}
}

View File

@ -201,9 +201,6 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type, int8_
cell = cell->pNext;
}
if (taosHashGetSize(pObj) == 0) {
goto _return;
}
*data = pObj;
colDataDestroy(out.columnData);
@ -386,8 +383,21 @@ int32_t sclInitParam(SNode *node, SScalarParam *param, SScalarCtx *ctx, int32_t
SCL_RET(TSDB_CODE_QRY_INVALID_INPUT);
}
int32_t type = ctx->type.peerType;
if (IS_VAR_DATA_TYPE(ctx->type.selfType) && IS_NUMERIC_TYPE(ctx->type.peerType)){
int32_t type = -1;
SListCell *cell = nodeList->pNodeList->pHead;
for (int32_t i = 0; i < nodeList->pNodeList->length; ++i) {
SValueNode *valueNode = (SValueNode *)cell->pNode;
cell = cell->pNext;
int32_t tmp = vectorGetConvertType(ctx->type.selfType, valueNode->node.resType.type);
if (tmp != 0 && IS_NUMERIC_TYPE(tmp) && tmp > type){
type = tmp;
}
}
if (IS_NUMERIC_TYPE(type)){
ctx->type.peerType = type;
}
type = ctx->type.peerType;
if (IS_VAR_DATA_TYPE(ctx->type.selfType) && IS_NUMERIC_TYPE(type)){
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilter, node, type, 1));
SCL_ERR_RET(scalarGenerateSetFromList((void **)&param->pHashFilterVar, node, ctx->type.selfType, 2));
} else {

View File

@ -2013,9 +2013,17 @@ int32_t doVectorCompare(SScalarParam *pLeft, SScalarParam *pLeftVar, SScalarPara
char *pLeftData = colDataGetData(pLeft->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter);
if (pLeftVar != NULL && !res){
pLeftData = colDataGetData(pLeftVar->columnData, i);
res = res || filterDoCompare(fpVar, optr, pLeftData, pRight->pHashFilterVar);
if (pLeftVar != NULL && taosHashGetSize(pRight->pHashFilterVar) > 0){
do{
if (optr == OP_TYPE_IN && res){
break;
}
if (optr == OP_TYPE_NOT_IN && !res){
break;
}
pLeftData = colDataGetData(pLeftVar->columnData, i);
res = filterDoCompare(fpVar, optr, pLeftData, pRight->pHashFilterVar);
}while(0);
}
colDataSetInt8(pOut->columnData, i, (int8_t *)&res);
if (res) {

View File

@ -152,8 +152,8 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (FLT_EQUAL(f, 0.0)) {
return 0;
}
if (fabs(f) < FLT_MAX / BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT)));
if (fabs(f) < INT32_MAX) {
int32_t t = (int32_t)(floor(f));
return (uint32_t)t;
} else {
return 0x7fc00000;
@ -168,8 +168,8 @@ uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (FLT_EQUAL(f, 0.0)) {
return 0;
}
if (fabs(f) < DBL_MAX / BASE - DLT) {
int32_t t = (int32_t)(round(BASE * (f + DLT)));
if (fabs(f) < INT32_MAX) {
int32_t t = (int32_t)(floor(f));
return (uint32_t)t;
} else {
return 0x7fc00000;

View File

@ -44,7 +44,7 @@ if $data20 != @ Time Range: [-9223372036854775808, 9223372036854775807]@ th
endi
sql select * from tb1 where fbool in (0, 3);
if $rows != 5 then
if $rows != 3 then
return -1
endi
@ -69,7 +69,7 @@ if $rows != 10 then
endi
sql select * from st1 where tbool in (0, 3);
if $rows != 15 then
if $rows != 5 then
return -1
endi

View File

@ -21,12 +21,17 @@ class TDTestCase:
tdSql.execute(f"use db")
# super tableUNSIGNED
tdSql.execute("CREATE TABLE t1( time TIMESTAMP, c1 BIGINT, c2 smallint, c3 double, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32));")
tdSql.execute("CREATE TABLE st( time TIMESTAMP, c1 BIGINT, c2 smallint, c3 double, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32)) tags(t1 binary(32), t2 nchar(32))")
tdSql.execute("create table t1 using st tags('1', '1.7')")
tdSql.execute("create table t2 using st tags('0', '')")
tdSql.execute("create table t3 using st tags('1', 'er')")
# create index for all tags
tdSql.execute("INSERT INTO t1 VALUES (1641024000000, 1, 1, 1, 1, 1, '1', '1.7')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000001, 0, 0, 1.7, 0, 0, '0', '')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t2 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t3 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
def check(self):
tdSql.query(f"SELECT * FROM t1 WHERE c1 = 1.7")
@ -84,6 +89,8 @@ class TDTestCase:
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2, 'sef')")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = 1.7")
tdSql.checkRows(1)
@ -106,6 +113,18 @@ class TDTestCase:
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in ('', 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM st WHERE t2 in ('', 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t2 not in ('', 2)")
tdSql.checkRows(4)
tdSql.query(f"SELECT * FROM st WHERE t1 in ('d343', 0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 not in (0, 2)")
tdSql.checkRows(4)
def run(self):
self.prepareData()
self.check()

View File

@ -20,12 +20,17 @@ class TDTestCase:
tdSql.execute(f"use db")
# super tableUNSIGNED
tdSql.execute("CREATE TABLE t1( time TIMESTAMP, c1 BIGINT, c2 smallint, c3 double, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32));")
tdSql.execute("CREATE TABLE st( time TIMESTAMP, c1 BIGINT, c2 smallint, c3 double, c4 int UNSIGNED, c5 bool, c6 binary(32), c7 nchar(32)) tags(t1 binary(32), t2 nchar(32))")
tdSql.execute("create table t1 using st tags('1', '1.7')")
tdSql.execute("create table t2 using st tags('0', '')")
tdSql.execute("create table t3 using st tags('1', 'er')")
# create index for all tags
tdSql.execute("INSERT INTO t1 VALUES (1641024000000, 1, 1, 1, 1, 1, '1', '1.7')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000001, 0, 0, 1.7, 0, 0, '0', '')")
tdSql.execute("INSERT INTO t1 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t2 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
tdSql.execute("INSERT INTO t3 VALUES (1641024000002, 1, 1, 1, 1, 1, '1', 'er')")
def check(self):
tdSql.query(f"SELECT * FROM t1 WHERE c1 = 1.7")
@ -83,6 +88,8 @@ class TDTestCase:
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c6 not in (0, 2, 'sef')")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM t1 WHERE c7 = 1.7")
tdSql.checkRows(1)
@ -105,6 +112,18 @@ class TDTestCase:
tdSql.query(f"SELECT * FROM t1 WHERE c7 not in ('', 2)")
tdSql.checkRows(2)
tdSql.query(f"SELECT * FROM st WHERE t2 in ('', 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t2 not in ('', 2)")
tdSql.checkRows(4)
tdSql.query(f"SELECT * FROM st WHERE t1 in ('d343', 0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 in (0, 2)")
tdSql.checkRows(1)
tdSql.query(f"SELECT * FROM st WHERE t1 not in (0, 2)")
tdSql.checkRows(4)
def run(self):
self.prepareData()
self.check()