fix: desciribe view and memory issues
This commit is contained in:
parent
099f72e84a
commit
9801d5d7b7
|
@ -1809,7 +1809,7 @@ int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
|
||||||
void tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
|
void tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SArray* pViewRsp; // Array of SViewMetaRsp;
|
SArray* pViewRsp; // Array of SViewMetaRsp*;
|
||||||
} SViewHbRsp;
|
} SViewHbRsp;
|
||||||
|
|
||||||
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
|
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
|
||||||
|
|
|
@ -37,6 +37,7 @@ enum {
|
||||||
CTG_DBG_DB_NUM = 1,
|
CTG_DBG_DB_NUM = 1,
|
||||||
CTG_DBG_META_NUM,
|
CTG_DBG_META_NUM,
|
||||||
CTG_DBG_STB_NUM,
|
CTG_DBG_STB_NUM,
|
||||||
|
CTG_DBG_VIEW_NUM,
|
||||||
CTG_DBG_DB_RENT_NUM,
|
CTG_DBG_DB_RENT_NUM,
|
||||||
CTG_DBG_STB_RENT_NUM,
|
CTG_DBG_STB_RENT_NUM,
|
||||||
CTG_DBG_VIEW_RENT_NUM,
|
CTG_DBG_VIEW_RENT_NUM,
|
||||||
|
|
|
@ -289,22 +289,34 @@ static int32_t hbProcessDynViewRsp(void *value, int32_t valueLen, struct SCatalo
|
||||||
return catalogUpdateDynViewVer(pCatalog, (SDynViewVersion*)value);
|
return catalogUpdateDynViewVer(pCatalog, (SDynViewVersion*)value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hbFreeSViewMetaInRsp(void* p) {
|
||||||
|
if (NULL == p || NULL == *(void**)p) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SViewMetaRsp *pRsp = *(SViewMetaRsp**)p;
|
||||||
|
tFreeSViewMetaRsp(pRsp);
|
||||||
|
taosMemoryFreeClear(pRsp);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
|
static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SViewHbRsp hbRsp = {0};
|
SViewHbRsp hbRsp = {0};
|
||||||
if (tDeserializeSViewHbRsp(value, valueLen, &hbRsp) != 0) {
|
if (tDeserializeSViewHbRsp(value, valueLen, &hbRsp) != 0) {
|
||||||
|
taosArrayDestroyEx(hbRsp.pViewRsp, hbFreeSViewMetaInRsp);
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numOfMeta = taosArrayGetSize(hbRsp.pViewRsp);
|
int32_t numOfMeta = taosArrayGetSize(hbRsp.pViewRsp);
|
||||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||||
SViewMetaRsp *rsp = taosArrayGet(hbRsp.pViewRsp, i);
|
SViewMetaRsp *rsp = taosArrayGetP(hbRsp.pViewRsp, i);
|
||||||
|
|
||||||
if (rsp->numOfCols < 0) {
|
if (rsp->numOfCols < 0) {
|
||||||
tscDebug("hb to remove view, db:%s, view:%s", rsp->dbFName, rsp->name);
|
tscDebug("hb to remove view, db:%s, view:%s", rsp->dbFName, rsp->name);
|
||||||
catalogRemoveViewMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->name, rsp->viewId);
|
catalogRemoveViewMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->name, rsp->viewId);
|
||||||
|
tFreeSViewMetaRsp(rsp);
|
||||||
|
taosMemoryFreeClear(rsp);
|
||||||
} else {
|
} else {
|
||||||
tscDebug("hb to update view, db:%s, view:%s", rsp->dbFName, rsp->name);
|
tscDebug("hb to update view, db:%s, view:%s", rsp->dbFName, rsp->name);
|
||||||
catalogUpdateViewMeta(pCatalog, rsp);
|
catalogUpdateViewMeta(pCatalog, rsp);
|
||||||
|
|
|
@ -9034,7 +9034,7 @@ int32_t tSerializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) {
|
||||||
int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp);
|
int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp);
|
||||||
if (tEncodeI32(&encoder, numOfMeta) < 0) return -1;
|
if (tEncodeI32(&encoder, numOfMeta) < 0) return -1;
|
||||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||||
SViewMetaRsp *pMetaRsp = taosArrayGet(pRsp->pViewRsp, i);
|
SViewMetaRsp *pMetaRsp = taosArrayGetP(pRsp->pViewRsp, i);
|
||||||
if (tEncodeSViewMetaRsp(&encoder, pMetaRsp) < 0) return -1;
|
if (tEncodeSViewMetaRsp(&encoder, pMetaRsp) < 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9053,15 +9053,16 @@ int32_t tDeserializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) {
|
||||||
|
|
||||||
int32_t numOfMeta = 0;
|
int32_t numOfMeta = 0;
|
||||||
if (tDecodeI32(&decoder, &numOfMeta) < 0) return -1;
|
if (tDecodeI32(&decoder, &numOfMeta) < 0) return -1;
|
||||||
pRsp->pViewRsp = taosArrayInit(numOfMeta, sizeof(SViewMetaRsp));
|
pRsp->pViewRsp = taosArrayInit(numOfMeta, POINTER_BYTES);
|
||||||
if (pRsp->pViewRsp == NULL) {
|
if (pRsp->pViewRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||||
SViewMetaRsp metaRsp = {0};
|
SViewMetaRsp* metaRsp = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
|
||||||
if (tDecodeSViewMetaRsp(&decoder, &metaRsp) < 0) return -1;
|
if (NULL == metaRsp) return -1;
|
||||||
|
if (tDecodeSViewMetaRsp(&decoder, metaRsp) < 0) return -1;
|
||||||
taosArrayPush(pRsp->pViewRsp, &metaRsp);
|
taosArrayPush(pRsp->pViewRsp, &metaRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9074,8 +9075,9 @@ int32_t tDeserializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) {
|
||||||
void tFreeSViewHbRsp(SViewHbRsp *pRsp) {
|
void tFreeSViewHbRsp(SViewHbRsp *pRsp) {
|
||||||
int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp);
|
int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp);
|
||||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||||
SViewMetaRsp *pMetaRsp = taosArrayGet(pRsp->pViewRsp, i);
|
SViewMetaRsp *pMetaRsp = taosArrayGetP(pRsp->pViewRsp, i);
|
||||||
tFreeSViewMetaRsp(pMetaRsp);
|
tFreeSViewMetaRsp(pMetaRsp);
|
||||||
|
taosMemoryFree(pMetaRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pRsp->pViewRsp);
|
taosArrayDestroy(pRsp->pViewRsp);
|
||||||
|
|
|
@ -1735,6 +1735,7 @@ int32_t catalogUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg) {
|
||||||
CTG_API_ENTER();
|
CTG_API_ENTER();
|
||||||
|
|
||||||
if (NULL == pCtg || NULL == pMsg) {
|
if (NULL == pCtg || NULL == pMsg) {
|
||||||
|
tFreeSViewMetaRsp(pMsg);
|
||||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1294,7 +1294,7 @@ int32_t ctgUpdateViewMetaEnqueue(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncOp
|
||||||
if (NULL == msg) {
|
if (NULL == msg) {
|
||||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateViewMetaMsg));
|
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateViewMetaMsg));
|
||||||
taosMemoryFree(op);
|
taosMemoryFree(op);
|
||||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *p = strchr(pRsp->dbFName, '.');
|
char *p = strchr(pRsp->dbFName, '.');
|
||||||
|
|
|
@ -372,6 +372,10 @@ int32_t ctgdGetTbMetaNum(SCtgDBCache *dbCache) {
|
||||||
return dbCache->tbCache ? (int32_t)taosHashGetSize(dbCache->tbCache) : 0;
|
return dbCache->tbCache ? (int32_t)taosHashGetSize(dbCache->tbCache) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ctgdGetViewNum(SCtgDBCache *dbCache) {
|
||||||
|
return dbCache->viewCache ? (int32_t)taosHashGetSize(dbCache->viewCache) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t ctgdGetStbNum(SCtgDBCache *dbCache) {
|
int32_t ctgdGetStbNum(SCtgDBCache *dbCache) {
|
||||||
return dbCache->stbCache ? (int32_t)taosHashGetSize(dbCache->stbCache) : 0;
|
return dbCache->stbCache ? (int32_t)taosHashGetSize(dbCache->stbCache) : 0;
|
||||||
}
|
}
|
||||||
|
@ -420,6 +424,8 @@ int32_t ctgdGetClusterCacheNum(SCatalog *pCtg, int32_t type) {
|
||||||
case CTG_DBG_STB_NUM:
|
case CTG_DBG_STB_NUM:
|
||||||
num += ctgdGetStbNum(dbCache);
|
num += ctgdGetStbNum(dbCache);
|
||||||
break;
|
break;
|
||||||
|
case CTG_DBG_VIEW_NUM:
|
||||||
|
num += ctgdGetViewNum(dbCache);
|
||||||
default:
|
default:
|
||||||
ctgError("invalid type:%d", type);
|
ctgError("invalid type:%d", type);
|
||||||
break;
|
break;
|
||||||
|
@ -472,6 +478,7 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) {
|
||||||
dbFName = taosHashGetKey(pIter, &len);
|
dbFName = taosHashGetKey(pIter, &len);
|
||||||
|
|
||||||
int32_t metaNum = dbCache->tbCache ? taosHashGetSize(dbCache->tbCache) : 0;
|
int32_t metaNum = dbCache->tbCache ? taosHashGetSize(dbCache->tbCache) : 0;
|
||||||
|
int32_t viewNum = dbCache->viewCache ? taosHashGetSize(dbCache->viewCache) : 0;
|
||||||
int32_t stbNum = dbCache->stbCache ? taosHashGetSize(dbCache->stbCache) : 0;
|
int32_t stbNum = dbCache->stbCache ? taosHashGetSize(dbCache->stbCache) : 0;
|
||||||
int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||||
int32_t hashMethod = -1;
|
int32_t hashMethod = -1;
|
||||||
|
@ -492,8 +499,8 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgDebug("[%d] db [%.*s][0x%" PRIx64
|
ctgDebug("[%d] db [%.*s][0x%" PRIx64
|
||||||
"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, stateTs:%" PRId64 ", hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d",
|
"] %s: metaNum:%d, viewNum:%d, stbNum:%d, vgVersion:%d, stateTs:%" PRId64 ", hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d",
|
||||||
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted ? "deleted" : "", metaNum, stbNum, vgVersion, stateTs,
|
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted ? "deleted" : "", metaNum, viewNum, stbNum, vgVersion, stateTs,
|
||||||
hashMethod, hashPrefix, hashSuffix, vgNum);
|
hashMethod, hashPrefix, hashSuffix, vgNum);
|
||||||
|
|
||||||
if (dbCache->vgCache.vgInfo) {
|
if (dbCache->vgCache.vgInfo) {
|
||||||
|
@ -543,9 +550,10 @@ void ctgdShowClusterCache(SCatalog *pCtg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctgDebug("## cluster 0x%" PRIx64 " %p cache Info BEGIN ##", pCtg->clusterId, pCtg);
|
ctgDebug("## cluster 0x%" PRIx64 " %p cache Info BEGIN ##", pCtg->clusterId, pCtg);
|
||||||
ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM),
|
ctgDebug("db:%d tbmeta:%d viewmeta:%d stb:%d dbRent:%d stbRent:%d viewRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM),
|
||||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM),
|
ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_VIEW_NUM),
|
||||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM));
|
ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM),
|
||||||
|
ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_VIEW_RENT_NUM));
|
||||||
|
|
||||||
ctgdShowDBCache(pCtg, pCtg->dbCache);
|
ctgdShowDBCache(pCtg, pCtg->dbCache);
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ int32_t reserveTableCfgInCache(int32_t acctId, const char* pDb, const char* pTab
|
||||||
int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache);
|
int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache);
|
||||||
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
|
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
|
||||||
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
|
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
|
||||||
|
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta);
|
||||||
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo);
|
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo);
|
||||||
int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup);
|
int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup);
|
||||||
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
|
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
|
||||||
|
|
|
@ -164,17 +164,16 @@ static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
|
||||||
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
||||||
SNode* pTagCond = NULL;
|
SNode* pTagCond = NULL;
|
||||||
STableNode* pTable = (STableNode*)pNode;
|
STableNode* pTable = (STableNode*)pNode;
|
||||||
|
#ifdef TD_ENTERPRISE
|
||||||
SName name;
|
SName name;
|
||||||
STableMeta* pTableMeta = NULL;
|
STableMeta* pTableMeta = NULL;
|
||||||
int32_t code = getTargetMetaImpl(
|
int32_t code = getTargetMetaImpl(
|
||||||
pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name), &pTableMeta, true);
|
pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name), &pTableMeta, true);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS == code && TSDB_VIEW_TABLE == pTableMeta->tableType) {
|
||||||
pAuthCxt->errCode = code;
|
|
||||||
return DEAL_RES_ERROR;
|
|
||||||
} else if (TSDB_VIEW_TABLE == pTableMeta->tableType) {
|
|
||||||
isView = true;
|
isView = true;
|
||||||
}
|
}
|
||||||
taosMemoryFree(pTableMeta);
|
taosMemoryFree(pTableMeta);
|
||||||
|
#endif
|
||||||
if (!isView) {
|
if (!isView) {
|
||||||
pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
|
pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
|
||||||
if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
|
if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
|
||||||
|
|
|
@ -455,15 +455,6 @@ static int32_t refreshGetTableMeta(STranslateContext* pCxt, const char* pDbName,
|
||||||
|
|
||||||
code = catalogRefreshGetTableMeta(pParCxt->pCatalog, &conn, &name, pMeta, false);
|
code = catalogRefreshGetTableMeta(pParCxt->pCatalog, &conn, &name, pMeta, false);
|
||||||
}
|
}
|
||||||
#ifdef TD_ENTERPRISE
|
|
||||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
|
||||||
int32_t origCode = code;
|
|
||||||
code = getViewMetaFromCache(pCxt->pMetaCache, &name, pMeta);
|
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
|
||||||
code = origCode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
parserError("0x%" PRIx64 " catalogRefreshGetTableMeta error, code:%s, dbName:%s, tbName:%s",
|
parserError("0x%" PRIx64 " catalogRefreshGetTableMeta error, code:%s, dbName:%s, tbName:%s",
|
||||||
pCxt->pParseCxt->requestId, tstrerror(code), pDbName, pTableName);
|
pCxt->pParseCxt->requestId, tstrerror(code), pDbName, pTableName);
|
||||||
|
@ -6653,7 +6644,41 @@ static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) {
|
static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) {
|
||||||
return refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
int32_t code = refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
||||||
|
#ifdef TD_ENTERPRISE
|
||||||
|
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
||||||
|
int32_t origCode = code;
|
||||||
|
SName name;
|
||||||
|
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name);
|
||||||
|
SViewMeta* pMeta = NULL;
|
||||||
|
code = getViewMetaFromMetaCache(pCxt, &name, &pMeta);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
code = origCode;
|
||||||
|
} else {
|
||||||
|
SParseSqlRes res = {.resType = PARSE_SQL_RES_SCHEMA};
|
||||||
|
char dbFName[TSDB_DB_FNAME_LEN];
|
||||||
|
tNameGetFullDbName(&name, dbFName);
|
||||||
|
code = (*pCxt->pParseCxt->parseSqlFp)(pCxt->pParseCxt->parseSqlParam, name.dbname, pMeta->querySql, false, pMeta->user, &res);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = collectUseTable(&name, pCxt->pTargetTables);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SViewMeta viewMeta = {0};
|
||||||
|
viewMeta.viewId = pMeta->viewId;
|
||||||
|
viewMeta.precision = res.schemaRes.precision;
|
||||||
|
viewMeta.type = pMeta->type;
|
||||||
|
viewMeta.version = pMeta->version;
|
||||||
|
viewMeta.numOfCols = res.schemaRes.numOfCols;
|
||||||
|
viewMeta.pSchema = res.schemaRes.pSchema;
|
||||||
|
code = buildTableMetaFromViewMeta(&pStmt->pMeta, &viewMeta);
|
||||||
|
parserDebug("rebuild view meta, view:%s.%s, numOfCols:%d, code:0x%x", dbFName, pStmt->tableName, viewMeta.numOfCols, code);
|
||||||
|
}
|
||||||
|
taosMemoryFree(res.schemaRes.pSchema);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateCompactRange(STranslateContext* pCxt, SCompactDatabaseStmt* pStmt, SCompactDbReq* pReq) {
|
static int32_t translateCompactRange(STranslateContext* pCxt, SCompactDatabaseStmt* pStmt, SCompactDbReq* pReq) {
|
||||||
|
|
|
@ -905,28 +905,33 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) {
|
||||||
|
*pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema));
|
||||||
|
if (NULL == *pMeta) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
(*pMeta)->uid = pViewMeta->viewId;
|
||||||
|
(*pMeta)->vgId = MNODE_HANDLE;
|
||||||
|
(*pMeta)->tableType = TSDB_VIEW_TABLE;
|
||||||
|
(*pMeta)->sversion = pViewMeta->version;
|
||||||
|
(*pMeta)->tversion = pViewMeta->version;
|
||||||
|
(*pMeta)->tableInfo.precision = pViewMeta->precision;
|
||||||
|
(*pMeta)->tableInfo.numOfColumns = pViewMeta->numOfCols;
|
||||||
|
memcpy((*pMeta)->schema, pViewMeta->pSchema, sizeof(SSchema) * pViewMeta->numOfCols);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pViewMeta->numOfCols; ++i) {
|
||||||
|
(*pMeta)->tableInfo.rowSize += (*pMeta)->schema[i].bytes;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
|
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
|
||||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||||
tNameExtractFullName(pName, fullName);
|
tNameExtractFullName(pName, fullName);
|
||||||
SViewMeta* pViewMeta = NULL;
|
SViewMeta* pViewMeta = NULL;
|
||||||
int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pViews, (void**)&pViewMeta);
|
int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pViews, (void**)&pViewMeta);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema));
|
code = buildTableMetaFromViewMeta(pMeta, pViewMeta);
|
||||||
if (NULL == *pMeta) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
(*pMeta)->uid = pViewMeta->viewId;
|
|
||||||
(*pMeta)->vgId = MNODE_HANDLE;
|
|
||||||
(*pMeta)->tableType = TSDB_VIEW_TABLE;
|
|
||||||
(*pMeta)->sversion = pViewMeta->version;
|
|
||||||
(*pMeta)->tversion = pViewMeta->version;
|
|
||||||
(*pMeta)->tableInfo.precision = pViewMeta->precision;
|
|
||||||
(*pMeta)->tableInfo.numOfColumns = pViewMeta->numOfCols;
|
|
||||||
memcpy((*pMeta)->schema, pViewMeta->pSchema, sizeof(SSchema) * pViewMeta->numOfCols);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pViewMeta->numOfCols; ++i) {
|
|
||||||
(*pMeta)->tableInfo.rowSize += (*pMeta)->schema[i].bytes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
sql connect
|
||||||
|
sql use testa;
|
||||||
|
|
||||||
|
print == create view sta1
|
||||||
|
sql create view sta1 as select * from stv;
|
||||||
|
sql select * from sta1;
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql desc sta1;
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql show create table sta1;
|
||||||
|
sql show create view sta1;
|
||||||
|
sql create view view1 as select * from sta1;
|
||||||
|
sql select * from view1;
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print == drop view sta1
|
||||||
|
sql reset query cache
|
||||||
|
sql drop view sta1;
|
||||||
|
sql select * from sta1;
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql desc sta1;
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql show create table sta1;
|
||||||
|
sql_error show create view sta1;
|
||||||
|
sql select * from view1;
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print == create view sta1, drop table sta1
|
||||||
|
sql reset query cache
|
||||||
|
sql create view sta1 as select * from stv;
|
||||||
|
sql drop table sta1;
|
||||||
|
sql select * from sta1;
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql desc sta1;
|
||||||
|
if $rows != 3 then
|
||||||
|
print $rows
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql_error show create table sta1;
|
||||||
|
sql show create view sta1;
|
||||||
|
sql select * from view1;
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql desc view1;
|
||||||
|
if $rows != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print == restore data
|
||||||
|
sql drop view sta1;
|
||||||
|
sql drop view view1;
|
||||||
|
sql create table sta1(ts timestamp, f int, g int) tags (t int);
|
||||||
|
sql insert into cta11 using sta1 tags(1) values('2023-10-16 09:10:11', 100111, 1001110);
|
||||||
|
sql insert into cta12 using sta1 tags(2) values('2023-10-16 09:10:12', 100112, 1001120);
|
||||||
|
sql insert into cta13 using sta1 tags(3) values('2023-10-16 09:10:13', 100113, 1001130);
|
||||||
|
sql insert into cta14 using sta1 tags(4) values('2023-10-16 09:10:14', 100114, 1001140);
|
||||||
|
|
|
@ -21,6 +21,9 @@ sql insert into cta24 using st2 tags(4) values('2023-10-16 09:10:14', 100224, 10
|
||||||
sql create table stt(ts timestamp, f int, g int) tags (t int);
|
sql create table stt(ts timestamp, f int, g int) tags (t int);
|
||||||
sql create table tt using stt tags(99);
|
sql create table tt using stt tags(99);
|
||||||
|
|
||||||
|
sql create table stv(ts timestamp, h int) tags (t1 int);
|
||||||
|
sql insert into ctv1 using stv tags(1) values('2023-10-16 10:10:10', 1);
|
||||||
|
|
||||||
sql drop database if exists testb
|
sql drop database if exists testb
|
||||||
sql create database testb vgroups 1;
|
sql create database testb vgroups 1;
|
||||||
sql use testb;
|
sql use testb;
|
||||||
|
@ -37,25 +40,27 @@ 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 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);
|
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_basic_view.sim
|
||||||
#run tsim/view/privilege_nested_view.sim
|
run tsim/view/privilege_nested_view.sim
|
||||||
#run tsim/view/create_drop_view.sim
|
run tsim/view/create_drop_view.sim
|
||||||
run tsim/view/query_view.sim
|
run tsim/view/query_view.sim
|
||||||
#run tsim/view/insert_view.sim
|
run tsim/view/insert_view.sim
|
||||||
#run tsim/view/stream_view.sim
|
run tsim/view/stream_view.sim
|
||||||
#run tsim/view/show_desc_view.sim
|
run tsim/view/show_desc_view.sim
|
||||||
|
run tsim/view/same_name_tb_view.sim
|
||||||
|
|
||||||
#print ================== restart server to commit data into disk
|
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 stop -x SIGINT
|
||||||
#system sh/exec.sh -n dnode1 -s start
|
system sh/exec.sh -n dnode1 -s start
|
||||||
#print ================== server restart completed
|
print ================== server restart completed
|
||||||
|
|
||||||
#run tsim/view/privilege_basic_view.sim
|
run tsim/view/privilege_basic_view.sim
|
||||||
#run tsim/view/privilege_nested_view.sim
|
run tsim/view/privilege_nested_view.sim
|
||||||
#run tsim/view/create_drop_view.sim
|
run tsim/view/create_drop_view.sim
|
||||||
#run tsim/view/query_view.sim
|
run tsim/view/query_view.sim
|
||||||
#run tsim/view/insert_view.sim
|
run tsim/view/insert_view.sim
|
||||||
#run tsim/view/stream_view.sim
|
run tsim/view/stream_view.sim
|
||||||
#run tsim/view/show_desc_view.sim
|
run tsim/view/show_desc_view.sim
|
||||||
|
run tsim/view/same_name_tb_view.sim
|
||||||
|
|
||||||
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
Loading…
Reference in New Issue