feat: add show create view implement
This commit is contained in:
parent
d229492616
commit
478de7ae56
|
@ -336,6 +336,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_SHOW_VNODES_STMT,
|
QUERY_NODE_SHOW_VNODES_STMT,
|
||||||
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
|
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
|
||||||
QUERY_NODE_SHOW_VIEWS_STMT,
|
QUERY_NODE_SHOW_VIEWS_STMT,
|
||||||
|
QUERY_NODE_SHOW_CREATE_VIEW_STMT,
|
||||||
QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
|
QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
|
||||||
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
|
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
|
||||||
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
||||||
|
|
|
@ -188,40 +188,40 @@
|
||||||
#define TK_VNODES 169
|
#define TK_VNODES 169
|
||||||
#define TK_ALIVE 170
|
#define TK_ALIVE 170
|
||||||
#define TK_VIEWS 171
|
#define TK_VIEWS 171
|
||||||
#define TK_NORMAL 172
|
#define TK_VIEW 172
|
||||||
#define TK_CHILD 173
|
#define TK_NORMAL 173
|
||||||
#define TK_LIKE 174
|
#define TK_CHILD 174
|
||||||
#define TK_TBNAME 175
|
#define TK_LIKE 175
|
||||||
#define TK_QTAGS 176
|
#define TK_TBNAME 176
|
||||||
#define TK_AS 177
|
#define TK_QTAGS 177
|
||||||
#define TK_SYSTEM 178
|
#define TK_AS 178
|
||||||
#define TK_INDEX 179
|
#define TK_SYSTEM 179
|
||||||
#define TK_FUNCTION 180
|
#define TK_INDEX 180
|
||||||
#define TK_INTERVAL 181
|
#define TK_FUNCTION 181
|
||||||
#define TK_COUNT 182
|
#define TK_INTERVAL 182
|
||||||
#define TK_LAST_ROW 183
|
#define TK_COUNT 183
|
||||||
#define TK_META 184
|
#define TK_LAST_ROW 184
|
||||||
#define TK_ONLY 185
|
#define TK_META 185
|
||||||
#define TK_TOPIC 186
|
#define TK_ONLY 186
|
||||||
#define TK_CONSUMER 187
|
#define TK_TOPIC 187
|
||||||
#define TK_GROUP 188
|
#define TK_CONSUMER 188
|
||||||
#define TK_DESC 189
|
#define TK_GROUP 189
|
||||||
#define TK_DESCRIBE 190
|
#define TK_DESC 190
|
||||||
#define TK_RESET 191
|
#define TK_DESCRIBE 191
|
||||||
#define TK_QUERY 192
|
#define TK_RESET 192
|
||||||
#define TK_CACHE 193
|
#define TK_QUERY 193
|
||||||
#define TK_EXPLAIN 194
|
#define TK_CACHE 194
|
||||||
#define TK_ANALYZE 195
|
#define TK_EXPLAIN 195
|
||||||
#define TK_VERBOSE 196
|
#define TK_ANALYZE 196
|
||||||
#define TK_NK_BOOL 197
|
#define TK_VERBOSE 197
|
||||||
#define TK_RATIO 198
|
#define TK_NK_BOOL 198
|
||||||
#define TK_NK_FLOAT 199
|
#define TK_RATIO 199
|
||||||
#define TK_OUTPUTTYPE 200
|
#define TK_NK_FLOAT 200
|
||||||
#define TK_AGGREGATE 201
|
#define TK_OUTPUTTYPE 201
|
||||||
#define TK_BUFSIZE 202
|
#define TK_AGGREGATE 202
|
||||||
#define TK_LANGUAGE 203
|
#define TK_BUFSIZE 203
|
||||||
#define TK_REPLACE 204
|
#define TK_LANGUAGE 204
|
||||||
#define TK_VIEW 205
|
#define TK_REPLACE 205
|
||||||
#define TK_STREAM 206
|
#define TK_STREAM 206
|
||||||
#define TK_INTO 207
|
#define TK_INTO 207
|
||||||
#define TK_PAUSE 208
|
#define TK_PAUSE 208
|
||||||
|
@ -364,6 +364,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TK_NK_SPACE 600
|
#define TK_NK_SPACE 600
|
||||||
#define TK_NK_COMMENT 601
|
#define TK_NK_COMMENT 601
|
||||||
#define TK_NK_ILLEGAL 602
|
#define TK_NK_ILLEGAL 602
|
||||||
|
|
|
@ -358,6 +358,8 @@ SMetaData* catalogCloneMetaData(SMetaData* pData);
|
||||||
|
|
||||||
void catalogFreeMetaData(SMetaData* pData);
|
void catalogFreeMetaData(SMetaData* pData);
|
||||||
|
|
||||||
|
int32_t catalogRemoveViewMeta(SCatalog* pCtg, SName* pViewName);
|
||||||
|
|
||||||
int32_t ctgdEnableDebug(char* option, bool enable);
|
int32_t ctgdEnableDebug(char* option, bool enable);
|
||||||
|
|
||||||
int32_t ctgdHandleDbgCommand(char* command);
|
int32_t ctgdHandleDbgCommand(char* command);
|
||||||
|
|
|
@ -36,6 +36,11 @@ extern "C" {
|
||||||
#define SHOW_CREATE_TB_RESULT_FIELD1_LEN (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE)
|
#define SHOW_CREATE_TB_RESULT_FIELD1_LEN (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE)
|
||||||
#define SHOW_CREATE_TB_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN * 3)
|
#define SHOW_CREATE_TB_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN * 3)
|
||||||
|
|
||||||
|
#define SHOW_CREATE_VIEW_RESULT_COLS 2
|
||||||
|
#define SHOW_CREATE_VIEW_RESULT_FIELD1_LEN (TSDB_VIEW_FNAME_LEN + 4 + VARSTR_HEADER_SIZE)
|
||||||
|
#define SHOW_CREATE_VIEW_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN + VARSTR_HEADER_SIZE)
|
||||||
|
|
||||||
|
|
||||||
#define SHOW_LOCAL_VARIABLES_RESULT_COLS 3
|
#define SHOW_LOCAL_VARIABLES_RESULT_COLS 3
|
||||||
#define SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE)
|
#define SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE)
|
||||||
#define SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE)
|
#define SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE)
|
||||||
|
@ -297,6 +302,13 @@ typedef struct SShowCreateTableStmt {
|
||||||
void* pTableCfg; // STableCfg
|
void* pTableCfg; // STableCfg
|
||||||
} SShowCreateTableStmt;
|
} SShowCreateTableStmt;
|
||||||
|
|
||||||
|
typedef struct SShowCreateViewStmt {
|
||||||
|
ENodeType type;
|
||||||
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
|
char viewName[TSDB_VIEW_NAME_LEN];
|
||||||
|
void* pViewMeta;
|
||||||
|
} SShowCreateViewStmt;
|
||||||
|
|
||||||
typedef struct SShowTableDistributedStmt {
|
typedef struct SShowTableDistributedStmt {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
char dbName[TSDB_DB_NAME_LEN];
|
char dbName[TSDB_DB_NAME_LEN];
|
||||||
|
|
|
@ -99,6 +99,7 @@ enum {
|
||||||
CTG_OP_UPDATE_TB_INDEX,
|
CTG_OP_UPDATE_TB_INDEX,
|
||||||
CTG_OP_DROP_TB_INDEX,
|
CTG_OP_DROP_TB_INDEX,
|
||||||
CTG_OP_UPDATE_VIEW_META,
|
CTG_OP_UPDATE_VIEW_META,
|
||||||
|
CTG_OP_DROP_VIEW_META,
|
||||||
CTG_OP_CLEAR_CACHE,
|
CTG_OP_CLEAR_CACHE,
|
||||||
CTG_OP_MAX
|
CTG_OP_MAX
|
||||||
};
|
};
|
||||||
|
@ -535,6 +536,13 @@ typedef struct SCtgUpdateViewMetaMsg {
|
||||||
SViewMetaRsp* pRsp;
|
SViewMetaRsp* pRsp;
|
||||||
} SCtgUpdateViewMetaMsg;
|
} SCtgUpdateViewMetaMsg;
|
||||||
|
|
||||||
|
typedef struct SCtgDropViewMetaMsg {
|
||||||
|
SCatalog* pCtg;
|
||||||
|
char dbFName[TSDB_DB_FNAME_LEN];
|
||||||
|
char viewName[TSDB_VIEW_NAME_LEN];
|
||||||
|
uint64_t dbId;
|
||||||
|
} SCtgDropViewMetaMsg;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SCtgCacheOperation {
|
typedef struct SCtgCacheOperation {
|
||||||
int32_t opId;
|
int32_t opId;
|
||||||
|
@ -897,6 +905,7 @@ int32_t ctgOpDropDbCache(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpDropDbVgroup(SCtgCacheOperation* action);
|
int32_t ctgOpDropDbVgroup(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpDropStbMeta(SCtgCacheOperation* action);
|
int32_t ctgOpDropStbMeta(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpDropTbMeta(SCtgCacheOperation* action);
|
int32_t ctgOpDropTbMeta(SCtgCacheOperation* action);
|
||||||
|
int32_t ctgOpDropViewMeta(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpUpdateUser(SCtgCacheOperation* action);
|
int32_t ctgOpUpdateUser(SCtgCacheOperation* action);
|
||||||
int32_t ctgOpUpdateEpset(SCtgCacheOperation* operation);
|
int32_t ctgOpUpdateEpset(SCtgCacheOperation* operation);
|
||||||
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char* dbFName, SCtgDBCache** pCache);
|
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char* dbFName, SCtgDBCache** pCache);
|
||||||
|
@ -918,6 +927,7 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput* output, bool sy
|
||||||
int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp* pAuth, bool syncReq);
|
int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp* pAuth, bool syncReq);
|
||||||
int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char* dbFName, int32_t vgId, SEpSet* pEpSet);
|
int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char* dbFName, int32_t vgId, SEpSet* pEpSet);
|
||||||
int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex** pIndex, bool syncOp);
|
int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex** pIndex, bool syncOp);
|
||||||
|
int32_t ctgDropViewMetaEnqueue(SCatalog *pCtg, const char *dbFName, int64_t dbId, const char *viewName, bool syncOp);
|
||||||
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool clearMeta, bool freeCtg, bool stopQueue, bool syncOp);
|
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool clearMeta, bool freeCtg, bool stopQueue, bool syncOp);
|
||||||
int32_t ctgMetaRentInit(SCtgRentMgmt* mgmt, uint32_t rentSec, int8_t type, int32_t size);
|
int32_t ctgMetaRentInit(SCtgRentMgmt* mgmt, uint32_t rentSec, int8_t type, int32_t size);
|
||||||
int32_t ctgMetaRentAdd(SCtgRentMgmt* mgmt, void* meta, int64_t id, int32_t size);
|
int32_t ctgMetaRentAdd(SCtgRentMgmt* mgmt, void* meta, int64_t id, int32_t size);
|
||||||
|
@ -1017,6 +1027,7 @@ void ctgClearSubTaskRes(SCtgSubRes* pRes);
|
||||||
void ctgFreeQNode(SCtgQNode* node);
|
void ctgFreeQNode(SCtgQNode* node);
|
||||||
void ctgClearHandle(SCatalog* pCtg);
|
void ctgClearHandle(SCatalog* pCtg);
|
||||||
void ctgFreeTbCacheImpl(SCtgTbCache* pCache, bool lock);
|
void ctgFreeTbCacheImpl(SCtgTbCache* pCache, bool lock);
|
||||||
|
void ctgFreeViewCacheImpl(SCtgViewCache* pCache, bool lock);
|
||||||
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
|
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
|
||||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user);
|
int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user);
|
||||||
int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup,
|
int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup,
|
||||||
|
|
|
@ -665,9 +665,34 @@ _return:
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32_t ctgRemoveViewMeta(SCatalog* pCtg, SName* pViewName) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
if (NULL == pCtg || NULL == pViewName) {
|
||||||
|
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL == pCtg->dbCache) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
|
tNameGetFullDbName(pViewName, dbFName);
|
||||||
|
CTG_ERR_JRET(ctgDropViewMetaEnqueue(pCtg, dbFName, 0, pViewName->tname, true));
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgProcessTimerEvent(void *param, void *tmrId) {
|
void ctgProcessTimerEvent(void *param, void *tmrId) {
|
||||||
CTG_API_NENTER();
|
CTG_API_NENTER();
|
||||||
|
|
||||||
|
ctgdShowCacheInfo();
|
||||||
|
ctgdShowStatInfo();
|
||||||
|
|
||||||
int32_t cacheMaxSize = atomic_load_32(&tsMetaCacheMaxSize);
|
int32_t cacheMaxSize = atomic_load_32(&tsMetaCacheMaxSize);
|
||||||
if (cacheMaxSize >= 0) {
|
if (cacheMaxSize >= 0) {
|
||||||
uint64_t cacheSize = 0;
|
uint64_t cacheSize = 0;
|
||||||
|
@ -1661,6 +1686,13 @@ void catalogFreeMetaData(SMetaData * pData) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t catalogRemoveViewMeta(SCatalog* pCtg, SName* pViewName) {
|
||||||
|
CTG_API_ENTER();
|
||||||
|
|
||||||
|
CTG_API_LEAVE(ctgRemoveViewMeta(pCtg, pViewName));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t catalogClearCache(void) {
|
int32_t catalogClearCache(void) {
|
||||||
CTG_API_ENTER_NOLOCK();
|
CTG_API_ENTER_NOLOCK();
|
||||||
|
|
||||||
|
|
|
@ -717,7 +717,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
|
||||||
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_USER, user, NULL));
|
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_USER, user, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tbHashNum > 0) {
|
if (viewNum > 0) {
|
||||||
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_VIEW, pReq->pView, NULL));
|
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_VIEW, pReq->pView, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {{CTG_OP_UPDATE_VGROUP, "update v
|
||||||
{CTG_OP_UPDATE_TB_INDEX, "update tbIndex", ctgOpUpdateTbIndex},
|
{CTG_OP_UPDATE_TB_INDEX, "update tbIndex", ctgOpUpdateTbIndex},
|
||||||
{CTG_OP_DROP_TB_INDEX, "drop tbIndex", ctgOpDropTbIndex},
|
{CTG_OP_DROP_TB_INDEX, "drop tbIndex", ctgOpDropTbIndex},
|
||||||
{CTG_OP_UPDATE_VIEW_META, "update viewMeta", ctgOpUpdateViewMeta},
|
{CTG_OP_UPDATE_VIEW_META, "update viewMeta", ctgOpUpdateViewMeta},
|
||||||
|
{CTG_OP_DROP_VIEW_META, "drop viewMeta", ctgOpDropTbMeta},
|
||||||
{CTG_OP_CLEAR_CACHE, "clear cache", ctgOpClearCache}};
|
{CTG_OP_CLEAR_CACHE, "clear cache", ctgOpClearCache}};
|
||||||
|
|
||||||
SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
||||||
|
@ -50,6 +51,7 @@ SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
||||||
{"TblCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_CFG,
|
{"TblCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_CFG,
|
||||||
{"TblTag ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_TAG,
|
{"TblTag ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_TAG,
|
||||||
{"IndexInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_INDEX_INFO,
|
{"IndexInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_INDEX_INFO,
|
||||||
|
{"viewMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_VIEW,
|
||||||
{"User ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_USER,
|
{"User ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_USER,
|
||||||
{"UDF ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_UDF,
|
{"UDF ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_UDF,
|
||||||
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} //CTG_CI_SVR_VER,
|
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} //CTG_CI_SVR_VER,
|
||||||
|
@ -1308,6 +1310,36 @@ int32_t ctgUpdateViewMetaEnqueue(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncOp
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ctgDropViewMetaEnqueue(SCatalog *pCtg, const char *dbFName, int64_t dbId, const char *viewName, bool syncOp) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation));
|
||||||
|
op->opId = CTG_OP_DROP_VIEW_META;
|
||||||
|
op->syncOp = syncOp;
|
||||||
|
|
||||||
|
SCtgDropViewMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgDropViewMetaMsg));
|
||||||
|
if (NULL == msg) {
|
||||||
|
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropViewMetaMsg));
|
||||||
|
taosMemoryFree(op);
|
||||||
|
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg->pCtg = pCtg;
|
||||||
|
tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
||||||
|
tstrncpy(msg->viewName, viewName, sizeof(msg->viewName));
|
||||||
|
msg->dbId = dbId;
|
||||||
|
|
||||||
|
op->data = msg;
|
||||||
|
|
||||||
|
CTG_ERR_JRET(ctgEnqueue(pCtg, op));
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
@ -2324,6 +2356,59 @@ _return:
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ctgOpDropViewMeta(SCtgCacheOperation *operation) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SCtgDropViewMetaMsg *msg = operation->data;
|
||||||
|
SCatalog *pCtg = msg->pCtg;
|
||||||
|
int32_t tblType = 0;
|
||||||
|
|
||||||
|
if (pCtg->stopUpdate) {
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
ctgGetDBCache(pCtg, msg->dbFName, &dbCache);
|
||||||
|
if (NULL == dbCache) {
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 != msg->dbId && dbCache->dbId != msg->dbId) {
|
||||||
|
ctgDebug("dbId 0x%" PRIx64 " not match with curId 0x%" PRIx64 ", dbFName:%s, viewName:%s", msg->dbId, dbCache->dbId,
|
||||||
|
msg->dbFName, msg->viewName);
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCtgViewCache *pViewCache = taosHashGet(dbCache->viewCache, msg->viewName, strlen(msg->viewName));
|
||||||
|
if (NULL == pViewCache) {
|
||||||
|
ctgDebug("view %s already not in cache", msg->viewName);
|
||||||
|
goto _return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t viewId = pViewCache->pMeta->viewId;
|
||||||
|
atomic_sub_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pViewCache->pMeta));
|
||||||
|
ctgFreeViewCacheImpl(pViewCache, true);
|
||||||
|
|
||||||
|
if (taosHashRemove(dbCache->viewCache, msg->viewName, strlen(msg->viewName))) {
|
||||||
|
ctgError("view %s not exist in cache, dbFName:%s", msg->viewName, msg->dbFName);
|
||||||
|
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||||
|
} else {
|
||||||
|
atomic_sub_fetch_64(&dbCache->dbCacheSize, sizeof(SCtgViewCache) + strlen(msg->viewName));
|
||||||
|
CTG_DB_NUM_DEC(CTG_CI_VIEW);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctgDebug("view %s removed from cache, dbFName:%s", msg->viewName, msg->dbFName);
|
||||||
|
|
||||||
|
CTG_ERR_JRET(ctgMetaRentRemove(&msg->pCtg->viewRent, viewId, ctgViewVersionSortCompare, ctgViewVersionSearchCompare));
|
||||||
|
|
||||||
|
ctgDebug("view %s removed from rent, dbFName:%s, viewId:0x%" PRIx64, msg->viewName, msg->dbFName, viewId);
|
||||||
|
|
||||||
|
_return:
|
||||||
|
|
||||||
|
taosMemoryFreeClear(msg);
|
||||||
|
|
||||||
|
CTG_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgClearFreeCache(SCtgCacheOperation *operation) {
|
void ctgClearFreeCache(SCtgCacheOperation *operation) {
|
||||||
SCtgClearCacheMsg *msg = operation->data;
|
SCtgClearCacheMsg *msg = operation->data;
|
||||||
|
@ -2427,6 +2512,7 @@ void ctgFreeCacheOperationData(SCtgCacheOperation *op) {
|
||||||
case CTG_OP_DROP_TB_META:
|
case CTG_OP_DROP_TB_META:
|
||||||
case CTG_OP_UPDATE_VG_EPSET:
|
case CTG_OP_UPDATE_VG_EPSET:
|
||||||
case CTG_OP_DROP_TB_INDEX:
|
case CTG_OP_DROP_TB_INDEX:
|
||||||
|
case CTG_OP_DROP_VIEW_META:
|
||||||
case CTG_OP_CLEAR_CACHE: {
|
case CTG_OP_CLEAR_CACHE: {
|
||||||
taosMemoryFreeClear(op->data);
|
taosMemoryFreeClear(op->data);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -253,6 +253,12 @@ int32_t ctgdEnableDebug(char *option, bool enable) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == strcasecmp(option, "stat")) {
|
||||||
|
gCTGDebug.statEnable = enable;
|
||||||
|
qDebug("catalog stat debug set to %d", enable);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
if (0 == strcasecmp(option, "stopUpdate")) {
|
if (0 == strcasecmp(option, "stopUpdate")) {
|
||||||
SCatalog *pCtg = NULL;
|
SCatalog *pCtg = NULL;
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,19 @@ void ctgFreeTbCacheImpl(SCtgTbCache* pCache, bool lock) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ctgFreeViewCacheImpl(SCtgViewCache* pCache, bool lock) {
|
||||||
|
if (lock) {
|
||||||
|
CTG_LOCK(CTG_WRITE, &pCache->viewLock);
|
||||||
|
}
|
||||||
|
if (pCache->pMeta) {
|
||||||
|
taosMemoryFree(pCache->pMeta->querySql);
|
||||||
|
taosMemoryFreeClear(pCache->pMeta);
|
||||||
|
}
|
||||||
|
if (lock) {
|
||||||
|
CTG_UNLOCK(CTG_WRITE, &pCache->viewLock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ctgFreeTbCache(SCtgDBCache* dbCache) {
|
void ctgFreeTbCache(SCtgDBCache* dbCache) {
|
||||||
if (NULL == dbCache->tbCache) {
|
if (NULL == dbCache->tbCache) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -467,6 +467,29 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
|
||||||
|
SSDataBlock* pBlock = createDataBlock();
|
||||||
|
if (NULL == pBlock) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD1_LEN, 1);
|
||||||
|
int32_t code = blockDataAppendColInfo(pBlock, &infoData);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD2_LEN, 2);
|
||||||
|
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pOutput = pBlock;
|
||||||
|
} else {
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||||
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
|
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
|
||||||
SSchema* pSchema = pCfg->pSchemas + i;
|
SSchema* pSchema = pCfg->pSchemas + i;
|
||||||
|
@ -710,6 +733,36 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
|
||||||
|
int32_t code = 0;
|
||||||
|
blockDataEnsureCapacity(pBlock, 1);
|
||||||
|
pBlock->info.rows = 1;
|
||||||
|
|
||||||
|
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
|
char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
|
||||||
|
snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
|
||||||
|
varDataSetLen(buf1, strlen(varDataVal(buf1)));
|
||||||
|
colDataSetVal(pCol1, 0, buf1, false);
|
||||||
|
|
||||||
|
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||||
|
char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
|
||||||
|
if (NULL == buf2) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
|
||||||
|
SViewMeta* pMeta = pStmt->pViewMeta;
|
||||||
|
snprintf(varDataVal(buf2), SHOW_CREATE_VIEW_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, "CREATE VIEW `%s`.`%s` AS %s", pStmt->dbName, pStmt->viewName, pMeta->querySql);
|
||||||
|
int32_t len = strlen(varDataVal(buf2));
|
||||||
|
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
||||||
|
colDataSetVal(pCol2, 0, buf2, false);
|
||||||
|
|
||||||
|
taosMemoryFree(buf2);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
SSDataBlock* pBlock = NULL;
|
SSDataBlock* pBlock = NULL;
|
||||||
int32_t code = buildCreateTbResultDataBlock(&pBlock);
|
int32_t code = buildCreateTbResultDataBlock(&pBlock);
|
||||||
|
@ -939,6 +992,19 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||||
|
SSDataBlock* pBlock = NULL;
|
||||||
|
int32_t code = buildCreateViewResultDataBlock(&pBlock);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = setCreateViewResultIntoDataBlock(pBlock, pStmt);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
|
||||||
|
}
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) {
|
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) {
|
||||||
switch (nodeType(pStmt)) {
|
switch (nodeType(pStmt)) {
|
||||||
case QUERY_NODE_DESCRIBE_STMT:
|
case QUERY_NODE_DESCRIBE_STMT:
|
||||||
|
@ -951,6 +1017,8 @@ int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieve
|
||||||
return execShowCreateTable((SShowCreateTableStmt*)pStmt, pRsp);
|
return execShowCreateTable((SShowCreateTableStmt*)pStmt, pRsp);
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return execShowCreateSTable((SShowCreateTableStmt*)pStmt, pRsp);
|
return execShowCreateSTable((SShowCreateTableStmt*)pStmt, pRsp);
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return execShowCreateView((SShowCreateViewStmt*)pStmt, pRsp);
|
||||||
case QUERY_NODE_ALTER_LOCAL_STMT:
|
case QUERY_NODE_ALTER_LOCAL_STMT:
|
||||||
return execAlterLocal((SAlterLocalStmt*)pStmt);
|
return execAlterLocal((SAlterLocalStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
|
|
|
@ -251,6 +251,8 @@ const char* nodesNodeName(ENodeType type) {
|
||||||
return "ShowCreateTablesStmt";
|
return "ShowCreateTablesStmt";
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return "ShowCreateStablesStmt";
|
return "ShowCreateStablesStmt";
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return "ShowCreateViewStmt";
|
||||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||||
return "ShowTableDistributedStmt";
|
return "ShowTableDistributedStmt";
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
|
@ -6593,6 +6595,33 @@ static int32_t jsonToShowCreateStableStmt(const SJson* pJson, void* pObj) {
|
||||||
return jsonToShowCreateTableStmt(pJson, pObj);
|
return jsonToShowCreateTableStmt(pJson, pObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* jkShowCreateViewStmtDbName = "DbName";
|
||||||
|
static const char* jkShowCreateViewStmtViewName = "ViewName";
|
||||||
|
|
||||||
|
static int32_t showCreateViewStmtToJson(const void* pObj, SJson* pJson) {
|
||||||
|
const SShowCreateViewStmt* pNode = (const SShowCreateViewStmt*)pObj;
|
||||||
|
|
||||||
|
int32_t code = tjsonAddStringToObject(pJson, jkShowCreateViewStmtDbName, pNode->dbName);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddStringToObject(pJson, jkShowCreateViewStmtViewName, pNode->viewName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int32_t jsonToShowCreateViewStmt(const SJson* pJson, void* pObj) {
|
||||||
|
SShowCreateViewStmt* pNode = (SShowCreateViewStmt*)pObj;
|
||||||
|
|
||||||
|
int32_t code = tjsonGetStringValue(pJson, jkShowCreateViewStmtDbName, pNode->dbName);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetStringValue(pJson, jkShowCreateViewStmtViewName, pNode->viewName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char* jkShowTableDistributedStmtDbName = "DbName";
|
static const char* jkShowTableDistributedStmtDbName = "DbName";
|
||||||
static const char* jkShowTableDistributedStmtTableName = "TableName";
|
static const char* jkShowTableDistributedStmtTableName = "TableName";
|
||||||
|
|
||||||
|
@ -6960,6 +6989,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
return showCreateTableStmtToJson(pObj, pJson);
|
return showCreateTableStmtToJson(pObj, pJson);
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return showCreateStableStmtToJson(pObj, pJson);
|
return showCreateStableStmtToJson(pObj, pJson);
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return showCreateViewStmtToJson(pObj, pJson);
|
||||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||||
return showTableDistributedStmtToJson(pObj, pJson);
|
return showTableDistributedStmtToJson(pObj, pJson);
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
|
@ -7281,6 +7312,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
||||||
return jsonToShowCreateTableStmt(pJson, pObj);
|
return jsonToShowCreateTableStmt(pJson, pObj);
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return jsonToShowCreateStableStmt(pJson, pObj);
|
return jsonToShowCreateStableStmt(pJson, pObj);
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return jsonToShowCreateViewStmt(pJson, pObj);
|
||||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||||
return jsonToShowTableDistributedStmt(pJson, pObj);
|
return jsonToShowTableDistributedStmt(pJson, pObj);
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
|
|
|
@ -452,6 +452,8 @@ SNode* nodesMakeNode(ENodeType type) {
|
||||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return makeNode(type, sizeof(SShowCreateTableStmt));
|
return makeNode(type, sizeof(SShowCreateTableStmt));
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return makeNode(type, sizeof(SShowCreateViewStmt));
|
||||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||||
return makeNode(type, sizeof(SShowTableDistributedStmt));
|
return makeNode(type, sizeof(SShowTableDistributedStmt));
|
||||||
case QUERY_NODE_KILL_QUERY_STMT:
|
case QUERY_NODE_KILL_QUERY_STMT:
|
||||||
|
@ -1085,6 +1087,7 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
taosMemoryFreeClear(((SShowCreateTableStmt*)pNode)->pDbCfg);
|
taosMemoryFreeClear(((SShowCreateTableStmt*)pNode)->pDbCfg);
|
||||||
destroyTableCfg((STableCfg*)(((SShowCreateTableStmt*)pNode)->pTableCfg));
|
destroyTableCfg((STableCfg*)(((SShowCreateTableStmt*)pNode)->pTableCfg));
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT: // no pointer field
|
||||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: // no pointer field
|
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: // no pointer field
|
||||||
case QUERY_NODE_KILL_CONNECTION_STMT: // no pointer field
|
case QUERY_NODE_KILL_CONNECTION_STMT: // no pointer field
|
||||||
case QUERY_NODE_KILL_QUERY_STMT: // no pointer field
|
case QUERY_NODE_KILL_QUERY_STMT: // no pointer field
|
||||||
|
@ -2370,4 +2373,4 @@ bool nodesIsStar(SNode* pNode) {
|
||||||
bool nodesIsTableStar(SNode* pNode) {
|
bool nodesIsTableStar(SNode* pNode) {
|
||||||
return (QUERY_NODE_COLUMN == nodeType(pNode)) && ('\0' != ((SColumnNode*)pNode)->tableAlias[0]) &&
|
return (QUERY_NODE_COLUMN == nodeType(pNode)) && ('\0' != ((SColumnNode*)pNode)->tableAlias[0]) &&
|
||||||
(0 == strcmp(((SColumnNode*)pNode)->colName, "*"));
|
(0 == strcmp(((SColumnNode*)pNode)->colName, "*"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,7 @@ SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, S
|
||||||
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||||
SNode* createShowAliveStmt(SAstCreateContext* pCxt, SNode* pDbName, ENodeType type);
|
SNode* createShowAliveStmt(SAstCreateContext* pCxt, SNode* pDbName, ENodeType type);
|
||||||
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
||||||
|
SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
||||||
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern);
|
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern);
|
||||||
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint);
|
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint);
|
||||||
|
|
|
@ -43,6 +43,7 @@ int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void
|
||||||
|
|
||||||
#ifdef TD_ENTERPRISE
|
#ifdef TD_ENTERPRISE
|
||||||
int32_t translateView(STranslateContext* pCxt, SNode** pTable, SName* pName);
|
int32_t translateView(STranslateContext* pCxt, SNode** pTable, SName* pName);
|
||||||
|
int32_t getViewMeta(STranslateContext* pCxt, SName* pName, SViewMeta** ppViewMeta);
|
||||||
#endif
|
#endif
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,6 +508,7 @@ cmd ::= SHOW VNODES.
|
||||||
cmd ::= SHOW db_name_cond_opt(A) ALIVE. { pCxt->pRootNode = createShowAliveStmt(pCxt, A, QUERY_NODE_SHOW_DB_ALIVE_STMT); }
|
cmd ::= SHOW db_name_cond_opt(A) ALIVE. { pCxt->pRootNode = createShowAliveStmt(pCxt, A, QUERY_NODE_SHOW_DB_ALIVE_STMT); }
|
||||||
cmd ::= SHOW CLUSTER ALIVE. { pCxt->pRootNode = createShowAliveStmt(pCxt, NULL, QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT); }
|
cmd ::= SHOW CLUSTER ALIVE. { pCxt->pRootNode = createShowAliveStmt(pCxt, NULL, QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT); }
|
||||||
cmd ::= SHOW db_name_cond_opt(A) VIEWS. { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VIEWS_STMT, A, NULL, OP_TYPE_LIKE); }
|
cmd ::= SHOW db_name_cond_opt(A) VIEWS. { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VIEWS_STMT, A, NULL, OP_TYPE_LIKE); }
|
||||||
|
cmd ::= SHOW CREATE VIEW full_table_name(A). { pCxt->pRootNode = createShowCreateViewStmt(pCxt, QUERY_NODE_SHOW_CREATE_VIEW_STMT, A); }
|
||||||
|
|
||||||
%type table_kind_db_name_cond_opt { SShowTablesOption }
|
%type table_kind_db_name_cond_opt { SShowTablesOption }
|
||||||
%destructor table_kind_db_name_cond_opt { }
|
%destructor table_kind_db_name_cond_opt { }
|
||||||
|
|
|
@ -1675,6 +1675,17 @@ SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) {
|
||||||
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
|
SShowCreateViewStmt* pStmt = (SShowCreateViewStmt*)nodesMakeNode(type);
|
||||||
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
|
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||||
|
strcpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName);
|
||||||
|
nodesDestroyNode(pRealTable);
|
||||||
|
return (SNode*)pStmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
|
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
|
||||||
CHECK_PARSER_STATUS(pCxt);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
SShowTableDistributedStmt* pStmt = (SShowTableDistributedStmt*)nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT);
|
SShowTableDistributedStmt* pStmt = (SShowTableDistributedStmt*)nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT);
|
||||||
|
|
|
@ -617,6 +617,23 @@ static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShow
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t collectMetaKeyFromShowCreateView(SCollectMetaKeyCxt* pCxt, SShowCreateViewStmt* pStmt) {
|
||||||
|
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
|
||||||
|
strcpy(name.dbname, pStmt->dbName);
|
||||||
|
strcpy(name.tname, pStmt->viewName);
|
||||||
|
int32_t code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, &name);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = reserveViewUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->viewName,
|
||||||
|
AUTH_TYPE_READ, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t collectMetaKeyFromShowApps(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
static int32_t collectMetaKeyFromShowApps(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_APPS,
|
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_APPS,
|
||||||
pCxt->pMetaCache);
|
pCxt->pMetaCache);
|
||||||
|
@ -783,6 +800,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
||||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return collectMetaKeyFromShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
|
return collectMetaKeyFromShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return collectMetaKeyFromShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_APPS_STMT:
|
case QUERY_NODE_SHOW_APPS_STMT:
|
||||||
return collectMetaKeyFromShowApps(pCxt, (SShowStmt*)pStmt);
|
return collectMetaKeyFromShowApps(pCxt, (SShowStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
||||||
|
|
|
@ -207,6 +207,12 @@ static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt)
|
||||||
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ, &pTagCond);
|
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ, &pTagCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t authShowCreateView(SAuthCxt* pCxt, SShowCreateViewStmt* pStmt) {
|
||||||
|
SNode* pTagCond = NULL;
|
||||||
|
// todo check tag condition for subtable
|
||||||
|
return checkViewAuth(pCxt, pStmt->dbName, pStmt->viewName, AUTH_TYPE_READ, &pTagCond);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
|
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
|
||||||
SNode* pTagCond = NULL;
|
SNode* pTagCond = NULL;
|
||||||
// todo check tag condition for subtable
|
// todo check tag condition for subtable
|
||||||
|
@ -302,6 +308,8 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return authShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
|
return authShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return authShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
|
||||||
case QUERY_NODE_CREATE_VIEW_STMT:
|
case QUERY_NODE_CREATE_VIEW_STMT:
|
||||||
return authCreateView(pCxt, (SCreateViewStmt*)pStmt);
|
return authCreateView(pCxt, (SCreateViewStmt*)pStmt);
|
||||||
case QUERY_NODE_DROP_VIEW_STMT:
|
case QUERY_NODE_DROP_VIEW_STMT:
|
||||||
|
|
|
@ -7603,6 +7603,16 @@ static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTabl
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateShowCreateView(STranslateContext* pCxt, SShowCreateViewStmt* pStmt) {
|
||||||
|
#ifndef TD_ENTERPRISE
|
||||||
|
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||||
|
#else
|
||||||
|
SName name;
|
||||||
|
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name);
|
||||||
|
return getViewMeta(pCxt, &name, (SViewMeta**)&pStmt->pViewMeta);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
switch (nodeType(pNode)) {
|
switch (nodeType(pNode)) {
|
||||||
|
@ -7761,6 +7771,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
code = translateShowCreateTable(pCxt, (SShowCreateTableStmt*)pNode);
|
code = translateShowCreateTable(pCxt, (SShowCreateTableStmt*)pNode);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
code = translateShowCreateView(pCxt, (SShowCreateViewStmt*)pNode);
|
||||||
|
break;
|
||||||
case QUERY_NODE_RESTORE_DNODE_STMT:
|
case QUERY_NODE_RESTORE_DNODE_STMT:
|
||||||
case QUERY_NODE_RESTORE_QNODE_STMT:
|
case QUERY_NODE_RESTORE_QNODE_STMT:
|
||||||
case QUERY_NODE_RESTORE_MNODE_STMT:
|
case QUERY_NODE_RESTORE_MNODE_STMT:
|
||||||
|
@ -7912,6 +7925,25 @@ static int32_t extractShowCreateTableResultSchema(int32_t* numOfCols, SSchema**
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||||
|
*numOfCols = SHOW_CREATE_VIEW_RESULT_COLS;
|
||||||
|
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||||
|
if (NULL == (*pSchema)) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*pSchema)[0].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
(*pSchema)[0].bytes = SHOW_CREATE_VIEW_RESULT_FIELD1_LEN;
|
||||||
|
strcpy((*pSchema)[0].name, "View");
|
||||||
|
|
||||||
|
(*pSchema)[1].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
(*pSchema)[1].bytes = SHOW_CREATE_VIEW_RESULT_FIELD2_LEN;
|
||||||
|
strcpy((*pSchema)[1].name, "Create View");
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||||
*numOfCols = 3;
|
*numOfCols = 3;
|
||||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||||
|
@ -7955,6 +7987,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS
|
||||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
return extractShowCreateTableResultSchema(numOfCols, pSchema);
|
return extractShowCreateTableResultSchema(numOfCols, pSchema);
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
|
return extractShowCreateViewResultSchema(numOfCols, pSchema);
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
case QUERY_NODE_SHOW_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_VARIABLES_STMT:
|
||||||
return extractShowVariablesResultSchema(numOfCols, pSchema);
|
return extractShowVariablesResultSchema(numOfCols, pSchema);
|
||||||
|
@ -9596,6 +9630,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
|
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
|
||||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||||
|
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||||
pQuery->execMode = QUERY_EXEC_MODE_LOCAL;
|
pQuery->execMode = QUERY_EXEC_MODE_LOCAL;
|
||||||
pQuery->haveResultSet = true;
|
pQuery->haveResultSet = true;
|
||||||
|
|
|
@ -831,9 +831,11 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = putTableDataToCache(pCatalogReq->pTableCfg, pMetaData->pTableCfg, &pMetaCache->pTableCfg);
|
code = putTableDataToCache(pCatalogReq->pTableCfg, pMetaData->pTableCfg, &pMetaCache->pTableCfg);
|
||||||
}
|
}
|
||||||
|
#ifdef TD_ENTERPRISE
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews);
|
code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
pMetaCache->pDnodes = pMetaData->pDnodeList;
|
pMetaCache->pDnodes = pMetaData->pDnodeList;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -84,6 +84,21 @@ TEST_F(ParserShowToUseTest, showCreateTable) {
|
||||||
run("SHOW CREATE TABLE t1");
|
run("SHOW CREATE TABLE t1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserShowToUseTest, showCreateView) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||||
|
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_SHOW_CREATE_VIEW_STMT);
|
||||||
|
ASSERT_EQ(pQuery->execMode, QUERY_EXEC_MODE_LOCAL);
|
||||||
|
ASSERT_TRUE(pQuery->haveResultSet);
|
||||||
|
ASSERT_NE(((SShowCreateViewStmt*)pQuery->pRoot)->pDbCfg, nullptr);
|
||||||
|
ASSERT_NE(((SShowCreateViewStmt*)pQuery->pRoot)->pTableCfg, nullptr);
|
||||||
|
});
|
||||||
|
|
||||||
|
run("SHOW CREATE VIEW view1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(ParserShowToUseTest, showDatabases) {
|
TEST_F(ParserShowToUseTest, showDatabases) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue