提交 84f60fcc 编写于 作者: X Xiaoyu Wang

TD-13747 deal memory leaks

上级 8ee10d50
...@@ -111,6 +111,8 @@ typedef struct SScalarFuncExecFuncs { ...@@ -111,6 +111,8 @@ typedef struct SScalarFuncExecFuncs {
int32_t fmFuncMgtInit(); int32_t fmFuncMgtInit();
void fmFuncMgtDestroy();
int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType); int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType);
int32_t fmGetFuncResultType(SFunctionNode* pFunc); int32_t fmGetFuncResultType(SFunctionNode* pFunc);
......
...@@ -152,6 +152,8 @@ int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc); ...@@ -152,6 +152,8 @@ int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc);
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell); SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
SNodeptr nodesListGetNode(SNodeList* pList, int32_t index); SNodeptr nodesListGetNode(SNodeList* pList, int32_t index);
void nodesDestroyList(SNodeList* pList); void nodesDestroyList(SNodeList* pList);
// Only clear the linked list structure, without releasing the elements inside
void nodesClearList(SNodeList* pList);
typedef enum EDealRes { typedef enum EDealRes {
DEAL_RES_CONTINUE = 1, DEAL_RES_CONTINUE = 1,
......
...@@ -48,6 +48,7 @@ typedef struct SScanLogicNode { ...@@ -48,6 +48,7 @@ typedef struct SScanLogicNode {
EScanType scanType; EScanType scanType;
uint8_t scanFlag; // denotes reversed scan of data or not uint8_t scanFlag; // denotes reversed scan of data or not
STimeWindow scanRange; STimeWindow scanRange;
SName tableName;
} SScanLogicNode; } SScanLogicNode;
typedef struct SJoinLogicNode { typedef struct SJoinLogicNode {
......
...@@ -24,6 +24,7 @@ extern "C" { ...@@ -24,6 +24,7 @@ extern "C" {
typedef struct SPlanContext { typedef struct SPlanContext {
uint64_t queryId; uint64_t queryId;
int32_t acctId;
SNode* pAstRoot; SNode* pAstRoot;
} SPlanContext; } SPlanContext;
......
...@@ -194,7 +194,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { ...@@ -194,7 +194,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) { int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
pRequest->type = pQuery->msgType; pRequest->type = pQuery->msgType;
SPlanContext cxt = { .queryId = pRequest->requestId, .pAstRoot = pQuery->pRoot }; SPlanContext cxt = { .queryId = pRequest->requestId, .pAstRoot = pQuery->pRoot, .acctId = pRequest->pTscObj->acctId };
int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList); int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
if (code != 0) { if (code != 0) {
return code; return code;
......
...@@ -94,3 +94,10 @@ bool fmIsAggFunc(int32_t funcId) { ...@@ -94,3 +94,10 @@ bool fmIsAggFunc(int32_t funcId) {
} }
return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, FUNC_MGT_AGG_FUNC); return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, FUNC_MGT_AGG_FUNC);
} }
void fmFuncMgtDestroy() {
void* m = gFunMgtService.pFuncNameHashTable;
if (m != NULL && atomic_val_compare_exchange_ptr(&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
taosHashCleanup(m);
}
}
...@@ -220,6 +220,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { ...@@ -220,6 +220,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
COPY_SCALAR_FIELD(scanType); COPY_SCALAR_FIELD(scanType);
COPY_SCALAR_FIELD(scanFlag); COPY_SCALAR_FIELD(scanFlag);
COPY_SCALAR_FIELD(scanRange); COPY_SCALAR_FIELD(scanRange);
COPY_SCALAR_FIELD(tableName);
return (SNode*)pDst; return (SNode*)pDst;
} }
......
...@@ -289,12 +289,52 @@ static int32_t jsonToPhysicPlanNode(const SJson* pJson, void* pObj) { ...@@ -289,12 +289,52 @@ static int32_t jsonToPhysicPlanNode(const SJson* pJson, void* pObj) {
return code; return code;
} }
static const char* jkNameType = "NameType";
static const char* jkNameAcctId = "AcctId";
static const char* jkNameDbName = "DbName";
static const char* jkNameTableName = "TableName";
static int32_t nameToJson(const void* pObj, SJson* pJson) {
const SName* pNode = (const SName*)pObj;
int32_t code = tjsonAddIntegerToObject(pJson, jkNameType, pNode->type);
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkNameAcctId, pNode->acctId);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddStringToObject(pJson, jkNameDbName, pNode->dbname);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddStringToObject(pJson, jkNameTableName, pNode->tname);
}
return code;
}
static int32_t jsonToName(const SJson* pJson, void* pObj) {
SName* pNode = (SName*)pObj;
int32_t code = tjsonGetUTinyIntValue(pJson, jkNameType, &pNode->type);
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetIntValue(pJson, jkNameAcctId, &pNode->acctId);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetStringValue(pJson, jkNameDbName, pNode->dbname);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetStringValue(pJson, jkNameTableName, pNode->tname);
}
return code;
}
static const char* jkScanPhysiPlanScanCols = "ScanCols"; static const char* jkScanPhysiPlanScanCols = "ScanCols";
static const char* jkScanPhysiPlanTableId = "TableId"; static const char* jkScanPhysiPlanTableId = "TableId";
static const char* jkScanPhysiPlanTableType = "TableType"; static const char* jkScanPhysiPlanTableType = "TableType";
static const char* jkScanPhysiPlanScanOrder = "ScanOrder"; static const char* jkScanPhysiPlanScanOrder = "ScanOrder";
static const char* jkScanPhysiPlanScanCount = "ScanCount"; static const char* jkScanPhysiPlanScanCount = "ScanCount";
static const char* jkScanPhysiPlanReverseScanCount = "ReverseScanCount"; static const char* jkScanPhysiPlanReverseScanCount = "ReverseScanCount";
static const char* jkScanPhysiPlanTableName = "TableName";
static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) { static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) {
const STagScanPhysiNode* pNode = (const STagScanPhysiNode*)pObj; const STagScanPhysiNode* pNode = (const STagScanPhysiNode*)pObj;
...@@ -318,6 +358,9 @@ static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) { ...@@ -318,6 +358,9 @@ static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) {
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanReverseScanCount, pNode->reverse); code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanReverseScanCount, pNode->reverse);
} }
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddObject(pJson, jkScanPhysiPlanTableName, nameToJson, &pNode->tableName);
}
return code; return code;
} }
...@@ -344,6 +387,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) { ...@@ -344,6 +387,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetIntValue(pJson, jkScanPhysiPlanReverseScanCount, &pNode->reverse); code = tjsonGetIntValue(pJson, jkScanPhysiPlanReverseScanCount, &pNode->reverse);
} }
if (TSDB_CODE_SUCCESS == code) {
code = tjsonToObject(pJson, jkScanPhysiPlanTableName, jsonToName, &pNode->tableName);
}
return code; return code;
} }
......
...@@ -183,16 +183,54 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) { ...@@ -183,16 +183,54 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
break; break;
} }
case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_LOGIC_CONDITION:
nodesDestroyList(((SLogicConditionNode*)(*pNode))->pParameterList); nodesClearList(((SLogicConditionNode*)(*pNode))->pParameterList);
break; break;
case QUERY_NODE_FUNCTION: case QUERY_NODE_FUNCTION:
nodesDestroyList(((SFunctionNode*)(*pNode))->pParameterList); nodesClearList(((SFunctionNode*)(*pNode))->pParameterList);
break;
case QUERY_NODE_REAL_TABLE: {
SRealTableNode* pReal = (SRealTableNode*)*pNode;
tfree(pReal->pMeta);
tfree(pReal->pVgroupList);
break;
}
case QUERY_NODE_TEMP_TABLE:
nodesDestroyNode(((STempTableNode*)(*pNode))->pSubquery);
break; break;
case QUERY_NODE_GROUPING_SET: case QUERY_NODE_GROUPING_SET:
nodesDestroyList(((SGroupingSetNode*)(*pNode))->pParameterList); nodesClearList(((SGroupingSetNode*)(*pNode))->pParameterList);
break; break;
case QUERY_NODE_NODE_LIST: case QUERY_NODE_NODE_LIST:
nodesDestroyList(((SNodeListNode*)(*pNode))->pNodeList); nodesClearList(((SNodeListNode*)(*pNode))->pNodeList);
break;
case QUERY_NODE_SELECT_STMT: {
SSelectStmt* pStmt = (SSelectStmt*)*pNode;
nodesDestroyList(pStmt->pProjectionList);
nodesDestroyNode(pStmt->pFromTable);
nodesDestroyNode(pStmt->pWhere);
nodesDestroyList(pStmt->pPartitionByList);
nodesDestroyNode(pStmt->pWindow);
nodesDestroyList(pStmt->pGroupByList);
nodesDestroyNode(pStmt->pHaving);
nodesDestroyList(pStmt->pOrderByList);
nodesDestroyNode(pStmt->pLimit);
nodesDestroyNode(pStmt->pSlimit);
break;
}
case QUERY_NODE_CREATE_TABLE_STMT: {
SCreateTableStmt* pStmt = (SCreateTableStmt*)*pNode;
nodesDestroyList(pStmt->pCols);
nodesDestroyList(pStmt->pTags);
break;
}
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: {
SCreateSubTableClause* pStmt = (SCreateSubTableClause*)*pNode;
nodesDestroyList(pStmt->pSpecificTags);
nodesDestroyList(pStmt->pValsOfTags);
break;
}
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables);
break; break;
default: default:
break; break;
...@@ -304,6 +342,20 @@ void nodesDestroyList(SNodeList* pList) { ...@@ -304,6 +342,20 @@ void nodesDestroyList(SNodeList* pList) {
tfree(pList); tfree(pList);
} }
void nodesClearList(SNodeList* pList) {
if (NULL == pList) {
return;
}
SListCell* pNext = pList->pHead;
while (NULL != pNext) {
SListCell* tmp = pNext;
pNext = pNext->pNext;
tfree(tmp);
}
tfree(pList);
}
void* nodesGetValueFromNode(SValueNode *pNode) { void* nodesGetValueFromNode(SValueNode *pNode) {
switch (pNode->node.resType.type) { switch (pNode->node.resType.type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
......
...@@ -533,12 +533,12 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL ...@@ -533,12 +533,12 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) { SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND,
createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, pExpr, pRight)); createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight));
} }
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) { SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR,
createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, pExpr, pRight)); createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight));
} }
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) { SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
...@@ -777,6 +777,7 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, cons ...@@ -777,6 +777,7 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, cons
strncpy(pStmt->dbName, pDbName->z, pDbName->n); strncpy(pStmt->dbName, pDbName->z, pDbName->n);
pStmt->ignoreExists = ignoreExists; pStmt->ignoreExists = ignoreExists;
pStmt->options = *pOptions; pStmt->options = *pOptions;
tfree(pOptions);
return (SNode*)pStmt; return (SNode*)pStmt;
} }
...@@ -839,6 +840,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, ...@@ -839,6 +840,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
pStmt->pCols = pCols; pStmt->pCols = pCols;
pStmt->pTags = pTags; pStmt->pTags = pTags;
pStmt->options = *pOptions; pStmt->options = *pOptions;
nodesDestroyList(pOptions->pSma);
tfree(pOptions);
nodesDestroyNode(pRealTable); nodesDestroyNode(pRealTable);
return (SNode*)pStmt; return (SNode*)pStmt;
} }
......
...@@ -508,7 +508,10 @@ static int32_t setTableVgroupList(STranslateContext *pCxt, SName* name, SVgroups ...@@ -508,7 +508,10 @@ static int32_t setTableVgroupList(STranslateContext *pCxt, SName* name, SVgroups
size_t vgroupNum = taosArrayGetSize(vgroupList); size_t vgroupNum = taosArrayGetSize(vgroupList);
SVgroupsInfo *vgList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum); SVgroupsInfo* vgList = calloc(1, sizeof(SVgroupsInfo) + sizeof(SVgroupInfo) * vgroupNum);
if (NULL == vgList) {
return TSDB_CODE_OUT_OF_MEMORY;
}
vgList->numOfVgroups = vgroupNum; vgList->numOfVgroups = vgroupNum;
for (int32_t i = 0; i < vgroupNum; ++i) { for (int32_t i = 0; i < vgroupNum; ++i) {
...@@ -582,7 +585,7 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect, bool ...@@ -582,7 +585,7 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect, bool
} }
*pIsSelectStar = true; *pIsSelectStar = true;
} else { } else {
// todo : t.*
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -1206,7 +1209,13 @@ static void destroyTranslateContext(STranslateContext* pCxt) { ...@@ -1206,7 +1209,13 @@ static void destroyTranslateContext(STranslateContext* pCxt) {
if (NULL != pCxt->pNsLevel) { if (NULL != pCxt->pNsLevel) {
} }
size_t size = taosArrayGetSize(pCxt->pNsLevel);
for (size_t i = 0; i < size; ++i) {
taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i));
}
taosArrayDestroy(pCxt->pNsLevel); taosArrayDestroy(pCxt->pNsLevel);
if (NULL != pCxt->pCmdMsg) { if (NULL != pCxt->pCmdMsg) {
tfree(pCxt->pCmdMsg->pMsg); tfree(pCxt->pCmdMsg->pMsg);
tfree(pCxt->pCmdMsg); tfree(pCxt->pCmdMsg);
......
...@@ -74,46 +74,46 @@ void initMetaDataEnv() { ...@@ -74,46 +74,46 @@ void initMetaDataEnv() {
stub.set(catalogGetTableMeta, __catalogGetTableMeta); stub.set(catalogGetTableMeta, __catalogGetTableMeta);
stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup); stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup);
stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo); stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo);
{ // {
AddrAny any("libcatalog.so"); // AddrAny any("libcatalog.so");
std::map<std::string,void*> result; // std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^catalogGetHandle$", result); // any.get_global_func_addr_dynsym("^catalogGetHandle$", result);
for (const auto& f : result) { // for (const auto& f : result) {
stub.set(f.second, __catalogGetHandle); // stub.set(f.second, __catalogGetHandle);
} // }
} // }
{ // {
AddrAny any("libcatalog.so"); // AddrAny any("libcatalog.so");
std::map<std::string,void*> result; // std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^catalogGetTableMeta$", result); // any.get_global_func_addr_dynsym("^catalogGetTableMeta$", result);
for (const auto& f : result) { // for (const auto& f : result) {
stub.set(f.second, __catalogGetTableMeta); // stub.set(f.second, __catalogGetTableMeta);
} // }
} // }
{ // {
AddrAny any("libcatalog.so"); // AddrAny any("libcatalog.so");
std::map<std::string,void*> result; // std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^catalogGetTableHashVgroup$", result); // any.get_global_func_addr_dynsym("^catalogGetTableHashVgroup$", result);
for (const auto& f : result) { // for (const auto& f : result) {
stub.set(f.second, __catalogGetTableHashVgroup); // stub.set(f.second, __catalogGetTableHashVgroup);
} // }
} // }
{ // {
AddrAny any("libcatalog.so"); // AddrAny any("libcatalog.so");
std::map<std::string,void*> result; // std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^catalogGetTableDistVgInfo$", result); // any.get_global_func_addr_dynsym("^catalogGetTableDistVgInfo$", result);
for (const auto& f : result) { // for (const auto& f : result) {
stub.set(f.second, __catalogGetTableDistVgInfo); // stub.set(f.second, __catalogGetTableDistVgInfo);
} // }
} // }
{ // {
AddrAny any("libcatalog.so"); // AddrAny any("libcatalog.so");
std::map<std::string,void*> result; // std::map<std::string,void*> result;
any.get_global_func_addr_dynsym("^catalogGetDBVgVersion$", result); // any.get_global_func_addr_dynsym("^catalogGetDBVgVersion$", result);
for (const auto& f : result) { // for (const auto& f : result) {
stub.set(f.second, __catalogGetDBVgVersion); // stub.set(f.second, __catalogGetDBVgVersion);
} // }
} // }
} }
void generateMetaData() { void generateMetaData() {
......
...@@ -77,10 +77,10 @@ private: ...@@ -77,10 +77,10 @@ private:
} }
TableBuilder(STableMeta* schemaMeta) : colId_(1), rowsize_(0), meta_(new MockTableMeta()) { TableBuilder(STableMeta* schemaMeta) : colId_(1), rowsize_(0), meta_(new MockTableMeta()) {
meta_->schema.reset(schemaMeta); meta_->schema = schemaMeta;
} }
std::shared_ptr<STableMeta> schema() { STableMeta* schema() {
return meta_->schema; return meta_->schema;
} }
...@@ -153,7 +153,7 @@ public: ...@@ -153,7 +153,7 @@ public:
throw std::runtime_error("copyTableSchemaMeta failed"); throw std::runtime_error("copyTableSchemaMeta failed");
} }
meta_[db][tbname].reset(new MockTableMeta()); meta_[db][tbname].reset(new MockTableMeta());
meta_[db][tbname]->schema.reset(table.release()); meta_[db][tbname]->schema = table.release();
meta_[db][tbname]->schema->uid = id_++; meta_[db][tbname]->schema->uid = id_++;
SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0,}; SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0,};
...@@ -275,14 +275,14 @@ private: ...@@ -275,14 +275,14 @@ private:
return (0 == colid ? "column" : (colid <= numOfTags ? "tag" : "column")); return (0 == colid ? "column" : (colid <= numOfTags ? "tag" : "column"));
} }
std::shared_ptr<STableMeta> getTableSchemaMeta(const std::string& db, const std::string& tbname) const { STableMeta* getTableSchemaMeta(const std::string& db, const std::string& tbname) const {
std::shared_ptr<MockTableMeta> table = getTableMeta(db, tbname); std::shared_ptr<MockTableMeta> table = getTableMeta(db, tbname);
return table ? table->schema : std::shared_ptr<STableMeta>(); return table ? table->schema : nullptr;
} }
int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, std::unique_ptr<STableMeta>* dst) const { int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, std::unique_ptr<STableMeta>* dst) const {
std::shared_ptr<STableMeta> src = getTableSchemaMeta(db, tbname); STableMeta* src = getTableSchemaMeta(db, tbname);
if (!src) { if (nullptr == src) {
return TSDB_CODE_TSC_INVALID_TABLE_NAME; return TSDB_CODE_TSC_INVALID_TABLE_NAME;
} }
int32_t len = sizeof(STableMeta) + sizeof(SSchema) * (src->tableInfo.numOfTags + src->tableInfo.numOfColumns); int32_t len = sizeof(STableMeta) + sizeof(SSchema) * (src->tableInfo.numOfTags + src->tableInfo.numOfColumns);
...@@ -290,7 +290,7 @@ private: ...@@ -290,7 +290,7 @@ private:
if (!dst) { if (!dst) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
memcpy(dst->get(), src.get(), len); memcpy(dst->get(), src, len);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -43,7 +43,11 @@ public: ...@@ -43,7 +43,11 @@ public:
}; };
struct MockTableMeta { struct MockTableMeta {
std::shared_ptr<STableMeta> schema; ~MockTableMeta() {
free(schema);
}
STableMeta* schema;
std::vector<SVgroupInfo> vgs; std::vector<SVgroupInfo> vgs;
}; };
......
...@@ -41,6 +41,16 @@ protected: ...@@ -41,6 +41,16 @@ protected:
} }
bool run(int32_t parseCode = TSDB_CODE_SUCCESS, int32_t translateCode = TSDB_CODE_SUCCESS) { bool run(int32_t parseCode = TSDB_CODE_SUCCESS, int32_t translateCode = TSDB_CODE_SUCCESS) {
query_ = nullptr;
bool res = runImpl(parseCode, translateCode);
qDestroyQuery(query_);
return res;
}
private:
static const int max_err_len = 1024;
bool runImpl(int32_t parseCode, int32_t translateCode) {
int32_t code = doParse(&cxt_, &query_); int32_t code = doParse(&cxt_, &query_);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
cout << "sql:[" << cxt_.pSql << "] parser code:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl; cout << "sql:[" << cxt_.pSql << "] parser code:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
...@@ -63,9 +73,6 @@ protected: ...@@ -63,9 +73,6 @@ protected:
return (TSDB_CODE_SUCCESS == translateCode); return (TSDB_CODE_SUCCESS == translateCode);
} }
private:
static const int max_err_len = 1024;
string toString(const SNode* pRoot, bool format = false) { string toString(const SNode* pRoot, bool format = false) {
char* pStr = NULL; char* pStr = NULL;
int32_t len = 0; int32_t len = 0;
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "mockCatalog.h" #include "mockCatalog.h"
#include "parToken.h"
#include "functionMgt.h"
class ParserEnv : public testing::Environment { class ParserEnv : public testing::Environment {
public: public:
...@@ -28,6 +30,8 @@ public: ...@@ -28,6 +30,8 @@ public:
virtual void TearDown() { virtual void TearDown() {
destroyMetaDataEnv(); destroyMetaDataEnv();
taosCleanupKeywordsTable();
fmFuncMgtDestroy();
} }
ParserEnv() {} ParserEnv() {}
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
typedef struct SLogicPlanContext { typedef struct SLogicPlanContext {
int32_t errCode; int32_t errCode;
int32_t planNodeId; int32_t planNodeId;
int32_t acctId;
} SLogicPlanContext; } SLogicPlanContext;
static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt); static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt);
...@@ -127,8 +128,8 @@ static SLogicNode* createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe ...@@ -127,8 +128,8 @@ static SLogicNode* createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe
CHECK_ALLOC(pScan, NULL); CHECK_ALLOC(pScan, NULL);
pScan->node.id = pCxt->planNodeId++; pScan->node.id = pCxt->planNodeId++;
pScan->pMeta = pRealTable->pMeta; TSWAP(pScan->pMeta, pRealTable->pMeta, STableMeta*);
pScan->pVgroupList = pRealTable->pVgroupList; TSWAP(pScan->pVgroupList, pRealTable->pVgroupList, SVgroupsInfo*);
// set columns to scan // set columns to scan
SNodeList* pCols = NULL; SNodeList* pCols = NULL;
...@@ -146,7 +147,11 @@ static SLogicNode* createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe ...@@ -146,7 +147,11 @@ static SLogicNode* createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe
pScan->scanType = SCAN_TYPE_TABLE; pScan->scanType = SCAN_TYPE_TABLE;
pScan->scanFlag = MAIN_SCAN; pScan->scanFlag = MAIN_SCAN;
pScan->scanRange = TSWINDOW_INITIALIZER; pScan->scanRange = TSWINDOW_INITIALIZER;
pScan->tableName.type = TSDB_TABLE_NAME_T;
pScan->tableName.acctId = pCxt->acctId;
strcpy(pScan->tableName.dbname, pRealTable->table.dbName);
strcpy(pScan->tableName.tname, pRealTable->table.tableName);
return (SLogicNode*)pScan; return (SLogicNode*)pScan;
} }
...@@ -373,7 +378,7 @@ static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt) { ...@@ -373,7 +378,7 @@ static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt) {
} }
int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) { int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) {
SLogicPlanContext cxt = { .errCode = TSDB_CODE_SUCCESS, .planNodeId = 1 }; SLogicPlanContext cxt = { .errCode = TSDB_CODE_SUCCESS, .planNodeId = 1, .acctId = pCxt->acctId };
SLogicNode* pRoot = createQueryLogicNode(&cxt, pCxt->pAstRoot); SLogicNode* pRoot = createQueryLogicNode(&cxt, pCxt->pAstRoot);
if (TSDB_CODE_SUCCESS != cxt.errCode) { if (TSDB_CODE_SUCCESS != cxt.errCode) {
nodesDestroyNode((SNode*)pRoot); nodesDestroyNode((SNode*)pRoot);
......
...@@ -231,6 +231,7 @@ static int32_t initScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanL ...@@ -231,6 +231,7 @@ static int32_t initScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanL
pScanPhysiNode->order = TSDB_ORDER_ASC; pScanPhysiNode->order = TSDB_ORDER_ASC;
pScanPhysiNode->count = 1; pScanPhysiNode->count = 1;
pScanPhysiNode->reverse = 0; pScanPhysiNode->reverse = 0;
memcpy(&pScanPhysiNode->tableName, &pScanLogicNode->tableName, sizeof(SName));
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -583,7 +584,7 @@ static int32_t splitLogicPlan(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, S ...@@ -583,7 +584,7 @@ static int32_t splitLogicPlan(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, S
(*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_MODIFY; (*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_MODIFY;
TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)(*pSubLogicPlan)->pNode)->pDataBlocks, SArray*); TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)(*pSubLogicPlan)->pNode)->pDataBlocks, SArray*);
} else { } else {
(*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_MERGE; (*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_SCAN;
} }
(*pSubLogicPlan)->id.queryId = pCxt->pPlanCxt->queryId; (*pSubLogicPlan)->id.queryId = pCxt->pPlanCxt->queryId;
setLogicNodeParent((*pSubLogicPlan)->pNode); setLogicNodeParent((*pSubLogicPlan)->pNode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册