From c5b37377026167e2abac828617d4182296fc715f Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Sun, 23 Apr 2023 11:21:01 +0800 Subject: [PATCH] fix: forbid delete from system table --- include/common/systable.h | 1 + source/common/src/systable.c | 4 ++++ source/libs/planner/src/planLogicCreater.c | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/common/systable.h b/include/common/systable.h index 558a1ca297..6e0c67bb3f 100644 --- a/include/common/systable.h +++ b/include/common/systable.h @@ -77,6 +77,7 @@ void getInfosDbMeta(const SSysTableMeta** pInfosTableMeta, size_t* size); void getPerfDbMeta(const SSysTableMeta** pPerfsTableMeta, size_t* size); void getVisibleInfosTablesNum(bool sysInfo, size_t* size); bool invisibleColumn(bool sysInfo, int8_t tableType, int8_t flags); +bool isSystemDb(const char *dbName); #ifdef __cplusplus } diff --git a/source/common/src/systable.c b/source/common/src/systable.c index cd3dd63ef0..de95a4a5be 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -448,3 +448,7 @@ bool invisibleColumn(bool sysInfo, int8_t tableType, int8_t flags) { } return 0 != (flags & COL_IS_SYSINFO); } + +bool isSystemDb(const char *dbName) { + return ((strcasecmp(dbName, TSDB_INFORMATION_SCHEMA_DB) == 0) || (strcasecmp(dbName, TSDB_PERFORMANCE_SCHEMA_DB) == 0)); +} diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index c9ee83a647..9e03095d2e 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -1442,8 +1442,12 @@ static int32_t createDeleteRootLogicNode(SLogicPlanContext* pCxt, SDeleteStmt* p } static int32_t createDeleteScanLogicNode(SLogicPlanContext* pCxt, SDeleteStmt* pDelete, SLogicNode** pLogicNode) { + if (isSystemDb(((SRealTableNode*)pDelete->pFromTable)->table.dbName)) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + SScanLogicNode* pScan = NULL; - int32_t code = makeScanLogicNode(pCxt, (SRealTableNode*)pDelete->pFromTable, false, (SLogicNode**)&pScan); + int32_t code = makeScanLogicNode(pCxt, (SRealTableNode*)pDelete->pFromTable, false, (SLogicNode**)&pScan); // set columns to scan if (TSDB_CODE_SUCCESS == code) {