diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 86d0c770d99f97216d3f630748e571101c1d2f06..b03e3c5f11b06d48679aff12cc19f53038fe6697 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -76,7 +76,6 @@ static int32_t getDelimiterIndex(SStrToken* pTableName); static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd); static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pCmd); -static int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStrToken* tableName, int32_t* len); static void getColumnName(tSqlExprItem* pItem, char* resultFieldName, char* rawName, int32_t nameLength); static int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t colIndex, tSqlExprItem* pItem, @@ -335,7 +334,7 @@ static int setColumnFilterInfoForTimestamp(SSqlCmd* pCmd, SQueryInfo* pQueryInfo STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); - if (convertTimestampStrToInt64(pVar, tinfo.precision) < -1) { + if (convertTimestampStrToInt64(pVar, tinfo.precision) < 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); } return TSDB_CODE_SUCCESS; @@ -1698,57 +1697,6 @@ static int32_t getDelimiterIndex(SStrToken* pTableName) { return -1; } -int32_t setObjFullName(char* fullName, const char* account, SStrToken* pDB, SStrToken* tableName, int32_t* xlen) { - int32_t totalLen = 0; - - if (account != NULL) { - int32_t len = (int32_t)strlen(account); - strcpy(fullName, account); - fullName[len] = TS_PATH_DELIMITER[0]; - totalLen += (len + 1); - } - - /* db name is not specified, the tableName dose not include db name */ - if (pDB != NULL) { - if (pDB->n >= TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN || pDB->n == 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - memcpy(&fullName[totalLen], pDB->z, pDB->n); - totalLen += pDB->n; - } - - if (tableName != NULL) { - if (pDB != NULL) { - fullName[totalLen] = TS_PATH_DELIMITER[0]; - totalLen += 1; - - /* here we only check the table name length limitation */ - if (!tscValidateTableNameLength(tableName->n)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } else { // pDB == NULL, the db prefix name is specified in tableName - /* the length limitation includes tablename + dbname + sep */ - if (tableName->n >= TSDB_TABLE_NAME_LEN + TSDB_DB_NAME_LEN) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } - - memcpy(&fullName[totalLen], tableName->z, tableName->n); - totalLen += tableName->n; - } - - if (xlen != NULL) { - *xlen = totalLen; - } - - if (totalLen < TSDB_TABLE_FNAME_LEN) { - fullName[totalLen] = 0; - } - - return (totalLen < TSDB_TABLE_FNAME_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_TSC_INVALID_OPERATION; -} - void tscInsertPrimaryTsSourceColumn(SQueryInfo* pQueryInfo, uint64_t tableUid) { SSchema s = {.type = TSDB_DATA_TYPE_TIMESTAMP, .bytes = TSDB_KEYSIZE, .colId = PRIMARYKEY_TIMESTAMP_COL_INDEX}; tscColumnListInsert(pQueryInfo->colList, PRIMARYKEY_TIMESTAMP_COL_INDEX, tableUid, &s); @@ -3737,11 +3685,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, } } - if (pExpr->tokenId == TK_LE || pExpr->tokenId == TK_LT) { - retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->upperBndd, colType, false); - - // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd - } else if (pExpr->tokenId == TK_IN) { + if (pExpr->tokenId == TK_IN) { tVariant *pVal; if (pRight->tokenId != TK_SET || !serializeExprListToVariant(pRight->Expr.paramList, &pVal, colType, timePrecision)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); @@ -3767,6 +3711,10 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, size_t len = twcslen((wchar_t*)pColumnFilter->pz); pColumnFilter->len = len * TSDB_NCHAR_SIZE; + } else if (pExpr->tokenId == TK_LE || pExpr->tokenId == TK_LT) { + retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->upperBndd, colType, false); + + // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd } else { retVal = tVariantDump(&pRight->value, (char*)&pColumnFilter->lowerBndd, colType, false); } @@ -3825,9 +3773,6 @@ typedef struct SCondExpr { tSqlExpr* pColumnCond; - tSqlExpr* pTableCond; - int16_t relType; // relation between table name in expression and other tag - // filter condition expression, TK_AND or TK_OR int16_t tableCondIndex; tSqlExpr* pJoinExpr; // join condition @@ -3836,51 +3781,6 @@ typedef struct SCondExpr { static int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t timePrecision); -static int32_t tablenameListToString(tSqlExpr* pExpr, SStringBuilder* sb) { - SArray* pList = pExpr->Expr.paramList; - - int32_t size = (int32_t) taosArrayGetSize(pList); - if (size <= 0) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - if (size > 0) { - taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN); - } - - for (int32_t i = 0; i < size; ++i) { - tSqlExprItem* pSub = taosArrayGet(pList, i); - tVariant* pVar = &pSub->pNode->value; - - taosStringBuilderAppendStringLen(sb, pVar->pz, pVar->nLen); - - if (i < size - 1) { - taosStringBuilderAppendString(sb, TBNAME_LIST_SEP); - } - - if (pVar->nLen <= 0 || !tscValidateTableNameLength(pVar->nLen)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t tablenameCondToString(tSqlExpr* pExpr, uint32_t opToken, SStringBuilder* sb) { - assert(opToken == TK_LIKE || opToken == TK_MATCH || opToken == TK_NMATCH); - if (opToken == TK_LIKE) { - taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN); - taosStringBuilderAppendString(sb, pExpr->value.pz); - } else if (opToken == TK_MATCH) { - taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN); - taosStringBuilderAppendString(sb, pExpr->value.pz); - } else if (opToken == TK_NMATCH) { - taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN); - taosStringBuilderAppendString(sb, pExpr->value.pz); - } - return TSDB_CODE_SUCCESS; -} - enum { TSQL_EXPR_TS = 1, TSQL_EXPR_TAG = 2, @@ -3898,7 +3798,6 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, pIndex->columnIndex); int32_t ret = 0; const char* msg1 = "non binary column not support like/match operator"; - const char* msg2 = "binary column not support this operator"; const char* msg3 = "bool column not support this operator"; const char* msg4 = "primary key not support this operator"; @@ -3919,19 +3818,7 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol pColFilter->filterstr = ((pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) ? 1 : 0); - if (pColFilter->filterstr) { - if (pExpr->tokenId != TK_EQ - && pExpr->tokenId != TK_NE - && pExpr->tokenId != TK_ISNULL - && pExpr->tokenId != TK_NOTNULL - && pExpr->tokenId != TK_LIKE - && pExpr->tokenId != TK_MATCH - && pExpr->tokenId != TK_NMATCH - && pExpr->tokenId != TK_IN) { - ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); - goto _err_ret; - } - } else { + if (!pColFilter->filterstr) { if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_NMATCH) { ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); goto _err_ret; @@ -3961,40 +3848,6 @@ _err_ret: return ret; } -static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pTableCond, SStringBuilder* sb) { - const char* msg0 = "invalid table name list"; - const char* msg1 = "not string following like"; - - if (pTableCond == NULL) { - return TSDB_CODE_SUCCESS; - } - - tSqlExpr* pLeft = pTableCond->pLeft; - tSqlExpr* pRight = pTableCond->pRight; - - if (!isTablenameToken(&pLeft->columnName)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - int32_t ret = TSDB_CODE_SUCCESS; - - if (pTableCond->tokenId == TK_IN) { - ret = tablenameListToString(pRight, sb); - } else if (pTableCond->tokenId == TK_LIKE || pTableCond->tokenId == TK_MATCH || pTableCond->tokenId == TK_NMATCH) { - if (pRight->tokenId != TK_STRING) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); - } - - ret = tablenameCondToString(pRight, pTableCond->tokenId, sb); - } - - if (ret != TSDB_CODE_SUCCESS) { - invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); - } - - return ret; -} - static int32_t getColQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr) { int32_t ret = TSDB_CODE_SUCCESS; @@ -4117,8 +3970,9 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS index.columnIndex = index.columnIndex - tscGetNumOfColumns(pTableMetaInfo->pTableMeta); if (tscColumnExists(pTableMetaInfo->tagColList, pTagSchema1->colId, pTableMetaInfo->pTableMeta->id.uid) < 0) { tscColumnListInsert(pTableMetaInfo->tagColList, index.columnIndex, pTableMeta->id.uid, pTagSchema1); + atomic_add_fetch_32(&pTableMetaInfo->joinTagNum, 1); - if (taosArrayGetSize(pTableMetaInfo->tagColList) > 1) { + if (pTableMetaInfo->joinTagNum > 1) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } } @@ -4150,7 +4004,9 @@ static int32_t checkAndSetJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tS if (tscColumnExists(pTableMetaInfo->tagColList, pTagSchema2->colId, pTableMeta->id.uid) < 0) { tscColumnListInsert(pTableMetaInfo->tagColList, index.columnIndex, pTableMeta->id.uid, pTagSchema2); - if (taosArrayGetSize(pTableMetaInfo->tagColList) > 1) { + atomic_add_fetch_32(&pTableMetaInfo->joinTagNum, 1); + + if (pTableMetaInfo->joinTagNum > 1) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } } @@ -4433,18 +4289,6 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr return true; } -static bool validTableNameOptr(tSqlExpr* pExpr) { - const char nameFilterOptr[] = {TK_IN, TK_LIKE, TK_MATCH, TK_NMATCH}; - - for (int32_t i = 0; i < tListLen(nameFilterOptr); ++i) { - if (pExpr->tokenId == nameFilterOptr[i]) { - return true; - } - } - - return false; -} - static int32_t setExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, const char* msg, int32_t parentOptr, char* msgBuf) { if (*parent != NULL) { if (parentOptr == TK_OR && msg != NULL) { @@ -4588,8 +4432,6 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql const char* msg2 = "illegal column name"; const char* msg4 = "too many join tables"; const char* msg5 = "not support ordinary column join"; - const char* msg6 = "only one query condition on tbname allowed"; - const char* msg7 = "only in/like allowed in filter table name"; tSqlExpr* pLeft = (*pExpr)->pLeft; tSqlExpr* pRight = (*pExpr)->pRight; @@ -4706,54 +4548,30 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); } - // in case of in operator, keep it in a seprate attribute - if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { - if (!validTableNameOptr(*pExpr)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); - } - - if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + if (pRight != NULL && pRight->tokenId == TK_ID) { // join on tag columns for stable query + if (!validateJoinExprNode(pCmd, pQueryInfo, *pExpr, &index)) { + return TSDB_CODE_TSC_INVALID_OPERATION; } - if (pCondExpr->pTableCond == NULL) { - pCondExpr->pTableCond = *pExpr; - pCondExpr->relType = parentOptr; - pCondExpr->tableCondIndex = index.tableIndex; - } else { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); + pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_QUERY; + ret = setExprToCond(&pCondExpr->pJoinExpr, *pExpr, NULL, parentOptr, pCmd->payload); + *pExpr = NULL; + if (type) { + *type |= TSQL_EXPR_JOIN; + } + } else { + // do nothing + // ret = setExprToCond(pCmd, &pCondExpr->pTagCond, + // *pExpr, NULL, parentOptr); + tSqlExpr *rexpr = NULL; + if ((*pExpr)->tokenId == TK_NE && (pSchema->type != TSDB_DATA_TYPE_BINARY && pSchema->type != TSDB_DATA_TYPE_NCHAR && pSchema->type != TSDB_DATA_TYPE_BOOL)) { + handleNeOptr(&rexpr, *pExpr); + *pExpr = rexpr; } - + if (type) { *type |= TSQL_EXPR_TAG; } - *pExpr = NULL; - } else { - if (pRight != NULL && pRight->tokenId == TK_ID) { // join on tag columns for stable query - if (!validateJoinExprNode(pCmd, pQueryInfo, *pExpr, &index)) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_QUERY; - ret = setExprToCond(&pCondExpr->pJoinExpr, *pExpr, NULL, parentOptr, pCmd->payload); - *pExpr = NULL; - if (type) { - *type |= TSQL_EXPR_JOIN; - } - } else { - // do nothing - // ret = setExprToCond(pCmd, &pCondExpr->pTagCond, - // *pExpr, NULL, parentOptr); - tSqlExpr *rexpr = NULL; - if ((*pExpr)->tokenId == TK_NE && (pSchema->type != TSDB_DATA_TYPE_BINARY && pSchema->type != TSDB_DATA_TYPE_NCHAR && pSchema->type != TSDB_DATA_TYPE_BOOL)) { - handleNeOptr(&rexpr, *pExpr); - *pExpr = rexpr; - } - - if (type) { - *type |= TSQL_EXPR_TAG; - } - } } } else { // query on other columns if (type) { @@ -4940,84 +4758,6 @@ int tableNameCompar(const void* lhs, const void* rhs) { return ret > 0 ? 1 : -1; } -static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, const char* account, - tSqlExpr* pExpr, int16_t tableCondIndex, SStringBuilder* sb) { - const char* msg = "table name too long"; - - if (pExpr == NULL) { - return TSDB_CODE_SUCCESS; - } - - STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableCondIndex); - - STagCond* pTagCond = &pQueryInfo->tagCond; - pTagCond->tbnameCond.uid = pTableMetaInfo->pTableMeta->id.uid; - - assert(pExpr->tokenId == TK_LIKE - || pExpr->tokenId == TK_MATCH - || pExpr->tokenId == TK_NMATCH - || pExpr->tokenId == TK_IN); - - if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_NMATCH) { - char* str = taosStringBuilderGetResult(sb, NULL); - pQueryInfo->tagCond.tbnameCond.cond = strdup(str); - pQueryInfo->tagCond.tbnameCond.len = (int32_t) strlen(str); - return TSDB_CODE_SUCCESS; - } else { - SStringBuilder sb1; - memset(&sb1, 0, sizeof(sb1)); - taosStringBuilderAppendStringLen(&sb1, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN); - - // remove the duplicated input table names - int32_t num = 0; - char* tableNameString = taosStringBuilderGetResult(sb, NULL); - - char** segments = strsplit(tableNameString + QUERY_COND_REL_PREFIX_IN_LEN, TBNAME_LIST_SEP, &num); - qsort(segments, num, POINTER_BYTES, tableNameCompar); - - int32_t j = 1; - for (int32_t i = 1; i < num; ++i) { - if (strcmp(segments[i], segments[i - 1]) != 0) { - segments[j++] = segments[i]; - } - } - num = j; - - char name[TSDB_DB_NAME_LEN] = {0}; - tNameGetDbName(&pTableMetaInfo->name, name); - SStrToken dbToken = {.type = TK_STRING, .z = name, .n = (uint32_t)strlen(name)}; - - for (int32_t i = 0; i < num; ++i) { - if (i >= 1) { - taosStringBuilderAppendStringLen(&sb1, TBNAME_LIST_SEP, 1); - } - - char idBuf[TSDB_TABLE_FNAME_LEN] = {0}; - int32_t xlen = (int32_t)strlen(segments[i]); - SStrToken t = {.z = segments[i], .n = xlen, .type = TK_STRING}; - - int32_t ret = setObjFullName(idBuf, account, &dbToken, &t, &xlen); - if (ret != TSDB_CODE_SUCCESS) { - taosStringBuilderDestroy(&sb1); - tfree(segments); - - invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg); - return ret; - } - - taosStringBuilderAppendString(&sb1, idBuf); - } - - char* str = taosStringBuilderGetResult(&sb1, NULL); - pQueryInfo->tagCond.tbnameCond.cond = strdup(str); - pQueryInfo->tagCond.tbnameCond.len = (int32_t)strlen(str); - - taosStringBuilderDestroy(&sb1); - tfree(segments); - return TSDB_CODE_SUCCESS; - } -} - int32_t mergeTimeRange(SSqlCmd* pCmd, STimeWindow* res, STimeWindow* win, int32_t optr) { const char* msg0 = "only one time stamp window allowed"; @@ -5157,10 +4897,6 @@ static int32_t validateJoinExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr } static void cleanQueryExpr(SCondExpr* pCondExpr) { - if (pCondExpr->pTableCond) { - tSqlExprDestroy(pCondExpr->pTableCond); - } - if (pCondExpr->pColumnCond) { tSqlExprDestroy(pCondExpr->pColumnCond); } @@ -5456,7 +5192,7 @@ static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr //multiple tables's query time range mixed together tExprNode* p = NULL; - SFilterInfo *filter = NULL; + void *filter = NULL; SArray* colList = taosArrayInit(10, sizeof(SColIndex)); ret = exprTreeFromSqlExpr(pCmd, &p, *pExpr, pQueryInfo, colList, NULL); @@ -5498,7 +5234,6 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq int32_t ret = TSDB_CODE_SUCCESS; // tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space - SStringBuilder sb; memset(&sb, 0, sizeof(sb)); SCondExpr condExpr = {0}; if ((*pExpr)->pLeft == NULL || (*pExpr)->pRight == NULL) { @@ -5531,12 +5266,12 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq condExpr.pTagCond = (*pExpr); *pExpr = NULL; - // 1. check if it is a join query + // check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } - // 2. get the query time range + // get the query time range if ((ret = convertTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } @@ -5544,19 +5279,13 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq if ((ret = getQueryTimeRange(&pSql->cmd, pQueryInfo, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } - - // 3. get the tag query condition + // get the tag query condition if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } - // 4. get the table name query condition - if ((ret = getTablenameCond(&pSql->cmd, pQueryInfo, condExpr.pTableCond, &sb)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; - } - - // 5. other column query condition + // other column query condition if ((ret = checkColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } @@ -5565,21 +5294,11 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq goto PARSE_WHERE_EXIT; } - - // 6. join condition + // join condition if ((ret = getJoinCondInfo(&pSql->cmd, pQueryInfo, condExpr.pJoinExpr)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } - // 7. query condition for table name - pQueryInfo->tagCond.relType = (condExpr.relType == TK_AND) ? TSDB_RELATION_AND : TSDB_RELATION_OR; - - ret = setTableCondForSTableQuery(&pSql->cmd, pQueryInfo, getAccountId(pSql), condExpr.pTableCond, condExpr.tableCondIndex, &sb); - taosStringBuilderDestroy(&sb); - if (ret) { - goto PARSE_WHERE_EXIT; - } - //if (!validateFilterExpr(pQueryInfo)) { // ret = invalidOperationMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); // goto PARSE_WHERE_EXIT; @@ -5650,6 +5369,10 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t pRight->flags &= ~(1 << EXPR_FLAG_NS_TIMESTAMP); } + if (pRight->value.nType == -1) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + tVariantDump(&pRight->value, (char*)&val, TSDB_DATA_TYPE_BIGINT, true); } @@ -9230,13 +8953,17 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS (*pExpr)->pVal = calloc(1, sizeof(tVariant)); tVariantAssign((*pExpr)->pVal, &pSqlExpr->value); - STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; - if (pCols != NULL && taosArrayGetSize(pCols) > 0) { - SColIndex* idx = taosArrayGet(pCols, 0); - SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); - // convert time by precision - if (pSchema != NULL && TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && TSDB_DATA_TYPE_BINARY == (*pExpr)->pVal->nType) { - ret = setColumnFilterInfoForTimestamp(pCmd, pQueryInfo, (*pExpr)->pVal); + STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, pQueryInfo->curTableIdx)->pTableMeta; + if (pCols != NULL) { + size_t colSize = taosArrayGetSize(pCols); + + if (colSize > 0) { + SColIndex* idx = taosArrayGet(pCols, colSize - 1); + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); + // convert time by precision + if (pSchema != NULL && TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && TSDB_DATA_TYPE_BINARY == (*pExpr)->pVal->nType) { + ret = setColumnFilterInfoForTimestamp(pCmd, pQueryInfo, (*pExpr)->pVal); + } } } return ret; @@ -9279,8 +9006,18 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS (*pExpr)->nodeType = TSQL_NODE_COL; (*pExpr)->pSchema = calloc(1, sizeof(SSchema)); - SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, index.columnIndex); - *(*pExpr)->pSchema = *pSchema; + SSchema* pSchema = NULL; + + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + pSchema = (*pExpr)->pSchema; + strcpy(pSchema->name, TSQL_TBNAME_L); + pSchema->type = TSDB_DATA_TYPE_BINARY; + pSchema->colId = TSDB_TBNAME_COLUMN_INDEX; + pSchema->bytes = -1; + } else { + pSchema = tscGetTableColumnSchema(pTableMeta, index.columnIndex); + *(*pExpr)->pSchema = *pSchema; + } if (pCols != NULL) { // record the involved columns SColIndex colIndex = {0}; @@ -9301,9 +9038,13 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS if (colSize > 0) { SColIndex* idx = taosArrayGet(pCols, colSize - 1); - SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); - if (pSchema != NULL) { - colType = pSchema->type; + if (idx->colIndex == TSDB_TBNAME_COLUMN_INDEX) { + colType = TSDB_DATA_TYPE_BINARY; + } else { + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); + if (pSchema != NULL) { + colType = pSchema->type; + } } } } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index b87ec92ff1f056fdc5eeb8992cec418d07158b0b..dcfbc857d5d6792b3796a098ea61046439fc5d0f 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -703,11 +703,6 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { } } - SCond* pCond = &pQueryInfo->tagCond.tbnameCond; - if (pCond->len > 0) { - srcColListSize += pCond->len; - } - return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + srcTagFilterSize + exprSize + tsBufSize + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; } @@ -956,8 +951,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->numOfOutput = htons((int16_t)query.numOfOutput); // this is the stage one output column number pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols); - pQueryMsg->tagNameRelType = htons(pQueryInfo->tagCond.relType); - pQueryMsg->tbnameCondLen = htonl(pQueryInfo->tagCond.tbnameCond.len); pQueryMsg->queryType = htonl(pQueryInfo->type); pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen); @@ -1076,12 +1069,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pMsg += pQueryInfo->bufLen; } - SCond* pCond = &pQueryInfo->tagCond.tbnameCond; - if (pCond->len > 0) { - strncpy(pMsg, pCond->cond, pCond->len); - pMsg += pCond->len; - } - // compressed ts block pQueryMsg->tsBuf.tsOffset = htonl((int32_t)(pMsg - pCmd->payload)); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 275042a238dc9bd580ff5d09b8e85874b9031031..99a2a79dc60c89530eb9c2c7f6b5645ca0133ba1 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1347,7 +1347,11 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow pCmd->command = TSDB_SQL_SELECT; tscResetForNextRetrieve(&pSql->res); - assert(pSupporter->f == NULL); + if (pSupporter->f != NULL) { + fclose(pSupporter->f); + pSupporter->f = NULL; + } + taosGetTmpfilePath("ts-join", pSupporter->path); // TODO check for failure diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 590584c6e55bd3f8007a3b717c7d3de734f96761..60a6e241ccdfd48c7eb5a68f2dd7a251f76097a5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -814,7 +814,7 @@ typedef struct SDummyInputInfo { SSDataBlock *block; STableQueryInfo *pTableQueryInfo; SSqlObj *pSql; // refactor: remove it - SFilterInfo *pFilterInfo; + void *pFilterInfo; } SDummyInputInfo; typedef struct SJoinStatus { @@ -830,7 +830,7 @@ typedef struct SJoinOperatorInfo { SRspResultInfo resultInfo; // todo refactor, add this info for each operator } SJoinOperatorInfo; -static void doSetupSDataBlock(SSqlRes* pRes, SSDataBlock* pBlock, SFilterInfo* pFilterInfo) { +static void doSetupSDataBlock(SSqlRes* pRes, SSDataBlock* pBlock, void* pFilterInfo) { int32_t offset = 0; char* pData = pRes->data; @@ -847,8 +847,9 @@ static void doSetupSDataBlock(SSqlRes* pRes, SSDataBlock* pBlock, SFilterInfo* p // filter data if needed if (pFilterInfo) { - //doSetFilterColumnInfo(pFilterInfo, numOfFilterCols, pBlock); - filterSetColFieldData(pFilterInfo, pBlock->info.numOfCols, pBlock->pDataBlock); + SColumnDataParam param = {.numOfCols = pBlock->info.numOfCols, .pDataBlock = pBlock->pDataBlock}; + filterSetColFieldData(pFilterInfo, ¶m, getColumnDataFromId); + bool gotNchar = false; filterConverNcharColumns(pFilterInfo, pBlock->info.rows, &gotNchar); int8_t* p = NULL; @@ -1111,7 +1112,7 @@ static void destroyDummyInputOperator(void* param, int32_t numOfOutput) { } // todo this operator servers as the adapter for Operator tree and SqlRes result, remove it later -SOperatorInfo* createDummyInputOperator(SSqlObj* pSql, SSchema* pSchema, int32_t numOfCols, SFilterInfo* pFilters) { +SOperatorInfo* createDummyInputOperator(SSqlObj* pSql, SSchema* pSchema, int32_t numOfCols, void* pFilters) { assert(numOfCols > 0); STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; @@ -1253,7 +1254,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue // if it is a join query, create join operator here int32_t numOfCol1 = pTableMeta->tableInfo.numOfColumns; - SFilterInfo *pFilters = NULL; + void *pFilters = NULL; STblCond *pCond = NULL; if (px->colCond) { pCond = tsGetTableFilter(px->colCond, pTableMeta->id.uid, 0); @@ -1280,7 +1281,7 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue for(int32_t i = 1; i < px->numOfTables; ++i) { STableMeta* pTableMeta1 = tscGetMetaInfo(px, i)->pTableMeta; numOfCol1 = pTableMeta1->tableInfo.numOfColumns; - SFilterInfo *pFilters1 = NULL; + void *pFilters1 = NULL; SSchema* pSchema1 = tscGetTableSchema(pTableMeta1); int32_t n = pTableMeta1->tableInfo.numOfColumns; @@ -2906,16 +2907,6 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId, int32_t int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { memset(dest, 0, sizeof(STagCond)); - if (src->tbnameCond.cond != NULL) { - dest->tbnameCond.cond = strdup(src->tbnameCond.cond); - if (dest->tbnameCond.cond == NULL) { - return -1; - } - } - - dest->tbnameCond.uid = src->tbnameCond.uid; - dest->tbnameCond.len = src->tbnameCond.len; - dest->joinInfo.hasJoin = src->joinInfo.hasJoin; for (int32_t i = 0; i < TSDB_MAX_JOIN_TABLE_NUM; ++i) { @@ -2934,9 +2925,6 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { } } - - dest->relType = src->relType; - if (src->pCond == NULL) { return 0; } @@ -3026,8 +3014,6 @@ void tscColCondRelease(SArray** pCond) { void tscTagCondRelease(STagCond* pTagCond) { - free(pTagCond->tbnameCond.cond); - if (pTagCond->pCond != NULL) { size_t s = taosArrayGetSize(pTagCond->pCond); for (int32_t i = 0; i < s; ++i) { diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index 0ede2e1e6f71c69aa6aaed2c05d671840679ce5c..bfeb3a6dfeee22f793c82748611c28ec537e8825 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -88,7 +88,6 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)); void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree); tExprNode* exprTreeFromBinary(const void* data, size_t size); -tExprNode* exprTreeFromTableName(const char* tbnameCond); tExprNode* exprdup(tExprNode* pTree); void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree); diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 6823de631fe65a27f527be011def4819dd77c73a..cc2bb8803badc2aae2e80200691be0439bac3afe 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -325,14 +325,6 @@ static void* exception_calloc(size_t nmemb, size_t size) { return p; } -static void* exception_malloc(size_t size) { - void* p = malloc(size); - if (p == NULL) { - THROW(TSDB_CODE_QRY_OUT_OF_MEMORY); - } - return p; -} - static UNUSED_FUNC char* exception_strdup(const char* str) { char* p = strdup(str); if (p == NULL) { @@ -395,97 +387,6 @@ tExprNode* exprTreeFromBinary(const void* data, size_t size) { return exprTreeFromBinaryImpl(&br); } -tExprNode* exprTreeFromTableName(const char* tbnameCond) { - if (!tbnameCond) { - return NULL; - } - - int32_t anchor = CLEANUP_GET_ANCHOR(); - - tExprNode* expr = exception_calloc(1, sizeof(tExprNode)); - CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, expr, NULL); - - expr->nodeType = TSQL_NODE_EXPR; - - tExprNode* left = exception_calloc(1, sizeof(tExprNode)); - expr->_node.pLeft = left; - - left->nodeType = TSQL_NODE_COL; - SSchema* pSchema = exception_calloc(1, sizeof(SSchema)); - left->pSchema = pSchema; - - *pSchema = *tGetTbnameColumnSchema(); - - tExprNode* right = exception_calloc(1, sizeof(tExprNode)); - expr->_node.pRight = right; - - if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN) == 0) { - right->nodeType = TSQL_NODE_VALUE; - expr->_node.optr = TSDB_RELATION_LIKE; - tVariant* pVal = exception_calloc(1, sizeof(tVariant)); - right->pVal = pVal; - size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN) + 1; - pVal->pz = exception_malloc(len); - memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_LIKE_LEN, len); - pVal->nType = TSDB_DATA_TYPE_BINARY; - pVal->nLen = (int32_t)len; - - } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN) == 0) { - right->nodeType = TSQL_NODE_VALUE; - expr->_node.optr = TSDB_RELATION_MATCH; - tVariant* pVal = exception_calloc(1, sizeof(tVariant)); - right->pVal = pVal; - size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN) + 1; - pVal->pz = exception_malloc(len); - memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN, len); - pVal->nType = TSDB_DATA_TYPE_BINARY; - pVal->nLen = (int32_t)len; - } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN) == 0) { - right->nodeType = TSQL_NODE_VALUE; - expr->_node.optr = TSDB_RELATION_NMATCH; - tVariant* pVal = exception_calloc(1, sizeof(tVariant)); - right->pVal = pVal; - size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN) + 1; - pVal->pz = exception_malloc(len); - memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN, len); - pVal->nType = TSDB_DATA_TYPE_BINARY; - pVal->nLen = (int32_t)len; - } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) { - right->nodeType = TSQL_NODE_VALUE; - expr->_node.optr = TSDB_RELATION_IN; - tVariant* pVal = exception_calloc(1, sizeof(tVariant)); - right->pVal = pVal; - pVal->nType = TSDB_DATA_TYPE_POINTER_ARRAY; - pVal->arr = taosArrayInit(2, POINTER_BYTES); - - const char* cond = tbnameCond + QUERY_COND_REL_PREFIX_IN_LEN; - for (const char *e = cond; *e != 0; e++) { - if (*e == TS_PATH_DELIMITER[0]) { - cond = e + 1; - } else if (*e == ',') { - size_t len = e - cond; - char* p = exception_malloc(len + VARSTR_HEADER_SIZE); - STR_WITH_SIZE_TO_VARSTR(p, cond, (VarDataLenT)len); - cond += len; - taosArrayPush(pVal->arr, &p); - } - } - - if (*cond != 0) { - size_t len = strlen(cond) + VARSTR_HEADER_SIZE; - - char* p = exception_malloc(len); - STR_WITH_SIZE_TO_VARSTR(p, cond, (VarDataLenT)(len - VARSTR_HEADER_SIZE)); - taosArrayPush(pVal->arr, &p); - } - - taosArraySortString(pVal->arr, taosArrayCompareString); - } - - CLEANUP_EXECUTE_TO(anchor, false); - return expr; -} - void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) { SBufferReader br = tbufInitReader(buf, len, false); uint32_t type = tbufReadUint32(&br); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index bb93c52142a73d00ebde9e039143a5e124eb6e9a..c3c8625fec3290e2d39d64f53a173b43cf21d7e3 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -492,7 +492,6 @@ typedef struct { SSessionWindow sw; // session window uint16_t tagCondLen; // tag length in current query uint16_t colCondLen; // column length in current query - uint32_t tbnameCondLen; // table name filter condition string length int16_t numOfGroupCols; // num of group by columns int16_t orderByIdx; int16_t orderType; // used in group by xx order by xxx @@ -502,7 +501,6 @@ typedef struct { int64_t offset; uint32_t queryType; // denote another query process int16_t numOfOutput; // final output columns numbers - int16_t tagNameRelType; // relation of tag criteria and tbname criteria int16_t fillType; // interpolate type uint64_t fillVal; // default value array list int32_t secondStageOutput; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index 089e30ac3728761c68fe155f960c8650a32c2f7a..4e11e4f2478fe0616701e0d183d38455b9526514 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -352,8 +352,7 @@ SArray *tsdbRetrieveDataBlock(TsdbQueryHandleT *pQueryHandle, SArray *pColumnIdL * @param pTagCond. tag query condition */ int32_t tsdbQuerySTableByTagCond(STsdbRepo *tsdb, uint64_t uid, TSKEY key, const char *pTagCond, size_t len, - int16_t tagNameRelType, const char *tbnameCond, STableGroupInfo *pGroupList, - SColIndex *pColIndex, int32_t numOfCols); + STableGroupInfo *pGroupList, SColIndex *pColIndex, int32_t numOfCols); /** * destroy the created table group list, which is generated by tag query diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index efc37403b46f2bfdd8e40eecd2ff53d00af6cd8a..4dfe424b11e82c78d5acbbcc7471c093cd75e7aa 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -569,7 +569,7 @@ static void shellPrintNChar(const char *str, int length, int width) { while (pos < length) { wchar_t wc; int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX); - if (bytes == 0) { + if (bytes <= 0) { break; } pos += bytes; diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index 19ca8e7ed8867f32c9625fe66ad4c04d64bc98e7..82f4f34a57c7d6d10a021fb2e426ff83cb3604e6 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -264,7 +264,7 @@ typedef struct SQueryAttr { SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query. SSingleColumnFilterInfo* pFilterInfo; - SFilterInfo *pFilters; + void *pFilters; void* tsdb; SMemRef memRef; @@ -399,7 +399,6 @@ typedef struct SQueryParam { char *sql; char *tagCond; char *colCond; - char *tbnameCond; char *prevResult; SArray *pTableIdList; SSqlExpr **pExpr; @@ -407,7 +406,7 @@ typedef struct SQueryParam { SExprInfo *pExprs; SExprInfo *pSecExprs; - SFilterInfo *pFilters; + void *pFilters; SColIndex *pGroupColIndex; SColumnInfo *pTagColumnInfo; @@ -417,6 +416,11 @@ typedef struct SQueryParam { SUdfInfo *pUdfInfo; } SQueryParam; +typedef struct SColumnDataParam{ + int32_t numOfCols; + SArray* pDataBlock; +} SColumnDataParam; + typedef struct STableScanInfo { void *pQueryHandle; int32_t numOfBlocks; @@ -640,11 +644,11 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlExpr **pExpr, SExprInfo *prevExpr, SUdfInfo *pUdfInfo); -int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters); +int32_t createQueryFilter(char *data, uint16_t len, void** pFilters); SGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code); SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs, - SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, SFilterInfo* pFilters, int32_t vgId, char* sql, uint64_t qId, SUdfInfo* pUdfInfo); + SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, void* pFilters, int32_t vgId, char* sql, uint64_t qId, SUdfInfo* pUdfInfo); int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, SQueryParam* param, char* start, int32_t prevResultLen, void* merger); @@ -684,5 +688,6 @@ void freeQueryAttr(SQueryAttr *pQuery); int32_t getMaximumIdleDurationSec(); void doInvokeUdf(SUdfInfo* pUdfInfo, SQLFunctionCtx *pCtx, int32_t idx, int32_t type); +int32_t getColumnDataFromId(void *param, int32_t id, void **data); #endif // TDENGINE_QEXECUTOR_H diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index af45b816f9e6725579403069843295895cf57cc8..c34a56cc1cd6e135947eee897f87d060880f15c7 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -83,6 +83,12 @@ enum { RANGE_TYPE_MR_CTX = 3, }; +enum { + FI_ACTION_NO_NEED = 1, + FI_ACTION_CONTINUE, + FI_ACTION_STOP, +}; + typedef struct OptrStr { uint16_t optr; char *str; @@ -106,6 +112,7 @@ typedef struct SFilterColRange { typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); typedef int32_t(*filter_desc_compare_func)(const void *, const void *); typedef bool(*filter_exec_func)(void *, int32_t, int8_t**, SDataStatis *, int16_t); +typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **); typedef struct SFilterRangeCompare { int64_t s; @@ -323,14 +330,16 @@ typedef struct SFilterInfo { #define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY) -extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options); +extern int32_t filterInitFromTree(tExprNode* tree, void **pinfo, uint32_t options); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols); -extern int32_t filterSetColFieldData(SFilterInfo *info, int32_t numOfCols, SArray* pDataBlock); +extern int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from_id fp); extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win); extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar); extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); extern void filterFreeInfo(SFilterInfo *info); extern bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t numOfCols, int32_t numOfRows); +extern int32_t filterIsIndexedColumnQuery(SFilterInfo* info, int32_t idxId, bool *res); +extern int32_t filterGetIndexedColumnInfo(SFilterInfo* info, char** val, int32_t *order, int32_t *flag); #ifdef __cplusplus } diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 746c5f8569ac98c465e8283a2401e27c18cadcc4..948a1ae91e01331c4f566ac5089485f717fc5632 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -38,12 +38,6 @@ typedef struct SJoinInfo { } SJoinInfo; typedef struct STagCond { - // relation between tbname list and query condition, including : TK_AND or TK_OR - int16_t relType; - - // tbname query condition, only support tbname query condition on one table - SCond tbnameCond; - // join condition, only support two tables join currently SJoinInfo joinInfo; @@ -93,6 +87,7 @@ typedef struct STableMetaInfo { SName name; char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql SArray *tagColList; // SArray, involved tag columns + int32_t joinTagNum; } STableMetaInfo; struct SQInfo; // global merge operator @@ -100,7 +95,7 @@ struct SQueryAttr; // query object typedef struct STableFilter { uint64_t uid; - SFilterInfo info; + void *info; } STableFilter; typedef struct SQueryInfo { diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index aa4942bde10b6c03cd0856dac8e11241fda6fcd8..982996d70d6e8c05c45425e737b57a08daf331c9 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2969,6 +2969,10 @@ void filterRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInf } if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { + if (i < (numOfRows - 1)) { + all = false; + } + break; } } @@ -3010,11 +3014,15 @@ void filterColRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock p[offset] = true; } - if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { + if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { + if (i < (numOfRows - 1)) { + all = false; + } + break; } } - + // save the cursor status pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf); } else { @@ -3076,6 +3084,22 @@ void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFi } } +FORCE_INLINE int32_t getColumnDataFromId(void *param, int32_t id, void **data) { + int32_t numOfCols = ((SColumnDataParam *)param)->numOfCols; + SArray* pDataBlock = ((SColumnDataParam *)param)->pDataBlock; + + for (int32_t j = 0; j < numOfCols; ++j) { + SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j); + if (id == pColInfo->info.colId) { + *data = pColInfo->pData; + break; + } + } + + return TSDB_CODE_SUCCESS; +} + + int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { *status = BLK_DATA_NO_NEEDED; @@ -3230,7 +3254,8 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa } if (pQueryAttr->pFilters != NULL) { - filterSetColFieldData(pQueryAttr->pFilters, pBlock->info.numOfCols, pBlock->pDataBlock); + SColumnDataParam param = {.numOfCols = pBlock->info.numOfCols, .pDataBlock = pBlock->pDataBlock}; + filterSetColFieldData(pQueryAttr->pFilters, ¶m, getColumnDataFromId); } if (pQueryAttr->pFilters != NULL || pRuntimeEnv->pTsBuf != NULL) { @@ -7517,7 +7542,6 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->order = htons(pQueryMsg->order); pQueryMsg->orderColId = htons(pQueryMsg->orderColId); pQueryMsg->queryType = htonl(pQueryMsg->queryType); - pQueryMsg->tagNameRelType = htons(pQueryMsg->tagNameRelType); pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols); pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput); @@ -7532,7 +7556,6 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->tsBuf.tsOrder = htonl(pQueryMsg->tsBuf.tsOrder); pQueryMsg->numOfTags = htonl(pQueryMsg->numOfTags); - pQueryMsg->tbnameCondLen = htonl(pQueryMsg->tbnameCondLen); pQueryMsg->secondStageOutput = htonl(pQueryMsg->secondStageOutput); pQueryMsg->sqlstrLen = htonl(pQueryMsg->sqlstrLen); pQueryMsg->prevResultLen = htonl(pQueryMsg->prevResultLen); @@ -7776,17 +7799,6 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pMsg += pQueryMsg->prevResultLen; } - if (pQueryMsg->tbnameCondLen > 0) { - param->tbnameCond = calloc(1, pQueryMsg->tbnameCondLen + 1); - if (param->tbnameCond == NULL) { - code = TSDB_CODE_QRY_OUT_OF_MEMORY; - goto _cleanup; - } - - strncpy(param->tbnameCond, pMsg, pQueryMsg->tbnameCondLen); - pMsg += pQueryMsg->tbnameCondLen; - } - //skip ts buf if ((pQueryMsg->tsBuf.tsOffset + pQueryMsg->tsBuf.tsLen) > 0) { pMsg = (char *)pQueryMsg + pQueryMsg->tsBuf.tsOffset + pQueryMsg->tsBuf.tsLen; @@ -8167,7 +8179,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp return TSDB_CODE_SUCCESS; } -int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { +int32_t createQueryFilter(char *data, uint16_t len, void** pFilters) { tExprNode* expr = NULL; TRY(TSDB_MAX_TAG_CONDITIONS) { @@ -8421,7 +8433,7 @@ FORCE_INLINE bool checkQIdEqual(void *qHandle, uint64_t qId) { } SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, SExprInfo* pExprs, - SExprInfo* pSecExprs, STableGroupInfo* pTableGroupInfo, SColumnInfo* pTagCols, SFilterInfo* pFilters, int32_t vgId, + SExprInfo* pSecExprs, STableGroupInfo* pTableGroupInfo, SColumnInfo* pTagCols, void* pFilters, int32_t vgId, char* sql, uint64_t qId, SUdfInfo* pUdfInfo) { int16_t numOfCols = pQueryMsg->numOfCols; int16_t numOfOutput = pQueryMsg->numOfOutput; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 5e8ff126d1510cd32446d695d5c8d698aa32d1b9..c7a7ea963d5635c76030d2199ac99a60924d99a7 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -28,14 +28,14 @@ OptrStr gOptrStr[] = { {TSDB_RELATION_GREATER_EQUAL, ">="}, {TSDB_RELATION_NOT_EQUAL, "!="}, {TSDB_RELATION_LIKE, "like"}, - {TSDB_RELATION_MATCH, "match"}, - {TSDB_RELATION_MATCH, "nmatch"}, {TSDB_RELATION_ISNULL, "is null"}, {TSDB_RELATION_NOTNULL, "not null"}, {TSDB_RELATION_IN, "in"}, {TSDB_RELATION_AND, "and"}, {TSDB_RELATION_OR, "or"}, - {TSDB_RELATION_NOT, "not"} + {TSDB_RELATION_NOT, "not"}, + {TSDB_RELATION_MATCH, "match"}, + {TSDB_RELATION_NMATCH, "nmatch"}, }; static FORCE_INLINE int32_t filterFieldColDescCompare(const void *desc1, const void *desc2) { @@ -937,7 +937,7 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) { return TSDB_CODE_SUCCESS; } -int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType) { +int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType, bool tolower) { SBufferReader br = tbufInitReader(buf, len, false); uint32_t sType = tbufReadUint32(&br); SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false); @@ -1113,6 +1113,10 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 } t = varDataLen(tmp); pvar = varDataVal(tmp); + + if (tolower) { + strntolower_s(pvar, pvar, (int32_t)t); + } break; } case TSDB_DATA_TYPE_NCHAR: { @@ -1157,7 +1161,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { void *data = NULL; - filterConvertSetFromBinary((void **)&data, var->pz, var->nLen, type); + filterConvertSetFromBinary((void **)&data, var->pz, var->nLen, type, false); CHK_LRET(data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); if (taosHashGetSize((SHashObj *)data) <= 0) { @@ -1484,19 +1488,6 @@ _return: return code; } -#if 0 -int32_t filterInitUnitFunc(SFilterInfo *info) { - for (uint16_t i = 0; i < info->unitNum; ++i) { - SFilterUnit* unit = &info->units[i]; - - info->cunits[i].func = getComparFunc(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); - } - - return TSDB_CODE_SUCCESS; -} -#endif - - void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) { if (qDebugFlag & DEBUG_DEBUG) { CHK_LRETV(info == NULL, "%s - FilterInfo: EMPTY", msg); @@ -1811,7 +1802,10 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } if (unit->compare.optr == TSDB_RELATION_IN) { - filterConvertSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); + SSchema *sch = FILTER_UNIT_COL_DESC(info, unit); + bool tolower = (sch->colId == -1) ? true : false; + + filterConvertSetFromBinary((void **)&fi->data, var->pz, var->nLen, type, tolower); CHK_LRET(fi->data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); FILTER_SET_FLAG(fi->flag, FLD_DATA_IS_HASH); @@ -2544,8 +2538,6 @@ int32_t filterPostProcessRange(SFilterInfo *info) { int32_t filterGenerateComInfo(SFilterInfo *info) { - uint16_t n = 0; - info->cunits = malloc(info->unitNum * sizeof(*info->cunits)); info->blkUnitRes = malloc(sizeof(*info->blkUnitRes) * info->unitNum); info->blkUnits = malloc(sizeof(*info->blkUnits) * (info->unitNum + 1) * info->groupNum); @@ -2573,24 +2565,6 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { info->cunits[i].dataSize = FILTER_UNIT_COL_SIZE(info, unit); info->cunits[i].dataType = FILTER_UNIT_DATA_TYPE(unit); } - - uint16_t cgroupNum = info->groupNum + 1; - - for (uint16_t i = 0; i < info->groupNum; ++i) { - cgroupNum += info->groups[i].unitNum; - } - - info->cgroups = malloc(cgroupNum * sizeof(*info->cgroups)); - - for (uint16_t i = 0; i < info->groupNum; ++i) { - info->cgroups[n++] = info->groups[i].unitNum; - - for (uint16_t m = 0; m < info->groups[i].unitNum; ++m) { - info->cgroups[n++] = info->groups[i].unitIdxs[m]; - } - } - - info->cgroups[n] = 0; return TSDB_CODE_SUCCESS; } @@ -2664,10 +2638,12 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t SDataStatis* pDataBlockst = &pDataStatis[index]; void *minVal, *maxVal; + float minv = 0; + float maxv = 0; if (cunit->dataType == TSDB_DATA_TYPE_FLOAT) { - float minv = (float)(*(double *)(&pDataBlockst->min)); - float maxv = (float)(*(double *)(&pDataBlockst->max)); + minv = (float)(*(double *)(&pDataBlockst->min)); + maxv = (float)(*(double *)(&pDataBlockst->max)); minVal = &minv; maxVal = &maxv; @@ -2786,8 +2762,10 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p, bool all = true; uint16_t *unitIdx = NULL; - *p = calloc(numOfRows, sizeof(int8_t)); - + if (*p == NULL) { + *p = calloc(numOfRows, sizeof(int8_t)); + } + for (int32_t i = 0; i < numOfRows; ++i) { //FILTER_UNIT_CLR_F(info); @@ -2889,12 +2867,14 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, return all; } - *p = calloc(numOfRows, sizeof(int8_t)); + if (*p == NULL) { + *p = calloc(numOfRows, sizeof(int8_t)); + } for (int32_t i = 0; i < numOfRows; ++i) { uint16_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - (*p)[i] = isNull(colData, info->cunits[uidx].dataType); + (*p)[i] = ((colData == NULL) || isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { all = false; } @@ -2910,12 +2890,14 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows return all; } - *p = calloc(numOfRows, sizeof(int8_t)); - + if (*p == NULL) { + *p = calloc(numOfRows, sizeof(int8_t)); + } + for (int32_t i = 0; i < numOfRows; ++i) { uint16_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - (*p)[i] = !isNull(colData, info->cunits[uidx].dataType); + (*p)[i] = ((colData != NULL) && !isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { all = false; } @@ -2938,10 +2920,12 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SDataSta return all; } - *p = calloc(numOfRows, sizeof(int8_t)); + if (*p == NULL) { + *p = calloc(numOfRows, sizeof(int8_t)); + } for (int32_t i = 0; i < numOfRows; ++i) { - if (isNull(colData, info->cunits[0].dataType)) { + if (colData == NULL || isNull(colData, info->cunits[0].dataType)) { all = false; colData += dataSize; continue; @@ -2966,13 +2950,16 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStat if (filterExecuteBasedOnStatis(info, numOfRows, p, statis, numOfCols, &all) == 0) { return all; } - - *p = calloc(numOfRows, sizeof(int8_t)); + + if (*p == NULL) { + *p = calloc(numOfRows, sizeof(int8_t)); + } for (int32_t i = 0; i < numOfRows; ++i) { uint16_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - if (isNull(colData, info->cunits[uidx].dataType)) { + if (colData == NULL || isNull(colData, info->cunits[uidx].dataType)) { + (*p)[i] = 0; all = false; continue; } @@ -2996,8 +2983,10 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis * return all; } - *p = calloc(numOfRows, sizeof(int8_t)); - + if (*p == NULL) { + *p = calloc(numOfRows, sizeof(int8_t)); + } + for (int32_t i = 0; i < numOfRows; ++i) { //FILTER_UNIT_CLR_F(info); @@ -3013,7 +3002,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis * //} else { uint8_t optr = cunit->optr; - if (isNull(colData, cunit->dataType)) { + if (colData == NULL || isNull(colData, cunit->dataType)) { (*p)[i] = optr == TSDB_RELATION_ISNULL ? true : false; } else { if (optr == TSDB_RELATION_NOTNULL) { @@ -3132,7 +3121,7 @@ _return: return TSDB_CODE_SUCCESS; } -int32_t filterSetColFieldData(SFilterInfo *info, int32_t numOfCols, SArray* pDataBlock) { +int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from_id fp) { CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); CHK_LRET(info->fields[FLD_TYPE_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); @@ -3143,15 +3132,8 @@ int32_t filterSetColFieldData(SFilterInfo *info, int32_t numOfCols, SArray* pDat for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SSchema* sch = fi->desc; - - for (int32_t j = 0; j < numOfCols; ++j) { - SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j); - if (sch->colId == pColInfo->info.colId) { - fi->data = pColInfo->pData; - - break; - } - } + + (*fp)(param, sch->colId, &fi->data); } filterUpdateComUnits(info); @@ -3160,7 +3142,7 @@ int32_t filterSetColFieldData(SFilterInfo *info, int32_t numOfCols, SArray* pDat } -int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options) { +int32_t filterInitFromTree(tExprNode* tree, void **pinfo, uint32_t options) { int32_t code = TSDB_CODE_SUCCESS; SFilterInfo *info = NULL; @@ -3197,8 +3179,6 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option taosArrayDestroy(group); return code; } - - //ERR_JRET(filterInitUnitFunc(info)); } info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); @@ -3257,30 +3237,35 @@ bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t num break; } - if ((pDataStatis[index].numOfNull <= 0) && (ctx->isnull && !ctx->notnull && !ctx->isrange)) { - ret = false; - break; - } - - // all data in current column are NULL, no need to check its boundary value - if (pDataStatis[index].numOfNull == numOfRows) { - - // if isNULL query exists, load the null data column - if ((ctx->notnull || ctx->isrange) && (!ctx->isnull)) { + if (pDataStatis[index].numOfNull <= 0) { + if (ctx->isnull && !ctx->notnull && !ctx->isrange) { ret = false; break; } + } else if (pDataStatis[index].numOfNull > 0) { + if (pDataStatis[index].numOfNull == numOfRows) { + if ((ctx->notnull || ctx->isrange) && (!ctx->isnull)) { + ret = false; + break; + } - continue; + continue; + } else { + if (ctx->isnull) { + continue; + } + } } SDataStatis* pDataBlockst = &pDataStatis[index]; SFilterRangeNode *r = ctx->rs; + float minv = 0; + float maxv = 0; if (ctx->type == TSDB_DATA_TYPE_FLOAT) { - float minv = (float)(*(double *)(&pDataBlockst->min)); - float maxv = (float)(*(double *)(&pDataBlockst->max)); + minv = (float)(*(double *)(&pDataBlockst->min)); + maxv = (float)(*(double *)(&pDataBlockst->max)); minVal = &minv; maxVal = &maxv; @@ -3441,6 +3426,52 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) { return TSDB_CODE_SUCCESS; } +int32_t filterIsIndexedColumnQuery(SFilterInfo* info, int32_t idxId, bool *res) { + CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "null parameter"); + + CHK_JMP(info->fields[FLD_TYPE_COLUMN].num > 1 || info->fields[FLD_TYPE_COLUMN].num <= 0); + + CHK_JMP(info->unitNum > 1 || info->unitNum <= 0); + + CHK_JMP(FILTER_GET_COL_FIELD_ID(FILTER_GET_COL_FIELD(info, 0)) != idxId); + + int32_t optr = FILTER_UNIT_OPTR(info->units); + + CHK_JMP(optr == TSDB_RELATION_LIKE || optr == TSDB_RELATION_IN || optr == TSDB_RELATION_MATCH + || optr == TSDB_RELATION_ISNULL || optr == TSDB_RELATION_NOTNULL); + + *res = true; + + return TSDB_CODE_SUCCESS; + +_return: + *res = false; + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterGetIndexedColumnInfo(SFilterInfo* info, char** val, int32_t *order, int32_t *flag) { + SFilterComUnit *cunit = info->cunits; + uint8_t optr = cunit->optr; + + *val = cunit->valData; + *order = TSDB_ORDER_ASC; + + if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { + *order = TSDB_ORDER_DESC; + } + + if (optr == TSDB_RELATION_NOT_EQUAL) { + *order = TSDB_ORDER_ASC|TSDB_ORDER_DESC; + } + + if (cunit->valData2 == cunit->valData && optr != TSDB_RELATION_EQUAL) { + FILTER_SET_FLAG(*flag, FI_ACTION_NO_NEED); + } + + return TSDB_CODE_SUCCESS; +} diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 1460fbdc0fd0324da28bf1161c34c564584258cd..c6e6eddce7d8f56095d5d78f4d1f84ed1d4f3c97 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -53,7 +53,6 @@ static void freeqinfoFn(void *qhandle) { void freeParam(SQueryParam *param) { tfree(param->sql); tfree(param->tagCond); - tfree(param->tbnameCond); tfree(param->pTableIdList); taosArrayDestroy(param->pOperator); tfree(param->pExprs); @@ -140,7 +139,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi qDebug("qmsg:%p query stable, uid:%"PRIu64", tid:%d", pQueryMsg, id->uid, id->tid); code = tsdbQuerySTableByTagCond(tsdb, id->uid, pQueryMsg->window.skey, param.tagCond, pQueryMsg->tagCondLen, - pQueryMsg->tagNameRelType, param.tbnameCond, &tableGroupInfo, param.pGroupColIndex, numOfGroupByCols); + &tableGroupInfo, param.pGroupColIndex, numOfGroupByCols); if (code != TSDB_CODE_SUCCESS) { qError("qmsg:%p failed to query stable, reason: %s", pQueryMsg, tstrerror(code)); diff --git a/src/tsdb/CMakeLists.txt b/src/tsdb/CMakeLists.txt index c5b77df5a25f9f0b1e9294228520f171b9befddd..efbed6f0a6e8218c3a0b46d2913f6a792bf48ce4 100644 --- a/src/tsdb/CMakeLists.txt +++ b/src/tsdb/CMakeLists.txt @@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) PROJECT(TDengine) INCLUDE_DIRECTORIES(inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) AUX_SOURCE_DIRECTORY(src SRC) ADD_LIBRARY(tsdb ${SRC}) TARGET_LINK_LIBRARIES(tsdb tfs common tutil) diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index da5481dae184b1cc0aa280f9e3d4a952571abfe1..4aab9dff7debc0b0f193e38d77222f1752196c65 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -25,6 +25,7 @@ #include "tlosertree.h" #include "tsdbint.h" #include "texpr.h" +#include "qFilter.h" #define EXTRA_BYTES 2 #define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) @@ -167,6 +168,7 @@ static int32_t doGetExternalRow(STsdbQueryHandle* pQueryHandle, int16_t type, SM static void* doFreeColumnInfoData(SArray* pColumnInfoData); static void* destroyTableCheckInfo(SArray* pTableCheckInfo); static bool tsdbGetExternalRow(TsdbQueryHandleT pHandle); +static int32_t tsdbQueryTableList(STable* pTable, SArray* pRes, void* filterInfo); static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { pBlockLoadInfo->slot = -1; @@ -2688,21 +2690,6 @@ static int32_t getAllTableList(STable* pSuperTable, SArray* list) { return TSDB_CODE_SUCCESS; } -static void destroyHelper(void* param) { - if (param == NULL) { - return; - } - - tQueryInfo* pInfo = (tQueryInfo*)param; - if (pInfo->optr != TSDB_RELATION_IN) { - tfree(pInfo->q); - } else { - taosHashCleanup((SHashObj *)(pInfo->q)); - } - - free(param); -} - static bool loadBlockOfActiveTable(STsdbQueryHandle* pQueryHandle) { if (pQueryHandle->checkFiles) { // check if the query range overlaps with the file data block @@ -3637,109 +3624,8 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC return pTableGroup; } -static bool tableFilterFp(const void* pNode, void* param) { - tQueryInfo* pInfo = (tQueryInfo*) param; - - STable* pTable = (STable*)(SL_GET_NODE_DATA((SSkipListNode*)pNode)); - - char* val = NULL; - if (pInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) { - val = (char*) TABLE_NAME(pTable); - } else { - val = tdGetKVRowValOfCol(pTable->tagVal, pInfo->sch.colId); - } - - if (pInfo->optr == TSDB_RELATION_ISNULL || pInfo->optr == TSDB_RELATION_NOTNULL) { - if (pInfo->optr == TSDB_RELATION_ISNULL) { - return (val == NULL) || isNull(val, pInfo->sch.type); - } else if (pInfo->optr == TSDB_RELATION_NOTNULL) { - return (val != NULL) && (!isNull(val, pInfo->sch.type)); - } - } else if (pInfo->optr == TSDB_RELATION_IN) { - int type = pInfo->sch.type; - if (type == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_TIMESTAMP) { - int64_t v; - GET_TYPED_DATA(v, int64_t, pInfo->sch.type, val); - return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); - } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { - uint64_t v; - GET_TYPED_DATA(v, uint64_t, pInfo->sch.type, val); - return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); - } - else if (type == TSDB_DATA_TYPE_DOUBLE || type == TSDB_DATA_TYPE_FLOAT) { - double v; - GET_TYPED_DATA(v, double, pInfo->sch.type, val); - return NULL != taosHashGet((SHashObj *)pInfo->q, (char *)&v, sizeof(v)); - } else if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR){ - return NULL != taosHashGet((SHashObj *)pInfo->q, varDataVal(val), varDataLen(val)); - } - - } - - int32_t ret = 0; - if (val == NULL) { //the val is possible to be null, so check it out carefully - ret = -1; // val is missing in table tags value pairs - } else { - ret = pInfo->compare(val, pInfo->q); - } - - switch (pInfo->optr) { - case TSDB_RELATION_EQUAL: { - return ret == 0; - } - case TSDB_RELATION_NOT_EQUAL: { - return ret != 0; - } - case TSDB_RELATION_GREATER_EQUAL: { - return ret >= 0; - } - case TSDB_RELATION_GREATER: { - return ret > 0; - } - case TSDB_RELATION_LESS_EQUAL: { - return ret <= 0; - } - case TSDB_RELATION_LESS: { - return ret < 0; - } - case TSDB_RELATION_LIKE: { - return ret == 0; - } - case TSDB_RELATION_MATCH: { - return ret == 0; - } - case TSDB_RELATION_NMATCH: { - return ret == 0; - } - case TSDB_RELATION_IN: { - return ret == 1; - } - - default: - assert(false); - } - - return true; -} - -static void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param); - -static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) { - // query according to the expression tree - SExprTraverseSupp supp = { - .nodeFilterFn = (__result_filter_fn_t) tableFilterFp, - .setupInfoFn = filterPrepare, - .pExtInfo = pSTable->tagSchema, - }; - - getTableListfromSkipList(pExpr, pSTable->pIndex, pRes, &supp); - tExprTreeDestroy(pExpr, destroyHelper); - return TSDB_CODE_SUCCESS; -} - -int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len, - int16_t tagNameRelType, const char* tbnameCond, STableGroupInfo* pGroupInfo, - SColIndex* pColIndex, int32_t numOfCols) { +int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len, + STableGroupInfo* pGroupInfo, SColIndex* pColIndex, int32_t numOfCols) { if (tsdbRLockRepoMeta(tsdb) < 0) goto _error; STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); @@ -3765,7 +3651,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons STSchema* pTagSchema = tsdbGetTableTagSchema(pTable); // no tags and tbname condition, all child tables of this stable are involved - if (tbnameCond == NULL && (pTagCond == NULL || len == 0)) { + if (pTagCond == NULL || len == 0) { int32_t ret = getAllTableList(pTable, res); if (ret != TSDB_CODE_SUCCESS) { tsdbUnlockRepoMeta(tsdb); @@ -3787,25 +3673,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons tExprNode* expr = NULL; TRY(TSDB_MAX_TAG_CONDITIONS) { - expr = exprTreeFromTableName(tbnameCond); - if (expr == NULL) { - expr = exprTreeFromBinary(pTagCond, len); - } else { - CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, expr, NULL); - tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len); - if (tagExpr != NULL) { - CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, tagExpr, NULL); - tExprNode* tbnameExpr = expr; - expr = calloc(1, sizeof(tExprNode)); - if (expr == NULL) { - THROW( TSDB_CODE_TDB_OUT_OF_MEMORY ); - } - expr->nodeType = TSQL_NODE_EXPR; - expr->_node.optr = (uint8_t)tagNameRelType; - expr->_node.pLeft = tagExpr; - expr->_node.pRight = tbnameExpr; - } - } + expr = exprTreeFromBinary(pTagCond, len); CLEANUP_EXECUTE(); } CATCH( code ) { @@ -3817,7 +3685,20 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons // TODO: more error handling } END_TRY - doQueryTableList(pTable, res, expr); + void *filterInfo = NULL; + + ret = filterInitFromTree(expr, &filterInfo, 0); + if (ret != TSDB_CODE_SUCCESS) { + terrno = ret; + goto _error; + } + + tsdbQueryTableList(pTable, res, filterInfo); + + filterFreeInfo(filterInfo); + + tExprTreeDestroy(expr, NULL); + pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); @@ -4001,259 +3882,115 @@ void tsdbDestroyTableGroup(STableGroupInfo *pGroupList) { pGroupList->numOfTables = 0; } -static void applyFilterToSkipListNode(SSkipList *pSkipList, tExprNode *pExpr, SArray *pResult, SExprTraverseSupp *param) { - SSkipListIterator* iter = tSkipListCreateIter(pSkipList); - - // Scan each node in the skiplist by using iterator - while (tSkipListIterNext(iter)) { - SSkipListNode *pNode = tSkipListIterGet(iter); - if (exprTreeApplyFilter(pExpr, pNode, param)) { - taosArrayPush(pResult, &(SL_GET_NODE_DATA(pNode))); - } - } - - tSkipListDestroyIter(iter); -} -typedef struct { - char* v; - int32_t optr; -} SEndPoint; - -typedef struct { - SEndPoint* start; - SEndPoint* end; -} SQueryCond; - -// todo check for malloc failure -static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { - int32_t optr = queryColInfo->optr; - - if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL || - optr == TSDB_RELATION_EQUAL || optr == TSDB_RELATION_NOT_EQUAL) { - pCond->start = calloc(1, sizeof(SEndPoint)); - pCond->start->optr = queryColInfo->optr; - pCond->start->v = queryColInfo->q; - } else if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { - pCond->end = calloc(1, sizeof(SEndPoint)); - pCond->end->optr = queryColInfo->optr; - pCond->end->v = queryColInfo->q; - } else if (optr == TSDB_RELATION_IN) { - pCond->start = calloc(1, sizeof(SEndPoint)); - pCond->start->optr = queryColInfo->optr; - pCond->start->v = queryColInfo->q; - } else if (optr == TSDB_RELATION_LIKE) { - assert(0); - } else if (optr == TSDB_RELATION_MATCH) { - assert(0); - } else if (optr == TSDB_RELATION_NMATCH) { - assert(0); +static FORCE_INLINE int32_t tsdbGetTagDataFromId(void *param, int32_t id, void **data) { + STable* pTable = (STable*)(SL_GET_NODE_DATA((SSkipListNode *)param)); + + if (id == TSDB_TBNAME_COLUMN_INDEX) { + *data = TABLE_NAME(pTable); + } else { + *data = tdGetKVRowValOfCol(pTable->tagVal, id); } return TSDB_CODE_SUCCESS; } -static void queryIndexedColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* result) { - SSkipListIterator* iter = NULL; - - SQueryCond cond = {0}; - if (setQueryCond(pQueryInfo, &cond) != TSDB_CODE_SUCCESS) { - //todo handle error - } - - if (cond.start != NULL) { - iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->type, TSDB_ORDER_ASC); - } else { - iter = tSkipListCreateIterFromVal(pSkipList, (char*)(cond.end ? cond.end->v: NULL), pSkipList->type, TSDB_ORDER_DESC); - } - - if (cond.start != NULL) { - int32_t optr = cond.start->optr; - - if (optr == TSDB_RELATION_EQUAL) { // equals - while(tSkipListIterNext(iter)) { - SSkipListNode* pNode = tSkipListIterGet(iter); - - int32_t ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v); - if (ret != 0) { - break; - } - - STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - } - } else if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL) { // greater equal - bool comp = true; - int32_t ret = 0; - - while(tSkipListIterNext(iter)) { - SSkipListNode* pNode = tSkipListIterGet(iter); - - if (comp) { - ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v); - assert(ret >= 0); - } - - if (ret == 0 && optr == TSDB_RELATION_GREATER) { - continue; - } else { - STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - comp = false; - } - } - } else if (optr == TSDB_RELATION_NOT_EQUAL) { // not equal - bool comp = true; - - while(tSkipListIterNext(iter)) { - SSkipListNode* pNode = tSkipListIterGet(iter); - comp = comp && (pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v) == 0); - if (comp) { - continue; - } - - STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - } - tSkipListDestroyIter(iter); - comp = true; - iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->type, TSDB_ORDER_DESC); - while(tSkipListIterNext(iter)) { - SSkipListNode* pNode = tSkipListIterGet(iter); - comp = comp && (pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v) == 0); - if (comp) { - continue; - } - - STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - } +static void queryIndexedColumn(SSkipList* pSkipList, void* filterInfo, SArray* res) { + SSkipListIterator* iter = NULL; + char *startVal = NULL; + int32_t order = 0; + int32_t inRange = 0; + int32_t flag = 0; + bool all = false; + int8_t *addToResult = NULL; - } else if (optr == TSDB_RELATION_IN) { - while(tSkipListIterNext(iter)) { - SSkipListNode* pNode = tSkipListIterGet(iter); + filterGetIndexedColumnInfo(filterInfo, &startVal, &order, &flag); - int32_t ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v); - if (ret != 0) { - break; - } + tsdbDebug("filter index column start, order:%d, flag:%d", order, flag); - STableKeyInfo info = {.pTable = (void*)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - } - + while (order) { + if (FILTER_GET_FLAG(order, TSDB_ORDER_ASC)) { + iter = tSkipListCreateIterFromVal(pSkipList, startVal, pSkipList->type, TSDB_ORDER_ASC); + FILTER_CLR_FLAG(order, TSDB_ORDER_ASC); } else { - assert(0); + iter = tSkipListCreateIterFromVal(pSkipList, startVal, pSkipList->type, TSDB_ORDER_DESC); + FILTER_CLR_FLAG(order, TSDB_ORDER_DESC); } - } else { - int32_t optr = cond.end ? cond.end->optr : TSDB_RELATION_INVALID; - if (optr == TSDB_RELATION_LESS || optr == TSDB_RELATION_LESS_EQUAL) { - bool comp = true; - int32_t ret = 0; - - while (tSkipListIterNext(iter)) { - SSkipListNode *pNode = tSkipListIterGet(iter); - - if (comp) { - ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.end->v); - assert(ret <= 0); - } + + while (tSkipListIterNext(iter)) { + SSkipListNode *pNode = tSkipListIterGet(iter); - if (ret == 0 && optr == TSDB_RELATION_LESS) { - continue; - } else { - STableKeyInfo info = {.pTable = (void *)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - comp = false; // no need to compare anymore - } + if (inRange == 0 || !FILTER_GET_FLAG(flag, FI_ACTION_NO_NEED)) { + tsdbDebug("filter index column, filter it"); + filterSetColFieldData(filterInfo, pNode, tsdbGetTagDataFromId); + all = filterExecute(filterInfo, 1, &addToResult, NULL, 0); } - } else { - assert(pQueryInfo->optr == TSDB_RELATION_ISNULL || pQueryInfo->optr == TSDB_RELATION_NOTNULL); + + char *pData = SL_GET_NODE_DATA(pNode); - while (tSkipListIterNext(iter)) { - SSkipListNode *pNode = tSkipListIterGet(iter); + tsdbDebug("filter index column, table:%s, result:%d", ((STable *)pData)->name->data, all); - bool isnull = isNull(SL_GET_NODE_KEY(pSkipList, pNode), pQueryInfo->sch.type); - if ((pQueryInfo->optr == TSDB_RELATION_ISNULL && isnull) || - (pQueryInfo->optr == TSDB_RELATION_NOTNULL && (!isnull))) { - STableKeyInfo info = {.pTable = (void *)SL_GET_NODE_DATA(pNode), .lastKey = TSKEY_INITIAL_VAL}; - taosArrayPush(result, &info); - } + if (all || (addToResult && *addToResult)) { + STableKeyInfo info = {.pTable = (void*)pData, .lastKey = TSKEY_INITIAL_VAL}; + taosArrayPush(res, &info); + inRange = 1; + } else if (inRange){ + break; } } + + inRange = 0; + + tfree(addToResult); + tSkipListDestroyIter(iter); } - free(cond.start); - free(cond.end); - tSkipListDestroyIter(iter); + tsdbDebug("filter index column end"); } -static void queryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* res, __result_filter_fn_t filterFp) { +static void queryIndexlessColumn(SSkipList* pSkipList, void* filterInfo, SArray* res) { SSkipListIterator* iter = tSkipListCreateIter(pSkipList); + int8_t *addToResult = NULL; while (tSkipListIterNext(iter)) { - bool addToResult = false; SSkipListNode *pNode = tSkipListIterGet(iter); + filterSetColFieldData(filterInfo, pNode, tsdbGetTagDataFromId); + char *pData = SL_GET_NODE_DATA(pNode); - tstr *name = (tstr*) tsdbGetTableName((void*) pData); - - // todo speed up by using hash - if (pQueryInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) { - if (pQueryInfo->optr == TSDB_RELATION_IN) { - addToResult = pQueryInfo->compare(name, pQueryInfo->q); - } else if (pQueryInfo->optr == TSDB_RELATION_LIKE || - pQueryInfo->optr == TSDB_RELATION_MATCH || - pQueryInfo->optr == TSDB_RELATION_NMATCH) { - addToResult = !pQueryInfo->compare(name, pQueryInfo->q); - } - } else { - addToResult = filterFp(pNode, pQueryInfo); - } - if (addToResult) { + bool all = filterExecute(filterInfo, 1, &addToResult, NULL, 0); + + if (all || (addToResult && *addToResult)) { STableKeyInfo info = {.pTable = (void*)pData, .lastKey = TSKEY_INITIAL_VAL}; taosArrayPush(res, &info); - } + } } + tfree(addToResult); + tSkipListDestroyIter(iter); } -// Apply the filter expression to each node in the skiplist to acquire the qualified nodes in skip list -void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param) { - if (pExpr == NULL) { - return; - } - - tExprNode *pLeft = pExpr->_node.pLeft; - tExprNode *pRight = pExpr->_node.pRight; - // column project - if (pLeft->nodeType != TSQL_NODE_EXPR && pRight->nodeType != TSQL_NODE_EXPR) { - assert(pLeft->nodeType == TSQL_NODE_COL && (pRight->nodeType == TSQL_NODE_VALUE || pRight->nodeType == TSQL_NODE_DUMMY)); - - param->setupInfoFn(pExpr, param->pExtInfo); +static int32_t tsdbQueryTableList(STable* pTable, SArray* pRes, void* filterInfo) { + STSchema* pTSSchema = pTable->tagSchema; + bool indexQuery = false; + SSkipList *pSkipList = pTable->pIndex; + + filterIsIndexedColumnQuery(filterInfo, pTSSchema->columns->colId, &indexQuery); + + if (indexQuery) { + queryIndexedColumn(pSkipList, filterInfo, pRes); + } else { + queryIndexlessColumn(pSkipList, filterInfo, pRes); + } - tQueryInfo *pQueryInfo = pExpr->_node.info; - if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE - && pQueryInfo->optr != TSDB_RELATION_MATCH && pQueryInfo->optr != TSDB_RELATION_NMATCH - && pQueryInfo->optr != TSDB_RELATION_IN)) { - queryIndexedColumn(pSkipList, pQueryInfo, result); - } else { - queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); - } + return TSDB_CODE_SUCCESS; +} - return; - } - // The value of hasPK is always 0. - uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK; - assert(weight == 0 && pSkipList != NULL && taosArrayGetSize(result) == 0); - //apply the hierarchical filter expression to every node in skiplist to find the qualified nodes - applyFilterToSkipListNode(pSkipList, pExpr, result, param); -} diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 482dd8a6a15d1c7bf6aca76159b95b71ef244dd2..179fbd05a5a8f5ddfb28b68130f87e26ed4e522f 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -233,14 +233,20 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat int32_t i = 0; int32_t j = 0; + int32_t o = 0; + int32_t m = 0; while ((c = patterStr[i++]) != 0) { if (c == pInfo->matchAll) { /* Match "*" */ while ((c = patterStr[i++]) == pInfo->matchAll || c == pInfo->matchOne) { - if (c == pInfo->matchOne && (j > size || str[j++] == 0)) { - // empty string, return not match - return TSDB_PATTERN_NOWILDCARDMATCH; + if (c == pInfo->matchOne) { + if (j > size || str[j++] == 0) { + // empty string, return not match + return TSDB_PATTERN_NOWILDCARDMATCH; + } else { + ++o; + } } } @@ -249,9 +255,10 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat } char next[3] = {toupper(c), tolower(c), 0}; + m = o; while (1) { - size_t n = strcspn(str, next); - str += n; + size_t n = strcspn(str + m, next); + str += m + n; if (str[0] == 0 || (n >= size)) { break; @@ -261,12 +268,14 @@ int patternMatch(const char *patterStr, const char *str, size_t size, const SPat if (ret != TSDB_PATTERN_NOMATCH) { return ret; } + m = 0; } return TSDB_PATTERN_NOWILDCARDMATCH; } c1 = str[j++]; - + ++o; + if (j <= size) { if (c == '\\' && patterStr[i] == '_' && c1 == '_') { i++; continue; } if (c == c1 || tolower(c) == tolower(c1) || (c == pInfo->matchOne && c1 != 0)) { @@ -292,7 +301,7 @@ int WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t size, c if (c == matchAll) { /* Match "%" */ while ((c = patterStr[i++]) == matchAll || c == matchOne) { - if (c == matchOne && (j > size || str[j++] == 0)) { + if (c == matchOne && (j >= size || str[j++] == 0)) { return TSDB_PATTERN_NOWILDCARDMATCH; } } diff --git a/tests/pytest/functions/queryTestCases.py b/tests/pytest/functions/queryTestCases.py index 67ff6b95d640b06864ef98960d8370dbfdc962c8..a20b89d47c5fc09d032e72335edb9544eb50e0aa 100644 --- a/tests/pytest/functions/queryTestCases.py +++ b/tests/pytest/functions/queryTestCases.py @@ -769,7 +769,7 @@ class TDTestCase: tdSql.query(f"select distinct c1,c2 from (select * from t1 where c1 < {tbnum}) ") tdSql.checkRows(3) tdSql.query(f"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) ") - tdSql.checkRows(4) + tdSql.checkRows(0) tdSql.error("select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) ") tdSql.error("select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) ") tdSql.query("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4") diff --git a/tests/pytest/query/filterOtherTypes.py b/tests/pytest/query/filterOtherTypes.py index f80552138deb6850a87c63bed0c3f543036e7c17..7d62f2502eaf7ef5e2591adadb1628a618233628 100644 --- a/tests/pytest/query/filterOtherTypes.py +++ b/tests/pytest/query/filterOtherTypes.py @@ -80,10 +80,12 @@ class TDTestCase: tdSql.error("select * from st where tbcol1 like '____'") # > for nchar type on column - tdSql.error("select * from st where tbcol2 > 'taosdata'") + tdSql.query("select * from st where tbcol2 > 'taosdata'") + tdSql.checkRows(10) # >= for nchar type on column - tdSql.error("select * from st where tbcol2 >= 'taosdata'") + tdSql.query("select * from st where tbcol2 >= 'taosdata'") + tdSql.checkRows(10) # = for nchar type on column tdSql.query("select * from st where tbcol2 = 'taosdata1'") @@ -98,10 +100,12 @@ class TDTestCase: tdSql.checkRows(9) # > for nchar type on column - tdSql.error("select * from st where tbcol2 < 'taodata'") + tdSql.query("select * from st where tbcol2 < 'taodata'") + tdSql.checkRows(0) # >= for nchar type on column - tdSql.error("select * from st where tbcol2 <= 'taodata'") + tdSql.query("select * from st where tbcol2 <= 'taodata'") + tdSql.checkRows(0) # % for nchar type on column case 1 tdSql.query("select * from st where tbcol2 like '%'") @@ -140,10 +144,12 @@ class TDTestCase: tdSql.checkRows(10) # > for binary type on column - tdSql.error("select * from st where tbcol3 > '涛思数据'") + tdSql.query("select * from st where tbcol3 > '涛思数据'") + tdSql.checkRows(10) # >= for binary type on column - tdSql.error("select * from st where tbcol3 >= '涛思数据'") + tdSql.query("select * from st where tbcol3 >= '涛思数据'") + tdSql.checkRows(10) # = for binary type on column tdSql.query("select * from st where tbcol3 = '涛思数据1'") @@ -158,10 +164,12 @@ class TDTestCase: tdSql.checkRows(9) # > for binary type on column - tdSql.error("select * from st where tbcol3 < '涛思数据'") + tdSql.query("select * from st where tbcol3 < '涛思数据'") + tdSql.checkRows(0) # >= for binary type on column - tdSql.error("select * from st where tbcol3 <= '涛思数据'") + tdSql.query("select * from st where tbcol3 <= '涛思数据'") + tdSql.checkRows(0) # % for binary type on column case 1 tdSql.query("select * from st where tbcol3 like '%'") diff --git a/tests/pytest/query/isNullTest.py b/tests/pytest/query/isNullTest.py index 7b79679c7d9d9ac4629a69b32acb1a11b61a83c1..f9fbb47715043fb63a51fbb127cb7a889883fafb 100644 --- a/tests/pytest/query/isNullTest.py +++ b/tests/pytest/query/isNullTest.py @@ -66,7 +66,7 @@ class TDTestCase: tdSql.checkData(0, 0, 12) tdSql.query("select count(*) from st where t2 <> '' ") - tdSql.checkData(0, 0, 24) + tdSql.checkData(0, 0, 12) tdSql.query("select count(*) from st where t3 is null") tdSql.checkData(0, 0, 12) @@ -81,7 +81,7 @@ class TDTestCase: tdSql.checkData(0, 0, 12) tdSql.query("select count(*) from st where t3 <> '' ") - tdSql.checkData(0, 0, 24) + tdSql.checkData(0, 0, 12) tdSql.query("select count(*) from st where c1 is not null") tdSql.checkData(0, 0, 30) diff --git a/tests/script/general/parser/between_and.sim b/tests/script/general/parser/between_and.sim index cdced47cb65aea79618540b57e159b741bf9288a..5db40471d85bcbafbcb6dcaa5912e6cfb9a66bc5 100644 --- a/tests/script/general/parser/between_and.sim +++ b/tests/script/general/parser/between_and.sim @@ -159,7 +159,7 @@ if $data11 != 3 then endi sql_error select * from st2 where f7 between 2.0 and 3.0; -sql_error select * from st2 where f8 between 2.0 and 3.0; -sql_error select * from st2 where f9 between 2.0 and 3.0; +sql select * from st2 where f8 between 2.0 and 3.0; +sql select * from st2 where f9 between 2.0 and 3.0; system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index c3aed7e2a3b04c0ca2e27e2e62d92009e8b2fe8e..96cd1e80bd01ad6ffa197ccbe8c58ce6474f3339 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -2,7 +2,7 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 system sh/cfg.sh -n dnode1 -c walLevel -v 1 -system sh/cfg.sh -n dnode1 -c maxtablespervnode -v 4 +system sh/cfg.sh -n dnode1 -c maxtablespervnode -v 6 system sh/cfg.sh -n dnode1 -c cache -v 1 system sh/exec.sh -n dnode1 -s start @@ -135,11 +135,63 @@ while $i < $blockNum $ts0 = $ts0 + 259200000 endw +sql create table stb5 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 timestamp, t2 int, t3 float, t4 bigint, t5 smallint, t6 tinyint, t7 double, t8 bool, t9 binary(100), t10 nchar(10)) + +sql create table tb5_1 using stb5 tags('2021-05-05 18:19:01',1,1.0,1,1,1,1.0,true ,'111111111','1') +sql create table tb5_2 using stb5 tags('2021-05-05 18:19:02',2,2.0,2,2,2,2.0,true ,'222222222','2') +sql create table tb5_3 using stb5 tags('2021-05-05 18:19:03',3,3.0,3,3,3,3.0,false,'333333333','3') +sql create table tb5_4 using stb5 tags('2021-05-05 18:19:04',4,4.0,4,4,4,4.0,false,'444444444','4') +sql create table tb5_5 using stb5 tags('2021-05-05 18:19:05',5,5.0,5,5,5,5.0,true,'555555555','5') +sql create table tb5_6 using stb5 tags('2021-05-05 18:19:06',6,6.0,6,6,6,6.0,true,'666666666','6') +sql create table tb5_7 using stb5 tags(NULL,7,NULL,7,NULL,7,NULL,false,NULL,'7') +sql create table tb5_8 using stb5 tags('2021-05-05 18:19:08',NULL,8.0,NULL,8,NULL,8.0,NULL,'888888888',NULL) + +sql insert into tb5_1 values ('2021-05-05 18:19:00',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb5_1 values ('2021-05-05 18:19:01',2,2.0,2,2,2,2.0,true ,'2','2') +sql insert into tb5_1 values ('2021-05-05 18:19:02',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb5_1 values ('2021-05-05 18:19:03',4,4.0,4,4,4,4.0,false,'4','4') +sql insert into tb5_1 values ('2021-05-05 18:19:04',11,11.0,11,11,11,11.0,true ,'11','11') +sql insert into tb5_1 values ('2021-05-05 18:19:05',12,12.0,12,12,12,12.0,true ,'12','12') +sql insert into tb5_1 values ('2021-05-05 18:19:06',13,13.0,13,13,13,13.0,false,'13','13') +sql insert into tb5_1 values ('2021-05-05 18:19:07',14,14.0,14,14,14,14.0,false,'14','14') +sql insert into tb5_2 values ('2021-05-05 18:19:08',21,21.0,21,21,21,21.0,true ,'21','21') +sql insert into tb5_2 values ('2021-05-05 18:19:09',22,22.0,22,22,22,22.0,true ,'22','22') +sql insert into tb5_2 values ('2021-05-05 18:19:10',23,23.0,23,23,23,23.0,false,'23','23') +sql insert into tb5_2 values ('2021-05-05 18:19:11',24,24.0,24,24,24,24.0,false,'24','24') +sql insert into tb5_3 values ('2021-05-05 18:19:12',31,31.0,31,31,31,31.0,true ,'31','31') +sql insert into tb5_3 values ('2021-05-05 18:19:13',32,32.0,32,32,32,32.0,true ,'32','32') +sql insert into tb5_3 values ('2021-05-05 18:19:14',33,33.0,33,33,33,33.0,false,'33','33') +sql insert into tb5_3 values ('2021-05-05 18:19:15',34,34.0,34,34,34,34.0,false,'34','34') +sql insert into tb5_4 values ('2021-05-05 18:19:16',41,41.0,41,41,41,41.0,true ,'41','41') +sql insert into tb5_4 values ('2021-05-05 18:19:17',42,42.0,42,42,42,42.0,true ,'42','42') +sql insert into tb5_4 values ('2021-05-05 18:19:18',43,43.0,43,43,43,43.0,false,'43','43') +sql insert into tb5_4 values ('2021-05-05 18:19:19',44,44.0,44,44,44,44.0,false,'44','44') +sql insert into tb5_5 values ('2021-05-05 18:19:20',51,51.0,51,51,51,51.0,true ,'51','51') +sql insert into tb5_5 values ('2021-05-05 18:19:21',52,52.0,52,52,52,52.0,true ,'52','52') +sql insert into tb5_5 values ('2021-05-05 18:19:22',53,53.0,53,53,53,53.0,false,'53','53') +sql insert into tb5_5 values ('2021-05-05 18:19:23',54,54.0,54,54,54,54.0,false,'54','54') +sql insert into tb5_6 values ('2021-05-05 18:19:24',61,61.0,61,61,61,61.0,true ,'61','61') +sql insert into tb5_6 values ('2021-05-05 18:19:25',62,62.0,62,62,62,62.0,true ,'62','62') +sql insert into tb5_6 values ('2021-05-05 18:19:26',63,63.0,63,63,63,63.0,false,'63','63') +sql insert into tb5_6 values ('2021-05-05 18:19:27',64,64.0,64,64,64,64.0,false,'64','64') +sql insert into tb5_6 values ('2021-05-05 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) +sql insert into tb5_7 values ('2021-05-05 18:19:29',71,71.0,71,71,71,71.0,true ,'71','71') +sql insert into tb5_7 values ('2021-05-05 18:19:30',72,72.0,72,72,72,72.0,true ,'72','72') +sql insert into tb5_7 values ('2021-05-05 18:19:31',73,73.0,73,73,73,73.0,false,'73','73') +sql insert into tb5_7 values ('2021-05-05 18:19:32',74,74.0,74,74,74,74.0,false,'74','74') +sql insert into tb5_7 values ('2021-05-05 18:19:33',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) +sql insert into tb5_8 values ('2021-05-05 18:19:34',81,81.0,81,81,81,81.0,true ,'81','81') +sql insert into tb5_8 values ('2021-05-05 18:19:35',82,82.0,82,82,82,82.0,true ,'82','82') +sql insert into tb5_8 values ('2021-05-05 18:19:36',83,83.0,83,83,83,83.0,false,'83','83') +sql insert into tb5_8 values ('2021-05-05 18:19:37',84,84.0,84,84,84,84.0,false,'84','84') +sql insert into tb5_8 values ('2021-05-05 18:19:38',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) + sleep 100 sql connect run general/parser/condition_query.sim +run general/parser/condition_query2.sim print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT @@ -150,4 +202,90 @@ sql connect sleep 100 run general/parser/condition_query.sim +run general/parser/condition_query2.sim + +sql drop database if exists cdb + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 100 +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c maxtablespervnode -v 1000 +system sh/cfg.sh -n dnode1 -c minTablesPerVnode -v 1000 +system sh/exec.sh -n dnode1 -s start + +sql create database if not exists cdb +sql use cdb +sql create table stba (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int) +sql create table stbb (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 bool) +sql create table stbc (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 float) +sql create table stbd (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 binary(10)) +sql create table stbe (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 nchar(10)) + + +sql create table tba_0 using stba tags(0) +sql create table tba_1 using stba tags(1) +sql create table tba_2 using stba tags(2) +sql create table tba_3 using stba tags(3) +sql create table tba_4 using stba tags(4) +sql create table tba_5 using stba tags(5) +sql create table tba_6 using stba tags(6) +sql create table tba_7 using stba tags(7) +sql create table tba_8 using stba tags(8) +sql create table tba_9 using stba tags(9) + +sql create table tbb_0 using stbb tags(true) +sql create table tbb_1 using stbb tags(false) +sql create table tbb_2 using stbb tags(true) +sql create table tbb_3 using stbb tags(false) +sql create table tbb_4 using stbb tags(true) +sql create table tbb_5 using stbb tags(false) +sql create table tbb_6 using stbb tags(true) +sql create table tbb_7 using stbb tags(false) +sql create table tbb_8 using stbb tags(true) +sql create table tbb_9 using stbb tags(false) + +sql create table tbc_0 using stbc tags(0) +sql create table tbc_1 using stbc tags(1) +sql create table tbc_2 using stbc tags(2) +sql create table tbc_3 using stbc tags(3) +sql create table tbc_4 using stbc tags(4) +sql create table tbc_5 using stbc tags(5) +sql create table tbc_6 using stbc tags(6) +sql create table tbc_7 using stbc tags(7) +sql create table tbc_8 using stbc tags(8) +sql create table tbc_9 using stbc tags(9) + + +sql create table tbd_0 using stbd tags('0000') +sql create table tbd_1 using stbd tags('1111') +sql create table tbd_2 using stbd tags('2222') +sql create table tbd_3 using stbd tags('3333') +sql create table tbd_4 using stbd tags('4444') +sql create table tbd_5 using stbd tags('5555') +sql create table tbd_6 using stbd tags('6666') +sql create table tbd_7 using stbd tags('7777') +sql create table tbd_8 using stbd tags('8888') +sql create table tbd_9 using stbd tags('9999') + +sql create table tbe_0 using stbe tags('0000') +sql create table tbe_1 using stbe tags('1111') +sql create table tbe_2 using stbe tags('2222') +sql create table tbe_3 using stbe tags('3333') +sql create table tbe_4 using stbe tags('4444') +sql create table tbe_5 using stbe tags('5555') +sql create table tbe_6 using stbe tags('6666') +sql create table tbe_7 using stbe tags('7777') +sql create table tbe_8 using stbe tags('8888') +sql create table tbe_9 using stbe tags('9999') + + +run general/parser/condition_query3.sim + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 100 +system sh/exec.sh -n dnode1 -s start + +run general/parser/condition_query3.sim diff --git a/tests/script/general/parser/condition_query.sim b/tests/script/general/parser/condition_query.sim index 8dfa8dae0c9e0c56116cb4132d1e940e99f45d48..bebcbe709f005337795fe1286b34fc264b287cb0 100644 --- a/tests/script/general/parser/condition_query.sim +++ b/tests/script/general/parser/condition_query.sim @@ -1,4 +1,3 @@ - sql use cdb; print "column test" @@ -11,7 +10,7 @@ if $rows != 28 then return -1 endi -sql_error select * from stb1 where c8 > 0 + sql_error select * from stb1 where c7 in (0,2,3,1); sql_error select * from stb1 where c8 in (true); sql_error select * from stb1 where c8 in (1,2); @@ -33,14 +32,119 @@ sql_error select * from stb1 where c4 != 'null'; sql_error select * from stb1 where c5 >= 'null'; sql_error select * from stb1 where c6 <= 'null'; sql_error select * from stb1 where c7 < 'nuLl'; -sql_error select * from stb1 where c8 < 'nuLl'; -sql_error select * from stb1 where c9 > 'nuLl'; +sql_error select * from stb1 where c1 match '.*'; +sql_error select * from stb1 where c2 match '.*'; +sql_error select * from stb1 where c3 match '.*'; +sql_error select * from stb1 where c4 match '.*'; +sql_error select * from stb1 where c5 match '.*'; +sql_error select * from stb1 where c6 match '.*'; +sql_error select * from stb1 where c7 match '.*'; +sql_error select * from stb1 where c9 match '.*'; +sql_error select * from stb1 where ts match '.*'; +sql_error select * from stb1 where c1 nmatch '.*'; +sql_error select * from stb1 where c2 nmatch '.*'; +sql_error select * from stb1 where c3 nmatch '.*'; +sql_error select * from stb1 where c4 nmatch '.*'; +sql_error select * from stb1 where c5 nmatch '.*'; +sql_error select * from stb1 where c6 nmatch '.*'; +sql_error select * from stb1 where c7 nmatch '.*'; +sql_error select * from stb1 where c9 nmatch '.*'; +sql_error select * from stb1 where ts nmatch '.*'; + sql_error select * from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b; sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 or b.c1 < 60; sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and ((a.c1 > 50 and a.c1 < 60) or (b.c2 > 60)); sql_error select * from stb1 where 'c2' is null; sql_error select * from stb1 where 'c2' is not null; +sql select * from stb1 where c9 > 'nuLl'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c8 = '22' or c8 >= '62'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c8 < '11'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi + +sql select * from stb1 where c8 <> '11'; +if $rows != 27 then + return -1 +endi + + +sql select * from stb1 where c9 > 'nuLl'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 > '11' and c9 <= '21'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:08.000@ then + return -1 +endi + +sql select * from stb1 where c9 <= '11' and c9 > '2' and c9 <> 3; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where c8 > 0 +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c8 < 'nuLl'; +if $rows != 28 then + return -1 +endi + sql select * from stb1 where c2 > 3.0 or c2 < 60; if $rows != 28 then return -1 @@ -2071,179 +2175,61 @@ if $data20 != @21-07-16 01:00:00.899@ then return -1 endi - -print "ts test" -sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; -sql_error select * from stb1 where ts2 like '2021-05-05%'; -sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:05.000') and ts > '2021-05-05 18:19:01.000' and ts < '2021-05-05 18:19:27.000'; -sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000') and ts != '2021-05-05 18:19:25.000'; -sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); -sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; -sql select * from stb1 where ts is null; -if $rows != 0 then - return -1 -endi -sql select * from stb1 where ts is not null and ts is null; -if $rows != 0 then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; -if $rows != 0 then +sql select * from stb1 where c8 > 0; +if $rows != 28 then return -1 endi -sql select * from stb1 where ts is not null; -if $rows != 29 then +sql select * from stb1 where c8 > 1 and c8 <= 21 and c8 < 11 and c8 >= 3; +if $rows != 2 then return -1 endi - -sql select * from stb1 where ts is not null or ts is null; -if $rows != 29 then +if $data00 != @21-05-05 18:19:02.000@ then return -1 endi - -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:25.000'; -if $rows != 29 then +if $data10 != @21-05-05 18:19:03.000@ then return -1 endi -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:26.000'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:25.000@ then - return -1 -endi -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:28.000'; -if $rows != 29 then - return -1 -endi -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts > '2021-05-05 18:19:27.000'; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:26.000@ then +sql select * from stb1 where c8 = 11 or c8 = 12 or c8 is null or c8 in ('13','23') or (c8 like '%4' and c8 like '3_'); +if $rows != 6 then return -1 endi -if $data20 != @21-05-05 18:19:27.000@ then +if $data00 != @21-05-05 18:19:04.000@ then return -1 endi -if $data30 != @21-05-05 18:19:28.000@ then +if $data10 != @21-05-05 18:19:05.000@ then return -1 endi - -sql select ts,c1,c2 from stb1 where ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000' or ts != '2021-05-05 18:19:25.000'; -if $rows != 29 then +if $data20 != @21-05-05 18:19:06.000@ then return -1 endi - -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts <> '2021-05-05 18:19:25.000'; -if $rows != 29 then +if $data30 != @21-05-05 18:19:10.000@ then return -1 endi - -sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.999') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.999')); -if $rows != 16 then +if $data40 != @21-05-05 18:19:15.000@ then return -1 endi -if $data00 != @21-05-05 18:19:05.000@ then +if $data50 != @21-05-05 18:19:28.000@ then return -1 endi -sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:12.000' and ts <= '2021-05-05 18:19:14.000') or (ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:17.000'); +sql select * from stb1 where c9 >= 3 and c9 <= 33; if $rows != 13 then return -1 endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi - -sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:01.000' and ts <= '2021-05-05 18:19:08.000'); -if $rows != 10 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:06.000') or (ts >= '2021-05-05 18:19:03.000' and ts <= '2021-05-05 18:19:12.000')) and (ts >= '2021-05-05 18:19:10.000'); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:10.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:12.000@ then - return -1 -endi -sql select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:25.000' and ts != '2021-05-05 18:19:18'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:28.000@ then - return -1 -endi - - -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:28.000@ then - return -1 -endi - -sql select * from stb1 where ts < '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:25'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:25'; +sql select * from stb1 where c9 > 22 and c9 <= 38 and c8 < 30 and c8 >= 24; if $rows != 1 then return -1 endi -if $data00 != @21-05-05 18:19:24.000@ then +if $data00 != @21-05-05 18:19:11.000@ then return -1 endi -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:25'; -if $rows != 25 then + +sql select * from stb1 where c9 = 11 or c9 = 12 or c9 is null or c9 in ('13','23') or ((c9 like '%4' or c9 like '3_') and c9 <> 34 and c9 != 44) and c9 < 45 and c9 like '1_'; +if $rows != 6 then return -1 endi if $data00 != @21-05-05 18:19:04.000@ then @@ -2255,485 +2241,104 @@ endi if $data20 != @21-05-05 18:19:06.000@ then return -1 endi - -sql select * from stb1 where ts < '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:25'; -if $rows != 25 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25'; -if $rows != 29 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:26'); -if $rows != 2 then +if $data30 != @21-05-05 18:19:07.000@ then return -1 endi -if $data00 != @21-05-05 18:19:24.000@ then +if $data40 != @21-05-05 18:19:10.000@ then return -1 endi -if $data10 != @21-05-05 18:19:25.000@ then +if $data50 != @21-05-05 18:19:28.000@ then return -1 endi -sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' or ts > '2021-05-05 18:19:26'); +sql select * from stb1 where c8 match '^1.*'; if $rows != 5 then return -1 endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:28.000@ then - return -1 -endi - - -sql select * from stb2 where ts2 in ('2021-05-05 18:28:03','2021-05-05 18:28:05','2021-05-05 18:28:08'); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then +if $data00 != @21-05-05 18:19:00.000@ then return -1 endi if $data10 != @21-05-05 18:19:04.000@ then return -1 endi -if $data20 != @21-05-05 18:19:07.000@ then - return -1 -endi - -sql select * from stb2 where t3 in ('2021-05-05 18:38:38','2021-05-05 18:38:28','2021-05-05 18:38:08') and ts2 in ('2021-05-05 18:28:04','2021-05-05 18:28:04','2021-05-05 18:28:03'); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:03.000@ then - return -1 -endi - -sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.ts < '2021-05-05 18:19:03.000' or a.ts >= '2021-05-05 18:19:13.000') and (b.ts >= '2021-05-05 18:19:01.000' and b.ts <= '2021-05-05 18:19:14.000'); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:14.000@ then - return -1 -endi - -sql select a.ts,c.ts,b.c1,c.u1,c.u2 from (select * from stb1) a, (select * from stb1) b, (select * from stb2) c where a.ts=b.ts and b.ts=c.ts and a.ts <= '2021-05-05 18:19:12.000' and b.ts >= '2021-05-05 18:19:06.000' and c.ts >= '2021-05-05 18:19:08.000' and c.ts <= '2021-05-05 18:19:11.000' and a.ts != '2021-05-05 18:19:10.000'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:11.000@ then - return -1 -endi - -sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:06.000' or ts >= '2021-05-05 18:19:13.000') and (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:14.000') and ts != '2021-05-05 18:19:04.000'; -if $rows != 6 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:03.000@ then - return -1 -endi if $data20 != @21-05-05 18:19:05.000@ then return -1 endi if $data30 != @21-05-05 18:19:06.000@ then return -1 endi -if $data40 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data50 != @21-05-05 18:19:14.000@ then +if $data40 != @21-05-05 18:19:07.000@ then return -1 endi -sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:26.000' or ts = '2021-05-05 18:19:26.000') and ts != '2021-05-05 18:19:03.000' and ts != '2021-05-05 18:19:26.000'; -if $rows != 5 then +sql select * from stb1 where c8 match '1.*'; +if $rows != 10 then return -1 endi if $data00 != @21-05-05 18:19:00.000@ then return -1 endi -if $data10 != @21-05-05 18:19:01.000@ then +if $data10 != @21-05-05 18:19:04.000@ then return -1 endi -if $data20 != @21-05-05 18:19:02.000@ then +if $data20 != @21-05-05 18:19:05.000@ then return -1 endi -if $data30 != @21-05-05 18:19:27.000@ then +if $data30 != @21-05-05 18:19:06.000@ then return -1 endi -if $data40 != @21-05-05 18:19:28.000@ then +if $data40 != @21-05-05 18:19:07.000@ then return -1 endi - -print "tbname test" -sql_error select * from stb1 where tbname like '%3' and tbname like '%4'; - -sql select * from stb1 where tbname like 'tb%'; -if $rows != 29 then +if $data50 != @21-05-05 18:19:08.000@ then return -1 endi - -sql select * from stb1 where tbname like '%2'; -if $rows != 4 then +if $data60 != @21-05-05 18:19:12.000@ then return -1 endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then +if $data70 != @21-05-05 18:19:16.000@ then return -1 endi -if $data20 != @21-05-05 18:19:10.000@ then +if $data80 != @21-05-05 18:19:20.000@ then return -1 endi -if $data30 != @21-05-05 18:19:11.000@ then +if $data90 != @21-05-05 18:19:24.000@ then return -1 endi -print "tag test" -sql select * from stb1 where t1 in (1,2) and t1 in (2,3); +sql select * from stb1 where c8 match '1.+'; if $rows != 4 then return -1 endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:10.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:11.000@ then - return -1 -endi - -sql select * from stb2 where t1 in (1,2) and t2 in (2) and t3 in ('2021-05-05 18:58:57.000'); -if $rows != 0 then - return -1 -endi - -print "join test" -sql_error select * from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts =tb2_1.ts; -sql select tb1.ts from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.ts < '2021-05-05 18:19:06.000'; -if $rows != 2 then - return -1 -endi if $data00 != @21-05-05 18:19:04.000@ then return -1 endi if $data10 != @21-05-05 18:19:05.000@ then return -1 endi -sql select tb1.ts,tb1.*,tb2_1.* from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.u1 < 5; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:06.000@ then - return -1 -endi - -sql select tb1.ts,tb1.*,tb2_1.* from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts >= '2021-05-05 18:19:03.000' and tb1.c7=false and tb2_1.u3>4; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:07.000@ then - return -1 -endi - -sql select stb1.ts,stb1.c1,stb1.t1,stb2.ts,stb2.u1,stb2.t4 from stb1, stb2 where stb1.ts=stb2.ts and stb1.t1 = stb2.t4; -if $rows != 9 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data50 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data60 != @21-05-05 18:19:06.000@ then - return -1 -endi -if $data70 != @21-05-05 18:19:07.000@ then - return -1 -endi -if $data80 != @21-05-05 18:19:11.000@ then - return -1 -endi - -sql select stb1.ts,stb1.c1,stb1.t1,stb2.ts,stb2.u1,stb2.t4 from stb1, stb2 where stb1.ts=stb2.ts and stb1.t1 = stb2.t4 and stb1.c1 > 2 and stb2.u1 <=4; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:04.000@ then - return -1 -endi if $data20 != @21-05-05 18:19:06.000@ then return -1 endi - -print "column&ts test" -sql_error select count(*) from stb1 where ts > 0 or c1 > 0; -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:20.000' and (c1 > 23 or c1 < 14) and c7 in (true) and c8 like '%2'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:17.000@ then - return -1 -endi - -print "column&tbname test" -sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0; -sql select * from stb1 where tbname like '%3' and c6 < 34 and c5 != 33 and c4 > 31; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:13.000@ then +if $data30 != @21-05-05 18:19:07.000@ then return -1 endi -print "column&tag test" -sql_error select * from stb1 where t1 > 0 or c1 > 0 -sql_error select * from stb1 where c1 > 0 or t1 > 0 -sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 -sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 -sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 -sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 -sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 -sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 -sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) -sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 -sql_error select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.t1=b.t1; - -sql select * from stb1 where c1 < 63 and t1 > 5 -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -sql select * from stb1 where t1 > 3 and t1 < 5 and c1 != 42 and c1 != 44; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:16.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:18.000@ then - return -1 -endi -sql select * from stb1 where t1 > 1 and c1 > 21 and t1 < 3 and c1 < 24 and t1 != 3 and c1 != 23; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:09.000@ then - return -1 -endi -sql select * from stb1 where c1 > 1 and (t1 > 3 or t1 < 2) and (c2 > 2 and c2 < 62 and t1 != 4) and (t1 > 2 and t1 < 6) and c7 = true and c8 like '%2'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:21.000@ then +sql select * from stb1 where c8 nmatch '^1.*'; +if $rows != 23 then return -1 endi -sql select * from stb1 where c1!=31 and c1 !=32 and c1 <> 63 and c1 <>1 and c1 <> 21 and c1 <> 2 and c7 <> true and c8 <> '3' and c9 <> '4' and c2<>13 and c3 <> 23 and c4 <> 33 and c5 <> 34 and c6 <> 43 and c2 <> 53 and t1 <> 5 and t2 <>4; +sql select ts,c8 from stb1 where c8 nmatch '[2345]+'; if $rows != 3 then return -1 endi -if $data00 != @21-05-05 18:19:07.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:27.000@ then - return -1 -endi - - -print "column&join test" -sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.c1 > 0; - - -print "ts&tbname test" -sql_error select count(*) from stb1 where ts > 0 or tbname like 'tb%'; - -print "ts&tag test" -sql_error select count(*) from stb1 where ts > 0 or t1 > 0; - -sql select * from stb2 where t1!=1 and t2=2 and t3 in ('2021-05-05 18:58:58.000') and ts < '2021-05-05 18:19:13.000'; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:12.000@ then - return -1 -endi - -print "ts&join test" -sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts > 0; -sql select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts and (tb1.ts > '2021-05-05 18:19:05.000' or tb1.ts < '2021-05-05 18:19:03.000' or tb1.ts > 0); - - -print "tbname&tag test" -sql select * from stb1 where tbname like 'tb%' and (t1=1 or t2=2 or t3=3) and t1 > 2; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:12.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:14.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:15.000@ then - return -1 -endi - -print "tbname&join test" - -print "tag&join test" - - - - - -print "column&ts&tbname test" -sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0 or ts > 0; - -print "column&ts&tag test" -sql_error select count(*) from stb1 where t1 > 0 or c1 > 0 or ts > 0; -sql_error select count(*) from stb1 where c1 > 0 or t1 > 0 or ts > 0; - -sql select * from stb1 where (t1 > 0 or t1 > 2 ) and ts > '2021-05-05 18:19:10.000' and (c1 > 1 or c1 > 3) and (c6 > 40 or c6 < 30) and (c8 like '%3' or c8 like '_4') and (c9 like '1%' or c9 like '6%' or (c9 like '%3' and c9 != '23')) and ts > '2021-05-05 18:19:22.000' and ts <= '2021-05-05 18:19:26.000'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then +if $data00 != @21-05-05 18:19:00.000@ then return -1 endi -sql select * from stb1 where ts > '2021-05-05 18:19:00.000' and c1 > 2 and t1 != 1 and c2 >= 23 and t2 >= 3 and c3 < 63 and c7 = false and t3 > 3 and t3 < 6 and c8 like '4%' and ts < '2021-05-05 18:19:19.000' and c2 > 40 and c3 != 42; -if $rows != 1 then +if $data10 != @21-05-05 18:19:04.000@ then return -1 endi -if $data00 != @21-05-05 18:19:18.000@ then +if $data20 != @21-05-05 18:19:24.000@ then return -1 endi -print "column&ts&join test" - -print "column&tbname&tag test" -sql_error select count(*) from stb1 where c1 > 0 or tbname in ('tb1') or t1 > 0; - -print "column&tbname&join test" -print "column&tag&join test" -print "ts&tbname&tag test" -sql_error select count(*) from stb1 where ts > 0 or tbname in ('tb1') or t1 > 0; - -print "ts&tbname&join test" -print "ts&tag&join test" -print "tbname&tag&join test" - - - - -print "column&ts&tbname&tag test" -sql_error select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; -sql_error select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and col > 0 and t1 > 0; - - -print "column&ts&tbname&join test" -print "column&ts&tag&join test" -print "column&tbname&tag&join test" -print "ts&tbname&tag&join test" - - -print "column&ts&tbname&tag&join test" -#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/condition_query2.sim b/tests/script/general/parser/condition_query2.sim new file mode 100644 index 0000000000000000000000000000000000000000..513bb9900ba2e40a165cc6d76cdaf88a46fb00e5 --- /dev/null +++ b/tests/script/general/parser/condition_query2.sim @@ -0,0 +1,2345 @@ +sql use cdb; + +print "ts test" +sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; +sql_error select * from stb1 where ts2 like '2021-05-05%'; +sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:05.000') and ts > '2021-05-05 18:19:01.000' and ts < '2021-05-05 18:19:27.000'; +sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000') and ts != '2021-05-05 18:19:25.000'; +sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); +sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; +sql_error select tbname,ts,t1,t2 from stb5 where t1 > ''; + +sql select * from stb1 where ts is null; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where ts is not null and ts is null; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where ts is not null; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where ts is not null or ts is null; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:26.000'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:28.000'; +if $rows != 29 then + return -1 +endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts > '2021-05-05 18:19:27.000'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000' or ts != '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts <> '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.999') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.999')); +if $rows != 16 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:12.000' and ts <= '2021-05-05 18:19:14.000') or (ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:17.000'); +if $rows != 13 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:01.000' and ts <= '2021-05-05 18:19:08.000'); +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:06.000') or (ts >= '2021-05-05 18:19:03.000' and ts <= '2021-05-05 18:19:12.000')) and (ts >= '2021-05-05 18:19:10.000'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi + +sql select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:25.000' and ts != '2021-05-05 18:19:18'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:25'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25'; +if $rows != 29 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:26'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' or ts > '2021-05-05 18:19:26'); +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + + +sql select * from stb2 where ts2 in ('2021-05-05 18:28:03','2021-05-05 18:28:05','2021-05-05 18:28:08'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select * from stb2 where t3 in ('2021-05-05 18:38:38','2021-05-05 18:38:28','2021-05-05 18:38:08') and ts2 in ('2021-05-05 18:28:04','2021-05-05 18:28:04','2021-05-05 18:28:03'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi + +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.ts < '2021-05-05 18:19:03.000' or a.ts >= '2021-05-05 18:19:13.000') and (b.ts >= '2021-05-05 18:19:01.000' and b.ts <= '2021-05-05 18:19:14.000'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select a.ts,c.ts,b.c1,c.u1,c.u2 from (select * from stb1) a, (select * from stb1) b, (select * from stb2) c where a.ts=b.ts and b.ts=c.ts and a.ts <= '2021-05-05 18:19:12.000' and b.ts >= '2021-05-05 18:19:06.000' and c.ts >= '2021-05-05 18:19:08.000' and c.ts <= '2021-05-05 18:19:11.000' and a.ts != '2021-05-05 18:19:10.000'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:06.000' or ts >= '2021-05-05 18:19:13.000') and (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:14.000') and ts != '2021-05-05 18:19:04.000'; +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:26.000' or ts = '2021-05-05 18:19:26.000') and ts != '2021-05-05 18:19:03.000' and ts != '2021-05-05 18:19:26.000'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + +print "tbname test" +sql select tbname from stb1; +if $rows != 6 then + return -1 +endi + +sql select * from stb1 where tbname like '%3' and tbname like '%4'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where tbname like 'tb%'; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where tbname like '%2'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select tbname from stb1 where tbname = 'tb1'; +if $rows != 1 then + return -1 +endi +if $data00 != tb1 then + return -1 +endi + +sql select tbname from stb1 where tbname = 'tb1' or tbname = 'tb3'; +if $rows != 2 then + return -1 +endi +if $data00 != tb1 then + return -1 +endi +if $data10 != tb3 then + return -1 +endi + +sql select tbname from stb1 where tbname <> 'tb1'; +if $rows != 5 then + return -1 +endi +if $data00 != tb2 then + return -1 +endi +if $data10 != tb3 then + return -1 +endi +if $data20 != tb4 then + return -1 +endi +if $data30 != tb5 then + return -1 +endi +if $data40 != tb6 then + return -1 +endi + +sql select tbname from stb1 where tbname <> 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; +if $rows != 6 then + return -1 +endi +if $data00 != tb1 then + return -1 +endi +if $data10 != tb2 then + return -1 +endi +if $data20 != tb3 then + return -1 +endi +if $data30 != tb4 then + return -1 +endi +if $data40 != tb5 then + return -1 +endi +if $data50 != tb6 then + return -1 +endi + +sql select tbname from stb1 where tbname > 'tba'; +if $rows != 0 then + return -1 +endi + +sql select tbname from stb1 where tbname > 'tb2' and tbname <= 'tb5'; +if $rows != 3 then + return -1 +endi +if $data00 != tb3 then + return -1 +endi +if $data10 != tb4 then + return -1 +endi +if $data20 != tb5 then + return -1 +endi + +sql select tbname from stb1 where tbname >= 'tb5' or tbname <= 'tb2'; +if $rows != 4 then + return -1 +endi +if $data00 != tb1 then + return -1 +endi +if $data10 != tb2 then + return -1 +endi +if $data20 != tb5 then + return -1 +endi +if $data30 != tb6 then + return -1 +endi + +sql select tbname from stb1 where tbname is null; +if $rows != 0 then + return -1 +endi + + +sql select tbname from stb1 where tbname is not null; +if $rows != 6 then + return -1 +endi +if $data00 != tb1 then + return -1 +endi +if $data10 != tb2 then + return -1 +endi +if $data20 != tb3 then + return -1 +endi +if $data30 != tb4 then + return -1 +endi +if $data40 != tb5 then + return -1 +endi +if $data50 != tb6 then + return -1 +endi + +sql select tbname from stb1 where tbname in ('tb2','tb6'); +if $rows != 2 then + return -1 +endi +if $data00 != tb2 then + return -1 +endi +if $data10 != tb6 then + return -1 +endi + +sql select tbname from stb1 where tbname is not null and (tbname in ('tb2','tb6') or tbname like '%3'); +if $rows != 3 then + return -1 +endi +if $data00 != tb2 then + return -1 +endi +if $data10 != tb3 then + return -1 +endi +if $data20 != tb6 then + return -1 +endi + +sql select tbname from stb1 where (tbname like '%5' and tbname like 'tb%'); +if $rows != 1 then + return -1 +endi +if $data00 != tb5 then + return -1 +endi + +sql select * from stb1 where tbname = 'tb5' and tbname <> 'tb5'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where tbname = 'tb5' and tbname <> 'tb4'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select *,tbname from stb1 where tbname between 'tb2' and 'tb3'; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:15.000@ then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname match '^3'; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname match 'tb.?_[34]'; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:18.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:19.000@ then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname nmatch '[123467]+'; +if $rows != 9 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname in ('tb5_1', 'TB5_2'); +if $rows != 12 then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname in ('tb5_1', 'TB5_2') or tbname in ('tb5_3'); +if $rows != 16 then + return -1 +endi + +sql select ts,c1,t9,t10,tbname from stb5 where tbname in ('tb5_1', 'TB5_2') and tbname in ('tb5_2'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi +print "tag test" +sql_error select * from stb5 where t1 match '.*'; +sql_error select * from stb5 where t2 match '.*'; +sql_error select * from stb5 where t3 match '.*'; +sql_error select * from stb5 where t4 match '.*'; +sql_error select * from stb5 where t5 match '.*'; +sql_error select * from stb5 where t6 match '.*'; +sql_error select * from stb5 where t7 match '.*'; +sql_error select * from stb5 where t8 match '.*'; +sql_error select * from stb5 where t10 match '.*'; +sql_error select * from tb1 where t1 in (1,2) and t1 in (2,3); + +sql select * from stb1 where t1 in (1,2) and t1 in (2,3); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select * from stb1 where t1 in (1,2) or t1 in (2,3); +if $rows != 16 then + return -1 +endi + +sql select * from stb2 where t1 in (1,2) and t2 in (2) and t3 in ('2021-05-05 18:58:57.000'); +if $rows != 0 then + return -1 +endi + +sql select *,t1 from stb5 where t1 > 0; +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t1 from stb5 where ((t1 > 0 and t1 <= '2021-05-05 18:19:02.000') or (t1 >'2021-05-05 18:19:03.000' and t1 < '2021-05-05 18:19:06.000')) and t1 != '2021-05-05 18:19:04.000' and t1 is not null; +if $rows != 16 then + return -1 +endi + +sql select ts,c1,t1 from stb5 where ((t1 > 0 and t1 <= '2021-05-05 18:19:02.000') or (t1 >'2021-05-05 18:19:03.000' and t1 < '2021-05-05 18:19:06.000')) and t1 != '2021-05-05 18:19:04.000' and t1 is null; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t1 from stb5 where (((t1 > 0 and t1 <= '2021-05-05 18:19:02.000') or (t1 >'2021-05-05 18:19:03.000' and t1 < '2021-05-05 18:19:06.000')) and t1 != '2021-05-05 18:19:04.000') or t1 is null; +if $rows != 21 then + return -1 +endi + +sql select ts,c1,t2 from stb5 where t2 > 0 or t2 is null; +if $rows != 39 then + return -1 +endi + +sql select ts,c1,t2 from stb5 where (((t2 > 5 or t2 is null or t2 < 3) and t2 != 6) or t2 in (4, 3)) and t2 <= 3 and t2 >= 2; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:15.000@ then + return -1 +endi + +sql select ts,c1,t2 from stb5 where t2 > 5.5; +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:29.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:30.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:31.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:32.000@ then + return -1 +endi +if $data90 != @21-05-05 18:19:33.000@ then + return -1 +endi + +sql select ts,c1,t2 from stb5 where t2 >= 5.5; +if $rows != 14 then + return -1 +endi + +sql select ts,c1,t3,t4,t5,t6,t7 from stb5 where t3 is null or t4 is null; +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:29.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:30.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:31.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:32.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:33.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data90 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t3,t4,t5,t6,t7 from stb5 where t3 is null or t4 is null or t5 <= 1 or t6 in (2,3) or t7 < 5; +if $rows != 30 then + return -1 +endi + +sql select ts,c1,t8,t9 from stb5 where t8 = true; +if $rows != 21 then + return -1 +endi +sql select ts,c1,t8,t9 from stb5 where t8 <> true; +if $rows != 13 then + return -1 +endi + +sql select ts,c1,t8,t9 from stb5 where t8 = false; +if $rows != 13 then + return -1 +endi + +sql select ts,c1,t8,t9 from stb5 where t8 in (true, false); +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t8,t9 from stb5 where t8 in (true, false) or t8 is null; +if $rows != 39 then + return -1 +endi + +sql select ts,c1,t8,t9 from stb5 where t8 in (true) and t8 is not null; +if $rows != 21 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 > '12'; +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 = '11'; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 <> '111111111'; +if $rows != 26 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 = '111111111'; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 >= '888888888'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 > '222222222' and t9 < '444444444'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 > '0000000000' and t9 < '999999999'; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 like '_1'; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 like '%1'; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where (t9 like '%1' or t9 in ('222222222','444444444')) and t9 is null; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 is null; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:29.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:30.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:31.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:32.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:33.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 is not null; +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 is not null and t9 is null; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 like '_%' and t10 between 5 and 6; +if $rows != 9 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is not null; +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is null; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is not null and t10 like '%__'; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is not null and t10 like '%_%'; +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is not null and t10 like '%%_%%'; +if $rows != 34 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is not null and t10 like '%_%%%_'; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 like '_' and t10 between 2 and 3; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:15.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 in ('a','3','bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb') or t10 in (''); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t10 is null or (t10 > 1 and t10 < 7 and t10 in ('3','4','5') and t10 != 4 and t10 like '3'); +if $rows != 9 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t8,t9,t10 from stb5 where (t10 is null or t9 is null) and t8 is null; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t8,t9,t10 from stb5 where t10 between 3 and 7 and t9 between '' and '00000000000' and t9 like '_________' and (t10 like '3%'or t10 like '%4'); +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:18.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:19.000@ then + return -1 +endi + +sql select ts,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10 from stb5 where t1 is not null and t2 between 2 and 7 and t3 in (2, 4,6) and t8 != false and t9 > '111111111' and t10 <= 5; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select * from stb5 where t1 <> 1; +if $rows != 34 then + return -1 +endi + +sql select t1,ts,c1 from stb5 where t1 <> '2021-05-05 18:19:01.000' +if $rows != 26 then + return -1 +endi + +sql select t1,ts,c1 from stb5 where t1 <> '2021-05-05 18:19:01.000' and t1 <> '2021-05-05 18:19:08.000'; +if $rows != 21 then + return -1 +endi + +sql select t1,ts,c1 from stb5 where t1 > '2021-05-05 18:19:02.000'; +if $rows != 22 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 match '1.+'; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 match '[3-9]'; +if $rows != 22 then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 match '8.*'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,c1,t9,t10 from stb5 where t9 nmatch '^[12345]*\$'; +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:35.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:37.000@ then + return -1 +endi +if $data90 != @21-05-05 18:19:38.000@ then + return -1 +endi + +print "join test" +sql_error select * from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts =tb2_1.ts; +sql select tb1.ts from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.ts < '2021-05-05 18:19:06.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +sql select tb1.ts,tb1.*,tb2_1.* from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.u1 < 5; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select tb1.ts,tb1.*,tb2_1.* from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts >= '2021-05-05 18:19:03.000' and tb1.c7=false and tb2_1.u3>4; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb1.t1,stb2.ts,stb2.u1,stb2.t4 from stb1, stb2 where stb1.ts=stb2.ts and stb1.t1 = stb2.t4; +if $rows != 9 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb1.t1,stb2.ts,stb2.u1,stb2.t4 from stb1, stb2 where stb1.ts=stb2.ts and stb1.t1 = stb2.t4 and stb1.c1 > 2 and stb2.u1 <=4; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select stb1.ts,stb1.t1,stb1.c1,stb5.c2 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and (stb1.c1 between 20 and 50 and (stb5.c2 > 22 and stb5.c2 < 33)); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:13.000@ then + return -1 +endi + +sql select stb1.ts,stb1.t1,stb1.c1,stb5.c2 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts; +if $rows != 29 then + return -1 +endi + +sql select stb1.c1,stb5.c1 from stb1, stb5 where stb1.t1=stb5.t2 and (stb1.c1 > 10 and stb5.c1 < 20) and stb1.ts=stb5.ts ; +if $rows != 4 then + return -1 +endi +if $data00 != 11 then + return -1 +endi +if $data10 != 12 then + return -1 +endi +if $data20 != 13 then + return -1 +endi +if $data30 != 14 then + return -1 +endi + +print "column&ts test" +sql_error select count(*) from stb1 where ts > 0 or c1 > 0; +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:20.000' and (c1 > 23 or c1 < 14) and c7 in (true) and c8 like '%2'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:17.000@ then + return -1 +endi + +print "column&tbname test" +sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0; +sql select * from stb1 where tbname like '%3' and c6 < 34 and c5 != 33 and c4 > 31; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:13.000@ then + return -1 +endi + +sql select ts,c1,tbname from stb5 where c1 > 30 and tbname > 'tb5_3' and tbname < 'tb5_8' and c1 < 72 and c1 between 44 and 54; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:19.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select ts,c8,tbname from stb5 where (tbname like '%3' or tbname like '%4' or tbname = 'tb5_6') and tbname between 'tb5_2' and 'tb5_7' and (c8 like '3_' or c8 like '_4'); +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:19.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:27.000@ then + return -1 +endi + + +print "column&tag test" +sql_error select * from stb1 where t1 > 0 or c1 > 0 +sql_error select * from stb1 where c1 > 0 or t1 > 0 +sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 +sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) +sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 +sql_error select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.t1=b.t1; + +sql select * from stb1 where c1 < 63 and t1 > 5 +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +sql select * from stb1 where t1 > 3 and t1 < 5 and c1 != 42 and c1 != 44; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:18.000@ then + return -1 +endi +sql select * from stb1 where t1 > 1 and c1 > 21 and t1 < 3 and c1 < 24 and t1 != 3 and c1 != 23; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:09.000@ then + return -1 +endi +sql select * from stb1 where c1 > 1 and (t1 > 3 or t1 < 2) and (c2 > 2 and c2 < 62 and t1 != 4) and (t1 > 2 and t1 < 6) and c7 = true and c8 like '%2'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:21.000@ then + return -1 +endi + +sql select * from stb1 where c1!=31 and c1 !=32 and c1 <> 63 and c1 <>1 and c1 <> 21 and c1 <> 2 and c7 <> true and c8 <> '3' and c9 <> '4' and c2<>13 and c3 <> 23 and c4 <> 33 and c5 <> 34 and c6 <> 43 and c2 <> 53 and t1 <> 5 and t2 <>4; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select ts,t1,c1,t2 from stb5 where t1 in ('2021-05-05 18:19:02.000','2021-05-05 18:19:04.000','2021-05-05 18:19:06.000','2021-05-05 18:19:08.000') and c1 is null and t2 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:38.000@ then + return -1 +endi + +sql select ts,t1,c1,t2 from stb5 where t1 in ('2021-05-05 18:19:02.000','2021-05-05 18:19:04.000','2021-05-05 18:19:06.000','2021-05-05 18:19:08.000') and t2 is not null and ts between '2021-05-05 18:19:10.000' and '2021-05-05 18:19:20.000' and t2 < 3; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select ts,t1,c1,t2,tbname,t8,t9 from stb5 where (((t8 != false or t8 is null) and (t9 like '%8' or t9 like '%6') and t2 is not null) or (t8 in (false) and t1 is null)) and (c1 is null or (c1 > 62 and c1 <= 72)); +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:29.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:30.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:33.000@ then + return -1 +endi + +print "column&join test" +sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.c1 > 0; + +sql select stb5.ts,stb5.c1,stb5.t1,stb5.t8,stb5.t9,stb5.t10 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and (stb5.c1 > 60 or stb5.c1 <= 11 or stb5.c1 is null); +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data90 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select stb5.ts,stb5.c1,stb5.t1,stb5.t8,stb5.t9,stb5.t10 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and (stb5.c1 > 60 or stb5.c1 <= 11 or stb5.c1 is null or stb5.c2 between 30 and 40) and (stb1.c9 like '%3' or stb1.c8 like '%4') and stb5.c9 like '%3%'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi + + +print "ts&tbname test" +sql_error select count(*) from stb1 where ts > 0 or tbname like 'tb%'; +sql_error select tbname,ts,c1,tbname from stb5 where tbname like '%' and tbname between '' and 'tb5_3' and ts between '2021-05-05 18:19:05.000' and '2021-05-05 18:19:10.000' and ts <> '2021-05-05 18:19:07.000'; + +sql select tbname,ts,c1,tbname from stb5 where (tbname like '%5' or tbname like '%8') and ts between '2021-05-05 18:19:21.000' and '2021-05-05 18:19:35.000'; +if $rows != 5 then + return -1 +endi +if $data01 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data11 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data21 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data31 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data41 != @21-05-05 18:19:35.000@ then + return -1 +endi + +sql select tbname,ts,c1,tbname from stb5 where tbname like '%' and tbname between '' and 'tb5_3' and ts between '2021-05-05 18:19:10.000' and '2021-05-05 18:19:05.000'; +if $rows != 0 then + return -1 +endi + +sql select tbname,ts,c1,tbname from stb5 where tbname like '%' and tbname between '' and 'tb5_3' and ts between '2021-05-05 18:19:05.000' and '2021-05-05 18:19:10.000' and ts <> '2021-05-05 18:19:05.000' and ts != '2021-05-05 18:19:10.000' order by ts desc; +if $rows != 4 then + return -1 +endi +if $data01 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data11 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data21 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data31 != @21-05-05 18:19:06.000@ then + return -1 +endi + + +print "ts&tag test" +sql_error select count(*) from stb1 where ts > 0 or t1 > 0; + +sql select * from stb2 where t1!=1 and t2=2 and t3 in ('2021-05-05 18:58:58.000') and ts < '2021-05-05 18:19:13.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:12.000@ then + return -1 +endi + +sql select t1,ts,c1,t1,t2 from stb5 where (t1 > 1 or t1 is null or t2 is null) and (t1 in ('2021-05-05 18:19:02.000','2021-05-05 18:19:04.000') or t1 is null) and t2 >= 4 order by ts; +if $rows != 9 then + return -1 +endi +if $data01 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data11 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data21 != @21-05-05 18:19:18.000@ then + return -1 +endi +if $data31 != @21-05-05 18:19:19.000@ then + return -1 +endi +if $data41 != @21-05-05 18:19:29.000@ then + return -1 +endi +if $data51 != @21-05-05 18:19:30.000@ then + return -1 +endi +if $data61 != @21-05-05 18:19:31.000@ then + return -1 +endi +if $data71 != @21-05-05 18:19:32.000@ then + return -1 +endi +if $data81 != @21-05-05 18:19:33.000@ then + return -1 +endi + +print "ts&join test" +sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts > 0; +sql_error select stb1.tbname,stb5.tbname,stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and (stb1.ts = '2021-05-05 18:19:10.000' or stb1.ts = '2021-05-05 18:19:11.000'); + +sql select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts and (tb1.ts > '2021-05-05 18:19:05.000' or tb1.ts < '2021-05-05 18:19:03.000' or tb1.ts > 0) and tb1.ts between '0' and '2021-05-05 18:19:04.000' and tb2_1.ts < '2021-05-05 18:19:03.000'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select stb1.tbname,stb5.tbname,stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and (stb1.ts = '2021-05-05 18:19:10.000' or stb1.ts <= '2021-05-05 18:19:11.000') and stb5.ts > '2021-05-05 18:19:05.000' and stb5.ts != '2021-05-05 18:19:11.000'; +if $rows != 5 then + return -1 +endi +if $data02 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data12 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data22 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data32 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data42 != @21-05-05 18:19:10.000@ then + return -1 +endi + + +print "tbname&tag test" +sql select * from stb1 where tbname like 'tb%' and (t1=1 or t2=2 or t3=3) and t1 > 2; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi + +sql select ts,t1,c1,t2,tbname,t8,t9 from stb5 where tbname = 'tb5_1' or t1 = '2021-05-05 18:19:02.000'; +if $rows != 12 then + return -1 +endi + +sql select ts,t1,c1,t2,tbname,t8,t9 from stb5 where t1 = '2021-05-05 18:19:02.000' or tbname = 'tb5_1'; +if $rows != 12 then + return -1 +endi + +sql select t2,t1,t2,t3,t4,t8 from stb5 where t2 > 1 and t2 < 3 or t3 >= 1 and t3 <=1 or t8 in (false); +if $rows != 5 then + return -1 +endi + +sql select tbname,ts,c1,t1,t2,t3,t8 from stb5 where (t2 > 1 and t2 < 3 or t3 >= 1 and t3 <=1 or t8 in (false) or tbname like 'tb5_8' or tbname in ('tb5_5')) and tbname < 'tb5_3' and t3 > 1.0 and ts < '2021-05-05 18:19:10.000'; +if $rows != 2 then + return -1 +endi + + +print "tbname&join test" +sql select stb1.tbname,stb5.tbname,stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb1.tbname < 'tb4' and (stb5.tbname like 'tb5_3' or stb5.tbname = 'tb5_1') and stb5.tbname like '%____%_%'; +if $rows != 12 then + return -1 +endi + +sql select stb1.tbname,stb5.tbname,stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb1.tbname < 'tb4' and (stb5.tbname like 'tb5_3' or stb5.tbname = 'tb5_1') and stb5.tbname like '%____%_%_'; +if $rows != 0 then + return -1 +endi + + +print "tag&join test" +sql select stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb1.t1 >= -1 and stb1.t1 < 100 and stb1.t1 in (1,2,3,5,6) and stb1.t1 <> 3 and stb1.t1 <= 5 and stb1.t1 >=2; +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t6,stb5.t7,stb5.t8 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb5.t1 >'2021-05-05 18:19:01.000'; +if $rows != 21 then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb1.t1,stb5.t3,stb5.t6,stb5.t7,stb5.t8,stb5.t9 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.t9 like '_%_______5555%55_'; +if $rows != 0 then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb1.t1,stb5.t3,stb5.t6,stb5.t7,stb5.t8,stb5.t9 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.t9 like '%_%__55%%%%55%55'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + + +print "column&ts&tbname test" +sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0 or ts > 0; + +sql select * from stb5 where tbname > '' and (tbname like '%8') and tbname is null; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,ts,c1,ts,c1,c8 from stb5 where tbname > '' and (tbname like '%8' or tbname like '%3') and tbname is not null and tbname in ('tb5_2','tb5_8') and tbname < 'aaaaaaaaaaa' and ts <= 1620209977000 and (c9 like '_3' or c9 <> '82'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:34.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:36.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:37.000@ then + return -1 +endi + + +print "column&ts&tag test" +sql_error select count(*) from stb1 where t1 > 0 or c1 > 0 or ts > 0; +sql_error select count(*) from stb1 where c1 > 0 or t1 > 0 or ts > 0; + +sql select * from stb1 where (t1 > 0 or t1 > 2 ) and ts > '2021-05-05 18:19:10.000' and (c1 > 1 or c1 > 3) and (c6 > 40 or c6 < 30) and (c8 like '%3' or c8 like '_4') and (c9 like '1%' or c9 like '6%' or (c9 like '%3' and c9 != '23')) and ts > '2021-05-05 18:19:22.000' and ts <= '2021-05-05 18:19:26.000'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +sql select * from stb1 where ts > '2021-05-05 18:19:00.000' and c1 > 2 and t1 != 1 and c2 >= 23 and t2 >= 3 and c3 < 63 and c7 = false and t3 > 3 and t3 < 6 and c8 like '4%' and ts < '2021-05-05 18:19:19.000' and c2 > 40 and c3 != 42; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:18.000@ then + return -1 +endi + + +print "column&ts&join test" +sql select stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb1.ts > '2021-05-05 18:19:09.000' and stb5.ts < '2021-05-05 18:19:25.000' and stb1.c9 like '%4'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:19.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + +print "column&tbname&tag test" +sql_error select count(*) from stb1 where c1 > 0 or tbname in ('tb1') or t1 > 0; + +sql select * from stb5 where c1 > 10 and tbname in ('tb5_2','tb5_3','tb5_4') and t9 like '%4'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:18.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:19.000@ then + return -1 +endi + + +print "column&tbname&join test" +sql select stb1.ts,stb1.c1,stb5.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and (stb5.c1 > 10 or stb5.c1 is null) and stb5.tbname in ('tb5_2','tb5_3','tb5_6') and (stb5.c1 < 24 or stb5.c1 is null); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb5.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and (stb5.c1 > 10 or stb5.c1 is null) and stb5.tbname in ('tb5_2', 'tb5_3','tb5_6') and (stb5.c1 < 24 or stb5.c1 is null) and stb5.c1 is not null; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi + + +print "column&tag&join test" +sql select stb1.ts,stb1.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb1.t1 >= -1 and stb1.t1 < 100 and stb1.t1 in (1,2,3,5,6) and stb1.t1 <> 3 and stb1.t1 <= 5 and stb1.t1 >=2 and stb1.c1 >= 22 and stb1.c1 <= 53 and stb1.c1 in (23,24,50,54,21); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select stb1.ts,stb1.t3,stb1.tbname,stb1.c1,stb5.tbname from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb1.t2 > 1; +if $rows != 21 then + return -1 +endi + +sql select stb1.ts,stb1.t3,stb1.tbname,stb1.c1,stb5.t9,stb1.t2 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb1.t2 between 2 and 5 and (stb5.t9 like '%2' or stb5.t9 like '%3') and stb1.ts < '2021-05-05 18:19:14.000' and stb5.ts > '2021-05-05 18:19:09.000'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:13.000@ then + return -1 +endi + + +print "ts&tbname&tag test" +sql_error select count(*) from stb1 where ts > 0 or tbname in ('tb1') or t1 > 0; + +sql select tbname,ts,t1,t2 from stb5 where ts > 0 and ts between '2021-05-05 18:19:06.001' and '2021-05-05 18:19:30.000' and (tbname='tb5_6' or tbname in ('tb5_1')) and t1 > '2021-05-05 18:19:01.000'; +if $rows != 5 then + return -1 +endi +if $data01 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data11 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data21 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data31 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data41 != @21-05-05 18:19:28.000@ then + return -1 +endi + +print "ts&tbname&join test" + +sql_error select stb1.ts,stb1.c1,stb5.c1,stb1.t1 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.tbname in ('tb5_2', 'tb5_3','tb5_6') and stb5.ts < 1111111111111111111111; + +sql select stb1.ts,stb1.c1,stb5.c1,stb1.t1,stb1.tbname from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.tbname in ('tb5_2', 'tb5_3','tb5_6') and stb5.ts < 11111111111111111 and (stb1.tbname like '%6' or stb1.tbname in ('tb2')) and stb1.ts between '2021-05-05 18:19:10.000' and '2021-05-05 18:19:26.000'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:26.000@ then + return -1 +endi + +print "ts&tag&join test" +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t3,stb5.t6,stb5.t7,stb5.t8,stb5.t9 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.t1 > '2021-05-05 18:19:02.000' and stb5.t1 between '2021-05-05 18:19:05.000' and '2021-05-05 18:19:06.000' and stb5.ts between '2021-05-05 18:19:23.000' and '2021-05-05 18:19:25.000'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi + + +print "tbname&tag&join test" +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t3,stb5.t6,stb5.t7,stb5.t8,stb5.t9 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.t1 > '2021-05-05 18:19:01.000' and stb5.t1 between '2021-05-05 18:19:00.000' and '2021-05-05 18:19:06.000' and (stb5.tbname like '%3' or stb5.tbname like '%2'); +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:15.000@ then + return -1 +endi + +print "column&ts&tbname&tag test" +sql_error select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; +sql_error select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and col > 0 and t1 > 0; + +sql select t4,tbname,ts,c1 from stb5 where ((tbname like '%4') or t4 >= 6) and ts between '2021-05-05 18:19:20.000' and '2021-05-05 18:19:30.000' and (c1 is null or c1 >= 62 and c1 <= 71); +if $rows != 5 then + return -1 +endi +if $data02 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data12 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data22 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data32 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data42 != @21-05-05 18:19:29.000@ then + return -1 +endi + +print "column&ts&tbname&join test" + +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t3,stb5.t6,stb5.t7,stb5.t8,stb5.t9 from stb1, stb5 where stb1.t1=stb5.t2 and stb1.ts=stb5.ts and stb5.t1 > '2021-05-05 18:19:01.000' and stb5.t1 between '2021-05-05 18:19:00.000' and '2021-05-05 18:19:06.000' and (stb5.tbname like '%3' or stb5.tbname like '%2') and stb1.ts between '2021-05-05 18:19:09.000' and '2021-05-05 18:19:14.000' and stb1.c1 > 23; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:14.000@ then + return -1 +endi + +print "column&ts&tag&join test" +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t6,stb5.t7,stb5.t8 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb5.t8 = true and stb5.t7< 3.0000 and stb5.ts > '2021-05-05 18:19:02.000' and stb5.c1 between 10 and 22 and stb5.t1 >'2021-05-05 18:19:01.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi + +print "column&tbname&tag&join test" +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t6,stb5.t7,stb5.t8 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb1.c1 > 11 and (stb5.tbname like '%3' or stb5.tbname like '%6' or stb5.tbname = 'tb5_4') and stb5.t7 > 4 and stb5.t8 <> 'false'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi + + +print "ts&tbname&tag&join test" +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t6,stb5.t7,stb5.t8 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb1.ts between '2021-05-05 18:19:15.000' and '2099-05-05 18:19:15.000' and stb5.tbname in ('tb5_3','tb5_5','tb5_6') and stb5.t1 >= '2021-05-05 18:19:03.000' and stb5.t1 <= '2021-05-05 18:19:08.000' and stb5.ts <='2021-05-05 18:19:25.000'; +if $rows != 7 then + return -1 +endi +if $data00 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:25.000@ then + return -1 +endi + +print "column&ts&tbname&tag&join test" +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t6,stb5.t7,stb5.t8 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb1.ts between '2021-05-05 18:19:15.000' and '2099-05-05 18:19:15.000' and stb5.tbname in ('tb5_3','tb5_5','tb5_6') and stb5.t1 >= '2021-05-05 18:19:03.000' and stb5.t1 <= '2021-05-05 18:19:08.000' and stb5.ts <='2021-05-05 18:19:25.000' and stb1.c1 between 34 and 60; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:15.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb5.t1,stb5.t6,stb5.t7,stb5.t8 from stb1,stb5 where stb1.ts=stb5.ts and stb1.t3=stb5.t7 and stb5.tbname<>'tb5_1' and stb5.t1 <> '2021-05-05 18:19:02.000' and stb1.ts > '2021-05-05 18:19:12.000' and stb5.c1 != 32 and stb5.t6 > 3 and stb5.t7 < 6 and stb5.t8 <> false; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/condition_query3.sim b/tests/script/general/parser/condition_query3.sim new file mode 100644 index 0000000000000000000000000000000000000000..a88d75f40d2d638e19d356b2f0ef76789c42b2db --- /dev/null +++ b/tests/script/general/parser/condition_query3.sim @@ -0,0 +1,210 @@ +sql use cdb; + +print "index tag test" + +sql select tbname,t1 from stba; +if $rows != 10 then + return -1 +endi + +sql select tbname,t1 from stba where t1 > 2; +if $rows != 7 then + return -1 +endi + +sql select tbname,t1 from stba where t1 >= 4; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stba where t1 >= 3 and t1 <= 6; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stba where t1 = 3; +if $rows != 1 then + return -1 +endi + +sql select tbname,t1 from stba where t1 <> 6; +if $rows != 9 then + return -1 +endi + +sql select tbname,t1 from stba where t1 < 6; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stba where t1 < 6 and t1 >= 2; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stba where t1 is null; +if $rows != 0 then + return -1 +endi +sql select tbname,t1 from stba where t1 is not null; +if $rows != 10 then + return -1 +endi + +sql_error select tbname,t1 from stbb where t1 > true; +sql select tbname,t1 from stbb where t1 = true; +if $rows != 5 then + return -1 +endi + +sql select tbname,t1 from stbb where t1 <> true; +if $rows != 5 then + return -1 +endi + +sql select tbname,t1 from stbb where t1 is null; +if $rows != 0 then + return -1 +endi +sql select tbname,t1 from stbb where t1 is not null; +if $rows != 10 then + return -1 +endi + +sql select tbname,t1 from stbc; +if $rows != 10 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 > 2; +if $rows != 7 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 >= 4; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 >= 3 and t1 <= 6; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 = 3; +if $rows != 1 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 <> 6; +if $rows != 9 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 < 6; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 < 6 and t1 >= 2; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stbc where t1 is null; +if $rows != 0 then + return -1 +endi +sql select tbname,t1 from stbc where t1 is not null; +if $rows != 10 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 > '2222'; +if $rows != 7 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 >= '4444'; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 >= '3333' and t1 <= '6666'; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 = '3333'; +if $rows != 1 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 <> '6666'; +if $rows != 9 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 < '6666'; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 < '6666' and t1 >= '2222'; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stbd where t1 is null; +if $rows != 0 then + return -1 +endi +sql select tbname,t1 from stbd where t1 is not null; +if $rows != 10 then + return -1 +endi +sql select tbname,t1 from stbe where t1 > '2222'; +if $rows != 7 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 >= '4444'; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 >= '3333' and t1 <= '6666'; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 = '3333'; +if $rows != 1 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 <> '6666'; +if $rows != 9 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 < '6666'; +if $rows != 6 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 < '6666' and t1 >= '2222'; +if $rows != 4 then + return -1 +endi + +sql select tbname,t1 from stbe where t1 is null; +if $rows != 0 then + return -1 +endi +sql select tbname,t1 from stbe where t1 is not null; +if $rows != 10 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/general/parser/tbnameIn_query.sim b/tests/script/general/parser/tbnameIn_query.sim index db27886bbfde744910068b702199e2079d24c7d2..7fa579b9c2c9d1187c8630fd7f1dd17808b396f0 100644 --- a/tests/script/general/parser/tbnameIn_query.sim +++ b/tests/script/general/parser/tbnameIn_query.sim @@ -125,11 +125,10 @@ if $data21 != 2 then return -1 endi -# multiple tbname in is not allowed NOW -sql_error select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc -#if $rows != 4 then -# return -1 -#endi +sql select count(*) from $stb where tbname in ('ti_tb1', 'ti_tb300') and tbname in ('ti_tb5', 'ti_tb1000') group by t1 order by t1 asc +if $rows != 0 then + return -1 +endi #if $data00 != $rowNum then # return -1 #endi