diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index e3a0f159490907c9ea9ec15a396b2f0257a9a524..2dff94bee0e9381b7d4feb51f7df92b0dcd0ee9c 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2206,8 +2206,18 @@ static void doSetTagValueInParam(void *tsdb, STableId* pTableId, int32_t tagColI } if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + if (isNull(varDataVal(val), type)) { + tag->nType = TSDB_DATA_TYPE_NULL; + return; + } + tVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type); } else { + if (isNull(val, type)) { + tag->nType = TSDB_DATA_TYPE_NULL; + return; + } + tVariantCreateFromBinary(tag, val, bytes, type); } } @@ -4285,12 +4295,12 @@ static void sequentialTableProcess(SQInfo *pQInfo) { assert(taosArrayGetSize(s) >= 1); setTagVal(pRuntimeEnv, (STableId*) taosArrayGet(s, 0), pQInfo->tsdb); - if (isFirstLastRowQuery(pQuery)) { assert(taosArrayGetSize(s) == 1); } + taosArrayDestroy(s); - + // here we simply set the first table as current table pQuery->current = ((SGroupItem*) taosArrayGet(group, 0))->info; scanOneTableDataBlocks(pRuntimeEnv, pQuery->current->lastKey); diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 93f5ca93557111afd1d739540b162a00248d6880..732e8e900812acff6bc18ea7cd4277b74d1b917f 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1930,8 +1930,7 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { SColIndex* pColIndex = &pTableGroupSupp->pCols[i]; int32_t colIndex = pColIndex->colIndex; - assert((colIndex >= 0 && colIndex < schemaNCols(pTableGroupSupp->pTagSchema)) || - (colIndex == TSDB_TBNAME_COLUMN_INDEX)); + assert(colIndex >= TSDB_TBNAME_COLUMN_INDEX); char * f1 = NULL; char * f2 = NULL; @@ -1950,7 +1949,20 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { f1 = tdGetKVRowValOfCol(pTable1->tagVal, pCol->colId); f2 = tdGetKVRowValOfCol(pTable2->tagVal, pCol->colId); } - + + // this tags value may be NULL + if (f1 == NULL && f2 == NULL) { + continue; + } + + if (f1 == NULL) { + return -1; + } + + if (f2 == NULL) { + return 1; + } + int32_t ret = doCompare(f1, f2, type, bytes); if (ret == 0) { continue; diff --git a/tests/script/general/parser/set_tag_vals.sim b/tests/script/general/parser/set_tag_vals.sim index a684fd5406950ede213ad065a45a7aa79d355818..9d7ac9678daefde512ac9d126742b43aa3508017 100644 --- a/tests/script/general/parser/set_tag_vals.sim +++ b/tests/script/general/parser/set_tag_vals.sim @@ -9,7 +9,7 @@ sql connect $dbPrefix = db $tbPrefix = tb $stbPrefix = stb -$tbNum = 1000 +$tbNum = 100 $rowNum = 100 $totalNum = $tbNum * $rowNum $ts0 = 1537146000000 @@ -26,7 +26,7 @@ $stb = $stbPrefix . $i sql drop database $db -x step1 step1: sql create database $db -print ====== create tables +print ====== create $tbNum tables sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 binary(9), t2 binary(8))