fix: memory issues

This commit is contained in:
dapan1121 2023-10-27 11:36:17 +08:00
parent 6dcc555bbc
commit 099f72e84a
21 changed files with 391 additions and 117 deletions

View File

@ -30,6 +30,11 @@ extern "C" {
#define VGROUPS_INFO_SIZE(pInfo) \
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
typedef struct SAssociationNode {
SNode** pPlace;
SNode* pAssociationNode;
} SAssociationNode;
typedef struct SRawExprNode {
ENodeType nodeType;
char* p;

View File

@ -94,6 +94,7 @@ typedef struct SParseContext {
parseSqlFn parseSqlFp;
void* parseSqlParam;
int8_t biMode;
SArray* pSubMetaList;
} SParseContext;
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery);
@ -154,6 +155,8 @@ int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCr
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap);
void destoryCatalogReq(SCatalogReq *pCatalogReq);
#ifdef __cplusplus
}
#endif

View File

@ -447,6 +447,7 @@ void doDestroyRequest(void *p) {
qDestroyQuery(pRequest->pQuery);
nodesDestroyAllocator(pRequest->allocatorRefId);
taosMemoryFreeClear(pRequest->effectiveUser);
taosMemoryFreeClear(pRequest->sqlstr);
taosMemoryFree(pRequest);
tscTrace("end to destroy request %" PRIx64 " p:%p", reqId, pRequest);

View File

@ -311,7 +311,7 @@ static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatal
}
}
//tFreeSViewHbRsp(&hbRsp);
taosArrayDestroy(hbRsp.pViewRsp);
return TSDB_CODE_SUCCESS;
}

View File

@ -1176,6 +1176,7 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
code = schedulerExecJob(&req, &pRequest->body.queryJob);
taosArrayDestroy(pNodeList);
} else {
qDestroyQueryPlan(pDag);
tscDebug("0x%" PRIx64 " plan not executed, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
pRequest->requestId);
destorySqlCallbackWrapper(pWrapper);

View File

@ -879,39 +879,12 @@ int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
return code;
}
static void destoryTablesReq(void *p) {
STablesReq *pRes = (STablesReq *)p;
taosArrayDestroy(pRes->pTables);
}
static void destoryCatalogReq(SCatalogReq *pCatalogReq) {
if (NULL == pCatalogReq) {
return;
}
taosArrayDestroy(pCatalogReq->pDbVgroup);
taosArrayDestroy(pCatalogReq->pDbCfg);
taosArrayDestroy(pCatalogReq->pDbInfo);
if (pCatalogReq->cloned) {
taosArrayDestroy(pCatalogReq->pTableMeta);
taosArrayDestroy(pCatalogReq->pTableHash);
} else {
taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
}
taosArrayDestroy(pCatalogReq->pUdf);
taosArrayDestroy(pCatalogReq->pIndex);
taosArrayDestroy(pCatalogReq->pUser);
taosArrayDestroy(pCatalogReq->pTableIndex);
taosArrayDestroy(pCatalogReq->pTableCfg);
taosArrayDestroy(pCatalogReq->pTableTag);
taosMemoryFree(pCatalogReq);
}
void destorySqlCallbackWrapper(SSqlCallbackWrapper *pWrapper) {
if (NULL == pWrapper) {
return;
}
destoryCatalogReq(pWrapper->pCatalogReq);
taosMemoryFree(pWrapper->pCatalogReq);
qDestroyParseContext(pWrapper->pParseCtx);
taosMemoryFree(pWrapper);
}
@ -966,6 +939,7 @@ int32_t cloneCatalogReq(SCatalogReq **ppTarget, SCatalogReq *pSrc) {
pTarget->pTableIndex = taosArrayDup(pSrc->pTableIndex, NULL);
pTarget->pTableCfg = taosArrayDup(pSrc->pTableCfg, NULL);
pTarget->pTableTag = taosArrayDup(pSrc->pTableTag, NULL);
pTarget->pView = taosArrayDup(pSrc->pView, NULL);
pTarget->qNodeRequired = pSrc->qNodeRequired;
pTarget->dNodeRequired = pSrc->dNodeRequired;
pTarget->svrVerRequired = pSrc->svrVerRequired;
@ -1579,7 +1553,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
tsem_wait(&pParam->sem);
_return:
taosArrayDestroyEx(catalogReq.pTableMeta, destoryTablesReq);
destoryCatalogReq(&catalogReq);
destroyRequest(pRequest);
return code;
}

