1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "sql/dd/impl/system_views/tables.h"
#include <string>
#include "sql/stateless_allocator.h"
namespace dd {
namespace system_views {
const Tables_base &Tables::instance() {
static Tables_base *s_instance = new Tables();
return *s_instance;
}
Tables_base::Tables_base() {
m_target_def.add_field(FIELD_TABLE_CATALOG, "TABLE_CATALOG",
"cat.name" + m_target_def.fs_name_collation());
m_target_def.add_field(FIELD_TABLE_SCHEMA, "TABLE_SCHEMA",
"sch.name" + m_target_def.fs_name_collation());
m_target_def.add_field(FIELD_TABLE_NAME, "TABLE_NAME",
"tbl.name" + m_target_def.fs_name_collation());
m_target_def.add_field(FIELD_TABLE_TYPE, "TABLE_TYPE", "tbl.type");
m_target_def.add_field(FIELD_ENGINE, "ENGINE",
"IF(tbl.type = 'BASE TABLE', tbl.engine, NULL)");
m_target_def.add_field(
FIELD_VERSION, "VERSION",
"IF(tbl.type = 'VIEW', NULL, 10 /* FRM_VER_TRUE_VARCHAR */)");
m_target_def.add_field(FIELD_ROW_FORMAT, "ROW_FORMAT", "tbl.row_format");
m_target_def.add_field(FIELD_CREATE_TIME, "CREATE_TIME", "tbl.created");
m_target_def.add_field(FIELD_TABLE_COLLATION, "TABLE_COLLATION", "col.name");
m_target_def.add_field(
FIELD_CREATE_OPTIONS, "CREATE_OPTIONS",
"IF (tbl.type = 'VIEW', NULL,"
" GET_DD_CREATE_OPTIONS(tbl.options,"
" IF(IFNULL(tbl.partition_expression, 'NOT_PART_TBL')='NOT_PART_TBL',"
" 0, 1), IF(sch.default_encryption='YES',1,0)))");
m_target_def.add_field(
FIELD_TABLE_COMMENT, "TABLE_COMMENT",
"INTERNAL_GET_COMMENT_OR_ERROR(sch.name, tbl.name, tbl.type, "
"tbl.options, tbl.comment)");
m_target_def.add_from("mysql.tables tbl");
m_target_def.add_from("JOIN mysql.schemata sch ON tbl.schema_id=sch.id");
m_target_def.add_from(
"JOIN mysql.catalogs cat ON "
"cat.id=sch.catalog_id");
m_target_def.add_from(
"LEFT JOIN mysql.collations col ON "
"tbl.collation_id=col.id");
m_target_def.add_where("CAN_ACCESS_TABLE(sch.name, tbl.name)");
m_target_def.add_where("AND IS_VISIBLE_DD_OBJECT(tbl.hidden)");
}
/*
Adding column definition so as to pick cached table statistics from
mysql.table_stats.
*/
Tables::Tables() {
m_target_def.set_view_name(view_name());
/*
stat.<value> and stat.cached_time should be passed directly to UDFs
and UDF implementation should handle NULL value. Using IFNULL() as a
workaround until Bug#26389402 is fixed.
*/
m_target_def.add_field(FIELD_TABLE_ROWS, "TABLE_ROWS",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_TABLE_ROWS(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.table_rows, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_AVG_ROW_LENGTH, "AVG_ROW_LENGTH",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_AVG_ROW_LENGTH(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.avg_row_length, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_DATA_LENGTH, "DATA_LENGTH",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_DATA_LENGTH(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.data_length, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_MAX_DATA_LENGTH, "MAX_DATA_LENGTH",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_MAX_DATA_LENGTH(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.max_data_length, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_INDEX_LENGTH, "INDEX_LENGTH",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_INDEX_LENGTH(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.index_length, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_DATA_FREE, "DATA_FREE",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_DATA_FREE(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.data_free, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_AUTO_INCREMENT, "AUTO_INCREMENT",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_AUTO_INCREMENT(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, "
/*
Don't get AUTO_INCREMENT value for hidden tables or
GIPKs if they are not supposed to be visible in I_S
due to user setting.
*/
" IS_VISIBLE_DD_OBJECT(tbl.hidden, FALSE,"
" tbl.options) IS FALSE,"
" ts.se_private_data,"
" COALESCE(stat.auto_increment, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0), "
"tbl.se_private_data))");
m_target_def.add_field(FIELD_UPDATE_TIME, "UPDATE_TIME",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_UPDATE_TIME(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(CAST(stat.update_time as UNSIGNED), 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_CHECK_TIME, "CHECK_TIME",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_CHECK_TIME(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(CAST(stat.check_time as UNSIGNED), 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
m_target_def.add_field(FIELD_CHECKSUM, "CHECKSUM",
"IF (tbl.type = 'VIEW', NULL,"
"INTERNAL_CHECKSUM(sch.name, tbl.name,"
" IF(ISNULL(tbl.partition_type), tbl.engine, ''),"
" tbl.se_private_id, tbl.hidden != 'Visible', "
" ts.se_private_data,"
" COALESCE(stat.checksum, 0),"
" COALESCE(CAST(stat.cached_time as UNSIGNED), 0)))");
/*
Supply mysql.tablespaces.se_private_data to internal functions
INTERNAL_*(), which is used by SE to read the SE specific tablespace
metadata when fetching table dynamic statistics. E.g., InnoDB would
read the SE specific space_id from se_private_data column.
*/
m_target_def.add_from(
"LEFT JOIN mysql.tablespaces ts ON "
"tbl.tablespace_id=ts.id");
m_target_def.add_from(
"LEFT JOIN mysql.table_stats stat ON "
"tbl.name=stat.table_name "
"AND sch.name=stat.schema_name");
}
} // namespace system_views
} // namespace dd
|