diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 62c1505ff0..b04c595d3a 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -311,7 +311,7 @@ static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatal } } - tFreeSViewHbRsp(&hbRsp); + //tFreeSViewHbRsp(&hbRsp); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index e1ad9fcd8c..06ea703ff7 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -1867,8 +1867,11 @@ int32_t ctgHandleGetViewsRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* CTG_ERR_JRET(code); } + ctgDebug("start to update view meta to cache, view:%s, querySQL:%s", pRsp->name, pRsp->querySql); ctgUpdateViewMetaToCache(pCtg, pRsp, false); - + pMsgCtx->out = NULL; + pRsp = NULL; + SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx); pRes->code = 0; pRes->pRes = pViewMeta; diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index cc16f9967a..30099de409 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -1311,6 +1311,16 @@ int32_t ctgUpdateViewMetaEnqueue(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncOp CTG_ERR_RET(ctgEnqueue(pCtg, op)); return TSDB_CODE_SUCCESS; + + +_return: + + if (pRsp) { + tFreeSViewMetaRsp(pRsp); + taosMemoryFree(pRsp); + } + + CTG_RET(code); } int32_t ctgDropViewMetaEnqueue(SCatalog *pCtg, const char *dbFName, uint64_t dbId, const char *viewName, uint64_t viewId, bool syncOp) { @@ -1646,7 +1656,8 @@ int32_t ctgWriteViewMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFN CTG_DB_NUM_INC(CTG_CI_VIEW); - ctgDebug("view %s meta updated to cache, ver:%d", viewName, pMeta->version); + ctgDebug("new view meta updated to cache, view:%s, id:%" PRIu64 ", ver:%d, effectiveUser:%s, querySQL:%s", + viewName, pMeta->viewId, pMeta->version, pMeta->user, pMeta->querySql); CTG_ERR_RET(ctgUpdateRentViewVersion(pCtg, dbFName, viewName, dbCache->dbId, pMeta->viewId, &cache)); @@ -1657,7 +1668,7 @@ int32_t ctgWriteViewMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFN if (pCache->pMeta) { atomic_sub_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pCache->pMeta)); - taosMemoryFree(pCache->pMeta->querySql); + ctgFreeSViewMeta(pCache->pMeta); taosMemoryFree(pCache->pMeta); } @@ -1666,7 +1677,8 @@ int32_t ctgWriteViewMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFN atomic_add_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pMeta)); - ctgDebug("view %s meta updated to cache, ver:%d", viewName, pMeta->version); + ctgDebug("view meta updated to cache, view:%s, id:%" PRIu64 ", ver:%d, effectiveUser:%s, querySQL:%s", + viewName, pMeta->viewId, pMeta->version, pMeta->user, pMeta->querySql); CTG_ERR_RET(ctgUpdateRentViewVersion(pCtg, dbFName, viewName, dbCache->dbId, pMeta->viewId, pCache)); @@ -2365,6 +2377,7 @@ int32_t ctgOpUpdateViewMeta(SCtgCacheOperation *operation) { } 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)); @@ -3087,8 +3100,8 @@ int32_t ctgGetViewsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgViewsC } memcpy(pViewMeta, pCache->pMeta, sizeof(*pViewMeta)); - pViewMeta->querySql = strdup(pCache->pMeta->querySql); - pViewMeta->user = strdup(pCache->pMeta->user); + pViewMeta->querySql = tstrdup(pCache->pMeta->querySql); + pViewMeta->user = tstrdup(pCache->pMeta->user); if (NULL == pViewMeta->querySql || NULL == pViewMeta->user) { ctgReleaseViewMetaToCache(pCtg, dbCache, pCache); pViewMeta->pSchema = NULL; diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index f147847494..62bc4a98fb 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -2233,11 +2233,11 @@ int32_t ctgBuildViewNullRes(SCtgTask* pTask, SCtgViewsCtx* pCtx) { } int32_t dupViewMetaFromRsp(SViewMetaRsp* pRsp, SViewMeta* pViewMeta) { - pViewMeta->querySql = strdup(pRsp->querySql); + pViewMeta->querySql = tstrdup(pRsp->querySql); if (NULL == pViewMeta->querySql) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } - pViewMeta->user = strdup(pRsp->user); + pViewMeta->user = tstrdup(pRsp->user); if (NULL == pViewMeta->user) { CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c index a4fa4192c8..d965f16862 100644 --- a/source/libs/executor/src/projectoperator.c +++ b/source/libs/executor/src/projectoperator.c @@ -152,9 +152,11 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL); setOperatorStreamStateFn(pOperator, streamOperatorReleaseState, streamOperatorReloadState); - code = appendDownstream(pOperator, &downstream, 1); - if (code != TSDB_CODE_SUCCESS) { - goto _error; + if (NULL != downstream) { + code = appendDownstream(pOperator, &downstream, 1); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } } return pOperator; @@ -263,7 +265,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { st = taosGetTimestampUs(); } - SOperatorInfo* downstream = pOperator->pDownstream[0]; + SOperatorInfo* downstream = pOperator->numOfDownstream > 0 ? pOperator->pDownstream[0] : NULL; SLimitInfo* pLimitInfo = &pProjectInfo->limitInfo; if (downstream == NULL) { diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 410db11a20..aee86e2383 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -2254,7 +2254,7 @@ SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pVie while (isspace(*(pAs->z + i))) { ++i; } - pStmt->pQuerySql = strdup(pAs->z + i); + pStmt->pQuerySql = tstrdup(pAs->z + i); CHECK_OUT_OF_MEM(pStmt->pQuerySql); strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName); strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index a30fb98405..52cf367565 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -4376,8 +4376,8 @@ static int32_t translateInsertTable(STranslateContext* pCxt, SNode** pTable) { int32_t code = translateFrom(pCxt, pTable); if (TSDB_CODE_SUCCESS == code && TSDB_CHILD_TABLE != ((SRealTableNode*)*pTable)->pMeta->tableType && TSDB_NORMAL_TABLE != ((SRealTableNode*)*pTable)->pMeta->tableType) { - code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, - "insert data into super table is not supported"); + code = buildInvalidOperationMsg(&pCxt->msgBuf, "insert data into super table is not supported"); + } return code; } @@ -7623,7 +7623,7 @@ static int32_t translateCreateView(STranslateContext* pCxt, SCreateViewStmt* pSt snprintf(pStmt->createReq.fullname, sizeof(pStmt->createReq.fullname) - 1, "%s.%s", pStmt->createReq.dbFName, pStmt->viewName); TSWAP(pStmt->createReq.querySql, pStmt->pQuerySql); pStmt->createReq.orReplace = pStmt->orReplace; - pStmt->createReq.sql = strdup(pCxt->pParseCxt->pSql); + pStmt->createReq.sql = tstrdup(pCxt->pParseCxt->pSql); if (NULL == pStmt->createReq.sql) { code = TSDB_CODE_OUT_OF_MEMORY; } @@ -7648,7 +7648,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 = strdup(pCxt->pParseCxt->pSql); + dropReq.sql = tstrdup(pCxt->pParseCxt->pSql); if (NULL == dropReq.sql) { return TSDB_CODE_OUT_OF_MEMORY; } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index bdb040d0c8..bf87803908 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -668,6 +668,8 @@ int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) { return TSDB_CODE_INVALID_MSG; } + qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql); + *(SViewMetaRsp **)output = out; return TSDB_CODE_SUCCESS; diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index adc3e9fd27..6945029718 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1543,6 +1543,15 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) { return DEAL_RES_IGNORE_CHILD; } + if (QUERY_NODE_VALUE == nType && ((SValueNode*)pNode)->node.resType.type == TSDB_DATA_TYPE_BOOL) { + if (((SValueNode*)pNode)->datum.b) { + FILTER_SET_FLAG(ctx->info->status, FI_STATUS_ALL); + } else { + FILTER_SET_FLAG(ctx->info->status, FI_STATUS_EMPTY); + } + return DEAL_RES_END; + } + fltError("invalid node type for filter, type:%d", nodeType(pNode)); code = TSDB_CODE_QRY_INVALID_INPUT; @@ -3450,7 +3459,9 @@ int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) { return code; _return: - qInfo("init from node failed, code:%d", code); + if (code) { + qInfo("init from node failed, code:%d", code); + } return code; } diff --git a/tests/script/tsim/view/insert_view.sim b/tests/script/tsim/view/insert_view.sim index 8be74a6b4d..48b7c75059 100644 --- a/tests/script/tsim/view/insert_view.sim +++ b/tests/script/tsim/view/insert_view.sim @@ -8,3 +8,8 @@ sql insert into ctat select * from view1; sql drop view view1; sql drop table ctat; +sql use information_schema; +sql create view view1 as select * from ins_dnodes; +sql_error insert into ins_dnodes select * from view1; +sql drop view view1; + diff --git a/tests/script/tsim/view/query_view.sim b/tests/script/tsim/view/query_view.sim index 1b48d7296e..c387245b27 100644 --- a/tests/script/tsim/view/query_view.sim +++ b/tests/script/tsim/view/query_view.sim @@ -2,6 +2,8 @@ sql connect sql use testa; sql create view view1 as select * from sta1; +sql explain select * from view1 order by ts; +sql explain analyze select * from view1 order by ts; sql select * from view1 order by ts; if $rows != 4 then return -1 @@ -14,6 +16,8 @@ if $data01 != 100111 then endi sql create or replace view view1 as select 1, 2; +sql explain select * from view1; +sql explain analyze select * from view1; sql select * from view1; if $rows != 1 then return -1 @@ -26,6 +30,8 @@ if $data01 != 2 then endi sql create or replace view view1 as select tbname as a, f from sta1; +sql explain select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b; +sql explain analyze select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b; sql select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b; if $rows != 3 then return -1 @@ -40,12 +46,21 @@ if $data20 != 100114 then return -1 endi -#sql create or replace view view1 as select tbname, avg(f) from sta1 partition by tbname; -#sql select * from view1 partition by view1.tbname; +sql create or replace view view1 as select tbname, avg(f) from sta1 partition by tbname; +sql explain select * from view1 partition by view1.tbname; +sql explain analyze select * from view1 partition by view1.tbname; +sql select * from view1 partition by view1.tbname; +if $rows != 4 then + return -1 +endi sql create or replace view view1 as select * from sta1; sql create or replace view testb.view2 as select * from testb.stb1; +sql_error explain select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114; +sql_error explain analyze select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114; sql_error select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114; +sql explain select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114; +sql explain analyze select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114; sql select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114; if $rows != 1 then return -1 @@ -58,8 +73,43 @@ if $data01 != 110112.000000000 then return -1 endi +sql create or replace view view3 as select t1.ts ts, t1.f a1, t2.f a2 from view1 t1, testb.view2 t2 where t1.ts = t2.ts; +sql create or replace view view4 as select t1.ts ts, t1.f a1, t2.f a2 from testa.st2 t1, testb.st2 t2 where t1.ts = t2.ts; +sql create view view5 as select t3.ts, cast((t3.a1 + t4.a1) as bigint), cast((t3.a2 - t4.a2) as bigint) from view3 t3, view4 t4 where t3.ts = t4.ts order by t3.ts; +sql explain select * from view5; +sql explain analyze select * from view5; +sql select * from view5; +if $rows != 4 then + return -1 +endi +if $data00 != @23-10-16 09:10:11.000@ then + print $data00 + return -1 +endi +if $data01 != 200332 then + return -1 +endi +if $data02 != -110 then + return -1 +endi +if $data11 != 200334 then + return -1 +endi +if $data21 != 200336 then + return -1 +endi +if $data31 != 200338 then + return -1 +endi + sql drop view testb.view2; +sql drop view view3; +sql drop view view4; +sql drop view view5; + 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; sql select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114; if $rows != 1 then return -1 @@ -82,6 +132,8 @@ sql create view view3a as select a.ts ts, a.f, b.f from view1 a join view2 b on sql create view view4 as select _wstart, avg(bf) - avg(af) as b from view3 interval(1s); sql_error create view view4a as select _wstart, avg(b.f) - avg(a.f) as b from view3 interval(1s); sql create view view5 as select count(*),avg(b) from view4 interval(1s) having avg(b) > 0; +sql explain select * from view5; +sql explain analyze select * from view5; sql select * from view5; if $rows != 4 then return -1 @@ -102,6 +154,8 @@ sql drop view view5; sql use information_schema; sql create view view1 as select * from ins_views; +sql explain select * from view1; +sql explain analyze select * from view1; sql select * from view1; if $rows != 1 then return -1 @@ -109,6 +163,8 @@ endi sql drop view view1; sql use testa; sql create view information_schema.view1 as select * from information_schema.ins_views; +sql explain select * from information_schema.view1; +sql explain analyze select * from information_schema.view1; sql select * from information_schema.view1; if $rows != 1 then return -1 @@ -118,6 +174,8 @@ sql drop view information_schema.view1; sql use testa; sql create view view1 as select * from st2; sql use testb; +sql explain select f from testa.view1 order by f; +sql explain analyze select f from testa.view1 order by f; sql select f from testa.view1 order by f; if $rows != 4 then return -1 @@ -130,3 +188,35 @@ if $data10 != 100222 then return -1 endi sql drop view testa.view1; + +sql use performance_schema; +sql create view view1 as select 1; +sql create view view2 as select 2; +sql create view view3 as select server_status(); +sql create view view4 as select conn_id from perf_connections where 0>1; +sql create view view5 as select abs(-1) a; +sql create view view6 as select 1 union select conn_id from perf_connections; +sql create view view7 as select 1 union select conn_id from perf_connections where 0>1; +sql create view view8 as select 1 union all select case when conn_id != 1 then conn_id else conn_id + 1 end from perf_connections; +sql explain select * from view1 union all select * from view2 union all select * from view3 union all select * from view4 union all select a from view5 union all select * from view6 union all select * from view7 union all select * from view8; +sql explain analyze select * from view1 union all select * from view2 union all select * from view3 union all select * from view4 union all select a from view5 union all select * from view6 union all select * from view7 union all select * from view8; +sql select * from view1 union all select * from view2 union all select * from view3 union all select * from view4 union all select a from view5 union all select * from view6 union all select * from view7 union all select * from view8; +sql explain select * from view1 union select a from view5; +sql explain analyze select * from view1 union select a from view5; +sql select * from view1 union select a from view5; +if $rows != 1 then + return -1 +endi +if $data00 != 1 then + print $data00 + return -1 +endi +sql drop view view1; +sql drop view view2; +sql drop view view3; +sql drop view view4; +sql drop view view5; +sql drop view view6; +sql drop view view7; +sql drop view view8; + diff --git a/tests/script/tsim/view/view.sim b/tests/script/tsim/view/view.sim index a673977ac8..8302428713 100644 --- a/tests/script/tsim/view/view.sim +++ b/tests/script/tsim/view/view.sim @@ -41,6 +41,8 @@ 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 print ================== restart server to commit data into disk system sh/exec.sh -n dnode1 -s stop -x SIGINT @@ -51,5 +53,7 @@ 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 -#system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s stop -x SIGINT