提交 807a7c0b 编写于 作者: R rq0 提交者: wangzelin.wzl

modify mysql information_schema views

上级 81ec0c13
......@@ -597,6 +597,46 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const ObString& database_name, cons
break;
}
case PRIVILEGES: {
char *buf = NULL;
int64_t buf_len = 200;
int64_t pos = 0;
ObSessionPrivInfo session_priv;
session_->get_session_priv_info(session_priv);
if (OB_UNLIKELY(!session_priv.is_valid())) {
ret = OB_INVALID_ARGUMENT;
SERVER_LOG(WARN,
"session priv is invalid",
"tenant_id",
session_priv.tenant_id_,
"user_id",
session_priv.user_id_,
K(ret));
} else if (OB_ISNULL(buf = static_cast<char *>(allocator_->alloc(buf_len)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
SERVER_LOG(WARN, "fail to allocate memory", K(ret));
} else {
ObNeedPriv need_priv(
database_name, table_schema->get_table_name(), OB_PRIV_TABLE_LEVEL, OB_PRIV_SELECT, false);
if (OB_FAIL(fill_col_privs(session_priv, need_priv, OB_PRIV_SELECT, "select,", buf, buf_len, pos))) {
SERVER_LOG(WARN, "fail to fill col priv", K(need_priv), K(ret));
} else if (OB_FAIL(
fill_col_privs(session_priv, need_priv, OB_PRIV_INSERT, "insert,", buf, buf_len, pos))) {
SERVER_LOG(WARN, "fail to fill col priv", K(need_priv), K(ret));
} else if (OB_FAIL(
fill_col_privs(session_priv, need_priv, OB_PRIV_UPDATE, "update,", buf, buf_len, pos))) {
SERVER_LOG(WARN, "fail to fill col priv", K(need_priv), K(ret));
} else if (OB_FAIL(fill_col_privs(
session_priv, need_priv, OB_PRIV_REFERENCES, "reference,", buf, buf_len, pos))) {
SERVER_LOG(WARN, "fail to fill col priv", K(need_priv), K(ret));
} else {
if (pos > 0) {
cur_row_.cells_[cell_idx].set_varchar(ObString(0, pos - 1, buf));
} else {
cur_row_.cells_[cell_idx].set_varchar(ObString(""));
}
cells[cell_idx].set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
}
}
break;
}
case COLUMN_COMMENT: {
......@@ -630,5 +670,22 @@ int ObInfoSchemaColumnsTable::fill_row_cells(const ObString& database_name, cons
return ret;
}
int ObInfoSchemaColumnsTable::fill_col_privs(ObSessionPrivInfo &session_priv, ObNeedPriv &need_priv, ObPrivSet priv_set,
const char *priv_str, char *buf, const int64_t buf_len, int64_t &pos)
{
int ret = OB_SUCCESS;
need_priv.priv_set_ = priv_set;
if (OB_ISNULL(schema_guard_)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "data member is not init", KP(schema_guard_), K(ret));
} else if (OB_SUCC(schema_guard_->check_single_table_priv(session_priv, need_priv))) {
ret = databuff_printf(buf, buf_len, pos, "%s", priv_str);
} else if (OB_ERR_NO_TABLE_PRIVILEGE == ret) {
ret = OB_SUCCESS;
}
return ret;
}
} // namespace observer
} // namespace oceanbase
......@@ -83,8 +83,10 @@ private:
* If ob_sql_type_str failed to call, and the error code returned is OB_SIZE_OVERFLOW.
* realloc memory to the size of OB_MAX_EXTENDED_TYPE_INFO_LENGTH, then try again
*/
int get_type_str(const ObObjMeta& obj_meta, const ObAccuracy& accuracy, const common::ObIArray<ObString>& type_info,
const int16_t default_length_semantics, int64_t& pos);
int get_type_str(const ObObjMeta &obj_meta, const ObAccuracy &accuracy, const common::ObIArray<ObString> &type_info,
const int16_t default_length_semantics, int64_t &pos);
int fill_col_privs(ObSessionPrivInfo &session_priv, ObNeedPriv &need_priv, ObPrivSet priv_set, const char *priv_str,
char *buf, const int64_t buf_len, int64_t &pos);
private:
uint64_t tenant_id_;
......
......@@ -164,7 +164,7 @@ int ObInnerTableSchema::schemata_schema(ObTableSchema &table_schema)
table_schema.set_create_mem_version(1);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT 'def' AS CATALOG_NAME, DATABASE_NAME AS SCHEMA_NAME, 'utf8mb4' AS DEFAULT_CHARACTER_SET_NAME, 'utf8mb4_general_ci' AS DEFAULT_COLLATION_NAME, NULL AS SQL_PATH FROM oceanbase.__all_virtual_database a WHERE a.tenant_id = effective_tenant_id() and in_recyclebin = 0 and database_name != '__recyclebin' )__"))) {
if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT 'def' AS CATALOG_NAME, DATABASE_NAME AS SCHEMA_NAME, 'utf8mb4' AS DEFAULT_CHARACTER_SET_NAME, 'utf8mb4_general_ci' AS DEFAULT_COLLATION_NAME, NULL AS SQL_PATH, 'NO' as DEFAULT_ENCRYPTION FROM oceanbase.__all_virtual_database a WHERE a.tenant_id = effective_tenant_id() and in_recyclebin = 0 and database_name != '__recyclebin' )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}
......
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#define USING_LOG_PREFIX SHARE_SCHEMA
#include "ob_inner_table_schema.h"
#include "share/schema/ob_schema_macro_define.h"
#include "share/schema/ob_schema_service_sql_impl.h"
#include "share/schema/ob_table_schema.h"
namespace oceanbase
{
using namespace share::schema;
using namespace common;
namespace share
{
int ObInnerTableSchema::column_privileges_schema(ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
uint64_t column_id = OB_APP_MIN_COLUMN_ID - 1;
//generated fields:
table_schema.set_tenant_id(OB_SYS_TENANT_ID);
table_schema.set_tablegroup_id(OB_INVALID_ID);
table_schema.set_database_id(combine_id(OB_SYS_TENANT_ID, OB_INFORMATION_SCHEMA_ID));
table_schema.set_table_id(combine_id(OB_SYS_TENANT_ID, OB_COLUMN_PRIVILEGES_TID));
table_schema.set_rowkey_split_pos(0);
table_schema.set_is_use_bloomfilter(false);
table_schema.set_progressive_merge_num(0);
table_schema.set_rowkey_column_num(0);
table_schema.set_load_type(TABLE_LOAD_TYPE_IN_DISK);
table_schema.set_table_type(SYSTEM_VIEW);
table_schema.set_index_type(INDEX_TYPE_IS_NOT);
table_schema.set_def_type(TABLE_DEF_TYPE_INTERNAL);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_table_name(OB_COLUMN_PRIVILEGES_TNAME))) {
LOG_ERROR("fail to set table_name", K(ret));
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_compress_func_name(OB_DEFAULT_COMPRESS_FUNC_NAME))) {
LOG_ERROR("fail to set compress_func_name", K(ret));
}
}
table_schema.set_part_level(PARTITION_LEVEL_ZERO);
table_schema.set_charset_type(ObCharset::get_default_charset());
table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset()));
table_schema.set_create_mem_version(1);
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.set_view_definition(R"__(SELECT CAST(NULL AS VARCHAR(292)) AS GRANTEE, CAST('def' AS VARCHAR(512)) AS TABLE_CATALOG, CAST(NULL AS VARCHAR(64)) AS TABLE_SCHEMA, CAST(NULL AS VARCHAR(64)) AS TABLE_NAME, CAST(NULL AS VARCHAR(64)) AS COLUMN_NAME, CAST(NULL AS VARCHAR(64)) AS PRIVILEGE_TYPE, CAST(NULL AS VARCHAR(3)) AS IS_GRANTABLE FROM DUAL WHERE 1 = 0 )__"))) {
LOG_ERROR("fail to set view_definition", K(ret));
}
}
table_schema.set_index_using_type(USING_BTREE);
table_schema.set_row_store_type(FLAT_ROW_STORE);
table_schema.set_store_format(OB_STORE_FORMAT_COMPACT_MYSQL);
table_schema.set_progressive_merge_round(1);
table_schema.set_storage_format_version(3);
table_schema.set_max_used_column_id(column_id);
table_schema.get_part_option().set_max_used_part_id(table_schema.get_part_option().get_part_num() - 1);
table_schema.get_part_option().set_partition_cnt_within_partition_table(OB_ALL_CORE_TABLE_TID == common::extract_pure_id(table_schema.get_table_id()) ? 1 : 0);
return ret;
}
} // end namespace share
} // end namespace oceanbase
......@@ -1074,6 +1074,7 @@ public:
static int v_ob_all_clusters_schema(share::schema::ObTableSchema &table_schema);
static int cdb_ob_backup_archivelog_schema(share::schema::ObTableSchema &table_schema);
static int cdb_ob_backup_backup_archivelog_schema(share::schema::ObTableSchema &table_schema);
static int column_privileges_schema(share::schema::ObTableSchema &table_schema);
static int dba_synonyms_schema(share::schema::ObTableSchema &table_schema);
static int dba_objects_schema(share::schema::ObTableSchema &table_schema);
static int all_objects_schema(share::schema::ObTableSchema &table_schema);
......@@ -2126,6 +2127,7 @@ const schema_create_func sys_view_schema_creators [] = {
ObInnerTableSchema::v_ob_all_clusters_schema,
ObInnerTableSchema::cdb_ob_backup_archivelog_schema,
ObInnerTableSchema::cdb_ob_backup_backup_archivelog_schema,
ObInnerTableSchema::column_privileges_schema,
ObInnerTableSchema::dba_synonyms_schema,
ObInnerTableSchema::dba_objects_schema,
ObInnerTableSchema::all_objects_schema,
......@@ -2811,6 +2813,7 @@ const uint64_t tenant_space_tables [] = {
OB_GV_LOCK_TID,
OB_V_LOCK_TID,
OB_V_RESTORE_POINT_TID,
OB_COLUMN_PRIVILEGES_TID,
OB_DBA_SYNONYMS_TID,
OB_DBA_OBJECTS_TID,
OB_ALL_OBJECTS_TID,
......@@ -3667,6 +3670,7 @@ const char* const tenant_space_table_names [] = {
OB_GV_LOCK_TNAME,
OB_V_LOCK_TNAME,
OB_V_RESTORE_POINT_TNAME,
OB_COLUMN_PRIVILEGES_TNAME,
OB_DBA_SYNONYMS_TNAME,
OB_DBA_OBJECTS_TNAME,
OB_ALL_OBJECTS_TNAME,
......@@ -4049,10 +4053,10 @@ static inline bool is_only_rs_virtual_table(const uint64_t tid)
const int64_t OB_CORE_TABLE_COUNT = 5;
const int64_t OB_SYS_TABLE_COUNT = 187;
const int64_t OB_VIRTUAL_TABLE_COUNT = 463;
const int64_t OB_SYS_VIEW_COUNT = 359;
const int64_t OB_SYS_TENANT_TABLE_COUNT = 1015;
const int64_t OB_SYS_VIEW_COUNT = 360;
const int64_t OB_SYS_TENANT_TABLE_COUNT = 1016;
const int64_t OB_CORE_SCHEMA_VERSION = 1;
const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 1018;
const int64_t OB_BOOTSTRAP_SCHEMA_VERSION = 1019;
} // end namespace share
} // end namespace oceanbase
......
......@@ -807,6 +807,7 @@ const uint64_t OB_CDB_OB_BACKUP_BACKUPPIECE_TASK_HISTORY_TID = 21141; // "CDB_OB
const uint64_t OB_V_OB_ALL_CLUSTERS_TID = 21142; // "v$ob_all_clusters"
const uint64_t OB_CDB_OB_BACKUP_ARCHIVELOG_TID = 21143; // "CDB_OB_BACKUP_ARCHIVELOG"
const uint64_t OB_CDB_OB_BACKUP_BACKUP_ARCHIVELOG_TID = 21144; // "CDB_OB_BACKUP_BACKUP_ARCHIVELOG"
const uint64_t OB_COLUMN_PRIVILEGES_TID = 21150; // "COLUMN_PRIVILEGES"
const uint64_t OB_DBA_SYNONYMS_TID = 25001; // "DBA_SYNONYMS"
const uint64_t OB_DBA_OBJECTS_TID = 25002; // "DBA_OBJECTS"
const uint64_t OB_ALL_OBJECTS_TID = 25003; // "ALL_OBJECTS"
......@@ -1826,6 +1827,7 @@ const char *const OB_CDB_OB_BACKUP_BACKUPPIECE_TASK_HISTORY_TNAME = "CDB_OB_BACK
const char *const OB_V_OB_ALL_CLUSTERS_TNAME = "v$ob_all_clusters";
const char *const OB_CDB_OB_BACKUP_ARCHIVELOG_TNAME = "CDB_OB_BACKUP_ARCHIVELOG";
const char *const OB_CDB_OB_BACKUP_BACKUP_ARCHIVELOG_TNAME = "CDB_OB_BACKUP_BACKUP_ARCHIVELOG";
const char *const OB_COLUMN_PRIVILEGES_TNAME = "COLUMN_PRIVILEGES";
const char *const OB_DBA_SYNONYMS_TNAME = "DBA_SYNONYMS";
const char *const OB_DBA_OBJECTS_TNAME = "DBA_OBJECTS";
const char *const OB_ALL_OBJECTS_TNAME = "ALL_OBJECTS";
......
......@@ -10406,7 +10406,7 @@ def_table_schema(
gm_columns = [],
rowkey_columns = [],
view_definition = """
SELECT 'def' AS CATALOG_NAME, DATABASE_NAME AS SCHEMA_NAME, 'utf8mb4' AS DEFAULT_CHARACTER_SET_NAME, 'utf8mb4_general_ci' AS DEFAULT_COLLATION_NAME, NULL AS SQL_PATH FROM oceanbase.__all_virtual_database a WHERE a.tenant_id = effective_tenant_id() and in_recyclebin = 0 and database_name != '__recyclebin'
SELECT 'def' AS CATALOG_NAME, DATABASE_NAME AS SCHEMA_NAME, 'utf8mb4' AS DEFAULT_CHARACTER_SET_NAME, 'utf8mb4_general_ci' AS DEFAULT_COLLATION_NAME, NULL AS SQL_PATH, 'NO' as DEFAULT_ENCRYPTION FROM oceanbase.__all_virtual_database a WHERE a.tenant_id = effective_tenant_id() and in_recyclebin = 0 and database_name != '__recyclebin'
""".replace("\n", " "),
in_tenant_space = True,
......@@ -14536,6 +14536,29 @@ def_table_schema(
""".replace("\n", " ")
)
def_table_schema(
tablegroup_id = 'OB_INVALID_ID',
database_id = 'OB_INFORMATION_SCHEMA_ID',
table_name = 'COLUMN_PRIVILEGES',
table_id = '21150',
table_type = 'SYSTEM_VIEW',
rowkey_columns = [],
normal_columns = [],
gm_columns = [],
in_tenant_space = True,
view_definition = """SELECT
CAST(NULL AS VARCHAR(292)) AS GRANTEE,
CAST('def' AS VARCHAR(512)) AS TABLE_CATALOG,
CAST(NULL AS VARCHAR(64)) AS TABLE_SCHEMA,
CAST(NULL AS VARCHAR(64)) AS TABLE_NAME,
CAST(NULL AS VARCHAR(64)) AS COLUMN_NAME,
CAST(NULL AS VARCHAR(64)) AS PRIVILEGE_TYPE,
CAST(NULL AS VARCHAR(3)) AS IS_GRANTABLE
FROM DUAL
WHERE 1 = 0
""".replace("\n", " "),
)
################################################################################
# Oracle System View (25000, 30000]
# Data Dictionary View (25000, 28000]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册