Optimize the error msg when drop extension.

This commit is contained in:
TotaJ
2021-07-27 14:48:44 +08:00
parent 4f82829807
commit de60393fd9
6 changed files with 46 additions and 32 deletions

View File

@ -55,6 +55,35 @@ static bool CheckObjectDropPrivilege(ObjectType removeType, Oid objectId)
}
return (aclresult == ACLCHECK_OK) ? true : false;
}
static void DropExtensionIsSupported(List* objname)
{
static const char *supportList[] = {
"postgis",
"packages",
#ifndef ENABLE_MULTIPLE_NODES
"mysql_fdw",
"oracle_fdw",
"postgres_fdw",
"dblink",
"db_a_parser",
"db_b_parser",
"db_c_parser",
"db_pg_parser",
#endif
};
int len = lengthof(supportList);
const char* name = strVal(linitial(objname));
for (int i = 0; i < len; i++) {
if (pg_strcasecmp(name, supportList[i]) == 0) {
return;
}
}
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("EXTENSION is not yet supported.")));
}
/*
* @Description: drop one or more objects.
* We don't currently handle all object types here. Relations, for example,
@ -97,6 +126,8 @@ void RemoveObjects(DropStmt* stmt, bool missing_ok, bool is_securityadmin)
missing_ok = stmt->missing_ok;
does_not_exist_skipping(stmt->removeType, objname, objargs, missing_ok);
continue;
} else if (stmt->removeType == OBJECT_EXTENSION) {
DropExtensionIsSupported(objname);
}
/*

View File

@ -9445,30 +9445,6 @@ bool IsVariableinBlackList(const char* name)
return isInBlackList;
}
/*
* return true if the extension can be uninstall
*/
bool DropExtensionIsSupported(const char* query_string)
{
char* lower_string = lowerstr(query_string);
#ifndef ENABLE_MULTIPLE_NODES
if (strstr(lower_string, "drop") && (strstr(lower_string, "postgis") || strstr(lower_string, "packages") ||
strstr(lower_string, "mysql_fdw") || strstr(lower_string, "oracle_fdw") ||
strstr(lower_string, "postgres_fdw") || strstr(lower_string, "dblink") ||
strstr(lower_string, "db_b_parser") || strstr(lower_string, "db_a_parser") ||
strstr(lower_string, "db_c_parser") || strstr(lower_string, "db_pg_parser"))) {
#else
if (strstr(lower_string, "drop") && (strstr(lower_string, "postgis") || strstr(lower_string, "packages"))) {
#endif
pfree_ext(lower_string);
return true;
} else {
pfree_ext(lower_string);
return false;
}
}
/*
* Check if the object is in blacklist, if true, ALTER/DROP operation of the object is disabled.
* Note that only prescribed extensions are able droppable.
@ -9480,12 +9456,8 @@ void CheckObjectInBlackList(ObjectType obj_type, const char* query_string)
switch (obj_type) {
case OBJECT_EXTENSION:
tag = "EXTENSION";
/* Check if the extension is provided officially */
if (DropExtensionIsSupported(query_string))
return;
else
break;
/* Check black list in RemoveObjects */
return;
#ifdef ENABLE_MULTIPLE_NODES
case OBJECT_AGGREGATE:
tag = "AGGREGATE";

View File

@ -262,7 +262,7 @@ void ThreadPoolControler::ParseBindCpu()
bindNum = ParseRangeStr(psave, m_cpuInfo.isBindCpuArr, m_cpuInfo.totalCpuNum, "cpubind");
} else if (strncmp("nodebind", ptoken, strlen("nodebind")) == 0) {
m_cpuInfo.bindType = NODE_BIND;
m_cpuInfo.isBindNumaArr = (bool*)palloc0(sizeof(bool) * m_cpuInfo.totalCpuNum);
m_cpuInfo.isBindNumaArr = (bool*)palloc0(sizeof(bool) * m_cpuInfo.totalNumaNum);
bindNum = ParseRangeStr(psave, m_cpuInfo.isBindNumaArr, m_cpuInfo.totalNumaNum, "nodebind");
} else {
INVALID_ATTR_ERROR(errdetail("Only 'nobind', 'allbind', 'cpubind', and 'nodebind' are valid attribute."));

View File

@ -127,10 +127,16 @@ NOTICE: text search configuration "test_tsconfig_exists" does not exist, skippi
CREATE TEXT SEARCH CONFIGURATION test_tsconfig_exists (COPY=english);
DROP TEXT SEARCH CONFIGURATION test_tsconfig_exists;
-- extension
-- doesn't exists
DROP EXTENSION test_extension_exists;
ERROR: extension "test_extension_exists" does not exist
DROP EXTENSION IF EXISTS test_extension_exists;
NOTICE: extension "test_extension_exists" does not exist, skipping
-- exists but doesn't support drop
DROP EXTENSION plpgsql;
ERROR: EXTENSION is not yet supported.
DROP EXTENSION IF EXISTS plpgsql;
ERROR: EXTENSION is not yet supported.
-- functions
DROP FUNCTION test_function_exists();
ERROR: function test_function_exists does not exist

View File

@ -483,7 +483,8 @@ test: copyselect copy_error_log
# Another group of parallel tests
# ----------
test: create_function_3 vacuum
#test: constraints drop_if_exists
test: drop_if_exists
#test: constraints
#test: errors subplan_base
test: subplan_new

View File

@ -142,8 +142,12 @@ CREATE TEXT SEARCH CONFIGURATION test_tsconfig_exists (COPY=english);
DROP TEXT SEARCH CONFIGURATION test_tsconfig_exists;
-- extension
-- doesn't exists
DROP EXTENSION test_extension_exists;
DROP EXTENSION IF EXISTS test_extension_exists;
-- exists but doesn't support drop
DROP EXTENSION plpgsql;
DROP EXTENSION IF EXISTS plpgsql;
-- functions
DROP FUNCTION test_function_exists();