diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index b92674fc26..2745f7c15b 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -11875,11 +11875,18 @@ static int32_t checkShowTags(STranslateContext* pCxt, const SShowStmt* pShow) { toName(pCxt->pParseCxt->acctId, ((SValueNode*)pShow->pDbName)->literal, ((SValueNode*)pShow->pTbName)->literal, &name), &pTableMeta, true); - taosMemoryFreeClear(pTableMeta); if (TSDB_CODE_SUCCESS != code) { - return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); + code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code)); + goto _exit; + } + if (TSDB_SUPER_TABLE != pTableMeta->tableType && TSDB_CHILD_TABLE != pTableMeta->tableType) { + code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAGS_PC, + "The _TAGS pseudo column can only be used for child table and super table queries"); + goto _exit; } +_exit: + taosMemoryFreeClear(pTableMeta); return code; } diff --git a/tests/system-test/0-others/show_tag_index.py b/tests/system-test/0-others/show_tag_index.py index 1a7e6dca2c..d84d4193c4 100644 --- a/tests/system-test/0-others/show_tag_index.py +++ b/tests/system-test/0-others/show_tag_index.py @@ -121,6 +121,11 @@ class TDTestCase: tdSql.error(f'show tags from tb_undef from db', expectErrInfo='Fail to get table info, error: Table does not exist') tdSql.error(f'show tags from db.tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') tdSql.error(f'show tags from tb_undef', expectErrInfo='Fail to get table info, error: Table does not exist') + tdSql.error(f'show tags from ntb', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtb', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtb1', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtb2', expectErrInfo='Tags can only applied to super table and child table') + tdSql.error(f'show tags from vtbn', expectErrInfo='Tags can only applied to super table and child table') # show table tags tdSql.query(f'show table tags from stb')