Skip to content

Commit

Permalink
fix mem bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon9997 committed Jan 21, 2025
1 parent dd2078d commit 8d2eac3
Show file tree
Hide file tree
Showing 8 changed files with 95,478 additions and 3 deletions.
3 changes: 3 additions & 0 deletions source/libs/catalog/src/ctgAsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,7 @@ int32_t ctgHandleGetTbMetasRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBu
pRes->code = 0;
pRes->pRes = pOut->tbMeta;
pOut->tbMeta = NULL;
pOut->vctbMeta = NULL;
if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) {
TSWAP(pTask->res, ctx->pResList);
taskDone = true;
Expand Down Expand Up @@ -2136,8 +2137,10 @@ static int32_t ctgHandleGetTbNamesRsp(SCtgTaskReq* tReq, int32_t reqType, const
if (!pRes->pRes) {
pRes->code = 0;
pRes->pRes = pOut->tbMeta;
pOut->vctbMeta = NULL;
pOut->tbMeta = NULL;
} else {
taosMemoryFreeClear(pOut->vctbMeta);
taosMemoryFreeClear(pOut->tbMeta);
}

Expand Down
5 changes: 5 additions & 0 deletions source/libs/parser/src/parAstParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ static int32_t collectMetaKeyFromCreateVSubTable(SCollectMetaKeyCxt* pCxt, SCrea
// check org table's read auth
SNode *pNode = NULL;
SNodeList *pTmpNodeList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
if (NULL == pTmpNodeList) {
// no column reference
return TSDB_CODE_SUCCESS;
}

FOREACH(pNode, pTmpNodeList) {
SColumnRefNode *pColRef = (SColumnRefNode*)pNode;
if (NULL == pColRef) {
Expand Down
5 changes: 5 additions & 0 deletions source/libs/parser/src/parAuthenticator.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ static int32_t authCreateVSubTable(SAuthCxt* pCxt, SCreateVSubTableStmt* pStmt)
SNode *pNode = NULL;
SNodeList* pTmpList = pStmt->pSpecificColRefs ? pStmt->pSpecificColRefs : pStmt->pColRefs;
PAR_ERR_RET(checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL));
if (NULL == pTmpList) {
// no column reference
return TSDB_CODE_SUCCESS;
}

FOREACH(pNode, pTmpList) {
SColumnRefNode *pColRef = (SColumnRefNode*)pNode;
if (NULL == pColRef) {
Expand Down
11 changes: 8 additions & 3 deletions source/libs/parser/src/parTranslater.c
Original file line number Diff line number Diff line change
Expand Up @@ -3210,7 +3210,8 @@ static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SNode** pp
if (!isSelectStmt(pCxt->pCurrStmt) || NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
}
if (QUERY_NODE_REAL_TABLE != nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
if (QUERY_NODE_REAL_TABLE != nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) &&
QUERY_NODE_VIRTUAL_TABLE != nodeType(((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
*pRewriteToColumn = true;
return rewriteToColumnAndRetranslate(pCxt, ppNode, TSDB_CODE_PAR_INVALID_TBNAME);
}
Expand Down Expand Up @@ -14769,13 +14770,15 @@ static int32_t buildVirtualSubTableBatchReq(const SCreateVSubTableStmt* pStmt, S
}
PAR_ERR_JRET(setColRef(&req.colRef.pColRef[pSchema->colId - 1], pSchema->colId, pColRef->refColName, pColRef->refTableName));
}
} else {
} else if (pStmt->pColRefs){
col_id_t index = 1; // start from second column, don't set column ref for ts column
FOREACH(pCol, pStmt->pColRefs) {
SColumnRefNode* pColRef = (SColumnRefNode*)pCol;
PAR_ERR_JRET(setColRef(&req.colRef.pColRef[index], index + 1, pColRef->refColName, pColRef->refTableName));
index++;
}
} else {
// no column reference.
}

pBatch->info = *pVgroupInfo;
Expand Down Expand Up @@ -17056,7 +17059,7 @@ static int32_t rewriteCreateVirtualSubTable(STranslateContext* pCxt, SQuery* pQu
PAR_ERR_JRET(checkColRef(pCxt, pStmt->dbName, pColRef->refTableName, pColRef->refColName,
(SDataType){.type = pSchema->type, .bytes = pSchema->bytes}));
}
} else {
} else if (pStmt->pColRefs) {
int32_t index = 1;
FOREACH(pCol, pStmt->pColRefs) {
SColumnRefNode* pColRef = (SColumnRefNode*)pCol;
Expand All @@ -17065,6 +17068,8 @@ static int32_t rewriteCreateVirtualSubTable(STranslateContext* pCxt, SQuery* pQu
.bytes = pSuperTableMeta->schema[index].bytes}));
index++;
}
} else {
// no column reference, do nothing
}

PAR_ERR_JRET(getTableHashVgroupImpl(pCxt, &name, &info));
Expand Down
5 changes: 5 additions & 0 deletions source/libs/planner/src/planLogicCreater.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,11 @@ static int32_t createVirtualTableLogicNode(SLogicPlanContext* pCxt, SSelectStmt*
PLAN_ERR_JRET(nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pVirtualTable->table.tableAlias, COLLECT_COL_TYPE_TAG,
&pVtableScan->pScanPseudoCols));

PLAN_ERR_JRET(nodesCollectFuncs(pSelect, SQL_CLAUSE_FROM, pVirtualTable->table.tableAlias, fmIsScanPseudoColumnFunc,
&pVtableScan->pScanPseudoCols));

PLAN_ERR_JRET(rewriteExprsForSelect(pVtableScan->pScanPseudoCols, pSelect, SQL_CLAUSE_FROM, NULL));

SNode *pNode = NULL;
int32_t slotId = 0;
bool onlyTs = true;
Expand Down
95,333 changes: 95,333 additions & 0 deletions tests/army/vtable/ans/test_vctable_select_test_projection.ans

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions tests/army/vtable/in/test_vctable_select_test_projection.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
select * from test_vtable_select.vtb_virtual_ctb_full;
select * from test_vtable_select.vtb_virtual_ctb_half_full;
select * from test_vtable_select.vtb_virtual_ctb_empty;
select ts from test_vtable_select.vtb_virtual_ctb_full;
select ts from test_vtable_select.vtb_virtual_ctb_half_full;
select ts from test_vtable_select.vtb_virtual_ctb_empty;
select u_tinyint_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col, bool_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col, bool_col, binary_16_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col, bool_col, binary_16_col, nchar_16_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select u_tinyint_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col, bool_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col, bool_col, binary_16_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select u_tinyint_col, u_smallint_col, u_int_col, u_bigint_col, float_col, double_col, bool_col, binary_16_col, nchar_16_col from test_vtable_select.vtb_virtual_ctb_half_full limit 100;
select ts, u_tinyint_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select double_col from test_vtable_select.vtb_virtual_ctb_half_full;
select double_col from test_vtable_select.vtb_virtual_ctb_empty;

select int_tag from test_vtable_select.vtb_virtual_ctb_full limit 100;
select int_tag, bool_tag, float_tag, double_tag, nchar_32_tag, binary_32_tag from test_vtable_select.vtb_virtual_ctb_full limit 100;
select int_tag, bool_tag, * from test_vtable_select.vtb_virtual_ctb_full limit 100;
select int_tag, bool_tag, ts from test_vtable_select.vtb_virtual_ctb_full limit 100;
select int_tag, bool_tag, u_tinyint_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select int_tag, bool_tag, u_tinyint_col, u_smallint_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select int_tag, bool_tag, u_tinyint_col, u_smallint_col, u_int_col from test_vtable_select.vtb_virtual_ctb_full limit 100;
select count(*) from (select int_tag from test_vtable_select.vtb_virtual_ctb_full);
select count(*) from (select int_tag, bool_tag, float_tag, double_tag, nchar_32_tag, binary_32_tag from test_vtable_select.vtb_virtual_ctb_full);
select count(*) from (select int_tag, bool_tag, * from test_vtable_select.vtb_virtual_ctb_full);
select count(*) from (select int_tag, bool_tag, ts from test_vtable_select.vtb_virtual_ctb_full);
select count(*) from (select int_tag, bool_tag, u_tinyint_col from test_vtable_select.vtb_virtual_ctb_full);
select count(*) from (select int_tag, bool_tag, u_tinyint_col, u_smallint_col from test_vtable_select.vtb_virtual_ctb_full);
select count(*) from (select int_tag, bool_tag, u_tinyint_col, u_smallint_col, u_int_col from test_vtable_select.vtb_virtual_ctb_full);

76 changes: 76 additions & 0 deletions tests/army/vtable/test_vtable_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,66 @@ def prepare_org_tables(self):
"nchar_16_col nchar(16),"
"nchar_32_col nchar(32))")

tdSql.execute(f"CREATE STABLE `vtb_virtual_stb` ("
"ts timestamp, "
"u_tinyint_col tinyint unsigned, "
"u_smallint_col smallint unsigned, "
"u_int_col int unsigned, "
"u_bigint_col bigint unsigned, "
"tinyint_col tinyint, "
"smallint_col smallint, "
"int_col int, "
"bigint_col bigint, "
"float_col float, "
"double_col double, "
"bool_col bool, "
"binary_16_col binary(16),"
"binary_32_col binary(32),"
"nchar_16_col nchar(16),"
"nchar_32_col nchar(32)"
") TAGS ("
"int_tag int,"
"bool_tag bool,"
"float_tag float,"
"double_tag double,"
"nchar_32_tag nchar(32),"
"binary_32_tag binary(32))"
"VIRTUAL 1")

tdLog.info(f"prepare virtual child table.")

tdSql.execute(f"CREATE VTABLE `vtb_virtual_ctb_full` ("
"u_tinyint_col from vtb_org_normal_0.u_tinyint_col, "
"u_smallint_col from vtb_org_normal_1.u_smallint_col, "
"u_int_col from vtb_org_normal_2.u_int_col, "
"u_bigint_col from vtb_org_normal_0.u_bigint_col, "
"tinyint_col from vtb_org_normal_1.tinyint_col, "
"smallint_col from vtb_org_normal_2.smallint_col, "
"int_col from vtb_org_normal_0.int_col, "
"bigint_col from vtb_org_normal_1.bigint_col, "
"float_col from vtb_org_normal_2.float_col, "
"double_col from vtb_org_normal_0.double_col, "
"bool_col from vtb_org_normal_1.bool_col, "
"binary_16_col from vtb_org_normal_2.binary_16_col,"
"binary_32_col from vtb_org_normal_0.binary_32_col,"
"nchar_16_col from vtb_org_normal_1.nchar_16_col,"
"nchar_32_col from vtb_org_normal_2.nchar_32_col)"
"USING `vtb_virtual_stb` TAGS (0, false, 0, 0, 'child0', 'child0')")

tdSql.execute(f"CREATE VTABLE `vtb_virtual_ctb_half_full` ("
"u_tinyint_col from vtb_org_normal_0.u_tinyint_col, "
"u_smallint_col from vtb_org_normal_1.u_smallint_col, "
"u_int_col from vtb_org_normal_2.u_int_col, "
"int_col from vtb_org_normal_0.int_col, "
"bigint_col from vtb_org_normal_1.bigint_col, "
"float_col from vtb_org_normal_2.float_col, "
"binary_32_col from vtb_org_normal_0.binary_32_col,"
"nchar_16_col from vtb_org_normal_1.nchar_16_col,"
"nchar_32_col from vtb_org_normal_2.nchar_32_col)"
"USING `vtb_virtual_stb` TAGS (1, false, 1, 1, 'child1', 'child1')")

tdSql.execute(f"CREATE VTABLE `vtb_virtual_ctb_empty` "
"USING `vtb_virtual_stb` TAGS (2, false, 2, 2, 'child2', 'child2')")

def test_normal_query(self, testCase):
# read sql from .sql file and execute
Expand Down Expand Up @@ -194,11 +254,27 @@ def test_select_virtual_normal_table(self):
self.test_normal_query("test_vtable_select_test_group")
self.test_normal_query("test_vtable_select_test_orderby")

def test_select_virtual_child_table(self):

self.test_normal_query("test_vctable_select_test_projection")
#self.test_normal_query("test_vtable_select_test_projection_filter")
#self.test_normal_query("test_vtable_select_test_function")

#self.test_normal_query("test_vtable_select_test_interval")
#self.test_normal_query("test_vtable_select_test_state")
#self.test_normal_query("test_vtable_select_test_session")
#self.test_normal_query("test_vtable_select_test_event")
#self.test_normal_query("test_vtable_select_test_count")

#self.test_normal_query("test_vtable_select_test_partition")
#self.test_normal_query("test_vtable_select_test_group")
#self.test_normal_query("test_vtable_select_test_orderby")
def run(self):
tdLog.debug(f"start to excute {__file__}")

self.prepare_org_tables()
self.test_select_virtual_normal_table()
# self.test_select_virtual_child_table()


tdLog.success(f"{__file__} successfully executed")
Expand Down

0 comments on commit 8d2eac3

Please sign in to comment.