[td-2819]

This commit is contained in:
Haojun Liao 2021-03-29 13:23:29 +08:00
parent 0e0e6d5a78
commit f5bfcc0b84
4 changed files with 46 additions and 21 deletions

View File

@ -1285,8 +1285,6 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) {
for(int32_t j = 0; j < pSqlExpr->numOfParams; ++j) { for(int32_t j = 0; j < pSqlExpr->numOfParams; ++j) {
tVariantDestroy(&pSqlExpr->param[j]); tVariantDestroy(&pSqlExpr->param[j]);
} }
tfree(pInfo->pExpr->pExpr);
} }
} }
@ -1486,6 +1484,7 @@ void tscSqlExprAssign(SExprInfo* dst, const SExprInfo* src) {
assert(dst != NULL && src != NULL); assert(dst != NULL && src != NULL);
*dst = *src; *dst = *src;
dst->pExpr = exprdup(src->pExpr);
memset(dst->base.param, 0, sizeof(tVariant) * tListLen(dst->base.param)); memset(dst->base.param, 0, sizeof(tVariant) * tListLen(dst->base.param));
for (int32_t j = 0; j < src->base.numOfParams; ++j) { for (int32_t j = 0; j < src->base.numOfParams; ++j) {

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_TAST_H #ifndef TDENGINE_TEXPR_H
#define TDENGINE_TAST_H #define TDENGINE_TEXPR_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -62,32 +62,32 @@ typedef struct tExprNode {
uint8_t nodeType; uint8_t nodeType;
union { union {
struct { struct {
uint8_t optr; // filter operator uint8_t optr; // filter operator
uint8_t hasPK; // 0: do not contain primary filter, 1: contain uint8_t hasPK; // 0: do not contain primary filter, 1: contain
void * info; // support filter operation on this expression only available for leaf node void *info; // support filter operation on this expression only available for leaf node
struct tExprNode *pLeft; // left child pointer struct tExprNode *pLeft; // left child pointer
struct tExprNode *pRight; // right child pointer struct tExprNode *pRight; // right child pointer
} _node; } _node;
struct SSchema *pSchema;
tVariant * pVal; struct SSchema *pSchema;
tVariant *pVal;
}; };
} tExprNode; } tExprNode;
typedef struct SExprTraverseSupp { typedef struct SExprTraverseSupp {
__result_filter_fn_t nodeFilterFn; __result_filter_fn_t nodeFilterFn;
__do_filter_suppl_fn_t setupInfoFn; __do_filter_suppl_fn_t setupInfoFn;
void * pExtInfo; void *pExtInfo;
} SExprTraverseSupp; } SExprTraverseSupp;
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)); void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
tExprNode* exprTreeFromBinary(const void* data, size_t size); tExprNode* exprTreeFromBinary(const void* data, size_t size);
tExprNode* exprTreeFromTableName(const char* tbnameCond); tExprNode* exprTreeFromTableName(const char* tbnameCond);
tExprNode* exprdup(tExprNode* pTree);
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree); bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param);
bool exprTreeApplayFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param);
typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight, typedef void (*_arithmetic_operator_fn_t)(void *left, int32_t numLeft, int32_t leftType, void *right, int32_t numRight,
int32_t rightType, void *output, int32_t order); int32_t rightType, void *output, int32_t order);
@ -99,4 +99,4 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
} }
#endif #endif
#endif // TDENGINE_TAST_H #endif // TDENGINE_TEXPR_H

View File

@ -15,6 +15,7 @@
#include "os.h" #include "os.h"
#include "texpr.h"
#include "exception.h" #include "exception.h"
#include "taosdef.h" #include "taosdef.h"
#include "taosmsg.h" #include "taosmsg.h"
@ -145,25 +146,25 @@ static void doExprTreeDestroy(tExprNode **pExpr, void (*fp)(void *)) {
*pExpr = NULL; *pExpr = NULL;
} }
bool exprTreeApplayFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param) { bool exprTreeApplyFilter(tExprNode *pExpr, const void *pItem, SExprTraverseSupp *param) {
tExprNode *pLeft = pExpr->_node.pLeft; tExprNode *pLeft = pExpr->_node.pLeft;
tExprNode *pRight = pExpr->_node.pRight; tExprNode *pRight = pExpr->_node.pRight;
//non-leaf nodes, recursively traverse the expression tree in the post-root order //non-leaf nodes, recursively traverse the expression tree in the post-root order
if (pLeft->nodeType == TSQL_NODE_EXPR && pRight->nodeType == TSQL_NODE_EXPR) { if (pLeft->nodeType == TSQL_NODE_EXPR && pRight->nodeType == TSQL_NODE_EXPR) {
if (pExpr->_node.optr == TSDB_RELATION_OR) { // or if (pExpr->_node.optr == TSDB_RELATION_OR) { // or
if (exprTreeApplayFilter(pLeft, pItem, param)) { if (exprTreeApplyFilter(pLeft, pItem, param)) {
return true; return true;
} }
// left child does not satisfy the query condition, try right child // left child does not satisfy the query condition, try right child
return exprTreeApplayFilter(pRight, pItem, param); return exprTreeApplyFilter(pRight, pItem, param);
} else { // and } else { // and
if (!exprTreeApplayFilter(pLeft, pItem, param)) { if (!exprTreeApplyFilter(pLeft, pItem, param)) {
return false; return false;
} }
return exprTreeApplayFilter(pRight, pItem, param); return exprTreeApplyFilter(pRight, pItem, param);
} }
} }
@ -463,3 +464,28 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
CLEANUP_EXECUTE_TO(anchor, false); CLEANUP_EXECUTE_TO(anchor, false);
return expr; return expr;
} }
tExprNode* exprdup(tExprNode* pTree) {
if (pTree == NULL) {
return NULL;
}
tExprNode* pNode = calloc(1, sizeof(tExprNode));
if (pTree->nodeType == TSQL_NODE_EXPR) {
tExprNode* pLeft = exprdup(pTree->_node.pLeft);
tExprNode* pRight = exprdup(pTree->_node.pRight);
pNode->nodeType = TSQL_NODE_EXPR;
pNode->_node.pLeft = pLeft;
pNode->_node.pRight = pRight;
} else if (pTree->nodeType == TSQL_NODE_VALUE) {
pNode->pVal = calloc(1, sizeof(tVariant));
tVariantAssign(pNode->pVal, pTree->pVal);
} else if (pTree->nodeType == TSQL_NODE_COL) {
pNode->pSchema = calloc(1, sizeof(SSchema));
*pNode->pSchema = *pTree->pSchema;
}
return pNode;
}

View File

@ -3428,7 +3428,7 @@ static void applyFilterToSkipListNode(SSkipList *pSkipList, tExprNode *pExpr, SA
// Scan each node in the skiplist by using iterator // Scan each node in the skiplist by using iterator
while (tSkipListIterNext(iter)) { while (tSkipListIterNext(iter)) {
SSkipListNode *pNode = tSkipListIterGet(iter); SSkipListNode *pNode = tSkipListIterGet(iter);
if (exprTreeApplayFilter(pExpr, pNode, param)) { if (exprTreeApplyFilter(pExpr, pNode, param)) {
taosArrayPush(pResult, &(SL_GET_NODE_DATA(pNode))); taosArrayPush(pResult, &(SL_GET_NODE_DATA(pNode)));
} }
} }