View File

@ -1055,6 +1055,7 @@ void ctgGetGlobalCacheStat(SCtgCacheStat* pStat);
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res);
int32_t ctgBuildViewNullRes(SCtgTask* pTask, SCtgViewsCtx* pCtx);
int32_t dupViewMetaFromRsp(SViewMetaRsp* pRsp, SViewMeta* pViewMeta);
void ctgDestroySMetaData(SMetaData* pData);
void ctgGetGlobalCacheSize(uint64_t *pSize);
uint64_t ctgGetTbIndexCacheSize(STableIndex *pIndex);
uint64_t ctgGetViewMetaCacheSize(SViewMeta *pMeta);

View File

@ -1705,7 +1705,7 @@ int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth) {
}
void catalogFreeMetaData(SMetaData * pData) {
ctgDestroySMetaData(pData);
}
int32_t catalogRemoveViewMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* viewName, uint64_t viewId) {

View File

@ -463,6 +463,19 @@ int32_t ctgInitGetViewsTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
return TSDB_CODE_SUCCESS;
}
int32_t ctgHandleForceUpdateView(SCatalog* pCtg, const SCatalogReq* pReq) {
int32_t viewNum = taosArrayGetSize(pReq->pView);
for (int32_t i = 0; i < viewNum; ++i) {
STablesReq* p = taosArrayGet(pReq->pView, i);
int32_t viewNum = taosArrayGetSize(p->pTables);
for (int32_t m = 0; m < viewNum; ++m) {
SName* name = taosArrayGet(p->pTables, m);
ctgDropViewMetaEnqueue(pCtg, p->dbFName, 0, name->tname, 0, true);
}
}
return TSDB_CODE_SUCCESS;
}
int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, const SCatalogReq* pReq) {
SHashObj* pDb = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
@ -510,6 +523,12 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, con
}
}
dbNum = taosArrayGetSize(pReq->pView);
for (int32_t i = 0; i < dbNum; ++i) {
STablesReq* p = taosArrayGet(pReq->pView, i);
taosHashPut(pDb, p->dbFName, strlen(p->dbFName), p->dbFName, TSDB_DB_FNAME_LEN);
}
for (int32_t i = 0; i < pJob->tbCfgNum; ++i) {
SName* name = taosArrayGet(pReq->pTableCfg, i);
char dbFName[TSDB_DB_FNAME_LEN];
@ -554,7 +573,8 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, con
ctgDropTbIndexEnqueue(pCtg, name, true);
}
return TSDB_CODE_SUCCESS;
// REFRESH VIEW META
return ctgHandleForceUpdateView(pCtg, pReq);
}
int32_t ctgInitTask(SCtgJob* pJob, CTG_TASK_TYPE type, void* param, int32_t* taskId) {
@ -1869,7 +1889,7 @@ int32_t ctgHandleGetViewsRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf*
ctgDebug("start to update view meta to cache, view:%s, querySQL:%s", pRsp->name, pRsp->querySql);
ctgUpdateViewMetaToCache(pCtg, pRsp, false);
pMsgCtx->out = NULL;
taosMemoryFreeClear(pMsgCtx->out);
pRsp = NULL;
SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx);

View File

