提交 c6cb40bf 编写于 作者: H Haojun Liao

[td-225] fix bugs in tbname in query

上级 e46896bf
...@@ -3290,14 +3290,15 @@ static int32_t setExprToCond(tSQLExpr** parent, tSQLExpr* pExpr, const char* msg ...@@ -3290,14 +3290,15 @@ static int32_t setExprToCond(tSQLExpr** parent, tSQLExpr* pExpr, const char* msg
static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pCondExpr, int32_t* type, static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SCondExpr* pCondExpr, int32_t* type,
int32_t parentOptr) { int32_t parentOptr) {
const char* msg1 = "meter query cannot use tags filter"; const char* msg1 = "table query cannot use tags filter";
const char* msg2 = "illegal column name"; const char* msg2 = "illegal column name";
const char* msg3 = "only one query time range allowed"; const char* msg3 = "only one query time range allowed";
const char* msg4 = "only one join condition allowed"; const char* msg4 = "only one join condition allowed";
const char* msg5 = "not support ordinary column join"; const char* msg5 = "not support ordinary column join";
const char* msg6 = "only one query condition on tbname allowed"; const char* msg6 = "only one query condition on tbname allowed";
const char* msg7 = "only in/like allowed in filter table name"; const char* msg7 = "only in/like allowed in filter table name";
const char* msg8 = "wildcard string should be less than 20 characters";
tSQLExpr* pLeft = (*pExpr)->pLeft; tSQLExpr* pLeft = (*pExpr)->pLeft;
tSQLExpr* pRight = (*pExpr)->pRight; tSQLExpr* pRight = (*pExpr)->pRight;
...@@ -3344,7 +3345,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S ...@@ -3344,7 +3345,7 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S
// check for like expression // check for like expression
if ((*pExpr)->nSQLOptr == TK_LIKE) { if ((*pExpr)->nSQLOptr == TK_LIKE) {
if (pRight->val.nLen > TSDB_PATTERN_STRING_MAX_LEN) { if (pRight->val.nLen > TSDB_PATTERN_STRING_MAX_LEN) {
return TSDB_CODE_INVALID_SQL; return invalidSqlErrMsg(pQueryInfo->msg, msg8);
} }
SSchema* pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta); SSchema* pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
...@@ -3360,6 +3361,10 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S ...@@ -3360,6 +3361,10 @@ static int32_t handleExprInQueryCond(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, S
if (!validTableNameOptr(*pExpr)) { if (!validTableNameOptr(*pExpr)) {
return invalidSqlErrMsg(pQueryInfo->msg, msg7); return invalidSqlErrMsg(pQueryInfo->msg, msg7);
} }
if (!UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
return invalidSqlErrMsg(pQueryInfo->msg, msg1);
}
if (pCondExpr->pTableCond == NULL) { if (pCondExpr->pTableCond == NULL) {
pCondExpr->pTableCond = *pExpr; pCondExpr->pTableCond = *pExpr;
...@@ -3808,9 +3813,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql ...@@ -3808,9 +3813,7 @@ int32_t parseWhereClause(SQueryInfo* pQueryInfo, tSQLExpr** pExpr, SSqlObj* pSql
const char* msg2 = "invalid filter expression"; const char* msg2 = "invalid filter expression";
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
pQueryInfo->window = TSWINDOW_INITIALIZER;
pQueryInfo->window.skey = 0;
pQueryInfo->window.ekey = INT64_MAX;
// tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space // tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space
SStringBuilder sb; memset(&sb, 0, sizeof(sb)); SStringBuilder sb; memset(&sb, 0, sizeof(sb));
......
...@@ -61,7 +61,7 @@ TSKEY tscGetSubscriptionProgress(void* sub, int64_t uid, TSKEY dflt) { ...@@ -61,7 +61,7 @@ TSKEY tscGetSubscriptionProgress(void* sub, int64_t uid, TSKEY dflt) {
SSub* pSub = (SSub*)sub; SSub* pSub = (SSub*)sub;
SSubscriptionProgress target = {.uid = uid, .key = 0}; SSubscriptionProgress target = {.uid = uid, .key = 0};
SSubscriptionProgress* p = taosArraySearch(pSub->progress, tscCompareSubscriptionProgress, &target); SSubscriptionProgress* p = taosArraySearch(pSub->progress, &target, tscCompareSubscriptionProgress);
if (p == NULL) { if (p == NULL) {
return dflt; return dflt;
} }
...@@ -74,7 +74,7 @@ void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts) { ...@@ -74,7 +74,7 @@ void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts) {
SSub* pSub = (SSub*)sub; SSub* pSub = (SSub*)sub;
SSubscriptionProgress target = {.uid = uid, .key = ts}; SSubscriptionProgress target = {.uid = uid, .key = ts};
SSubscriptionProgress* p = taosArraySearch(pSub->progress, tscCompareSubscriptionProgress, &target); SSubscriptionProgress* p = taosArraySearch(pSub->progress, &target, tscCompareSubscriptionProgress);
if (p != NULL) { if (p != NULL) {
p->key = ts; p->key = ts;
} }
...@@ -211,7 +211,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { ...@@ -211,7 +211,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) {
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
SSubscriptionProgress target = {.uid = pTableMeta->uid, .key = 0}; SSubscriptionProgress target = {.uid = pTableMeta->uid, .key = 0};
SSubscriptionProgress* p = taosArraySearch(pSub->progress, tscCompareSubscriptionProgress, &target); SSubscriptionProgress* p = taosArraySearch(pSub->progress, &target, tscCompareSubscriptionProgress);
if (p == NULL) { if (p == NULL) {
taosArrayClear(pSub->progress); taosArrayClear(pSub->progress);
taosArrayPush(pSub->progress, &target); taosArrayPush(pSub->progress, &target);
......
...@@ -5745,7 +5745,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, ...@@ -5745,7 +5745,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList,
SGroupItem item = { .id = id }; SGroupItem item = { .id = id };
// NOTE: compare STableIdInfo with STableId // NOTE: compare STableIdInfo with STableId
// not a problem at present because we only use their 1st int64_t field // not a problem at present because we only use their 1st int64_t field
STableIdInfo* pTableId = taosArraySearch( pTableIdList, compareTableIdInfo, &id ); STableIdInfo* pTableId = taosArraySearch( pTableIdList, &id, compareTableIdInfo);
if (pTableId != NULL ) { if (pTableId != NULL ) {
window.skey = pTableId->key; window.skey = pTableId->key;
} else { } else {
......
...@@ -773,9 +773,6 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, ...@@ -773,9 +773,6 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo,
// todo refactor: // todo refactor:
tstr *name = ((STableIndexElem *)pData)->pTable->name; tstr *name = ((STableIndexElem *)pData)->pTable->name;
// char* name = NULL;
// tsdbGetTableName(pQueryInfo->, pTable, &name);
// todo speed up by using hash // todo speed up by using hash
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) { if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
if (pQueryInfo->optr == TSDB_RELATION_IN) { if (pQueryInfo->optr == TSDB_RELATION_IN) {
...@@ -1051,7 +1048,7 @@ static void* exception_malloc(size_t size) { ...@@ -1051,7 +1048,7 @@ static void* exception_malloc(size_t size) {
return p; return p;
} }
static char* exception_strdup(const char* str) { static UNUSED_FUNC char* exception_strdup(const char* str) {
char* p = strdup(str); char* p = strdup(str);
if (p == NULL) { if (p == NULL) {
THROW(TSDB_CODE_SERV_OUT_OF_MEMORY); THROW(TSDB_CODE_SERV_OUT_OF_MEMORY);
...@@ -1154,28 +1151,33 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { ...@@ -1154,28 +1151,33 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
tVariant* pVal = exception_calloc(1, sizeof(tVariant)); tVariant* pVal = exception_calloc(1, sizeof(tVariant));
right->pVal = pVal; right->pVal = pVal;
pVal->nType = TSDB_DATA_TYPE_ARRAY; pVal->nType = TSDB_DATA_TYPE_ARRAY;
pVal->arr = taosArrayInit(2, sizeof(char*)); pVal->arr = taosArrayInit(2, POINTER_BYTES);
const char* cond = tbnameCond + QUERY_COND_REL_PREFIX_IN_LEN; const char* cond = tbnameCond + QUERY_COND_REL_PREFIX_IN_LEN;
for (const char *e = cond; *e != 0; e++) { for (const char *e = cond; *e != 0; e++) {
if (*e == TS_PATH_DELIMITER[0]) { if (*e == TS_PATH_DELIMITER[0]) {
cond = e + 1; cond = e + 1;
} else if (*e == ',') { } else if (*e == ',') {
size_t len = e - cond + 1; size_t len = e - cond + VARSTR_HEADER_SIZE;
char* p = exception_malloc( len ); char* p = exception_malloc(len);
memcpy(p, cond, len); varDataSetLen(p, len - VARSTR_HEADER_SIZE);
p[len - 1] = 0; memcpy(varDataVal(p), cond, len);
cond += len; cond += len;
taosArrayPush(pVal->arr, &p); taosArrayPush(pVal->arr, &p);
} }
} }
if (*cond != 0) { if (*cond != 0) {
char* p = exception_strdup( cond ); size_t len = strlen(cond) + VARSTR_HEADER_SIZE;
taosArrayPush(pVal->arr, &p);
char* p = exception_malloc(len);
varDataSetLen(p, len - VARSTR_HEADER_SIZE);
memcpy(varDataVal(p), cond, len);
taosArrayPush(pVal->arr, &p);
} }
taosArraySortString(pVal->arr); taosArraySortString(pVal->arr, taosArrayCompareString);
} }
CLEANUP_EXECUTE_TO(anchor, false); CLEANUP_EXECUTE_TO(anchor, false);
......
...@@ -1678,7 +1678,7 @@ void filterPrepare(void* expr, void* param) { ...@@ -1678,7 +1678,7 @@ void filterPrepare(void* expr, void* param) {
tVariant* pCond = pExpr->_node.pRight->pVal; tVariant* pCond = pExpr->_node.pRight->pVal;
SSchema* pSchema = pExpr->_node.pLeft->pSchema; SSchema* pSchema = pExpr->_node.pLeft->pSchema;
// todo : if current super table does not change schema yet, this function may failed, add test case // todo : if current super table does not change schema yet, this function may fail to get correct schema, test case
int32_t index = getTagColumnIndex(pTSSchema, pSchema); int32_t index = getTagColumnIndex(pTSSchema, pSchema);
assert((index >= 0 && i < TSDB_MAX_TAGS) || (index == TSDB_TBNAME_COLUMN_INDEX)); assert((index >= 0 && i < TSDB_MAX_TAGS) || (index == TSDB_TBNAME_COLUMN_INDEX));
......
...@@ -129,7 +129,7 @@ void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)); ...@@ -129,7 +129,7 @@ void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*));
* sort string array * sort string array
* @param pArray * @param pArray
*/ */
void taosArraySortString(SArray* pArray); void taosArraySortString(SArray* pArray, __compar_fn_t comparFn);
/** /**
* search the array * search the array
...@@ -137,14 +137,14 @@ void taosArraySortString(SArray* pArray); ...@@ -137,14 +137,14 @@ void taosArraySortString(SArray* pArray);
* @param compar * @param compar
* @param key * @param key
*/ */
void* taosArraySearch(const SArray* pArray, int (*compar)(const void*, const void*), const void* key); void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn);
/** /**
* search the array * search the array
* @param pArray * @param pArray
* @param key * @param key
*/ */
char* taosArraySearchString(const SArray* pArray, const char* key); char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -34,16 +34,18 @@ typedef struct SPatternCompareInfo { ...@@ -34,16 +34,18 @@ typedef struct SPatternCompareInfo {
char matchOne; // symbol for match one wildcard, default: '_' char matchOne; // symbol for match one wildcard, default: '_'
} SPatternCompareInfo; } SPatternCompareInfo;
int patternMatch(const char *zPattern, const char *zString, size_t size, const SPatternCompareInfo *pInfo); int patternMatch(const char *pattern, const char *str, size_t size, const SPatternCompareInfo *pInfo);
int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size, const SPatternCompareInfo *pInfo); int WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size, const SPatternCompareInfo *pInfo);
int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size); int32_t doCompare(const char* a, const char* b, int32_t type, size_t size);
__compar_fn_t getKeyComparFunc(int32_t keyType); __compar_fn_t getKeyComparFunc(int32_t keyType);
__compar_fn_t getComparFunc(int32_t type, int32_t optr); __compar_fn_t getComparFunc(int32_t type, int32_t optr);
int32_t taosArrayCompareString(const void* a, const void* b);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -197,30 +197,23 @@ void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)) { ...@@ -197,30 +197,23 @@ void taosArraySort(SArray* pArray, int (*compar)(const void*, const void*)) {
qsort(pArray->pData, pArray->size, pArray->elemSize, compar); qsort(pArray->pData, pArray->size, pArray->elemSize, compar);
} }
void* taosArraySearch(const SArray* pArray, int (*compar)(const void*, const void*), const void* key) { void* taosArraySearch(const SArray* pArray, const void* key, __compar_fn_t comparFn) {
assert(pArray != NULL); assert(pArray != NULL && comparFn != NULL);
assert(compar != NULL);
assert(key != NULL); assert(key != NULL);
return bsearch(key, pArray->pData, pArray->size, pArray->elemSize, compar); return bsearch(key, pArray->pData, pArray->size, pArray->elemSize, comparFn);
}
static int taosArrayCompareString(const void* a, const void* b) {
const char* x = *(const char**)a;
const char* y = *(const char**)b;
return strcmp(x, y);
} }
void taosArraySortString(SArray* pArray) { void taosArraySortString(SArray* pArray, __compar_fn_t comparFn) {
assert(pArray != NULL); assert(pArray != NULL);
qsort(pArray->pData, pArray->size, pArray->elemSize, taosArrayCompareString); qsort(pArray->pData, pArray->size, pArray->elemSize, comparFn);
} }
char* taosArraySearchString(const SArray* pArray, const char* key) { char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t comparFn) {
assert(pArray != NULL); assert(pArray != NULL);
assert(key != NULL); assert(key != NULL);
void* p = bsearch(&key, pArray->pData, pArray->size, pArray->elemSize, taosArrayCompareString); void* p = bsearch(&key, pArray->pData, pArray->size, pArray->elemSize, comparFn);
if (p == NULL) { if (p == NULL) {
return NULL; return NULL;
} }
......
...@@ -227,9 +227,16 @@ static int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { ...@@ -227,9 +227,16 @@ static int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
} }
int32_t taosArrayCompareString(const void* a, const void* b) {
const char* x = *(const char**)a;
const char* y = *(const char**)b;
return compareLenPrefixedStr(x, y);
}
static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) { static int32_t compareFindStrInArray(const void* pLeft, const void* pRight) {
const SArray* arr = (const SArray*) pRight; const SArray* arr = (const SArray*) pRight;
return taosArraySearchString(arr, pLeft) == NULL ? 0 : 1; return taosArraySearchString(arr, pLeft, taosArrayCompareString) == NULL ? 0 : 1;
} }
static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) {
...@@ -248,25 +255,25 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -248,25 +255,25 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_SMALLINT: { case TSDB_DATA_TYPE_SMALLINT: {
comparFn = compareInt16Val; break; comparFn = compareInt16Val; break;
} }
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
comparFn = compareInt32Val; break; comparFn = compareInt32Val; break;
} }
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_TIMESTAMP: { case TSDB_DATA_TYPE_TIMESTAMP: {
comparFn = compareInt64Val; break; comparFn = compareInt64Val; break;
} }
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT:{ case TSDB_DATA_TYPE_TINYINT:{
comparFn = compareInt8Val; break; comparFn = compareInt8Val; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
comparFn = compareFloatVal; break; comparFn = compareFloatVal; break;
} }
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册