@ -1687,11 +1687,11 @@ int32_t ctgWriteViewMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFN
_return:
if (pMeta) {
taosMemoryFree(pMeta->querySql);
ctgFreeSViewMeta(pMeta);
taosMemoryFree(pMeta);
}
return TSDB_CODE_SUCCESS;
CTG_RET(code);
}
int32_t ctgUpdateTbMetaToCache(SCatalog *pCtg, STableMetaOutput *pOut, bool syncReq) {
@ -2358,31 +2358,34 @@ int32_t ctgOpUpdateViewMeta(SCtgCacheOperation *operation) {
SCatalog *pCtg = msg->pCtg;
SViewMetaRsp *pRsp = msg->pRsp;
SCtgDBCache *dbCache = NULL;
SViewMeta *pMeta = NULL;
taosMemoryFreeClear(msg);
if (pCtg->stopUpdate) {
return TSDB_CODE_SUCCESS;
goto _return;
}
CTG_ERR_RET(ctgGetAddDBCache(pCtg, pRsp->dbFName, pRsp->dbId, &dbCache));
CTG_ERR_JRET(ctgGetAddDBCache(pCtg, pRsp->dbFName, pRsp->dbId, &dbCache));
if (NULL == dbCache) {
ctgInfo("conflict db update, ignore this update, dbFName:%s, dbId:0x%" PRIx64, pRsp->dbFName, pRsp->dbId);
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
}
SViewMeta *pMeta = taosMemoryCalloc(1, sizeof(SViewMeta));
pMeta = taosMemoryCalloc(1, sizeof(SViewMeta));
if (NULL == pMeta) {
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
}
CTG_ERR_JRET(dupViewMetaFromRsp(pRsp, pMeta));
ASSERT(strlen(pMeta->querySql) > 0 && strlen(pMeta->user) > 0);
CTG_RET(ctgWriteViewMetaToCache(pCtg, dbCache, pRsp->dbFName, pRsp->name, pMeta));
code = ctgWriteViewMetaToCache(pCtg, dbCache, pRsp->dbFName, pRsp->name, pMeta);
pMeta = NULL;
_return:
tFreeSViewMetaRsp(pRsp);
taosMemoryFree(pRsp);
ctgFreeSViewMeta(pMeta);
taosMemoryFree(pMeta);

View File

@ -187,6 +187,9 @@ void ctgFreeSMetaData(SMetaData* pData) {
taosArrayDestroy(pData->pTableTag);
pData->pTableTag = NULL;
taosArrayDestroy(pData->pView);
pData->pView = NULL;
taosMemoryFreeClear(pData->pSvrVer);
}
@ -258,7 +261,7 @@ void ctgFreeViewCacheImpl(SCtgViewCache* pCache, bool lock) {
CTG_LOCK(CTG_WRITE, &pCache->viewLock);
}
if (pCache->pMeta) {
taosMemoryFree(pCache->pMeta->querySql);
ctgFreeSViewMeta(pCache->pMeta);
taosMemoryFreeClear(pCache->pMeta);
}
if (lock) {
@ -583,6 +586,7 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
SViewMetaRsp* pOut = *(SViewMetaRsp**)pCtx->out;
if (NULL != pOut) {
tFreeSViewMetaRsp(pOut);
taosMemoryFree(pOut);
}
taosMemoryFreeClear(pCtx->out);
}
@ -927,7 +931,7 @@ void ctgFreeTaskCtx(SCtgTask* pTask) {
void ctgFreeTask(SCtgTask* pTask, bool freeRes) {
ctgFreeMsgCtx(&pTask->msgCtx);
if (freeRes) {
if (freeRes || pTask->subTask) {
ctgFreeTaskRes(pTask->type, &pTask->res);
}
ctgFreeTaskCtx(pTask);
@ -1570,9 +1574,9 @@ static void* ctgCloneVgroupInfo(void* pSrc) {
static void ctgFreeVgroupInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); }
static void* ctgCloneTableIndices(void* pSrc) { return taosArrayDup((const SArray*)pSrc, NULL); }
static void* ctgCloneTableIndexs(void* pSrc) { return taosArrayDup((const SArray*)pSrc, NULL); }
static void ctgFreeTableIndices(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
static void ctgFreeTableIndexs(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
static void* ctgCloneFuncInfo(void* pSrc) {
SFuncInfo* pDst = taosMemoryMalloc(sizeof(SFuncInfo));
@ -1626,6 +1630,34 @@ static void* ctgCloneDnodeList(void* pSrc) { return taosArrayDup((const SArray*)
static void ctgFreeDnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
static void* ctgCloneViewMeta(void* pSrc) {
SViewMeta* pSrcMeta = pSrc;
SViewMeta* pDst = taosMemoryMalloc(sizeof(SViewMeta));
if (NULL == pDst) {
return NULL;
}
pDst->user = tstrdup(pSrcMeta->user);
pDst->querySql = tstrdup(pSrcMeta->querySql);
pDst->pSchema = taosMemoryMalloc(pSrcMeta->numOfCols * sizeof(*pSrcMeta->pSchema));
if (NULL == pDst->pSchema) {
return pDst;
}
memcpy(pDst->pSchema, pSrcMeta->pSchema, pSrcMeta->numOfCols * sizeof(*pSrcMeta->pSchema));
return pDst;
}
static void ctgFreeViewMeta(void* p) {
SViewMeta* pMeta = ((SMetaRes*)p)->pRes;
if (NULL == pMeta) {
return;
}
taosMemoryFree(pMeta->user);
taosMemoryFree(pMeta->querySql);
taosMemoryFree(pMeta->pSchema);
taosMemoryFree(pMeta);
}
int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
int32_t code = 0;
STableMeta* pMeta = NULL;
@ -1940,7 +1972,7 @@ SMetaData* catalogCloneMetaData(SMetaData* pData) {
}
#endif
void ctgFreeMetaData(SMetaData* pData) {
void ctgDestroySMetaData(SMetaData* pData) {
if (NULL == pData) {
return;
}
@ -1950,15 +1982,15 @@ void ctgFreeMetaData(SMetaData* pData) {
taosArrayDestroyEx(pData->pDbInfo, ctgFreeDbInfo);
taosArrayDestroyEx(pData->pTableMeta, ctgFreeTableMeta);
taosArrayDestroyEx(pData->pTableHash, ctgFreeVgroupInfo);
taosArrayDestroyEx(pData->pTableIndex, ctgFreeTableIndices);
taosArrayDestroyEx(pData->pTableIndex, ctgFreeTableIndexs);
taosArrayDestroyEx(pData->pUdfList, ctgFreeFuncInfo);
taosArrayDestroyEx(pData->pIndex, ctgFreeIndexInfo);
taosArrayDestroyEx(pData->pUser, ctgFreeUserAuth);
taosArrayDestroyEx(pData->pQnodeList, ctgFreeQnodeList);
taosArrayDestroyEx(pData->pTableCfg, ctgFreeTableCfg);
taosArrayDestroyEx(pData->pDnodeList, ctgFreeDnodeList);
taosArrayDestroyEx(pData->pView, ctgFreeViewMeta);
taosMemoryFreeClear(pData->pSvrVer);
taosMemoryFree(pData);
}
uint64_t ctgGetTbIndexCacheSize(STableIndex *pIndex) {

View File

@ -1062,7 +1062,8 @@ void nodesDestroyNode(SNode* pNode) {
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
case QUERY_NODE_SHOW_TAGS_STMT:
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT: {
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
case QUERY_NODE_SHOW_VIEWS_STMT: {
SShowStmt* pStmt = (SShowStmt*)pNode;
nodesDestroyNode(pStmt->pDbName);
nodesDestroyNode(pStmt->pTbName);

View File

@ -40,6 +40,7 @@ int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, vo
int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placeholderNo, SArray* pPlaceholderValues);
int32_t translateTable(STranslateContext* pCxt, SNode** pTable);
int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput);
void tfreeSParseQueryRes(void* p);
#ifdef TD_ENTERPRISE
int32_t translateView(STranslateContext* pCxt, SNode** pTable, SName* pName);

View File

@ -164,7 +164,6 @@ static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
SNode* pTagCond = NULL;
STableNode* pTable = (STableNode*)pNode;
#ifdef TD_ENTERPRISE
SName name;
STableMeta* pTableMeta = NULL;
int32_t code = getTargetMetaImpl(
@ -176,7 +175,6 @@ static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
isView = true;
}
taosMemoryFree(pTableMeta);
#endif
if (!isView) {
pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {

View File

@ -18,10 +18,17 @@
#include "scalar.h"
#include "ttime.h"
typedef struct SNodeReplaceContext {
SNode* pTarget;
SNode* pNew;
bool replaced;
} SNodeReplaceContext;
typedef struct SCalcConstContext {
SParseContext* pParseCxt;
SMsgBuf msgBuf;
int32_t code;
SParseContext* pParseCxt;
SNodeReplaceContext replaceCxt;
SMsgBuf msgBuf;
int32_t code;
} SCalcConstContext;
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery);
@ -166,7 +173,35 @@ static int32_t calcConstStmtCondition(SCalcConstContext* pCxt, SNode** pCond, bo
return code;
}
static int32_t calcConstProject(SNode* pProject, bool dual, SNode** pNew) {
static EDealRes doFindAndReplaceNode(SNode** pNode, void* pContext) {
SCalcConstContext* pCxt = pContext;
if (pCxt->replaceCxt.pTarget == *pNode) {
nodesDestroyNode(*pNode);
*pNode = nodesCloneNode(pCxt->replaceCxt.pNew);
if (NULL == *pNode) {
pCxt->code = TSDB_CODE_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
pCxt->replaceCxt.replaced = true;
return DEAL_RES_END;
}
return DEAL_RES_CONTINUE;
}
static int32_t findAndReplaceNode(SCalcConstContext* pCxt, SNode** pRoot, SNode* pTarget, SNode* pNew, bool strict) {
pCxt->replaceCxt.pNew = pNew;
pCxt->replaceCxt.pTarget = pTarget;
nodesRewriteExprPostOrder(pRoot, doFindAndReplaceNode, pCxt);
if (TSDB_CODE_SUCCESS == pCxt->code && strict && !pCxt->replaceCxt.replaced) {
parserError("target replace node not found");
return TSDB_CODE_PAR_INTERNAL_ERROR;
}
return pCxt->code;
}
static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool dual, SNode** pNew) {
SArray* pAssociation = NULL;
if (NULL != ((SExprNode*)pProject)->pAssociation) {
pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation, NULL);
@ -188,12 +223,20 @@ static int32_t calcConstProject(SNode* pProject, bool dual, SNode** pNew) {
if (QUERY_NODE_VALUE == nodeType(*pNew) && NULL != pAssociation) {
int32_t size = taosArrayGetSize(pAssociation);
for (int32_t i = 0; i < size; ++i) {
SNode** pCol = taosArrayGetP(pAssociation, i);
nodesDestroyNode(*pCol);
*pCol = nodesCloneNode(*pNew);
if (NULL == *pCol) {
code = TSDB_CODE_OUT_OF_MEMORY;
break;
SAssociationNode* pAssNode = taosArrayGet(pAssociation, i);
SNode** pCol = pAssNode->pPlace;
if (*pCol == pAssNode->pAssociationNode) {
nodesDestroyNode(*pCol);
*pCol = nodesCloneNode(*pNew);
if (NULL == *pCol) {
code = TSDB_CODE_OUT_OF_MEMORY;
break;
}
} else {
code = findAndReplaceNode(pCxt, pCol, pAssNode->pAssociationNode, *pNew, true);
if (TSDB_CODE_SUCCESS != code) {
break;
}
}
}
}
@ -247,7 +290,7 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelec
continue;
}
SNode* pNew = NULL;
int32_t code = calcConstProject(pProj, (NULL == pSelect->pFromTable), &pNew);
int32_t code = calcConstProject(pCxt, pProj, (NULL == pSelect->pFromTable), &pNew);
if (TSDB_CODE_SUCCESS == code) {
REPLACE_NODE(pNew);
} else {
@ -514,7 +557,7 @@ static void resetProjectNullTypeImpl(SNodeList* pProjects) {
SExprNode* pExpr = (SExprNode*)pProj;
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
pExpr->resType.type = TSDB_DATA_TYPE_VARCHAR;
pExpr->resType.bytes = 0;
pExpr->resType.bytes = VARSTR_HEADER_SIZE;
}
}
}

View File

@ -915,9 +915,13 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
SColumnNode* pCol = *pColRef;
if (NULL == pExpr->pAssociation) {
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SAssociationNode));
}
taosArrayPush(pExpr->pAssociation, &pColRef);
SAssociationNode assNode;
assNode.pPlace = (SNode**)pColRef;
assNode.pAssociationNode = (SNode*)*pColRef;
taosArrayPush(pExpr->pAssociation, &assNode);
strcpy(pCol->tableAlias, pTable->table.tableAlias);
pCol->colId = isPrimaryKey(pTable, (SNode*)pExpr) ? PRIMARYKEY_TIMESTAMP_COL_ID : 0;
strcpy(pCol->colName, pExpr->aliasName);
@ -4360,7 +4364,7 @@ static int32_t translateInsertProject(STranslateContext* pCxt, SInsertStmt* pIns
}
snprintf(pExpr->aliasName, sizeof(pExpr->aliasName), "%s", pCol->colName);
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) {
pPrimaryKeyExpr = pProj;
pPrimaryKeyExpr = (SNode*)pExpr;
}
}
@ -7648,7 +7652,7 @@ static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt)
tNameGetFullDbName(&name, dropReq.dbFName);
strncpy(dropReq.name, pStmt->viewName, sizeof(dropReq.name) - 1);
snprintf(dropReq.fullname, sizeof(dropReq.fullname) - 1, "%s.%s", dropReq.dbFName, dropReq.name);
dropReq.sql = tstrdup(pCxt->pParseCxt->pSql);
dropReq.sql = (char*)pCxt->pParseCxt->pSql;
if (NULL == dropReq.sql) {
return TSDB_CODE_OUT_OF_MEMORY;
}
@ -8173,7 +8177,7 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t*
SExprNode* pExpr = (SExprNode*)pNode;
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
(*pSchema)[index].type = TSDB_DATA_TYPE_VARCHAR;
(*pSchema)[index].bytes = 0;
(*pSchema)[index].bytes = VARSTR_HEADER_SIZE;
} else {
(*pSchema)[index].type = pExpr->resType.type;
(*pSchema)[index].bytes = pExpr->resType.bytes;

View File

@ -248,11 +248,58 @@ int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, void** pRes
return code;
}
static void destoryTablesReq(void *p) {
STablesReq *pRes = (STablesReq *)p;
taosArrayDestroy(pRes->pTables);
}
void destoryCatalogReq(SCatalogReq *pCatalogReq) {
if (NULL == pCatalogReq) {
return;
}
taosArrayDestroy(pCatalogReq->pDbVgroup);
taosArrayDestroy(pCatalogReq->pDbCfg);
taosArrayDestroy(pCatalogReq->pDbInfo);
if (pCatalogReq->cloned) {
taosArrayDestroy(pCatalogReq->pTableMeta);
taosArrayDestroy(pCatalogReq->pTableHash);
#ifdef TD_ENTERPRISE
taosArrayDestroy(pCatalogReq->pView);
#endif
} else {
taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
#ifdef TD_ENTERPRISE
taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
#endif
}
taosArrayDestroy(pCatalogReq->pUdf);
taosArrayDestroy(pCatalogReq->pIndex);
taosArrayDestroy(pCatalogReq->pUser);
taosArrayDestroy(pCatalogReq->pTableIndex);
taosArrayDestroy(pCatalogReq->pTableCfg);
taosArrayDestroy(pCatalogReq->pTableTag);
}
void tfreeSParseQueryRes(void* p) {
if (NULL == p) {
return;
}
SParseQueryRes* pRes = p;
destoryCatalogReq(pRes->pCatalogReq);
taosMemoryFree(pRes->pCatalogReq);
catalogFreeMetaData(&pRes->meta);
}
void qDestroyParseContext(SParseContext* pCxt) {
if (NULL == pCxt) {
return;
}
taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
taosArrayDestroy(pCxt->pTableMetaPos);
taosArrayDestroy(pCxt->pTableVgroupPos);
taosMemoryFree(pCxt);

View File

@ -5,6 +5,7 @@ sql create view view1 as select * from sta1;
sql drop view view1;
sql create or replace view view2 as select f from cta11;
sql_error create view view2 as select * from cta11;
sql drop view if exists view2;
sql drop view if exists view3;
sql_error drop view view2;
@ -38,3 +39,9 @@ sql create view view1 as select * from ins_tables;
sql drop view view1;
sql create view information_schema.view1 as select * from ins_tags;
sql drop view information_schema.view1;
sql use testa
sql_error create view testb.view1 as select * from sta1;
sql create view testb.view1 as select * from stb1;
sql_error drop view view1
sql drop view testb.view1

View File

@ -14,6 +14,20 @@ endi
if $data01 != 100111 then
return -1
endi
sql select ts from view1 order by ts;
if $rows != 4 then
return -1
endi
if $data00 != @23-10-16 09:10:11.000@ then
return -1
endi
sql select view1.ts from view1 order by view1.ts;
if $rows != 4 then
return -1
endi
if $data00 != @23-10-16 09:10:11.000@ then
return -1
endi
sql create or replace view view1 as select 1, 2;
sql explain select * from view1;
@ -102,11 +116,13 @@ if $data31 != 200338 then
return -1
endi
sql drop view view1;
sql drop view testb.view2;
sql drop view view3;
sql drop view view4;
sql drop view view5;
sql create or replace view view1 as select * from sta1;
sql create or replace view view2 as select * from st2;
sql explain select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114;
sql explain analyze select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114;

View File

@ -1,41 +1,156 @@
sql connect
sql use test;
sql use testa;
sql create view view1 as select * from st;
sql show views;
sql create or replace view view2 as select f from ct1;
sql drop view if exists view2;
sql drop view if exists view3;
sql_error drop view view2;
sql_error drop view view3;
sql create view view3 as select avg(f) from st2;
sql create or replace view view3 as select f fa from st;
sql_error create view view3 as select * from st2;
sql create view view4 as select * from view3;
sql create or replace view view4 as select fa from view3;
sql drop view view3;
sql_error create view view5 as select * from view3;
sql drop view view4;
sql use information_schema;
sql create view view1 as select * from ins_views;
sql create view view1 as select * from sta1;
sql show views;
if $rows != 1 then
return -1
endi
sql describe view1;
sql show create view view1;
sql drop view view1;
sql use testa;
sql create view information_schema.view1 as select * from information_schema.ins_views;
sql show views;
if $rows != 0 then
if $data00 != view1 then
return -1
endi
sql describe information_schema.view1;
sql show create view information_schema.view1;
if $data01 != testa then
return -1
endi
if $data02 != root then
return -1
endi
if $data04 != NORMAL then
return -1
endi
if $data05 != @select * from sta1;@ then
return -1
endi
if $data06 != @`ts` TIMESTAMP, `f` INT, `g` INT, `t` INT@ then
return -1
endi
if $data07 != NULL then
return -1
endi
if $data08 != NULL then
return -1
endi
if $data09 != NULL then
return -1
endi
sql desc view1
if $rows != 4 then
return -1
endi
if $data00 != ts then
return -1
endi
if $data01 != TIMESTAMP then
return -1
endi
if $data02 != 8 then
return -1
endi
if $data03 != @VIEW COL@ then
return -1
endi
if $data10 != f then
return -1
endi
if $data20 != g then
return -1
endi
if $data30 != t then
return -1
endi
sql show create view view1;
if $rows != 1 then
return -1
endi
if $data00 != @`testa`.`view1`@ then
return -1
endi
if $data01 != @CREATE VIEW `testa`.`view1` AS select * from sta1;@ then
return -1
endi
sql create or replace view view2 as select null;
sql desc view2;
if $rows != 1 then
return -1
endi
if $data00 != null then
return -1
endi
if $data01 != VARCHAR then
return -1
endi
if $data02 != 0 then
return -1
endi
sql create or replace view view2 as select null a;
sql desc view2;
if $rows != 1 then
return -1
endi
if $data00 != a then
return -1
endi
if $data01 != VARCHAR then
return -1
endi
if $data02 != 0 then
return -1
endi
sql show views;
if $rows != 2 then
return -1
endi
sql create view testb.view1 as select * from stb1;
sql show views;
if $rows != 2 then
return -1
endi
sql show testb.views;
if $rows != 1 then
return -1
endi
sql show create view testb.view1;
if $rows != 1 then
return -1
endi
if $data00 != @`testb`.`view1`@ then
return -1
endi
if $data01 != @CREATE VIEW `testb`.`view1` AS select * from stb1;@ then
return -1
endi
sql desc testb.view1;
if $rows != 4 then
return -1
endi
sql use information_schema;
sql create view view1 as select * from ins_views;
sql select * from view1;
if $rows != 4 then
return -1
endi
sql select * from view1 where db_name = 'testa';
if $rows != 2 then
return -1
endi
sql select * from view1 where db_name like 'test%';
if $rows != 3 then
return -1
endi
sql select * from view1 where view_name='view1';
if $rows != 3 then
return -1
endi
sql select concat(db_name, '.', view_name) from view1 where view_name='view1';
if $rows != 3 then
return -1
endi
sql drop view testa.view1;
sql drop view testa.view2;
sql drop view testb.view1;
sql drop view information_schema.view1;

View File

@ -37,23 +37,25 @@ sql insert into ctb22 using st2 tags(2) values('2023-10-16 09:10:12', 110222, 11
sql insert into ctb23 using st2 tags(3) values('2023-10-16 09:10:13', 110223, 1102230);
sql insert into ctb24 using st2 tags(4) values('2023-10-16 09:10:14', 110224, 1102240);
run tsim/view/privilege_basic_view.sim
run tsim/view/privilege_nested_view.sim
run tsim/view/create_drop_view.sim
#run tsim/view/privilege_basic_view.sim
#run tsim/view/privilege_nested_view.sim
#run tsim/view/create_drop_view.sim
run tsim/view/query_view.sim
run tsim/view/insert_view.sim
run tsim/view/stream_view.sim
#run tsim/view/insert_view.sim
#run tsim/view/stream_view.sim
#run tsim/view/show_desc_view.sim
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
#print ================== restart server to commit data into disk
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
#system sh/exec.sh -n dnode1 -s start
#print ================== server restart completed
run tsim/view/privilege_basic_view.sim
run tsim/view/privilege_nested_view.sim
run tsim/view/create_drop_view.sim
run tsim/view/query_view.sim
run tsim/view/insert_view.sim
run tsim/view/stream_view.sim
#run tsim/view/privilege_basic_view.sim
#run tsim/view/privilege_nested_view.sim
#run tsim/view/create_drop_view.sim
#run tsim/view/query_view.sim
#run tsim/view/insert_view.sim
#run tsim/view/stream_view.sim
#run tsim/view/show_desc_view.sim
system sh/exec.sh -n dnode1 -s stop -x SIGINT
#system sh/exec.sh -n dnode1 -s stop -x SIGINT