github.com/dolthub/go-mysql-server@v0.18.0/sql/information_schema/information_schema.go (about) 1 // Copyright 2020-2022 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package information_schema 16 17 import ( 18 "bytes" 19 "errors" 20 "fmt" 21 "io" 22 "sort" 23 "strings" 24 25 "github.com/dolthub/vitess/go/sqltypes" 26 "github.com/dolthub/vitess/go/vt/sqlparser" 27 28 gmstime "github.com/dolthub/go-mysql-server/internal/time" 29 . "github.com/dolthub/go-mysql-server/sql" 30 "github.com/dolthub/go-mysql-server/sql/mysql_db" 31 "github.com/dolthub/go-mysql-server/sql/plan" 32 "github.com/dolthub/go-mysql-server/sql/planbuilder" 33 "github.com/dolthub/go-mysql-server/sql/types" 34 ) 35 36 const ( 37 // AdministrableRoleAuthorizationsTableName is the name of the ADMINISTRABLE_ROLE_AUTHORIZATIONS table. 38 AdministrableRoleAuthorizationsTableName = "administrable_role_authorizations" 39 // ApplicableRolesTableName is the name of the APPLICABLE_ROLES table. 40 ApplicableRolesTableName = "applicable_roles" 41 // CharacterSetsTableName is the name of the CHARACTER_SETS table 42 CharacterSetsTableName = "character_sets" 43 // CheckConstraintsTableName is the name of CHECK_CONSTRAINTS table 44 CheckConstraintsTableName = "check_constraints" 45 // CollationCharSetApplicabilityTableName is the name of COLLATION_CHARACTER_SET_APPLICABILITY table. 46 CollationCharSetApplicabilityTableName = "collation_character_set_applicability" 47 // CollationsTableName is the name of the COLLATIONS table. 48 CollationsTableName = "collations" 49 // ColumnPrivilegesTableName is the name of the COLUMN_PRIVILEGES table. 50 ColumnPrivilegesTableName = "column_privileges" 51 // ColumnStatisticsTableName is the name of the COLUMN_STATISTICS table. 52 ColumnStatisticsTableName = "column_statistics" 53 // ColumnsTableName is the name of the COLUMNS table. 54 ColumnsTableName = "columns" 55 // ColumnsExtensionsTableName is the name of the COLUMN_EXTENSIONS table. 56 ColumnsExtensionsTableName = "columns_extensions" 57 // EnabledRolesTablesName is the name of the ENABLED_ROLES table. 58 EnabledRolesTablesName = "enabled_roles" 59 // EnginesTableName is the name of the ENGINES table 60 EnginesTableName = "engines" 61 // EventsTableName is the name of the EVENTS table. 62 EventsTableName = "events" 63 // FilesTableName is the name of the FILES table. 64 FilesTableName = "files" 65 // KeyColumnUsageTableName is the name of the KEY_COLUMN_USAGE table. 66 KeyColumnUsageTableName = "key_column_usage" 67 // KeywordsTableName is the name of the KEYWORDS table. 68 KeywordsTableName = "keywords" 69 // OptimizerTraceTableName is the name of the OPTIMIZER_TRACE table. 70 OptimizerTraceTableName = "optimizer_trace" 71 // ParametersTableName is the name of the PARAMETERS table. 72 ParametersTableName = "parameters" 73 // PartitionsTableName is the name of the PARTITIONS table 74 PartitionsTableName = "partitions" 75 // PluginsTableName is the name of the PLUGINS table. 76 PluginsTableName = "plugins" 77 // ProcessListTableName is the name of the PROCESSLIST table 78 ProcessListTableName = "processlist" 79 // ProfilingTableName is the name of the PROFILING table. 80 ProfilingTableName = "profiling" 81 // ReferentialConstraintsTableName is the name of the TABLE_CONSTRAINTS table. 82 ReferentialConstraintsTableName = "referential_constraints" 83 // ResourceGroupsTableName is the name of the RESOURCE_GROUPS table. 84 ResourceGroupsTableName = "resource_groups" 85 // RoleColumnGrantsTableName is the name of the ROLE_COLUMNS_GRANTS table. 86 RoleColumnGrantsTableName = "role_column_grants" 87 // RoleRoutineGrantsTableName is the name of the ROLE_ROUTINE_GRANTS table. 88 RoleRoutineGrantsTableName = "role_routine_grants" 89 // RoleTableGrantsTableName is the name of the ROLE_TABLE_GRANTS table. 90 RoleTableGrantsTableName = "role_table_grants" 91 // RoutinesTableName is the name of the ROUTINES table. 92 RoutinesTableName = "routines" 93 // SchemaPrivilegesTableName is the name of the SCHEMA_PRIVILEGES table. 94 SchemaPrivilegesTableName = "schema_privileges" 95 // SchemataTableName is the name of the SCHEMATA table. 96 SchemataTableName = "schemata" 97 // SchemataExtensionsTableName is the name of the SCHEMATA_EXTENSIONS table. 98 SchemataExtensionsTableName = "schemata_extensions" 99 // StGeometryColumnsTableName is the name of the ST_GEOMETRY_COLUMNS table. 100 StGeometryColumnsTableName = "st_geometry_columns" 101 // StSpatialReferenceSystemsTableName is the name of the ST_SPATIAL_REFERENCE_SYSTEMS table. 102 StSpatialReferenceSystemsTableName = "st_spatial_reference_systems" 103 // StUnitsOfMeasureTableName is the name of the ST_UNITS_OF_MEASURE 104 StUnitsOfMeasureTableName = "st_units_of_measure" 105 // StatisticsTableName is the name of the STATISTICS table. 106 StatisticsTableName = "statistics" 107 // TableConstraintsTableName is the name of the TABLE_CONSTRAINTS table. 108 TableConstraintsTableName = "table_constraints" 109 // TableConstraintsExtensionsTableName is the name of the TABLE_CONSTRAINTS_EXTENSIONS table. 110 TableConstraintsExtensionsTableName = "table_constraints_extensions" 111 // TablePrivilegesTableName is the name of the TABLE_PRIVILEGES table. 112 TablePrivilegesTableName = "table_privileges" 113 // TablesTableName is the name of the TABLES table. 114 TablesTableName = "tables" 115 // TablesExtensionsTableName is the name of TABLE_EXTENSIONS table. 116 TablesExtensionsTableName = "tables_extensions" 117 // TablespacesTableName is the names of the TABLESPACES table. 118 TablespacesTableName = "tablespaces" 119 // TablespacesExtensionsTableName is the name of the TABLESPACES_EXTENSIONS table. 120 TablespacesExtensionsTableName = "tablespaces_extensions" 121 // TriggersTableName is the name of the TRIGGERS table. 122 TriggersTableName = "triggers" 123 // UserAttributesTableName is the name of the USER_ATTRIBUTES table. 124 UserAttributesTableName = "user_attributes" 125 // UserPrivilegesTableName is the name of the USER_PRIVILEGES table 126 UserPrivilegesTableName = "user_privileges" 127 // ViewRoutineUsageTableName is the name of VIEW_ROUTINE_USAGE table. 128 ViewRoutineUsageTableName = "view_routine_usage" 129 // ViewTableUsageTableName is the name of the VIEW_TABLE_USAGE table. 130 ViewTableUsageTableName = "view_table_usage" 131 // ViewsTableName is the name of the VIEWS table. 132 ViewsTableName = "views" 133 // defaultInfoSchemaRowCount is a default row count estimate 134 defaultInfoSchemaRowCount = 1000 135 ) 136 137 var sqlModeSetType = types.MustCreateSetType([]string{ 138 "ALLOW_INVALID_DATES", "ANSI", "ANSI_QUOTES", "ERROR_FOR_DIVISION_BY_ZERO", "HIGH_NOT_PRECEDENCE", 139 "IGNORE_SPACE", "NOT_USED", "NOT_USED_10", "NOT_USED_11", "NOT_USED_12", "NOT_USED_13", "NOT_USED_14", 140 "NOT_USED_15", "NOT_USED_16", "NOT_USED_17", "NOT_USED_18", "NOT_USED_29", "NOT_USED_9", "NO_AUTO_VALUE_ON_ZERO", 141 "NO_BACKSLASH_ESCAPES", "NO_DIR_IN_CREATE", "NO_ENGINE_SUBSTITUTION", "NO_UNSIGNED_SUBTRACTION", "NO_ZERO_DATE", 142 "NO_ZERO_IN_DATE", "ONLY_FULL_GROUP_BY", "PAD_CHAR_TO_FULL_LENGTH", "PIPES_AS_CONCAT", "REAL_AS_FLOAT", 143 "STRICT_ALL_TABLES", "STRICT_TRANS_TABLES", "TIME_TRUNCATE_FRACTIONAL", "TRADITIONAL"}, Collation_Information_Schema_Default) 144 145 var _ Database = (*informationSchemaDatabase)(nil) 146 147 type informationSchemaDatabase struct { 148 name string 149 tables map[string]Table 150 } 151 152 type informationSchemaTable struct { 153 name string 154 schema Schema 155 catalog Catalog 156 reader func(*Context, Catalog) (RowIter, error) 157 } 158 159 type informationSchemaPartition struct { 160 key []byte 161 } 162 163 type informationSchemaPartitionIter struct { 164 informationSchemaPartition 165 pos int 166 } 167 168 var ( 169 _ Database = (*informationSchemaDatabase)(nil) 170 _ Table = (*informationSchemaTable)(nil) 171 _ StatisticsTable = (*informationSchemaTable)(nil) 172 _ Databaseable = (*informationSchemaTable)(nil) 173 _ Partition = (*informationSchemaPartition)(nil) 174 _ PartitionIter = (*informationSchemaPartitionIter)(nil) 175 ) 176 177 var administrableRoleAuthorizationsSchema = Schema{ 178 {Name: "USER", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 179 {Name: "HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 180 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 181 {Name: "GRANTEE_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 182 {Name: "ROLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 183 {Name: "ROLE_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 184 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: AdministrableRoleAuthorizationsTableName}, 185 {Name: "IS_DEFAULT", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: AdministrableRoleAuthorizationsTableName}, 186 {Name: "IS_MANDATORY", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: AdministrableRoleAuthorizationsTableName}, 187 } 188 189 var applicableRolesSchema = Schema{ 190 {Name: "USER", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 191 {Name: "HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 192 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 193 {Name: "GRANTEE_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 194 {Name: "ROLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 195 {Name: "ROLE_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 196 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ApplicableRolesTableName}, 197 {Name: "IS_DEFAULT", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ApplicableRolesTableName}, 198 {Name: "IS_MANDATORY", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ApplicableRolesTableName}, 199 } 200 201 var characterSetsSchema = Schema{ 202 {Name: "CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CharacterSetsTableName}, 203 {Name: "DEFAULT_COLLATE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CharacterSetsTableName}, 204 {Name: "DESCRIPTION", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CharacterSetsTableName}, 205 {Name: "MAXLEN", Type: types.Uint32, Default: nil, Nullable: false, Source: CharacterSetsTableName}, 206 } 207 208 var checkConstraintsSchema = Schema{ 209 {Name: "CONSTRAINT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: CheckConstraintsTableName}, 210 {Name: "CONSTRAINT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: CheckConstraintsTableName}, 211 {Name: "CONSTRAINT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CheckConstraintsTableName}, 212 {Name: "CHECK_CLAUSE", Type: types.LongText, Default: nil, Nullable: false, Source: CheckConstraintsTableName}, 213 } 214 215 var collationCharacterSetApplicabilitySchema = Schema{ 216 {Name: "COLLATION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CollationCharSetApplicabilityTableName}, 217 {Name: "CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CollationCharSetApplicabilityTableName}, 218 } 219 220 var collationsSchema = Schema{ 221 {Name: "COLLATION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CollationsTableName}, 222 {Name: "CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CollationsTableName}, 223 {Name: "ID", Type: types.Uint64, Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), "0", types.Uint64, false), Nullable: false, Source: CollationsTableName}, 224 {Name: "IS_DEFAULT", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: CollationsTableName}, 225 {Name: "IS_COMPILED", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: true, Source: CollationsTableName}, 226 {Name: "SORTLEN", Type: types.Uint32, Default: nil, Nullable: false, Source: CollationsTableName}, 227 {Name: "PAD_ATTRIBUTE", Type: types.MustCreateEnumType([]string{"PAD SPACE", "NO PAD"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: CollationsTableName}, 228 } 229 230 var columnPrivilegesSchema = Schema{ 231 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.VarChar, 292, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 232 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 512, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 233 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 234 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 235 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 236 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 237 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: ColumnPrivilegesTableName}, 238 } 239 240 var columnStatisticsSchema = Schema{ 241 {Name: "SCHEMA_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnStatisticsTableName}, 242 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnStatisticsTableName}, 243 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnStatisticsTableName}, 244 {Name: "HISTOGRAM", Type: types.JSON, Default: nil, Nullable: false, Source: ColumnStatisticsTableName}, 245 } 246 247 var columnsSchema = Schema{ 248 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 249 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 250 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 251 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 252 {Name: "ORDINAL_POSITION", Type: types.Uint32, Default: nil, Nullable: false, Source: ColumnsTableName}, 253 {Name: "COLUMN_DEFAULT", Type: types.Text, Default: nil, Nullable: true, Source: ColumnsTableName}, 254 {Name: "IS_NULLABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), false), Nullable: false, Source: ColumnsTableName}, 255 {Name: "DATA_TYPE", Type: types.LongText, Default: nil, Nullable: true, Source: ColumnsTableName}, 256 {Name: "CHARACTER_MAXIMUM_LENGTH", Type: types.Int64, Default: nil, Nullable: true, Source: ColumnsTableName}, 257 {Name: "CHARACTER_OCTET_LENGTH", Type: types.Int64, Default: nil, Nullable: true, Source: ColumnsTableName}, 258 {Name: "NUMERIC_PRECISION", Type: types.Uint64, Default: nil, Nullable: true, Source: ColumnsTableName}, 259 {Name: "NUMERIC_SCALE", Type: types.Uint64, Default: nil, Nullable: true, Source: ColumnsTableName}, 260 {Name: "DATETIME_PRECISION", Type: types.Uint32, Default: nil, Nullable: true, Source: ColumnsTableName}, 261 {Name: "CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 262 {Name: "COLLATION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 263 {Name: "COLUMN_TYPE", Type: types.MediumText, Default: nil, Nullable: false, Source: ColumnsTableName}, 264 {Name: "COLUMN_KEY", Type: types.MustCreateEnumType([]string{"", "PRI", "UNI", "MUL"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnsTableName}, 265 {Name: "EXTRA", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 266 {Name: "PRIVILEGES", Type: types.MustCreateString(sqltypes.VarChar, 154, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsTableName}, 267 {Name: "COLUMN_COMMENT", Type: types.Text, Default: nil, Nullable: false, Source: ColumnsTableName}, 268 {Name: "GENERATION_EXPRESSION", Type: types.LongText, Default: nil, Nullable: false, Source: ColumnsTableName}, 269 {Name: "SRS_ID", Type: types.Uint32, Default: nil, Nullable: true, Source: ColumnsTableName}, 270 } 271 272 var columnsExtensionsSchema = Schema{ 273 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnsExtensionsTableName}, 274 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnsExtensionsTableName}, 275 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ColumnsExtensionsTableName}, 276 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ColumnsExtensionsTableName}, 277 {Name: "ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: ColumnsExtensionsTableName}, 278 {Name: "SECONDARY_ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: ColumnsExtensionsTableName}, 279 } 280 281 var enabledRolesSchema = Schema{ 282 {Name: "ROLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EnabledRolesTablesName}, 283 {Name: "ROLE_HOST", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EnabledRolesTablesName}, 284 {Name: "IS_DEFAULT", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EnabledRolesTablesName}, 285 {Name: "IS_MANDATORY", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: EnabledRolesTablesName}, 286 } 287 288 var enginesSchema = Schema{ 289 {Name: "ENGINE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: EnginesTableName}, 290 {Name: "SUPPORT", Type: types.MustCreateString(sqltypes.VarChar, 8, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: EnginesTableName}, 291 {Name: "COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 80, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: EnginesTableName}, 292 {Name: "TRANSACTIONS", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: true, Source: EnginesTableName}, 293 {Name: "XA", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: true, Source: EnginesTableName}, 294 {Name: "SAVEPOINTS", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: true, Source: EnginesTableName}, 295 } 296 297 var eventsSchema = Schema{ 298 {Name: "EVENT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EventsTableName}, 299 {Name: "EVENT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EventsTableName}, 300 {Name: "EVENT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 301 {Name: "DEFINER", Type: types.MustCreateString(sqltypes.VarChar, 288, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 302 {Name: "TIME_ZONE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 303 {Name: "EVENT_BODY", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: EventsTableName}, 304 {Name: "EVENT_DEFINITION", Type: types.LongText, Default: nil, Nullable: false, Source: EventsTableName}, 305 {Name: "EVENT_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 9, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.LongText, false), Nullable: false, Source: EventsTableName}, 306 {Name: "EXECUTE_AT", Type: types.Datetime, Default: nil, Nullable: true, Source: EventsTableName}, 307 {Name: "INTERVAL_VALUE", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EventsTableName}, 308 {Name: "INTERVAL_FIELD", Type: types.MustCreateEnumType([]string{ 309 "YEAR", "QUARTER", "MONTH", "DAY", "HOUR", "MINUTE", "WEEK", "SECOND", "MICROSECOND", "YEAR_MONTH", 310 "DAY_HOUR", "DAY_MINUTE", "DAY_SECOND", "HOUR_MINUTE", "HOUR_SECOND", "MINUTE_SECOND", 311 "DAY_MICROSECOND", "HOUR_MICROSECOND", "MINUTE_MICROSECOND", "SECOND_MICROSECOND"}, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: EventsTableName}, 312 {Name: "SQL_MODE", Type: sqlModeSetType, Default: nil, Nullable: false, Source: EventsTableName}, 313 {Name: "STARTS", Type: types.Datetime, Default: nil, Nullable: true, Source: EventsTableName}, 314 {Name: "ENDS", Type: types.Datetime, Default: nil, Nullable: true, Source: EventsTableName}, 315 {Name: "STATUS", Type: types.MustCreateEnumType([]string{"ENABLED", "DISABLED", "SLAVESIDE_DISABLED"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 316 {Name: "ON_COMPLETION", Type: types.MustCreateString(sqltypes.VarChar, 12, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.MustCreateString(sqltypes.VarChar, 12, Collation_Information_Schema_Default), false), Nullable: false, Source: EventsTableName}, 317 {Name: "CREATED", Type: types.Timestamp, Default: nil, Nullable: false, Source: EventsTableName}, 318 {Name: "LAST_ALTERED", Type: types.Timestamp, Default: nil, Nullable: false, Source: EventsTableName}, 319 {Name: "LAST_EXECUTED", Type: types.Datetime, Default: nil, Nullable: true, Source: EventsTableName}, 320 {Name: "EVENT_COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 321 {Name: "ORIGINATOR", Type: types.Uint32, Default: nil, Nullable: false, Source: EventsTableName}, 322 {Name: "CHARACTER_SET_CLIENT", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 323 {Name: "COLLATION_CONNECTION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 324 {Name: "DATABASE_COLLATION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: EventsTableName}, 325 } 326 327 var filesSchema = Schema{ 328 {Name: "FILE_ID", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 329 {Name: "FILE_NAME", Type: types.Text, Default: nil, Nullable: true, Source: FilesTableName}, 330 {Name: "FILE_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 331 {Name: "TABLESPACE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 268, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 332 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.Char, 0, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.MustCreateString(sqltypes.Char, 0, Collation_Information_Schema_Default), false), Nullable: true, Source: FilesTableName}, 333 {Name: "TABLE_SCHEMA", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 334 {Name: "TABLE_NAME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 335 {Name: "LOGFILE_GROUP_NAME", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 336 {Name: "LOGFILE_GROUP_NUMBER", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 337 {Name: "ENGINE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 338 {Name: "FULLTEXT_KEYS", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 339 {Name: "DELETED_ROWS", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 340 {Name: "UPDATE_COUNT", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 341 {Name: "FREE_EXTENTS", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 342 {Name: "TOTAL_EXTENTS", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 343 {Name: "EXTENT_SIZE", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 344 {Name: "INITIAL_SIZE", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 345 {Name: "MAXIMUM_SIZE", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 346 {Name: "AUTOEXTEND_SIZE", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 347 {Name: "CREATION_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 348 {Name: "LAST_UPDATE_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 349 {Name: "LAST_ACCESS_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 350 {Name: "RECOVER_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 351 {Name: "TRANSACTION_COUNTER", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 352 {Name: "VERSION", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 353 {Name: "ROW_FORMAT", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 354 {Name: "TABLE_ROWS", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 355 {Name: "AVG_ROW_LENGTH", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 356 {Name: "DATA_LENGTH", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 357 {Name: "MAX_DATA_LENGTH", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 358 {Name: "INDEX_LENGTH", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 359 {Name: "DATA_FREE", Type: types.Int64, Default: nil, Nullable: true, Source: FilesTableName}, 360 {Name: "CREATE_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 361 {Name: "UPDATE_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 362 {Name: "CHECK_TIME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 363 {Name: "CHECKSUM", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: FilesTableName}, 364 {Name: "STATUS", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 365 {Name: "EXTRA", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: FilesTableName}, 366 } 367 368 var keyColumnUsageSchema = Schema{ 369 {Name: "CONSTRAINT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 370 {Name: "CONSTRAINT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 371 {Name: "CONSTRAINT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 372 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 373 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 374 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 375 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 376 {Name: "ORDINAL_POSITION", Type: types.Uint32, Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), "0", types.Uint32, false), Nullable: false, Source: KeyColumnUsageTableName}, 377 {Name: "POSITION_IN_UNIQUE_CONSTRAINT", Type: types.Uint32, Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 378 {Name: "REFERENCED_TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 379 {Name: "REFERENCED_TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 380 {Name: "REFERENCED_COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeyColumnUsageTableName}, 381 } 382 383 var keywordsSchema = Schema{ 384 {Name: "WORD", Type: types.MustCreateString(sqltypes.VarChar, 128, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: KeywordsTableName}, 385 {Name: "RESERVED", Type: types.Int32, Default: nil, Nullable: true, Source: KeywordsTableName}, 386 } 387 388 var optimizerTraceSchema = Schema{ 389 {Name: "QUERY", Type: types.MustCreateString(sqltypes.VarChar, 65535, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: OptimizerTraceTableName}, 390 {Name: "TRACE", Type: types.MustCreateString(sqltypes.VarChar, 65535, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: OptimizerTraceTableName}, 391 {Name: "MISSING_BYTES_BEYOND_MAX_MEM_SIZE", Type: types.Int32, Default: nil, Nullable: false, Source: OptimizerTraceTableName}, 392 {Name: "INSUFFICIENT_PRIVILEGES", Type: types.MustCreateBitType(1), Default: nil, Nullable: false, Source: OptimizerTraceTableName}, 393 } 394 395 var parametersSchema = Schema{ 396 {Name: "SPECIFIC_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ParametersTableName}, 397 {Name: "SPECIFIC_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ParametersTableName}, 398 {Name: "SPECIFIC_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ParametersTableName}, 399 {Name: "ORDINAL_POSITION", Type: types.Uint64, Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), "0", types.Uint64, false), Nullable: false, Source: ParametersTableName}, 400 {Name: "PARAMETER_MODE", Type: types.MustCreateString(sqltypes.VarChar, 5, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ParametersTableName}, 401 {Name: "PARAMETER_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ParametersTableName}, 402 {Name: "DATA_TYPE", Type: types.LongText, Default: nil, Nullable: true, Source: ParametersTableName}, 403 {Name: "CHARACTER_MAXIMUM_LENGTH", Type: types.Int64, Default: nil, Nullable: true, Source: ParametersTableName}, 404 {Name: "CHARACTER_OCTET_LENGTH", Type: types.Int64, Default: nil, Nullable: true, Source: ParametersTableName}, 405 {Name: "NUMERIC_PRECISION", Type: types.Uint32, Default: nil, Nullable: true, Source: ParametersTableName}, 406 {Name: "NUMERIC_SCALE", Type: types.Int64, Default: nil, Nullable: true, Source: ParametersTableName}, 407 {Name: "DATETIME_PRECISION", Type: types.Uint32, Default: nil, Nullable: true, Source: ParametersTableName}, 408 {Name: "CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ParametersTableName}, 409 {Name: "COLLATION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ParametersTableName}, 410 {Name: "DTD_IDENTIFIER", Type: types.MediumText, Default: nil, Nullable: false, Source: ParametersTableName}, 411 {Name: "ROUTINE_TYPE", Type: types.MustCreateEnumType([]string{"FUNCTION", "PROCEDURE"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ParametersTableName}, 412 } 413 414 var partitionsSchema = Schema{ 415 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 416 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 417 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PartitionsTableName}, 418 {Name: "PARTITION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 419 {Name: "SUBPARTITION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 420 {Name: "PARTITION_ORDINAL_POSITION", Type: types.Uint32, Default: nil, Nullable: true, Source: PartitionsTableName}, 421 {Name: "SUBPARTITION_ORDINAL_POSITION", Type: types.Uint32, Default: nil, Nullable: true, Source: PartitionsTableName}, 422 {Name: "PARTITION_METHOD", Type: types.MustCreateString(sqltypes.VarChar, 13, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 423 {Name: "SUBPARTITION_METHOD", Type: types.MustCreateString(sqltypes.VarChar, 13, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 424 {Name: "PARTITION_EXPRESSION", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 425 {Name: "SUBPARTITION_EXPRESSION", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 426 {Name: "PARTITION_DESCRIPTION", Type: types.Text, Default: nil, Nullable: true, Source: PartitionsTableName}, 427 {Name: "TABLE_ROWS", Type: types.Uint64, Default: nil, Nullable: true, Source: PartitionsTableName}, 428 {Name: "AVG_ROW_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: PartitionsTableName}, 429 {Name: "DATA_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: PartitionsTableName}, 430 {Name: "MAX_DATA_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: PartitionsTableName}, 431 {Name: "INDEX_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: PartitionsTableName}, 432 {Name: "DATA_FREE", Type: types.Uint64, Default: nil, Nullable: true, Source: PartitionsTableName}, 433 {Name: "CREATE_TIME", Type: types.Timestamp, Default: nil, Nullable: false, Source: PartitionsTableName}, 434 {Name: "UPDATE_TIME", Type: types.Datetime, Default: nil, Nullable: true, Source: PartitionsTableName}, 435 {Name: "CHECK_TIME", Type: types.Datetime, Default: nil, Nullable: true, Source: PartitionsTableName}, 436 {Name: "CHECKSUM", Type: types.Int64, Default: nil, Nullable: true, Source: PartitionsTableName}, 437 {Name: "PARTITION_COMMENT", Type: types.Text, Default: nil, Nullable: false, Source: PartitionsTableName}, 438 {Name: "NODEGROUP", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 439 {Name: "TABLESPACE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 268, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PartitionsTableName}, 440 } 441 442 var pluginsSchema = Schema{ 443 {Name: "PLUGIN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PluginsTableName}, 444 {Name: "PLUGIN_VERSION", Type: types.MustCreateString(sqltypes.VarChar, 20, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PluginsTableName}, 445 {Name: "PLUGIN_STATUS", Type: types.MustCreateString(sqltypes.VarChar, 10, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PluginsTableName}, 446 {Name: "PLUGIN_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 80, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PluginsTableName}, 447 {Name: "PLUGIN_TYPE_VERSION", Type: types.MustCreateString(sqltypes.VarChar, 20, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PluginsTableName}, 448 {Name: "PLUGIN_LIBRARY", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PluginsTableName}, 449 {Name: "PLUGIN_LIBRARY_VERSION", Type: types.MustCreateString(sqltypes.VarChar, 20, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PluginsTableName}, 450 {Name: "PLUGIN_AUTHOR", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PluginsTableName}, 451 {Name: "PLUGIN_DESCRIPTION", Type: types.MustCreateString(sqltypes.VarChar, 65535, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PluginsTableName}, 452 {Name: "PLUGIN_LICENSE", Type: types.MustCreateString(sqltypes.VarChar, 80, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: PluginsTableName}, 453 {Name: "LOAD_OPTION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: PluginsTableName}, 454 } 455 456 var processListSchema = Schema{ 457 {Name: "ID", Type: types.Uint64, Default: nil, Nullable: false, Source: ProcessListTableName}, 458 {Name: "USER", Type: types.MustCreateString(sqltypes.VarChar, 32, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ProcessListTableName}, 459 {Name: "HOST", Type: types.MustCreateString(sqltypes.VarChar, 261, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ProcessListTableName}, 460 {Name: "DB", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ProcessListTableName}, 461 {Name: "COMMAND", Type: types.MustCreateString(sqltypes.VarChar, 16, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ProcessListTableName}, 462 {Name: "TIME", Type: types.Int32, Default: nil, Nullable: false, Source: ProcessListTableName}, 463 {Name: "STATE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ProcessListTableName}, 464 {Name: "INFO", Type: types.MustCreateString(sqltypes.VarChar, 65535, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ProcessListTableName}, 465 } 466 467 var profilingSchema = Schema{ 468 {Name: "QUERY_ID", Type: types.Int32, Default: nil, Nullable: false, Source: ProfilingTableName}, 469 {Name: "SEQ", Type: types.Int32, Default: nil, Nullable: false, Source: ProfilingTableName}, 470 {Name: "STATE", Type: types.MustCreateString(sqltypes.VarChar, 30, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ProfilingTableName}, 471 {Name: "DURATION", Type: types.MustCreateDecimalType(types.DecimalTypeMaxPrecision, 0), Default: nil, Nullable: false, Source: ProfilingTableName}, 472 {Name: "CPU_USER", Type: types.MustCreateDecimalType(types.DecimalTypeMaxPrecision, 0), Default: nil, Nullable: true, Source: ProfilingTableName}, 473 {Name: "CPU_SYSTEM", Type: types.MustCreateDecimalType(types.DecimalTypeMaxPrecision, 0), Default: nil, Nullable: true, Source: ProfilingTableName}, 474 {Name: "CONTEXT_VOLUNTARY", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 475 {Name: "CONTEXT_INVOLUNTARY", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 476 {Name: "BLOCK_OPS_IN", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 477 {Name: "BLOCK_OPS_OUT", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 478 {Name: "MESSAGES_SENT", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 479 {Name: "MESSAGES_RECEIVED", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 480 {Name: "PAGE_FAULTS_MAJOR", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 481 {Name: "PAGE_FAULTS_MINOR", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 482 {Name: "SWAPS", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 483 {Name: "SOURCE_FUNCTION", Type: types.MustCreateString(sqltypes.VarChar, 30, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ProfilingTableName}, 484 {Name: "SOURCE_FILE", Type: types.MustCreateString(sqltypes.VarChar, 20, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ProfilingTableName}, 485 {Name: "SOURCE_LINE", Type: types.Int32, Default: nil, Nullable: true, Source: ProfilingTableName}, 486 } 487 488 var referentialConstraintsSchema = Schema{ 489 {Name: "CONSTRAINT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 490 {Name: "CONSTRAINT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 491 {Name: "CONSTRAINT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ReferentialConstraintsTableName}, 492 {Name: "UNIQUE_CONSTRAINT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 493 {Name: "UNIQUE_CONSTRAINT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 494 {Name: "UNIQUE_CONSTRAINT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ReferentialConstraintsTableName}, 495 {Name: "MATCH_OPTION", Type: types.MustCreateEnumType([]string{"NONE", "PARTIAL", "FULL"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 496 {Name: "UPDATE_RULE", Type: types.MustCreateEnumType([]string{"NO ACTION", "RESTRICT", "CASCADE", "SET NULL", "SET DEFAULT"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 497 {Name: "DELETE_RULE", Type: types.MustCreateEnumType([]string{"NO ACTION", "RESTRICT", "CASCADE", "SET NULL", "SET DEFAULT"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 498 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 499 {Name: "REFERENCED_TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ReferentialConstraintsTableName}, 500 } 501 502 var resourceGroupsSchema = Schema{ 503 {Name: "RESOURCE_GROUP_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ResourceGroupsTableName}, 504 {Name: "RESOURCE_GROUP_TYPE", Type: types.MustCreateEnumType([]string{"SYSTEM", "USER"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ResourceGroupsTableName}, 505 {Name: "RESOURCE_GROUP_ENABLE", Type: types.MustCreateBitType(1), Default: nil, Nullable: false, Source: ResourceGroupsTableName}, 506 {Name: "VPCUS_IDS", Type: types.Blob, Default: nil, Nullable: true, Source: ResourceGroupsTableName}, 507 {Name: "THREAD_PRIORITY", Type: types.Int32, Default: nil, Nullable: false, Source: ResourceGroupsTableName}, 508 } 509 510 var roleColumnGrantsSchema = Schema{ 511 {Name: "GRANTOR", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoleColumnGrantsTableName}, 512 {Name: "GRANTOR_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoleColumnGrantsTableName}, 513 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.Char, 32, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 514 {Name: "GRANTEE_HOST", Type: types.MustCreateString(sqltypes.Char, 255, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 515 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 516 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 517 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 518 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 519 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateSetType([]string{"Select", "Insert", "Update", "References"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 520 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleColumnGrantsTableName}, 521 } 522 523 var roleRoutineGrantsSchema = Schema{ 524 {Name: "GRANTOR", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoleRoutineGrantsTableName}, 525 {Name: "GRANTOR_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoleRoutineGrantsTableName}, 526 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.Char, 32, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 527 {Name: "GRANTEE_HOST", Type: types.MustCreateString(sqltypes.Char, 255, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 528 {Name: "SPECIFIC_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 529 {Name: "SPECIFIC_SCHEMA", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 530 {Name: "SPECIFIC_NAME", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 531 {Name: "ROUTINE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 532 {Name: "ROUTINE_SCHEMA", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 533 {Name: "ROUTINE_NAME", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 534 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateSetType([]string{"Execute", "Alter Routine", "Grant"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 535 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleRoutineGrantsTableName}, 536 } 537 538 var roleTableGrantsSchema = Schema{ 539 {Name: "GRANTOR", Type: types.MustCreateString(sqltypes.VarChar, 97, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoleTableGrantsTableName}, 540 {Name: "GRANTOR_HOST", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoleTableGrantsTableName}, 541 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.Char, 32, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 542 {Name: "GRANTEE_HOST", Type: types.MustCreateString(sqltypes.Char, 255, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 543 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 544 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 545 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.Char, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 546 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateSetType([]string{"Select", "Insert", "Update", "Delete", "Create", "Drop", "Grant", "References", "Index", "Alter", "Create View", "Show view", "Trigger"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 547 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoleTableGrantsTableName}, 548 } 549 550 var routinesSchema = Schema{ 551 {Name: "SPECIFIC_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 552 {Name: "ROUTINE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoutinesTableName}, 553 {Name: "ROUTINE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoutinesTableName}, 554 {Name: "ROUTINE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 555 {Name: "ROUTINE_TYPE", Type: types.MustCreateEnumType([]string{"FUNCTION", "PROCEDURE"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 556 {Name: "DATA_TYPE", Type: types.LongText, Default: nil, Nullable: true, Source: RoutinesTableName}, 557 {Name: "CHARACTER_MAXIMUM_LENGTH", Type: types.Int64, Default: nil, Nullable: true, Source: RoutinesTableName}, 558 {Name: "CHARACTER_OCTET_LENGTH", Type: types.Int64, Default: nil, Nullable: true, Source: RoutinesTableName}, 559 {Name: "NUMERIC_PRECISION", Type: types.Uint32, Default: nil, Nullable: true, Source: RoutinesTableName}, 560 {Name: "NUMERIC_SCALE", Type: types.Uint32, Default: nil, Nullable: true, Source: RoutinesTableName}, 561 {Name: "DATETIME_PRECISION", Type: types.Uint32, Default: nil, Nullable: true, Source: RoutinesTableName}, 562 {Name: "CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoutinesTableName}, 563 {Name: "COLLATION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: RoutinesTableName}, 564 {Name: "DTD_IDENTIFIER", Type: types.LongText, Default: nil, Nullable: true, Source: RoutinesTableName}, 565 {Name: "ROUTINE_BODY", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `""`, types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), false), Nullable: false, Source: RoutinesTableName}, 566 {Name: "ROUTINE_DEFINITION", Type: types.LongText, Default: nil, Nullable: true, Source: RoutinesTableName}, 567 {Name: "EXTERNAL_NAME", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: RoutinesTableName}, 568 {Name: "EXTERNAL_LANGUAGE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: planbuilder.MustStringToColumnDefaultValue(NewEmptyContext(), `"SQL"`, types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), false), Nullable: false, Source: RoutinesTableName}, 569 {Name: "PARAMETER_STYLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 570 {Name: "IS_DETERMINISTIC", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 571 {Name: "SQL_DATA_ACCESS", Type: types.MustCreateEnumType([]string{"CONTAINS SQL", "NO SQL", "READS SQL DATA", "MODIFIES SQL DATA"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 572 {Name: "SQL_PATH", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: RoutinesTableName}, 573 {Name: "SECURITY_TYPE", Type: types.MustCreateEnumType([]string{"DEFAULT", "INVOKER", "DEFINER"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 574 {Name: "CREATED", Type: types.Timestamp, Default: nil, Nullable: false, Source: RoutinesTableName}, 575 {Name: "LAST_ALTERED", Type: types.Timestamp, Default: nil, Nullable: false, Source: RoutinesTableName}, 576 {Name: "SQL_MODE", Type: sqlModeSetType, Default: nil, Nullable: false, Source: RoutinesTableName}, 577 {Name: "ROUTINE_COMMENT", Type: types.Text, Default: nil, Nullable: false, Source: RoutinesTableName}, 578 {Name: "DEFINER", Type: types.MustCreateString(sqltypes.VarChar, 288, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 579 {Name: "CHARACTER_SET_CLIENT", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 580 {Name: "COLLATION_CONNECTION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 581 {Name: "DATABASE_COLLATION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: RoutinesTableName}, 582 } 583 584 var schemaPrivilegesSchema = Schema{ 585 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.VarChar, 292, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemaPrivilegesTableName}, 586 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 512, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemaPrivilegesTableName}, 587 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemaPrivilegesTableName}, 588 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemaPrivilegesTableName}, 589 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemaPrivilegesTableName}, 590 } 591 592 var schemataSchema = Schema{ 593 {Name: "CATALOG_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: SchemataTableName}, 594 {Name: "SCHEMA_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: SchemataTableName}, 595 {Name: "DEFAULT_CHARACTER_SET_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemataTableName}, 596 {Name: "DEFAULT_COLLATION_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemataTableName}, 597 {Name: "SQL_PATH", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: SchemataTableName}, 598 {Name: "DEFAULT_ENCRYPTION", Type: types.MustCreateEnumType([]string{"NO", "YES"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: SchemataTableName}, 599 } 600 601 var schemataExtensionsSchema = Schema{ 602 {Name: "CATALOG_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: SchemataExtensionsTableName}, 603 {Name: "SCHEMA_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: SchemataExtensionsTableName}, 604 {Name: "OPTIONS", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: SchemataExtensionsTableName}, 605 } 606 607 var stGeometryColumnsSchema = Schema{ 608 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 609 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 610 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 611 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 612 {Name: "SRS_NAME", Type: types.MustCreateString(sqltypes.VarChar, 80, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 613 {Name: "SRS_ID", Type: types.Uint32, Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 614 {Name: "GEOMETRY_TYPE_NAME", Type: types.LongText, Default: nil, Nullable: true, Source: StGeometryColumnsTableName}, 615 } 616 617 var stSpatialReferenceSystemsSchema = Schema{ 618 {Name: "SRS_NAME", Type: types.MustCreateString(sqltypes.VarChar, 80, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StSpatialReferenceSystemsTableName}, 619 {Name: "SRS_ID", Type: types.Uint32, Default: nil, Nullable: false, Source: StSpatialReferenceSystemsTableName}, 620 {Name: "ORGANIZATION", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StSpatialReferenceSystemsTableName}, 621 {Name: "ORGANIZATION_COORDSYS_ID", Type: types.Uint32, Default: nil, Nullable: true, Source: StSpatialReferenceSystemsTableName}, 622 {Name: "DEFINITION", Type: types.MustCreateString(sqltypes.VarChar, 4096, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StSpatialReferenceSystemsTableName}, 623 {Name: "DESCRIPTION", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StSpatialReferenceSystemsTableName}, 624 } 625 626 var stUnitsOfMeasureSchema = Schema{ 627 {Name: "UNIT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StUnitsOfMeasureTableName}, 628 {Name: "UNIT_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 7, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StUnitsOfMeasureTableName}, 629 {Name: "CONVERSION_FACTOR", Type: types.Float64, Default: nil, Nullable: true, Source: StUnitsOfMeasureTableName}, 630 {Name: "DESCRIPTION", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StUnitsOfMeasureTableName}, 631 } 632 633 var statisticsSchema = Schema{ 634 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 635 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 636 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 637 {Name: "NON_UNIQUE", Type: types.Int32, Default: nil, Nullable: false, Source: StatisticsTableName}, 638 {Name: "INDEX_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 639 {Name: "INDEX_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 640 {Name: "SEQ_IN_INDEX", Type: types.Uint32, Default: nil, Nullable: false, Source: StatisticsTableName}, 641 {Name: "COLUMN_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 642 {Name: "COLLATION", Type: types.MustCreateString(sqltypes.VarChar, 1, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: StatisticsTableName}, 643 {Name: "CARDINALITY", Type: types.Int64, Default: nil, Nullable: true, Source: StatisticsTableName}, 644 {Name: "SUB_PART", Type: types.Int64, Default: nil, Nullable: true, Source: StatisticsTableName}, 645 {Name: "PACKED", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: StatisticsTableName}, 646 {Name: "NULLABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StatisticsTableName}, 647 {Name: "INDEX_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 11, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StatisticsTableName}, 648 {Name: "COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 8, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StatisticsTableName}, 649 {Name: "INDEX_COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StatisticsTableName}, 650 {Name: "IS_VISIBLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: StatisticsTableName}, 651 {Name: "EXPRESSION", Type: types.LongText, Default: nil, Nullable: true, Source: StatisticsTableName}, 652 } 653 654 var tableConstraintsSchema = Schema{ 655 {Name: "CONSTRAINT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TableConstraintsTableName}, 656 {Name: "CONSTRAINT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TableConstraintsTableName}, 657 {Name: "CONSTRAINT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TableConstraintsTableName}, 658 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TableConstraintsTableName}, 659 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TableConstraintsTableName}, 660 {Name: "CONSTRAINT_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 11, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TableConstraintsTableName}, 661 {Name: "ENFORCED", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TableConstraintsTableName}, 662 } 663 664 var tableConstraintsExtensionsSchema = Schema{ 665 {Name: "CONSTRAINT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TableConstraintsExtensionsTableName}, 666 {Name: "CONSTRAINT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TableConstraintsExtensionsTableName}, 667 {Name: "CONSTRAINT_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TableConstraintsExtensionsTableName}, 668 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TableConstraintsExtensionsTableName}, 669 {Name: "ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: TableConstraintsExtensionsTableName}, 670 {Name: "SECONDARY_ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: TableConstraintsExtensionsTableName}, 671 } 672 673 var tablePrivilegesSchema = Schema{ 674 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.VarChar, 292, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablePrivilegesTableName}, 675 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 512, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablePrivilegesTableName}, 676 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablePrivilegesTableName}, 677 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablePrivilegesTableName}, 678 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablePrivilegesTableName}, 679 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablePrivilegesTableName}, 680 } 681 682 var tablesSchema = Schema{ 683 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 684 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 685 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 686 {Name: "TABLE_TYPE", Type: types.MustCreateEnumType([]string{"BASE TABLE", "VIEW", "SYSTEM VIEW"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablesTableName}, 687 {Name: "ENGINE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 688 {Name: "VERSION", Type: types.Int32, Default: nil, Nullable: true, Source: TablesTableName}, 689 {Name: "ROW_FORMAT", Type: types.MustCreateEnumType([]string{"Fixed", "Dynamic", "Compressed", "Redundant", "Compact", "Paged"}, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 690 {Name: "TABLE_ROWS", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 691 {Name: "AVG_ROW_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 692 {Name: "DATA_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 693 {Name: "MAX_DATA_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 694 {Name: "INDEX_LENGTH", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 695 {Name: "DATA_FREE", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 696 {Name: "AUTO_INCREMENT", Type: types.Uint64, Default: nil, Nullable: true, Source: TablesTableName}, 697 {Name: "CREATE_TIME", Type: types.Timestamp, Default: nil, Nullable: false, Source: TablesTableName}, 698 {Name: "UPDATE_TIME", Type: types.Datetime, Default: nil, Nullable: true, Source: TablesTableName}, 699 {Name: "CHECK_TIME", Type: types.Datetime, Default: nil, Nullable: true, Source: TablesTableName}, 700 {Name: "TABLE_COLLATION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 701 {Name: "CHECKSUM", Type: types.Int64, Default: nil, Nullable: true, Source: TablesTableName}, 702 {Name: "CREATE_OPTIONS", Type: types.MustCreateString(sqltypes.VarChar, 256, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablesTableName}, 703 {Name: "TABLE_COMMENT", Type: types.Text, Default: nil, Nullable: true, Source: TablesTableName}, 704 } 705 706 var tablesExtensionsSchema = Schema{ 707 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablesExtensionsTableName}, 708 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablesExtensionsTableName}, 709 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablesExtensionsTableName}, 710 {Name: "ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: TablesExtensionsTableName}, 711 {Name: "SECONDARY_ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: TablesExtensionsTableName}, 712 } 713 714 var tablespacesSchema = Schema{ 715 {Name: "TABLESPACE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablespacesTableName}, 716 {Name: "ENGINE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablespacesTableName}, 717 {Name: "TABLESPACE_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablespacesTableName}, 718 {Name: "LOGFILE_GROUP_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablespacesTableName}, 719 {Name: "EXTENT_SIZE", Type: types.Uint64, Default: nil, Nullable: true, Source: TablespacesTableName}, 720 {Name: "AUTOEXTEND_SIZE", Type: types.Uint64, Default: nil, Nullable: true, Source: TablespacesTableName}, 721 {Name: "MAXIMUM_SIZE", Type: types.Uint64, Default: nil, Nullable: true, Source: TablespacesTableName}, 722 {Name: "NODEGROUP_ID", Type: types.Uint64, Default: nil, Nullable: true, Source: TablespacesTableName}, 723 {Name: "TABLESPACE_COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 2048, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TablespacesTableName}, 724 } 725 726 var tablespacesExtensionsSchema = Schema{ 727 {Name: "TABLESPACE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 268, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TablespacesExtensionsTableName}, 728 {Name: "ENGINE_ATTRIBUTE", Type: types.JSON, Default: nil, Nullable: true, Source: TablespacesExtensionsTableName}, 729 } 730 731 var triggersSchema = Schema{ 732 {Name: "TRIGGER_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TriggersTableName}, 733 {Name: "TRIGGER_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TriggersTableName}, 734 {Name: "TRIGGER_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 735 {Name: "EVENT_MANIPULATION", Type: types.MustCreateEnumType([]string{"INSERT", "UPDATE", "DELETE"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 736 {Name: "EVENT_OBJECT_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TriggersTableName}, 737 {Name: "EVENT_OBJECT_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TriggersTableName}, 738 {Name: "EVENT_OBJECT_TABLE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: TriggersTableName}, 739 {Name: "ACTION_ORDER", Type: types.Uint32, Default: nil, Nullable: false, Source: TriggersTableName}, 740 {Name: "ACTION_CONDITION", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: TriggersTableName}, 741 {Name: "ACTION_STATEMENT", Type: types.LongText, Default: nil, Nullable: false, Source: TriggersTableName}, 742 {Name: "ACTION_ORIENTATION", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 743 {Name: "ACTION_TIMING", Type: types.MustCreateEnumType([]string{"BEFORE", "AFTER"}, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 744 {Name: "ACTION_REFERENCE_OLD_TABLE", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: TriggersTableName}, 745 {Name: "ACTION_REFERENCE_NEW_TABLE", Type: types.MustCreateBinary(sqltypes.Binary, 0), Default: nil, Nullable: true, Source: TriggersTableName}, 746 {Name: "ACTION_REFERENCE_OLD_ROW", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 747 {Name: "ACTION_REFERENCE_NEW_ROW", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 748 {Name: "CREATED", Type: types.Timestamp, Default: nil, Nullable: false, Source: TriggersTableName}, 749 {Name: "SQL_MODE", Type: sqlModeSetType, Default: nil, Nullable: false, Source: TriggersTableName}, 750 {Name: "DEFINER", Type: types.MustCreateString(sqltypes.VarChar, 288, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 751 {Name: "CHARACTER_SET_CLIENT", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 752 {Name: "COLLATION_CONNECTION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 753 {Name: "DATABASE_COLLATION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: TriggersTableName}, 754 } 755 756 var userAttributesSchema = Schema{ 757 {Name: "USER", Type: types.MustCreateString(sqltypes.VarChar, 32, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: UserAttributesTableName}, 758 {Name: "HOST", Type: types.MustCreateString(sqltypes.VarChar, 255, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: UserAttributesTableName}, 759 {Name: "ATTRIBUTE", Type: types.LongText, Default: nil, Nullable: true, Source: UserAttributesTableName}, 760 } 761 762 var userPrivilegesSchema = Schema{ 763 {Name: "GRANTEE", Type: types.MustCreateString(sqltypes.VarChar, 292, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: UserPrivilegesTableName}, 764 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 512, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: UserPrivilegesTableName}, 765 {Name: "PRIVILEGE_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: UserPrivilegesTableName}, 766 {Name: "IS_GRANTABLE", Type: types.MustCreateString(sqltypes.VarChar, 3, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: UserPrivilegesTableName}, 767 } 768 769 var viewRoutineUsageSchema = Schema{ 770 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewRoutineUsageTableName}, 771 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewRoutineUsageTableName}, 772 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewRoutineUsageTableName}, 773 {Name: "SPECIFIC_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewRoutineUsageTableName}, 774 {Name: "SPECIFIC_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewRoutineUsageTableName}, 775 {Name: "SPECIFIC_TABLE", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ViewRoutineUsageTableName}, 776 } 777 778 var viewTableUsageSchema = Schema{ 779 {Name: "VIEW_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewTableUsageTableName}, 780 {Name: "VIEW_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewTableUsageTableName}, 781 {Name: "VIEW_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewTableUsageTableName}, 782 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewTableUsageTableName}, 783 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewTableUsageTableName}, 784 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewTableUsageTableName}, 785 } 786 787 var viewsSchema = Schema{ 788 {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 789 {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 790 {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 791 {Name: "VIEW_DEFINITION", Type: types.LongText, Default: nil, Nullable: true, Source: ViewsTableName}, 792 {Name: "CHECK_OPTION", Type: types.MustCreateEnumType([]string{"NONE", "LOCAL", "CASCADED"}, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 793 {Name: "IS_UPDATABLE", Type: types.MustCreateEnumType([]string{"NO", "YES"}, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 794 {Name: "DEFINER", Type: types.MustCreateString(sqltypes.VarChar, 288, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 795 {Name: "SECURITY_TYPE", Type: types.MustCreateString(sqltypes.VarChar, 7, Collation_Information_Schema_Default), Default: nil, Nullable: true, Source: ViewsTableName}, 796 {Name: "CHARACTER_SET_CLIENT", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ViewsTableName}, 797 {Name: "COLLATION_CONNECTION", Type: types.MustCreateString(sqltypes.VarChar, 64, Collation_Information_Schema_Default), Default: nil, Nullable: false, Source: ViewsTableName}, 798 } 799 800 // characterSetsRowIter implements the sql.RowIter for the information_schema.CHARACTER_SETS table. 801 func characterSetsRowIter(ctx *Context, c Catalog) (RowIter, error) { 802 var rows []Row 803 for _, c := range SupportedCharsets { 804 rows = append(rows, Row{ 805 c.String(), 806 c.DefaultCollation().Name(), 807 c.Description(), 808 uint64(c.MaxLength()), 809 }) 810 } 811 return RowsToRowIter(rows...), nil 812 } 813 814 // checkConstraintsRowIter implements the sql.RowIter for the information_schema.CHECK_CONSTRAINTS table. 815 func checkConstraintsRowIter(ctx *Context, c Catalog) (RowIter, error) { 816 var rows []Row 817 for _, db := range c.AllDatabases(ctx) { 818 tableNames, err := db.GetTableNames(ctx) 819 if err != nil { 820 return nil, err 821 } 822 823 for _, tableName := range tableNames { 824 tbl, _, err := c.DatabaseTable(ctx, db, tableName) 825 if err != nil { 826 return nil, err 827 } 828 829 checkTbl, ok := tbl.(CheckTable) 830 if ok { 831 checkDefinitions, err := checkTbl.GetChecks(ctx) 832 if err != nil { 833 return nil, err 834 } 835 836 for _, checkDefinition := range checkDefinitions { 837 rows = append(rows, Row{"def", db.Name(), checkDefinition.Name, checkDefinition.CheckExpression}) 838 } 839 } 840 } 841 } 842 843 return RowsToRowIter(rows...), nil 844 } 845 846 // collationCharacterSetApplicabilityRowIter implements the sql.RowIter for the information_schema.COLLATION_CHARACTER_SET_APPLICABILITY table. 847 func collationCharacterSetApplicabilityRowIter(ctx *Context, c Catalog) (RowIter, error) { 848 var rows []Row 849 collIter := NewCollationsIterator() 850 for c, ok := collIter.Next(); ok; c, ok = collIter.Next() { 851 rows = append(rows, Row{ 852 c.Name, 853 c.CharacterSet.String(), 854 }) 855 } 856 return RowsToRowIter(rows...), nil 857 } 858 859 // collationsRowIter implements the sql.RowIter for the information_schema.COLLATIONS table. 860 func collationsRowIter(ctx *Context, c Catalog) (RowIter, error) { 861 var rows []Row 862 collIter := NewCollationsIterator() 863 for c, ok := collIter.Next(); ok; c, ok = collIter.Next() { 864 rows = append(rows, Row{ 865 c.Name, 866 c.CharacterSet.Name(), 867 uint64(c.ID), 868 c.ID.IsDefault(), 869 c.ID.IsCompiled(), 870 c.ID.SortLength(), 871 c.ID.PadAttribute(), 872 }) 873 } 874 return RowsToRowIter(rows...), nil 875 } 876 877 // columnStatisticsRowIter implements the sql.RowIter for the information_schema.COLUMN_STATISTICS table. 878 func columnStatisticsRowIter(ctx *Context, c Catalog) (RowIter, error) { 879 var rows []Row 880 privSet, privSetCount := ctx.GetPrivilegeSet() 881 if privSetCount == 0 { 882 return nil, nil 883 } 884 if privSet == nil { 885 return RowsToRowIter(rows...), nil 886 } 887 for _, db := range c.AllDatabases(ctx) { 888 dbName := db.Name() 889 privSetDb := privSet.Database(dbName) 890 891 err := DBTableIter(ctx, db, func(t Table) (cont bool, err error) { 892 privSetTbl := privSetDb.Table(t.Name()) 893 tableStats, err := c.GetTableStats(ctx, dbName, t.Name()) 894 if err != nil { 895 return true, nil 896 } 897 for _, stats := range tableStats { 898 for _, c := range stats.Columns() { 899 if privSetTbl.Count() == 0 && privSetDb.Count() == 0 && privSetTbl.Column(c).Count() == 0 { 900 continue 901 } 902 } 903 rows = append(rows, Row{ 904 db.Name(), // table_schema 905 t.Name(), // table_name 906 strings.Join(stats.Columns(), ","), // column_name 907 stats, 908 }) 909 } 910 return true, nil 911 }) 912 913 if err != nil { 914 return nil, err 915 } 916 } 917 return RowsToRowIter(rows...), nil 918 } 919 920 // columnsExtensionsRowIter implements the sql.RowIter for the information_schema.COLUMNS_EXTENSIONS table. 921 func columnsExtensionsRowIter(ctx *Context, cat Catalog) (RowIter, error) { 922 var rows []Row 923 for _, db := range cat.AllDatabases(ctx) { 924 dbName := db.Name() 925 err := DBTableIter(ctx, db, func(t Table) (cont bool, err error) { 926 tblName := t.Name() 927 for _, col := range t.Schema() { 928 rows = append(rows, Row{ 929 "def", // table_catalog 930 dbName, // table_schema 931 tblName, // table_name 932 col.Name, // column_name 933 nil, // engine_attribute // TODO: reserved for future use 934 nil, // secondary_engine_attribute // TODO: reserved for future use 935 }) 936 } 937 return true, nil 938 }) 939 if err != nil { 940 return nil, err 941 } 942 } 943 return RowsToRowIter(rows...), nil 944 } 945 946 // enginesRowIter implements the sql.RowIter for the information_schema.ENGINES table. 947 func enginesRowIter(ctx *Context, cat Catalog) (RowIter, error) { 948 var rows []Row 949 for _, c := range SupportedEngines { 950 rows = append(rows, Row{ 951 c.String(), 952 c.Support(), 953 c.Comment(), 954 c.Transactions(), 955 c.XA(), 956 c.Savepoints(), 957 }) 958 } 959 return RowsToRowIter(rows...), nil 960 } 961 962 // eventsRowIter implements the sql.RowIter for the information_schema.EVENTS table. 963 func eventsRowIter(ctx *Context, c Catalog) (RowIter, error) { 964 var rows []Row 965 966 characterSetClient, err := ctx.GetSessionVariable(ctx, "character_set_client") 967 if err != nil { 968 return nil, err 969 } 970 collationConnection, err := ctx.GetSessionVariable(ctx, "collation_connection") 971 972 for _, db := range c.AllDatabases(ctx) { 973 dbCollation := plan.GetDatabaseCollation(ctx, db) 974 dbName := db.Name() 975 eventDb, ok := db.(EventDatabase) 976 if ok { 977 eventDefs, _, err := eventDb.GetEvents(ctx) 978 if err != nil { 979 return nil, err 980 } 981 if len(eventDefs) == 0 { 982 continue 983 } 984 985 for _, e := range eventDefs { 986 ed := e.ConvertTimesFromUTCToTz(gmstime.SystemTimezoneOffset()) 987 var at, intervalVal, intervalField, starts, ends interface{} 988 var eventType, status string 989 if ed.HasExecuteAt { 990 eventType = "ONE TIME" 991 at = ed.ExecuteAt.Format(EventDateSpaceTimeFormat) 992 } else { 993 eventType = "RECURRING" 994 interval, err := EventOnScheduleEveryIntervalFromString(ed.ExecuteEvery) 995 if err != nil { 996 return nil, err 997 } 998 intervalVal, intervalField = interval.GetIntervalValAndField() 999 starts = ed.Starts.Format(EventDateSpaceTimeFormat) 1000 if ed.HasEnds { 1001 ends = ed.Ends.Format(EventDateSpaceTimeFormat) 1002 } 1003 } 1004 1005 eventStatus, err := EventStatusFromString(ed.Status) 1006 if err != nil { 1007 return nil, err 1008 } 1009 switch eventStatus { 1010 case EventStatus_Enable: 1011 status = "ENABLED" 1012 case EventStatus_Disable: 1013 status = "DISABLED" 1014 case EventStatus_DisableOnSlave: 1015 status = "SLAVESIDE_DISABLED" 1016 } 1017 1018 onCompPerserve := "NOT PRESERVE" 1019 if ed.OnCompletionPreserve { 1020 onCompPerserve = "PRESERVE" 1021 } 1022 1023 created := ed.CreatedAt.Format(EventDateSpaceTimeFormat) 1024 lastAltered := ed.LastAltered.Format(EventDateSpaceTimeFormat) 1025 lastExecuted := ed.LastExecuted.Format(EventDateSpaceTimeFormat) 1026 // TODO: timezone should use e.TimezoneOffest, but is always 'SYSTEM' for now. 1027 1028 rows = append(rows, Row{ 1029 "def", // event_catalog 1030 dbName, // event_schema 1031 ed.Name, // event_name 1032 ed.Definer, // definer 1033 "SYSTEM", // time_zone 1034 "SQL", // event_body 1035 ed.EventBody, // event_definition 1036 eventType, // event_type 1037 at, // execute_at 1038 intervalVal, // interval_value 1039 intervalField, // interval_field 1040 e.SqlMode, // sql_mode 1041 starts, // starts 1042 ends, // ends 1043 status, // status 1044 onCompPerserve, // on_completion 1045 created, // created 1046 lastAltered, // last_altered 1047 lastExecuted, // last_executed 1048 ed.Comment, // event_comment 1049 0, // originator 1050 characterSetClient, // character_set_client 1051 collationConnection, // collation_connection 1052 dbCollation.String(), // database_collation 1053 }) 1054 } 1055 } 1056 } 1057 1058 return RowsToRowIter(rows...), nil 1059 } 1060 1061 // keyColumnUsageRowIter implements the sql.RowIter for the information_schema.KEY_COLUMN_USAGE table. 1062 func keyColumnUsageRowIter(ctx *Context, c Catalog) (RowIter, error) { 1063 var rows []Row 1064 for _, db := range c.AllDatabases(ctx) { 1065 tableNames, err := db.GetTableNames(ctx) 1066 if err != nil { 1067 return nil, err 1068 } 1069 1070 for _, tableName := range tableNames { 1071 tbl, _, err := c.DatabaseTable(ctx, db, tableName) 1072 if err != nil { 1073 return nil, err 1074 } 1075 1076 // Get UNIQUEs, PRIMARY KEYs 1077 // TODO: Doesn't correctly consider primary keys from table implementations that don't implement sql.IndexedTable 1078 indexTable, ok := tbl.(IndexAddressable) 1079 if ok { 1080 indexes, err := indexTable.GetIndexes(ctx) 1081 if err != nil { 1082 return nil, err 1083 } 1084 1085 for _, index := range indexes { 1086 // In this case we have a multi-index which is not represented in this table 1087 if index.ID() != "PRIMARY" && !index.IsUnique() { 1088 continue 1089 } 1090 1091 colNames := getColumnNamesFromIndex(index, tbl) 1092 1093 // Create a Row for each column this index refers too. 1094 for i, colName := range colNames { 1095 ordinalPosition := i + 1 // Ordinal Positions starts at one 1096 1097 rows = append(rows, Row{"def", db.Name(), index.ID(), "def", db.Name(), tbl.Name(), colName, ordinalPosition, nil, nil, nil, nil}) 1098 } 1099 } 1100 } 1101 1102 // Get FKs 1103 fkTable, ok := tbl.(ForeignKeyTable) 1104 if ok { 1105 fks, err := fkTable.GetDeclaredForeignKeys(ctx) 1106 if err != nil { 1107 return nil, err 1108 } 1109 1110 for _, fk := range fks { 1111 for j, colName := range fk.Columns { 1112 ordinalPosition := j + 1 1113 1114 referencedSchema := fk.ParentDatabase 1115 referencedTableName := fk.ParentTable 1116 referencedColumnName := strings.Replace(fk.ParentColumns[j], "`", "", -1) // get rid of backticks 1117 1118 rows = append(rows, Row{"def", db.Name(), fk.Name, "def", db.Name(), tbl.Name(), colName, ordinalPosition, ordinalPosition, referencedSchema, referencedTableName, referencedColumnName}) 1119 } 1120 } 1121 } 1122 } 1123 } 1124 1125 return RowsToRowIter(rows...), nil 1126 } 1127 1128 // keywordsRowIter implements the sql.RowIter for the information_schema.KEYWORDS table. 1129 func keywordsRowIter(ctx *Context, cat Catalog) (RowIter, error) { 1130 var rows []Row 1131 for _, spRef := range keywordsArray { 1132 rows = append(rows, Row{ 1133 spRef.Word, // word 1134 spRef.Reserved, // reserved 1135 }) 1136 } 1137 1138 return RowsToRowIter(rows...), nil 1139 } 1140 1141 // processListRowIter implements the sql.RowIter for the information_schema.PROCESSLIST table. 1142 func processListRowIter(ctx *Context, c Catalog) (RowIter, error) { 1143 processes := ctx.ProcessList.Processes() 1144 var rows = make([]Row, len(processes)) 1145 1146 for i, proc := range processes { 1147 var status []string 1148 for name, progress := range proc.Progress { 1149 status = append(status, fmt.Sprintf("%s(%s)", name, progress)) 1150 } 1151 if len(status) == 0 && proc.Command == ProcessCommandQuery { 1152 status = []string{"running"} 1153 } 1154 sort.Strings(status) 1155 1156 var db interface{} 1157 if proc.Database != "" { 1158 db = proc.Database 1159 } 1160 1161 rows[i] = Row{ 1162 uint64(proc.Connection), // id 1163 proc.User, // user 1164 proc.Host, // host 1165 db, // db 1166 string(proc.Command), // command 1167 int32(proc.Seconds()), // time 1168 strings.Join(status, ", "), // state 1169 proc.Query, // info 1170 } 1171 } 1172 1173 return RowsToRowIter(rows...), nil 1174 } 1175 1176 // referentialConstraintsRowIter implements the sql.RowIter for the information_schema.REFERENTIAL_CONSTRAINTS table. 1177 func referentialConstraintsRowIter(ctx *Context, c Catalog) (RowIter, error) { 1178 var rows []Row 1179 for _, db := range c.AllDatabases(ctx) { 1180 tableNames, err := db.GetTableNames(ctx) 1181 if err != nil { 1182 return nil, err 1183 } 1184 1185 for _, tableName := range tableNames { 1186 tbl, _, err := c.DatabaseTable(ctx, db, tableName) 1187 if err != nil { 1188 return nil, err 1189 } 1190 1191 // Get FKs 1192 fkTable, ok := tbl.(ForeignKeyTable) 1193 if ok { 1194 fks, err := fkTable.GetDeclaredForeignKeys(ctx) 1195 if err != nil { 1196 return nil, err 1197 } 1198 1199 for _, fk := range fks { 1200 var uniqueConstName interface{} 1201 referencedSchema := fk.ParentDatabase 1202 referencedTableName := fk.ParentTable 1203 referencedCols := make(map[string]struct{}) 1204 for _, refCol := range fk.ParentColumns { 1205 referencedCols[refCol] = struct{}{} 1206 } 1207 1208 onUpdate := string(fk.OnUpdate) 1209 if fk.OnUpdate == ForeignKeyReferentialAction_DefaultAction { 1210 onUpdate = "NO ACTION" 1211 } 1212 onDelete := string(fk.OnDelete) 1213 if fk.OnDelete == ForeignKeyReferentialAction_DefaultAction { 1214 onDelete = "NO ACTION" 1215 } 1216 1217 // ErrTableNotFound is returned when the referenced table is dropped, so `unique_constraint_name` column will not be filled. 1218 refTbl, _, refErr := c.Table(ctx, referencedSchema, referencedTableName) 1219 if refErr == nil { 1220 indexTable, iok := refTbl.(IndexAddressable) 1221 if iok { 1222 indexes, ierr := indexTable.GetIndexes(ctx) 1223 if ierr != nil { 1224 1225 } 1226 for _, index := range indexes { 1227 if index.ID() != "PRIMARY" && !index.IsUnique() { 1228 continue 1229 } 1230 colNames := getColumnNamesFromIndex(index, refTbl) 1231 if len(colNames) == len(referencedCols) { 1232 var hasAll = true 1233 for _, colName := range colNames { 1234 _, hasAll = referencedCols[colName] 1235 } 1236 if hasAll { 1237 uniqueConstName = index.ID() 1238 } 1239 } 1240 } 1241 } 1242 } else if !ErrTableNotFound.Is(refErr) { 1243 return nil, refErr 1244 } 1245 1246 rows = append(rows, Row{ 1247 "def", // constraint_catalog 1248 db.Name(), // constraint_schema 1249 fk.Name, // constraint_name 1250 "def", // unique_constraint_catalog 1251 referencedSchema, // unique_constraint_schema 1252 uniqueConstName, // unique_constraint_name 1253 "NONE", // match_option 1254 onUpdate, // update_rule 1255 onDelete, // delete_rule 1256 tbl.Name(), // table_name 1257 referencedTableName, // referenced_table_name 1258 }) 1259 } 1260 } 1261 } 1262 } 1263 1264 return RowsToRowIter(rows...), nil 1265 } 1266 1267 // schemaPrivilegesRowIter implements the sql.RowIter for the information_schema.SCHEMA_PRIVILEGES table. 1268 func schemaPrivilegesRowIter(ctx *Context, c Catalog) (RowIter, error) { 1269 var rows []Row 1270 privSet, _ := ctx.GetPrivilegeSet() 1271 if privSet == nil { 1272 privSet = mysql_db.NewPrivilegeSet() 1273 } 1274 if privSet.Has(PrivilegeType_Select) || privSet.Database("mysql").Has(PrivilegeType_Select) { 1275 db, err := c.Database(ctx, "mysql") 1276 if err != nil { 1277 return nil, err 1278 } 1279 1280 mysqlDb, ok := db.(*mysql_db.MySQLDb) 1281 if !ok { 1282 return nil, ErrDatabaseNotFound.New("mysql") 1283 } 1284 1285 dbTbl, _, err := mysqlDb.GetTableInsensitive(ctx, "db") 1286 if err != nil { 1287 return nil, err 1288 } 1289 1290 var keys []mysql_db.UserPrimaryKey 1291 err = iterRows(ctx, dbTbl, func(r Row) error { 1292 // mysql.db table will have 'Host', 'Db', 'User' as first 3 columns in string format. 1293 keys = append(keys, mysql_db.UserPrimaryKey{ 1294 Host: r[0].(string), 1295 User: r[2].(string), 1296 }) 1297 return nil 1298 }) 1299 if err != nil { 1300 return nil, err 1301 } 1302 1303 rd := mysqlDb.Reader() 1304 defer rd.Close() 1305 1306 users := make(map[*mysql_db.User]struct{}) 1307 for _, userKey := range keys { 1308 user := mysqlDb.GetUser(rd, userKey.User, userKey.Host, false) 1309 if user == nil { 1310 continue 1311 } 1312 users[user] = struct{}{} 1313 } 1314 for user := range users { 1315 grantee := user.UserHostToString("'") 1316 for _, privSetDb := range user.PrivilegeSet.GetDatabases() { 1317 rows = append(rows, getSchemaPrivsRowsFromPrivDbSet(privSetDb, grantee)...) 1318 } 1319 } 1320 } else { 1321 // If current client does not have SELECT privilege on 'mysql' db, only available schema privileges are 1322 // their current schema privileges. 1323 currClient := ctx.Session.Client() 1324 grantee := fmt.Sprintf("'%s'@'%s'", currClient.User, currClient.Address) 1325 dbs := c.AllDatabases(ctx) 1326 for _, db := range dbs { 1327 dbName := db.Name() 1328 privSetDb := privSet.Database(dbName) 1329 rows = append(rows, getSchemaPrivsRowsFromPrivDbSet(privSetDb, grantee)...) 1330 } 1331 } 1332 1333 return RowsToRowIter(rows...), nil 1334 } 1335 1336 // schemataRowIter implements the sql.RowIter for the information_schema.SCHEMATA table. 1337 func schemataRowIter(ctx *Context, c Catalog) (RowIter, error) { 1338 dbs := c.AllDatabases(ctx) 1339 1340 var rows []Row 1341 for _, db := range dbs { 1342 collation := plan.GetDatabaseCollation(ctx, db) 1343 rows = append(rows, Row{ 1344 "def", // catalog_name 1345 db.Name(), // schema_name 1346 collation.CharacterSet().String(), // default_character_set_name 1347 collation.String(), // default_collation_name 1348 nil, // sql_path 1349 "NO", // default_encryption 1350 }) 1351 } 1352 1353 return RowsToRowIter(rows...), nil 1354 } 1355 1356 // schemataExtensionsRowIter implements the sql.RowIter for the information_schema.SCHEMATA_EXTENSIONS table. 1357 func schemataExtensionsRowIter(ctx *Context, c Catalog) (RowIter, error) { 1358 var rows []Row 1359 for _, db := range c.AllDatabases(ctx) { 1360 var readOnly string 1361 if rodb, ok := db.(ReadOnlyDatabase); ok { 1362 if rodb.IsReadOnly() { 1363 readOnly = "READ ONLY=1" 1364 } 1365 } 1366 rows = append(rows, Row{ 1367 "def", // catalog_name 1368 db.Name(), // schema_name 1369 readOnly, // options 1370 }) 1371 } 1372 1373 return RowsToRowIter(rows...), nil 1374 } 1375 1376 // stGeometryColumnsRowIter implements the sql.RowIter for the information_schema.ST_GEOMETRY_COLUMNS table. 1377 func stGeometryColumnsRowIter(ctx *Context, cat Catalog) (RowIter, error) { 1378 var rows []Row 1379 for _, db := range cat.AllDatabases(ctx) { 1380 dbName := db.Name() 1381 1382 err := DBTableIter(ctx, db, func(t Table) (cont bool, err error) { 1383 tblName := t.Name() 1384 1385 for _, col := range t.Schema() { 1386 s, ok := col.Type.(SpatialColumnType) 1387 if !ok { 1388 continue 1389 } 1390 var ( 1391 colName = col.Name 1392 srsName interface{} 1393 srsId interface{} 1394 ) 1395 typeName, _ := getDtdIdAndDataType(col.Type) 1396 1397 if srid, d := s.GetSpatialTypeSRID(); d { 1398 srsName = types.SupportedSRIDs[srid].Name 1399 srsId = srid 1400 } 1401 1402 rows = append(rows, Row{ 1403 "def", // table_catalog 1404 dbName, // table_schema 1405 tblName, // table_name 1406 colName, // column_name 1407 srsName, // srs_name 1408 srsId, // srs_id 1409 typeName, // geometry_type_name 1410 }) 1411 } 1412 return true, nil 1413 }) 1414 if err != nil { 1415 return nil, err 1416 } 1417 } 1418 1419 return RowsToRowIter(rows...), nil 1420 } 1421 1422 // stSpatialReferenceSystemsRowIter implements the sql.RowIter for the information_schema.ST_SPATIAL_REFERENCE_SYSTEMS table. 1423 func stSpatialReferenceSystemsRowIter(ctx *Context, cat Catalog) (RowIter, error) { 1424 var rows []Row 1425 for _, spRef := range types.SupportedSRIDs { 1426 rows = append(rows, Row{ 1427 spRef.Name, // srs_name 1428 spRef.ID, // srs_id 1429 spRef.Organization, // organization 1430 spRef.OrgCoordsysId, // organization_coordsys_id 1431 spRef.Definition, // definition 1432 spRef.Description, // description 1433 }) 1434 } 1435 1436 return RowsToRowIter(rows...), nil 1437 } 1438 1439 // stUnitsOfMeasureRowIter implements the sql.RowIter for the information_schema.ST_UNITS_OF_MEASURE table. 1440 func stUnitsOfMeasureRowIter(ctx *Context, cat Catalog) (RowIter, error) { 1441 var rows []Row 1442 for _, spRef := range unitsOfMeasureArray { 1443 rows = append(rows, Row{ 1444 spRef.Name, // unit_name 1445 spRef.Type, // unit_type 1446 spRef.ConversionFactor, // conversion_factor 1447 spRef.Description, // description 1448 }) 1449 } 1450 1451 return RowsToRowIter(rows...), nil 1452 } 1453 1454 // statisticsRowIter implements the sql.RowIter for the information_schema.STATISTICS table. 1455 func statisticsRowIter(ctx *Context, c Catalog) (RowIter, error) { 1456 var rows []Row 1457 dbs := c.AllDatabases(ctx) 1458 1459 for _, db := range dbs { 1460 tableNames, tErr := db.GetTableNames(ctx) 1461 if tErr != nil { 1462 return nil, tErr 1463 } 1464 1465 for _, tableName := range tableNames { 1466 tbl, _, err := c.DatabaseTable(ctx, db, tableName) 1467 if err != nil { 1468 return nil, err 1469 } 1470 1471 indexTable, ok := tbl.(IndexAddressable) 1472 if ok { 1473 indexes, iErr := indexTable.GetIndexes(ctx) 1474 if iErr != nil { 1475 return nil, iErr 1476 } 1477 1478 for _, index := range indexes { 1479 var ( 1480 nonUnique int 1481 indexComment string 1482 indexName string 1483 comment = "" 1484 isVisible string 1485 ) 1486 indexName = index.ID() 1487 if index.IsUnique() { 1488 nonUnique = 0 1489 } else { 1490 nonUnique = 1 1491 } 1492 indexType := index.IndexType() 1493 indexComment = index.Comment() 1494 // setting `VISIBLE` is not supported, so defaulting it to "YES" 1495 isVisible = "YES" 1496 1497 // Create a Row for each column this index refers too. 1498 i := 0 1499 for j, expr := range index.Expressions() { 1500 col := plan.GetColumnFromIndexExpr(expr, tbl) 1501 if col != nil { 1502 i += 1 1503 var ( 1504 collation string 1505 nullable string 1506 cardinality int64 1507 subPart interface{} 1508 ) 1509 1510 seqInIndex := i 1511 colName := strings.Replace(col.Name, "`", "", -1) // get rid of backticks 1512 1513 // collation is "A" for ASC ; "D" for DESC ; "NULL" for not sorted 1514 collation = "A" 1515 1516 // TODO : cardinality is an estimate of the number of unique values in the index. 1517 1518 if j < len(index.PrefixLengths()) { 1519 subPart = int64(index.PrefixLengths()[j]) 1520 } 1521 1522 // if nullable, 'YES'; if not, '' 1523 if col.Nullable { 1524 nullable = "YES" 1525 } else { 1526 nullable = "" 1527 } 1528 1529 // TODO: we currently don't support expression index such as ((i * 20)) 1530 1531 rows = append(rows, Row{ 1532 "def", // table_catalog 1533 db.Name(), // table_schema 1534 tbl.Name(), // table_name 1535 nonUnique, // non_unique NOT NULL 1536 db.Name(), // index_schema 1537 indexName, // index_name 1538 seqInIndex, // seq_in_index NOT NULL 1539 colName, // column_name 1540 collation, // collation 1541 cardinality, // cardinality 1542 subPart, // sub_part 1543 nil, // packed 1544 nullable, // is_nullable NOT NULL 1545 indexType, // index_type NOT NULL 1546 comment, // comment NOT NULL 1547 indexComment, // index_comment NOT NULL 1548 isVisible, // is_visible NOT NULL 1549 nil, // expression 1550 }) 1551 } 1552 } 1553 } 1554 } 1555 } 1556 } 1557 1558 return RowsToRowIter(rows...), nil 1559 } 1560 1561 // tableConstraintsRowIter implements the sql.RowIter for the information_schema.TABLE_CONSTRAINTS table. 1562 func tableConstraintsRowIter(ctx *Context, c Catalog) (RowIter, error) { 1563 var rows []Row 1564 for _, db := range c.AllDatabases(ctx) { 1565 tableNames, err := db.GetTableNames(ctx) 1566 if err != nil { 1567 return nil, err 1568 } 1569 1570 for _, tableName := range tableNames { 1571 tbl, _, err := c.DatabaseTable(ctx, db, tableName) 1572 if err != nil { 1573 return nil, err 1574 } 1575 1576 // Get all the CHECKs 1577 checkTbl, ok := tbl.(CheckTable) 1578 if ok { 1579 checkDefinitions, err := checkTbl.GetChecks(ctx) 1580 if err != nil { 1581 return nil, err 1582 } 1583 1584 for _, checkDefinition := range checkDefinitions { 1585 enforced := "YES" 1586 if !checkDefinition.Enforced { 1587 enforced = "NO" 1588 } 1589 rows = append(rows, Row{"def", db.Name(), checkDefinition.Name, db.Name(), tbl.Name(), "CHECK", enforced}) 1590 } 1591 } 1592 1593 // Get UNIQUEs, PRIMARY KEYs 1594 // TODO: Doesn't correctly consider primary keys from table implementations that don't implement sql.IndexedTable 1595 indexTable, ok := tbl.(IndexAddressable) 1596 if ok { 1597 indexes, err := indexTable.GetIndexes(ctx) 1598 if err != nil { 1599 return nil, err 1600 } 1601 1602 for _, index := range indexes { 1603 outputType := "PRIMARY KEY" 1604 if index.ID() != "PRIMARY" { 1605 if index.IsUnique() { 1606 outputType = "UNIQUE" 1607 } else { 1608 // In this case we have a multi-index which is not represented in this table 1609 continue 1610 } 1611 1612 } 1613 1614 rows = append(rows, Row{"def", db.Name(), index.ID(), db.Name(), tbl.Name(), outputType, "YES"}) 1615 } 1616 } 1617 1618 // Get FKs 1619 fkTable, ok := tbl.(ForeignKeyTable) 1620 if ok { 1621 fks, err := fkTable.GetDeclaredForeignKeys(ctx) 1622 if err != nil { 1623 return nil, err 1624 } 1625 1626 for _, fk := range fks { 1627 rows = append(rows, Row{"def", db.Name(), fk.Name, db.Name(), tbl.Name(), "FOREIGN KEY", "YES"}) 1628 } 1629 } 1630 } 1631 } 1632 1633 return RowsToRowIter(rows...), nil 1634 } 1635 1636 // tableConstraintsExtensionsRowIter implements the sql.RowIter for the information_schema.TABLE_CONSTRAINTS_EXTENSIONS table. 1637 func tableConstraintsExtensionsRowIter(ctx *Context, c Catalog) (RowIter, error) { 1638 var rows []Row 1639 for _, db := range c.AllDatabases(ctx) { 1640 dbName := db.Name() 1641 tableNames, err := db.GetTableNames(ctx) 1642 if err != nil { 1643 return nil, err 1644 } 1645 1646 for _, tableName := range tableNames { 1647 tbl, _, err := c.DatabaseTable(ctx, db, tableName) 1648 if err != nil { 1649 return nil, err 1650 } 1651 tblName := tbl.Name() 1652 1653 // Get UNIQUEs, PRIMARY KEYs 1654 // TODO: Doesn't correctly consider primary keys from table implementations that don't implement sql.IndexedTable 1655 indexTable, ok := tbl.(IndexAddressable) 1656 if ok { 1657 indexes, err := indexTable.GetIndexes(ctx) 1658 if err != nil { 1659 return nil, err 1660 } 1661 1662 for _, index := range indexes { 1663 rows = append(rows, Row{ 1664 "def", 1665 dbName, 1666 index.ID(), 1667 tblName, 1668 nil, 1669 nil, 1670 }) 1671 } 1672 } 1673 } 1674 } 1675 1676 return RowsToRowIter(rows...), nil 1677 } 1678 1679 type partitionIterable interface { 1680 Partitions(*Context) (PartitionIter, error) 1681 PartitionRows(*Context, Partition) (RowIter, error) 1682 } 1683 1684 func iterRows(ctx *Context, pii partitionIterable, cb func(Row) error) (rerr error) { 1685 pi, err := pii.Partitions(ctx) 1686 if err != nil { 1687 return err 1688 } 1689 defer func() { 1690 err := pi.Close(ctx) 1691 if rerr == nil { 1692 rerr = err 1693 } 1694 }() 1695 for { 1696 p, err := pi.Next(ctx) 1697 if err == io.EOF { 1698 return nil 1699 } 1700 if err != nil { 1701 return err 1702 } 1703 ri, err := pii.PartitionRows(ctx, p) 1704 if err != nil { 1705 return err 1706 } 1707 for { 1708 r, err := ri.Next(ctx) 1709 if err == io.EOF { 1710 ri.Close(ctx) 1711 break 1712 } 1713 if err != nil { 1714 ri.Close(ctx) 1715 return err 1716 } 1717 err = cb(r) 1718 if err != nil { 1719 ri.Close(ctx) 1720 return err 1721 } 1722 } 1723 } 1724 } 1725 1726 // tablePrivilegesRowIter implements the sql.RowIter for the information_schema.TABLE_PRIVILEGES table. 1727 func tablePrivilegesRowIter(ctx *Context, c Catalog) (RowIter, error) { 1728 var rows []Row 1729 privSet, _ := ctx.GetPrivilegeSet() 1730 if privSet == nil { 1731 privSet = mysql_db.NewPrivilegeSet() 1732 } 1733 if privSet.Has(PrivilegeType_Select) || privSet.Database("mysql").Has(PrivilegeType_Select) { 1734 db, err := c.Database(ctx, "mysql") 1735 if err != nil { 1736 return nil, err 1737 } 1738 1739 mysqlDb, ok := db.(*mysql_db.MySQLDb) 1740 if !ok { 1741 return nil, ErrDatabaseNotFound.New("mysql") 1742 } 1743 1744 tblsPriv, _, err := mysqlDb.GetTableInsensitive(ctx, "tables_priv") 1745 if err != nil { 1746 return nil, err 1747 } 1748 1749 var keys []mysql_db.UserPrimaryKey 1750 err = iterRows(ctx, tblsPriv, func(r Row) error { 1751 keys = append(keys, mysql_db.UserPrimaryKey{ 1752 Host: r[0].(string), 1753 User: r[2].(string), 1754 }) 1755 return nil 1756 }) 1757 if err != nil { 1758 return nil, err 1759 } 1760 1761 rd := mysqlDb.Reader() 1762 defer rd.Close() 1763 1764 users := make(map[*mysql_db.User]struct{}) 1765 for _, userKey := range keys { 1766 user := mysqlDb.GetUser(rd, userKey.User, userKey.Host, false) 1767 if user == nil { 1768 continue 1769 } 1770 users[user] = struct{}{} 1771 } 1772 for user := range users { 1773 grantee := user.UserHostToString("'") 1774 for _, privSetDb := range user.PrivilegeSet.GetDatabases() { 1775 dbName := privSetDb.Name() 1776 for _, privSetTbl := range privSetDb.GetTables() { 1777 rows = append(rows, getTablePrivsRowsFromPrivTblSet(privSetTbl, grantee, dbName)...) 1778 } 1779 } 1780 } 1781 } else { 1782 // If current client does not have SELECT privilege on 'mysql' db, only available table privileges are 1783 // their current table privileges. 1784 currClient := ctx.Session.Client() 1785 grantee := fmt.Sprintf("'%s'@'%s'", currClient.User, currClient.Address) 1786 dbs := c.AllDatabases(ctx) 1787 for _, db := range dbs { 1788 dbName := db.Name() 1789 privSetDb := privSet.Database(dbName) 1790 for _, privSetTbl := range privSetDb.GetTables() { 1791 rows = append(rows, getTablePrivsRowsFromPrivTblSet(privSetTbl, grantee, dbName)...) 1792 } 1793 } 1794 } 1795 1796 return RowsToRowIter(rows...), nil 1797 } 1798 1799 // tablesRowIter implements the sql.RowIter for the information_schema.TABLES table. 1800 func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) { 1801 var rows []Row 1802 var ( 1803 tableType string 1804 tableRows uint64 1805 avgRowLength uint64 1806 dataLength uint64 1807 engine interface{} 1808 rowFormat interface{} 1809 tableCollation interface{} 1810 autoInc interface{} 1811 ) 1812 1813 for _, db := range cat.AllDatabases(ctx) { 1814 if db.Name() == InformationSchemaDatabaseName { 1815 tableType = "SYSTEM VIEW" 1816 } else { 1817 tableType = "BASE TABLE" 1818 engine = "InnoDB" 1819 rowFormat = "Dynamic" 1820 } 1821 1822 y2k, _, _ := types.Timestamp.Convert("2000-01-01 00:00:00") 1823 err := DBTableIter(ctx, db, func(t Table) (cont bool, err error) { 1824 tableCollation = t.Collation().String() 1825 if db.Name() != InformationSchemaDatabaseName { 1826 if st, ok := t.(StatisticsTable); ok { 1827 tableRows, _, err = st.RowCount(ctx) 1828 if err != nil { 1829 return false, err 1830 } 1831 1832 // TODO: correct values for avg_row_length, data_length, max_data_length are missing (current values varies on gms vs Dolt) 1833 // index_length and data_free columns are not supported yet 1834 // the data length values differ from MySQL 1835 // MySQL uses default page size (16384B) as data length, and it adds another page size, if table data fills the current page block. 1836 // https://stackoverflow.com/questions/34211377/average-row-length-higher-than-possible has good explanation. 1837 dataLength, err = st.DataLength(ctx) 1838 if err != nil { 1839 return false, err 1840 } 1841 1842 if tableRows > uint64(0) { 1843 avgRowLength = dataLength / tableRows 1844 } 1845 } 1846 1847 if ai, ok := t.(AutoIncrementTable); ok { 1848 autoInc, err = ai.PeekNextAutoIncrementValue(ctx) 1849 if !errors.Is(err, ErrNoAutoIncrementCol) && err != nil { 1850 return false, err 1851 } 1852 1853 // table with no auto incremented column is qualified as AutoIncrementTable, and the nextAutoInc value is 0 1854 // table with auto incremented column and no rows, the nextAutoInc value is 1 1855 if autoInc == uint64(0) || autoInc == uint64(1) { 1856 autoInc = nil 1857 } 1858 } 1859 } 1860 1861 rows = append(rows, Row{ 1862 "def", // table_catalog 1863 db.Name(), // table_schema 1864 t.Name(), // table_name 1865 tableType, // table_type 1866 engine, // engine 1867 10, // version (protocol, always 10) 1868 rowFormat, // row_format 1869 tableRows, // table_rows 1870 avgRowLength, // avg_row_length 1871 dataLength, // data_length 1872 0, // max_data_length 1873 0, // index_length 1874 0, // data_free 1875 autoInc, // auto_increment 1876 y2k, // create_time 1877 y2k, // update_time 1878 nil, // check_time 1879 tableCollation, // table_collation 1880 nil, // checksum 1881 "", // create_options 1882 "", // table_comment 1883 }) 1884 1885 return true, nil 1886 }) 1887 1888 if err != nil { 1889 return nil, err 1890 } 1891 1892 views, err := viewsInDatabase(ctx, db) 1893 if err != nil { 1894 return nil, err 1895 } 1896 1897 for _, view := range views { 1898 rows = append(rows, Row{ 1899 "def", // table_catalog 1900 db.Name(), // table_schema 1901 view.Name, // table_name 1902 "VIEW", // table_type 1903 nil, // engine 1904 nil, // version (protocol, always 10) 1905 nil, // row_format 1906 nil, // table_rows 1907 nil, // avg_row_length 1908 nil, // data_length 1909 nil, // max_data_length 1910 nil, // max_data_length 1911 nil, // data_free 1912 nil, // auto_increment 1913 y2k, // create_time 1914 nil, // update_time 1915 nil, // check_time 1916 nil, // table_collation 1917 nil, // checksum 1918 nil, // create_options 1919 "VIEW", // table_comment 1920 }) 1921 } 1922 } 1923 1924 return RowsToRowIter(rows...), nil 1925 } 1926 1927 // tablesExtensionsRowIter implements the sql.RowIter for the information_schema.TABLES_EXTENSIONS table. 1928 func tablesExtensionsRowIter(ctx *Context, cat Catalog) (RowIter, error) { 1929 var rows []Row 1930 for _, db := range cat.AllDatabases(ctx) { 1931 dbName := db.Name() 1932 err := DBTableIter(ctx, db, func(t Table) (cont bool, err error) { 1933 rows = append(rows, Row{ 1934 "def", // table_catalog 1935 dbName, // table_schema 1936 t.Name(), // table_name 1937 nil, // engine_attribute // TODO: reserved for future use 1938 nil, // secondary_engine_attribute // TODO: reserved for future use 1939 }) 1940 return true, nil 1941 }) 1942 if err != nil { 1943 return nil, err 1944 } 1945 } 1946 return RowsToRowIter(rows...), nil 1947 } 1948 1949 // triggersRowIter implements the sql.RowIter for the information_schema.TRIGGERS table. 1950 func triggersRowIter(ctx *Context, c Catalog) (RowIter, error) { 1951 var rows []Row 1952 characterSetClient, err := ctx.GetSessionVariable(ctx, "character_set_client") 1953 if err != nil { 1954 return nil, err 1955 } 1956 collationConnection, err := ctx.GetSessionVariable(ctx, "collation_connection") 1957 if err != nil { 1958 return nil, err 1959 } 1960 1961 privSet, _ := ctx.GetPrivilegeSet() 1962 if privSet == nil { 1963 return RowsToRowIter(rows...), nil 1964 } 1965 hasGlobalTriggerPriv := privSet.Has(PrivilegeType_Trigger) 1966 for _, db := range c.AllDatabases(ctx) { 1967 dbCollation := plan.GetDatabaseCollation(ctx, db) 1968 triggerDb, ok := db.(TriggerDatabase) 1969 if ok { 1970 privDbSet := privSet.Database(db.Name()) 1971 hasDbTriggerPriv := privDbSet.Has(PrivilegeType_Trigger) 1972 triggers, err := triggerDb.GetTriggers(ctx) 1973 if err != nil { 1974 return nil, err 1975 } 1976 1977 if len(triggers) == 0 { 1978 continue 1979 } 1980 1981 var triggerPlans []*plan.CreateTrigger 1982 for _, trigger := range triggers { 1983 triggerSqlMode := NewSqlModeFromString(trigger.SqlMode) 1984 parsedTrigger, err := planbuilder.ParseWithOptions(ctx, c, trigger.CreateStatement, triggerSqlMode.ParserOptions()) 1985 if err != nil { 1986 return nil, err 1987 } 1988 triggerPlan, ok := parsedTrigger.(*plan.CreateTrigger) 1989 if !ok { 1990 return nil, ErrTriggerCreateStatementInvalid.New(trigger.CreateStatement) 1991 } 1992 triggerPlan.CreatedAt = trigger.CreatedAt // Keep stored created time 1993 triggerPlan.SqlMode = triggerSqlMode.String() 1994 triggerPlans = append(triggerPlans, triggerPlan) 1995 } 1996 1997 beforeTriggers, afterTriggers := plan.OrderTriggers(triggerPlans) 1998 var beforeDelete []*plan.CreateTrigger 1999 var beforeInsert []*plan.CreateTrigger 2000 var beforeUpdate []*plan.CreateTrigger 2001 var afterDelete []*plan.CreateTrigger 2002 var afterInsert []*plan.CreateTrigger 2003 var afterUpdate []*plan.CreateTrigger 2004 for _, triggerPlan := range beforeTriggers { 2005 switch triggerPlan.TriggerEvent { 2006 case sqlparser.DeleteStr: 2007 beforeDelete = append(beforeDelete, triggerPlan) 2008 case sqlparser.InsertStr: 2009 beforeInsert = append(beforeInsert, triggerPlan) 2010 case sqlparser.UpdateStr: 2011 beforeUpdate = append(beforeUpdate, triggerPlan) 2012 } 2013 } 2014 for _, triggerPlan := range afterTriggers { 2015 switch triggerPlan.TriggerEvent { 2016 case sqlparser.DeleteStr: 2017 afterDelete = append(afterDelete, triggerPlan) 2018 case sqlparser.InsertStr: 2019 afterInsert = append(afterInsert, triggerPlan) 2020 case sqlparser.UpdateStr: 2021 afterUpdate = append(afterUpdate, triggerPlan) 2022 } 2023 } 2024 2025 // These are grouped as such just to use the index as the action order. No special importance on the arrangement, 2026 // or the fact that these are slices in a larger slice rather than separate counts. 2027 for _, planGroup := range [][]*plan.CreateTrigger{beforeDelete, beforeInsert, beforeUpdate, afterDelete, afterInsert, afterUpdate} { 2028 for order, triggerPlan := range planGroup { 2029 triggerEvent := strings.ToUpper(triggerPlan.TriggerEvent) 2030 triggerTime := strings.ToUpper(triggerPlan.TriggerTime) 2031 tableName := triggerPlan.Table.(*plan.ResolvedTable).Name() 2032 definer := removeBackticks(triggerPlan.Definer) 2033 2034 // triggers cannot be created on table that is not in current schema, so the trigger_name = event_object_schema 2035 privTblSet := privDbSet.Table(tableName) 2036 2037 // To see information about a table's triggers, you must have the TRIGGER privilege for the table. 2038 if hasGlobalTriggerPriv || hasDbTriggerPriv || privTblSet.Has(PrivilegeType_Trigger) { 2039 rows = append(rows, Row{ 2040 "def", // trigger_catalog 2041 triggerDb.Name(), // trigger_schema 2042 triggerPlan.TriggerName, // trigger_name 2043 triggerEvent, // event_manipulation 2044 "def", // event_object_catalog 2045 triggerDb.Name(), // event_object_schema 2046 tableName, // event_object_table 2047 int64(order + 1), // action_order 2048 nil, // action_condition 2049 triggerPlan.BodyString, // action_statement 2050 "ROW", // action_orientation 2051 triggerTime, // action_timing 2052 nil, // action_reference_old_table 2053 nil, // action_reference_new_table 2054 "OLD", // action_reference_old_row 2055 "NEW", // action_reference_new_row 2056 triggerPlan.CreatedAt, // created 2057 triggerPlan.SqlMode, // sql_mode 2058 definer, // definer 2059 characterSetClient, // character_set_client 2060 collationConnection, // collation_connection 2061 dbCollation.String(), // database_collation 2062 }) 2063 } 2064 } 2065 } 2066 } 2067 } 2068 return RowsToRowIter(rows...), nil 2069 } 2070 2071 // userAttributesRowIter implements the sql.RowIter for the information_schema.USER_ATTRIBUTES table. 2072 func userAttributesRowIter(ctx *Context, catalog Catalog) (RowIter, error) { 2073 var rows []Row 2074 curUserPrivSet, _ := ctx.GetPrivilegeSet() 2075 if curUserPrivSet == nil { 2076 curUserPrivSet = mysql_db.NewPrivilegeSet() 2077 } 2078 // TODO: or has both of `CREATE USER` and `SYSTEM_USER` privileges 2079 if curUserPrivSet.Has(PrivilegeType_Select) || curUserPrivSet.Has(PrivilegeType_Update) || curUserPrivSet.Database("mysql").Has(PrivilegeType_Select) || curUserPrivSet.Database("mysql").Has(PrivilegeType_Update) { 2080 var users = make(map[*mysql_db.User]struct{}) 2081 db, err := catalog.Database(ctx, "mysql") 2082 if err != nil { 2083 return nil, err 2084 } 2085 2086 mysqlDb, ok := db.(*mysql_db.MySQLDb) 2087 if !ok { 2088 return nil, ErrDatabaseNotFound.New("mysql") 2089 } 2090 2091 reader := mysqlDb.Reader() 2092 defer reader.Close() 2093 2094 reader.VisitUsers(func(u *mysql_db.User) { 2095 users[u] = struct{}{} 2096 }) 2097 2098 for user := range users { 2099 var attributes interface{} 2100 if user.Attributes != nil { 2101 attributes = *user.Attributes 2102 } 2103 rows = append(rows, Row{ 2104 user.User, // user 2105 user.Host, // host 2106 attributes, // attributes 2107 }) 2108 } 2109 } else { 2110 // TODO: current user needs to be exposed to access user attribute from mysql_db 2111 currClient := ctx.Session.Client() 2112 rows = append(rows, Row{ 2113 currClient.User, // user 2114 currClient.Address, // host 2115 nil, // attributes 2116 }) 2117 } 2118 2119 return RowsToRowIter(rows...), nil 2120 } 2121 2122 // userPrivilegesRowIter implements the sql.RowIter for the information_schema.USER_PRIVILEGES table. 2123 func userPrivilegesRowIter(ctx *Context, catalog Catalog) (RowIter, error) { 2124 var rows []Row 2125 curUserPrivSet, _ := ctx.GetPrivilegeSet() 2126 if curUserPrivSet == nil { 2127 curUserPrivSet = mysql_db.NewPrivilegeSet() 2128 } 2129 if curUserPrivSet.Has(PrivilegeType_Select) || curUserPrivSet.Database("mysql").Has(PrivilegeType_Select) { 2130 var users = make(map[*mysql_db.User]struct{}) 2131 db, err := catalog.Database(ctx, "mysql") 2132 if err != nil { 2133 return nil, err 2134 } 2135 2136 mysqlDb, ok := db.(*mysql_db.MySQLDb) 2137 if !ok { 2138 return nil, ErrDatabaseNotFound.New("mysql") 2139 } 2140 2141 reader := mysqlDb.Reader() 2142 defer reader.Close() 2143 2144 reader.VisitUsers(func(u *mysql_db.User) { 2145 users[u] = struct{}{} 2146 }) 2147 2148 for user := range users { 2149 grantee := user.UserHostToString("'") 2150 rows = append(rows, getGlobalPrivsRowsFromPrivSet(user.PrivilegeSet, grantee)...) 2151 } 2152 } else { 2153 // If current client does not have SELECT privilege on 'mysql' db, only available schema privileges are 2154 // their current schema privileges. 2155 currClient := ctx.Session.Client() 2156 grantee := fmt.Sprintf("'%s'@'%s'", currClient.User, currClient.Address) 2157 rows = getGlobalPrivsRowsFromPrivSet(curUserPrivSet, grantee) 2158 } 2159 2160 return RowsToRowIter(rows...), nil 2161 } 2162 2163 // viewsRowIter implements the sql.RowIter for the information_schema.VIEWS table. 2164 func viewsRowIter(ctx *Context, catalog Catalog) (RowIter, error) { 2165 var rows []Row 2166 privSet, _ := ctx.GetPrivilegeSet() 2167 if privSet == nil { 2168 return RowsToRowIter(rows...), nil 2169 } 2170 hasGlobalShowViewPriv := privSet.Has(PrivilegeType_ShowView) 2171 for _, db := range catalog.AllDatabases(ctx) { 2172 dbName := db.Name() 2173 privDbSet := privSet.Database(dbName) 2174 hasDbShowViewPriv := privDbSet.Has(PrivilegeType_ShowView) 2175 2176 views, err := viewsInDatabase(ctx, db) 2177 if err != nil { 2178 return nil, err 2179 } 2180 2181 dbCollation := plan.GetDatabaseCollation(ctx, db) 2182 charset := dbCollation.CharacterSet().String() 2183 collation := dbCollation.String() 2184 2185 for _, view := range views { 2186 privTblSet := privDbSet.Table(view.Name) 2187 if !hasGlobalShowViewPriv && !hasDbShowViewPriv && !privTblSet.Has(PrivilegeType_ShowView) { 2188 continue 2189 } 2190 parsedView, err := planbuilder.ParseWithOptions(ctx, catalog, view.CreateViewStatement, NewSqlModeFromString(view.SqlMode).ParserOptions()) 2191 if err != nil { 2192 continue 2193 } 2194 viewPlan, ok := parsedView.(*plan.CreateView) 2195 if !ok { 2196 return nil, ErrTriggerCreateStatementInvalid.New(view.CreateViewStatement) 2197 } 2198 2199 viewDef := view.TextDefinition 2200 definer := removeBackticks(viewPlan.Definer) 2201 2202 // TODO: WITH CHECK OPTION is not supported yet. 2203 checkOpt := viewPlan.CheckOpt 2204 if checkOpt == "" { 2205 checkOpt = "NONE" 2206 } 2207 2208 isUpdatable := "YES" 2209 // TODO: this function call should be done at CREATE VIEW time, not here 2210 if !plan.GetIsUpdatableFromCreateView(viewPlan) { 2211 isUpdatable = "NO" 2212 } 2213 2214 securityType := viewPlan.Security 2215 if securityType == "" { 2216 securityType = "DEFINER" 2217 } 2218 2219 rows = append(rows, Row{ 2220 "def", // table_catalog 2221 dbName, // table_schema 2222 view.Name, // table_name 2223 viewDef, // view_definition 2224 checkOpt, // check_option 2225 isUpdatable, // is_updatable 2226 definer, // definer 2227 securityType, // security_type 2228 charset, // character_set_client 2229 collation, // collation_connection 2230 }) 2231 } 2232 } 2233 2234 return RowsToRowIter(rows...), nil 2235 } 2236 2237 // emptyRowIter implements the sql.RowIter for empty table. 2238 func emptyRowIter(ctx *Context, c Catalog) (RowIter, error) { 2239 return RowsToRowIter(), nil 2240 } 2241 2242 // NewInformationSchemaDatabase creates a new INFORMATION_SCHEMA Database. 2243 func NewInformationSchemaDatabase() Database { 2244 isDb := &informationSchemaDatabase{ 2245 name: InformationSchemaDatabaseName, 2246 tables: map[string]Table{ 2247 AdministrableRoleAuthorizationsTableName: &informationSchemaTable{ 2248 name: AdministrableRoleAuthorizationsTableName, 2249 schema: administrableRoleAuthorizationsSchema, 2250 reader: emptyRowIter, 2251 }, 2252 ApplicableRolesTableName: &informationSchemaTable{ 2253 name: ApplicableRolesTableName, 2254 schema: applicableRolesSchema, 2255 reader: emptyRowIter, 2256 }, 2257 CharacterSetsTableName: &informationSchemaTable{ 2258 name: CharacterSetsTableName, 2259 schema: characterSetsSchema, 2260 reader: characterSetsRowIter, 2261 }, 2262 CheckConstraintsTableName: &informationSchemaTable{ 2263 name: CheckConstraintsTableName, 2264 schema: checkConstraintsSchema, 2265 reader: checkConstraintsRowIter, 2266 }, 2267 CollationCharSetApplicabilityTableName: &informationSchemaTable{ 2268 name: CollationCharSetApplicabilityTableName, 2269 schema: collationCharacterSetApplicabilitySchema, 2270 reader: collationCharacterSetApplicabilityRowIter, 2271 }, 2272 CollationsTableName: &informationSchemaTable{ 2273 name: CollationsTableName, 2274 schema: collationsSchema, 2275 reader: collationsRowIter, 2276 }, 2277 ColumnPrivilegesTableName: &informationSchemaTable{ 2278 name: ColumnPrivilegesTableName, 2279 schema: columnPrivilegesSchema, 2280 reader: emptyRowIter, 2281 }, 2282 ColumnStatisticsTableName: &informationSchemaTable{ 2283 name: ColumnStatisticsTableName, 2284 schema: columnStatisticsSchema, 2285 reader: columnStatisticsRowIter, 2286 }, 2287 ColumnsTableName: &ColumnsTable{ 2288 name: ColumnsTableName, 2289 schema: columnsSchema, 2290 rowIter: columnsRowIter, 2291 }, 2292 ColumnsExtensionsTableName: &informationSchemaTable{ 2293 name: ColumnsExtensionsTableName, 2294 schema: columnsExtensionsSchema, 2295 reader: columnsExtensionsRowIter, 2296 }, 2297 EnabledRolesTablesName: &informationSchemaTable{ 2298 name: EnabledRolesTablesName, 2299 schema: enabledRolesSchema, 2300 reader: emptyRowIter, 2301 }, 2302 EnginesTableName: &informationSchemaTable{ 2303 name: EnginesTableName, 2304 schema: enginesSchema, 2305 reader: enginesRowIter, 2306 }, 2307 EventsTableName: &informationSchemaTable{ 2308 name: EventsTableName, 2309 schema: eventsSchema, 2310 reader: eventsRowIter, 2311 }, 2312 FilesTableName: &informationSchemaTable{ 2313 name: FilesTableName, 2314 schema: filesSchema, 2315 reader: emptyRowIter, 2316 }, 2317 KeyColumnUsageTableName: &informationSchemaTable{ 2318 name: KeyColumnUsageTableName, 2319 schema: keyColumnUsageSchema, 2320 reader: keyColumnUsageRowIter, 2321 }, 2322 KeywordsTableName: &informationSchemaTable{ 2323 name: KeywordsTableName, 2324 schema: keywordsSchema, 2325 reader: keywordsRowIter, 2326 }, 2327 OptimizerTraceTableName: &informationSchemaTable{ 2328 name: OptimizerTraceTableName, 2329 schema: optimizerTraceSchema, 2330 reader: emptyRowIter, 2331 }, 2332 ParametersTableName: &routineTable{ 2333 name: ParametersTableName, 2334 schema: parametersSchema, 2335 rowIter: parametersRowIter, 2336 }, 2337 PartitionsTableName: &informationSchemaTable{ 2338 name: PartitionsTableName, 2339 schema: partitionsSchema, 2340 reader: emptyRowIter, 2341 }, 2342 PluginsTableName: &informationSchemaTable{ 2343 name: PluginsTableName, 2344 schema: pluginsSchema, 2345 reader: emptyRowIter, 2346 }, 2347 ProcessListTableName: &informationSchemaTable{ 2348 name: ProcessListTableName, 2349 schema: processListSchema, 2350 reader: processListRowIter, 2351 }, 2352 ProfilingTableName: &informationSchemaTable{ 2353 name: ProfilingTableName, 2354 schema: profilingSchema, 2355 reader: emptyRowIter, 2356 }, 2357 ReferentialConstraintsTableName: &informationSchemaTable{ 2358 name: ReferentialConstraintsTableName, 2359 schema: referentialConstraintsSchema, 2360 reader: referentialConstraintsRowIter, 2361 }, 2362 ResourceGroupsTableName: &informationSchemaTable{ 2363 name: ResourceGroupsTableName, 2364 schema: resourceGroupsSchema, 2365 reader: emptyRowIter, 2366 }, 2367 RoleColumnGrantsTableName: &informationSchemaTable{ 2368 name: RoleColumnGrantsTableName, 2369 schema: roleColumnGrantsSchema, 2370 reader: emptyRowIter, 2371 }, 2372 RoleRoutineGrantsTableName: &informationSchemaTable{ 2373 name: RoleRoutineGrantsTableName, 2374 schema: roleRoutineGrantsSchema, 2375 reader: emptyRowIter, 2376 }, 2377 RoleTableGrantsTableName: &informationSchemaTable{ 2378 name: RoleTableGrantsTableName, 2379 schema: roleTableGrantsSchema, 2380 reader: emptyRowIter, 2381 }, 2382 RoutinesTableName: &routineTable{ 2383 name: RoutinesTableName, 2384 schema: routinesSchema, 2385 rowIter: routinesRowIter, 2386 }, 2387 SchemaPrivilegesTableName: &informationSchemaTable{ 2388 name: SchemaPrivilegesTableName, 2389 schema: schemaPrivilegesSchema, 2390 reader: schemaPrivilegesRowIter, 2391 }, 2392 SchemataTableName: &informationSchemaTable{ 2393 name: SchemataTableName, 2394 schema: schemataSchema, 2395 reader: schemataRowIter, 2396 }, 2397 SchemataExtensionsTableName: &informationSchemaTable{ 2398 name: SchemataExtensionsTableName, 2399 schema: schemataExtensionsSchema, 2400 reader: schemataExtensionsRowIter, 2401 }, 2402 StGeometryColumnsTableName: &informationSchemaTable{ 2403 name: StGeometryColumnsTableName, 2404 schema: stGeometryColumnsSchema, 2405 reader: stGeometryColumnsRowIter, 2406 }, 2407 StSpatialReferenceSystemsTableName: &informationSchemaTable{ 2408 name: StSpatialReferenceSystemsTableName, 2409 schema: stSpatialReferenceSystemsSchema, 2410 reader: stSpatialReferenceSystemsRowIter, 2411 }, 2412 StUnitsOfMeasureTableName: &informationSchemaTable{ 2413 name: StUnitsOfMeasureTableName, 2414 schema: stUnitsOfMeasureSchema, 2415 reader: stUnitsOfMeasureRowIter, 2416 }, 2417 TableConstraintsTableName: &informationSchemaTable{ 2418 name: TableConstraintsTableName, 2419 schema: tableConstraintsSchema, 2420 reader: tableConstraintsRowIter, 2421 }, 2422 TableConstraintsExtensionsTableName: &informationSchemaTable{ 2423 name: TableConstraintsExtensionsTableName, 2424 schema: tableConstraintsExtensionsSchema, 2425 reader: tableConstraintsExtensionsRowIter, 2426 }, 2427 TablePrivilegesTableName: &informationSchemaTable{ 2428 name: TablePrivilegesTableName, 2429 schema: tablePrivilegesSchema, 2430 reader: tablePrivilegesRowIter, 2431 }, 2432 TablesTableName: &informationSchemaTable{ 2433 name: TablesTableName, 2434 schema: tablesSchema, 2435 reader: tablesRowIter, 2436 }, 2437 TablesExtensionsTableName: &informationSchemaTable{ 2438 name: TablesExtensionsTableName, 2439 schema: tablesExtensionsSchema, 2440 reader: tablesExtensionsRowIter, 2441 }, 2442 TablespacesTableName: &informationSchemaTable{ 2443 name: TablespacesTableName, 2444 schema: tablespacesSchema, 2445 reader: emptyRowIter, 2446 }, 2447 TablespacesExtensionsTableName: &informationSchemaTable{ 2448 name: TablespacesExtensionsTableName, 2449 schema: tablespacesExtensionsSchema, 2450 reader: emptyRowIter, 2451 }, 2452 TriggersTableName: &informationSchemaTable{ 2453 name: TriggersTableName, 2454 schema: triggersSchema, 2455 reader: triggersRowIter, 2456 }, 2457 UserAttributesTableName: &informationSchemaTable{ 2458 name: UserAttributesTableName, 2459 schema: userAttributesSchema, 2460 reader: userAttributesRowIter, 2461 }, 2462 UserPrivilegesTableName: &informationSchemaTable{ 2463 name: UserPrivilegesTableName, 2464 schema: userPrivilegesSchema, 2465 reader: userPrivilegesRowIter, 2466 }, 2467 ViewRoutineUsageTableName: &informationSchemaTable{ 2468 name: ViewRoutineUsageTableName, 2469 schema: viewRoutineUsageSchema, 2470 reader: emptyRowIter, 2471 }, 2472 ViewTableUsageTableName: &informationSchemaTable{ 2473 name: ViewTableUsageTableName, 2474 schema: viewTableUsageSchema, 2475 reader: emptyRowIter, 2476 }, 2477 ViewsTableName: &informationSchemaTable{ 2478 name: ViewsTableName, 2479 schema: viewsSchema, 2480 reader: viewsRowIter, 2481 }, 2482 InnoDBBufferPageName: &informationSchemaTable{ 2483 name: InnoDBBufferPageName, 2484 schema: innoDBBufferPageSchema, 2485 reader: emptyRowIter, 2486 }, 2487 InnoDBBufferPageLRUName: &informationSchemaTable{ 2488 name: InnoDBBufferPageLRUName, 2489 schema: innoDBBufferPageLRUSchema, 2490 reader: emptyRowIter, 2491 }, 2492 InnoDBBufferPoolStatsName: &informationSchemaTable{ 2493 name: InnoDBBufferPoolStatsName, 2494 schema: innoDBBufferPoolStatsSchema, 2495 reader: emptyRowIter, 2496 }, 2497 InnoDBCachedIndexesName: &informationSchemaTable{ 2498 name: InnoDBCachedIndexesName, 2499 schema: innoDBCachedIndexesSchema, 2500 reader: emptyRowIter, 2501 }, 2502 InnoDBCmpName: &informationSchemaTable{ 2503 name: InnoDBCmpName, 2504 schema: innoDBCmpSchema, 2505 reader: emptyRowIter, 2506 }, 2507 InnoDBCmpResetName: &informationSchemaTable{ 2508 name: InnoDBCmpResetName, 2509 schema: innoDBCmpResetSchema, 2510 reader: emptyRowIter, 2511 }, 2512 InnoDBCmpmemName: &informationSchemaTable{ 2513 name: InnoDBCmpmemName, 2514 schema: innoDBCmpmemSchema, 2515 reader: emptyRowIter, 2516 }, 2517 InnoDBCmpmemResetName: &informationSchemaTable{ 2518 name: InnoDBCmpmemResetName, 2519 schema: innoDBCmpmemResetSchema, 2520 reader: emptyRowIter, 2521 }, 2522 InnoDBCmpPerIndexName: &informationSchemaTable{ 2523 name: InnoDBCmpPerIndexName, 2524 schema: innoDBCmpPerIndexSchema, 2525 reader: emptyRowIter, 2526 }, 2527 InnoDBCmpPerIndexResetName: &informationSchemaTable{ 2528 name: InnoDBCmpPerIndexResetName, 2529 schema: innoDBCmpPerIndexResetSchema, 2530 reader: emptyRowIter, 2531 }, 2532 InnoDBColumnsName: &informationSchemaTable{ 2533 name: InnoDBColumnsName, 2534 schema: innoDBColumnsSchema, 2535 reader: emptyRowIter, 2536 }, 2537 InnoDBDatafilesName: &informationSchemaTable{ 2538 name: InnoDBDatafilesName, 2539 schema: innoDBDatafilesSchema, 2540 reader: emptyRowIter, 2541 }, 2542 InnoDBFieldsName: &informationSchemaTable{ 2543 name: InnoDBFieldsName, 2544 schema: innoDBFieldsSchema, 2545 reader: emptyRowIter, 2546 }, 2547 InnoDBForeignName: &informationSchemaTable{ 2548 name: InnoDBForeignName, 2549 schema: innoDBForeignSchema, 2550 reader: emptyRowIter, 2551 }, 2552 InnoDBForeignColsName: &informationSchemaTable{ 2553 name: InnoDBForeignColsName, 2554 schema: innoDBForeignColsSchema, 2555 reader: emptyRowIter, 2556 }, 2557 InnoDBFtBeingDeletedName: &informationSchemaTable{ 2558 name: InnoDBFtBeingDeletedName, 2559 schema: innoDBFtBeingDeletedSchema, 2560 reader: emptyRowIter, 2561 }, 2562 InnoDBFtConfigName: &informationSchemaTable{ 2563 name: InnoDBFtConfigName, 2564 schema: innoDBFtConfigSchema, 2565 reader: emptyRowIter, 2566 }, 2567 InnoDBFtDefaultStopwordName: &informationSchemaTable{ 2568 name: InnoDBFtDefaultStopwordName, 2569 schema: innoDBFtDefaultStopwordSchema, 2570 reader: emptyRowIter, 2571 }, 2572 InnoDBFtDeletedName: &informationSchemaTable{ 2573 name: InnoDBFtDeletedName, 2574 schema: innoDBFtDeletedSchema, 2575 reader: emptyRowIter, 2576 }, 2577 InnoDBFtIndexCacheName: &informationSchemaTable{ 2578 name: InnoDBFtIndexCacheName, 2579 schema: innoDBFtIndexCacheSchema, 2580 reader: emptyRowIter, 2581 }, 2582 InnoDBFtIndexTableName: &informationSchemaTable{ 2583 name: InnoDBFtIndexTableName, 2584 schema: innoDBFtIndexTableSchema, 2585 reader: emptyRowIter, 2586 }, 2587 InnoDBIndexesName: &informationSchemaTable{ 2588 name: InnoDBIndexesName, 2589 schema: innoDBIndexesSchema, 2590 reader: emptyRowIter, 2591 }, 2592 InnoDBMetricsName: &informationSchemaTable{ 2593 name: InnoDBMetricsName, 2594 schema: innoDBMetricsSchema, 2595 reader: emptyRowIter, 2596 }, 2597 InnoDBSessionTempTablespacesName: &informationSchemaTable{ 2598 name: InnoDBSessionTempTablespacesName, 2599 schema: innoDBSessionTempTablespacesSchema, 2600 reader: emptyRowIter, 2601 }, 2602 InnoDBTablesName: &informationSchemaTable{ 2603 name: InnoDBTablesName, 2604 schema: innoDBTablesSchema, 2605 reader: emptyRowIter, 2606 }, 2607 InnoDBTablespacesName: &informationSchemaTable{ 2608 name: InnoDBTablespacesName, 2609 schema: innoDBTablespacesSchema, 2610 reader: emptyRowIter, 2611 }, 2612 InnoDBTablespacesBriefName: &informationSchemaTable{ 2613 name: InnoDBTablespacesBriefName, 2614 schema: innoDBTablespacesBriefSchema, 2615 reader: emptyRowIter, 2616 }, 2617 InnoDBTablestatsName: &informationSchemaTable{ 2618 name: InnoDBTablestatsName, 2619 schema: innoDBTablestatsSchema, 2620 reader: emptyRowIter, 2621 }, 2622 InnoDBTempTableInfoName: &informationSchemaTable{ 2623 name: InnoDBTempTableInfoName, 2624 schema: innoDBTempTableSchema, 2625 reader: innoDBTempTableRowIter, 2626 }, 2627 InnoDBTrxName: &informationSchemaTable{ 2628 name: InnoDBTrxName, 2629 schema: innoDBTrxSchema, 2630 reader: emptyRowIter, 2631 }, 2632 InnoDBVirtualName: &informationSchemaTable{ 2633 name: InnoDBVirtualName, 2634 schema: innoDBVirtualSchema, 2635 reader: emptyRowIter, 2636 }, 2637 }, 2638 } 2639 2640 isDb.tables[StatisticsTableName] = NewDefaultStats() 2641 2642 return isDb 2643 } 2644 2645 // Name implements the sql.Database interface. 2646 func (db *informationSchemaDatabase) Name() string { return db.name } 2647 2648 func (db *informationSchemaDatabase) GetTableInsensitive(ctx *Context, tblName string) (Table, bool, error) { 2649 // The columns table has dynamic information that can't be cached across queries 2650 if strings.ToLower(tblName) == ColumnsTableName { 2651 return &ColumnsTable{}, true, nil 2652 } 2653 2654 tbl, ok := GetTableInsensitive(tblName, db.tables) 2655 return tbl, ok, nil 2656 } 2657 2658 func (db *informationSchemaDatabase) GetTableNames(ctx *Context) ([]string, error) { 2659 tblNames := make([]string, 0, len(db.tables)) 2660 for k := range db.tables { 2661 tblNames = append(tblNames, k) 2662 } 2663 2664 return tblNames, nil 2665 } 2666 2667 // Name implements the sql.Table interface. 2668 func (t *informationSchemaTable) Name() string { 2669 return t.name 2670 } 2671 2672 // Database implements the sql.Databaseable interface. 2673 func (c *informationSchemaTable) Database() string { 2674 return InformationSchemaDatabaseName 2675 } 2676 2677 // Schema implements the sql.Table interface. 2678 func (t *informationSchemaTable) Schema() Schema { 2679 return t.schema 2680 } 2681 2682 func (t *informationSchemaTable) DataLength(_ *Context) (uint64, error) { 2683 return uint64(len(t.Schema()) * int(types.Text.MaxByteLength()) * defaultInfoSchemaRowCount), nil 2684 } 2685 2686 func (t *informationSchemaTable) RowCount(ctx *Context) (uint64, bool, error) { 2687 return defaultInfoSchemaRowCount, false, nil 2688 } 2689 2690 // Collation implements the sql.Table interface. 2691 func (t *informationSchemaTable) Collation() CollationID { 2692 return Collation_Information_Schema_Default 2693 } 2694 2695 func (t *informationSchemaTable) AssignCatalog(cat Catalog) Table { 2696 t.catalog = cat 2697 return t 2698 } 2699 2700 // Partitions implements the sql.Table interface. 2701 func (t *informationSchemaTable) Partitions(ctx *Context) (PartitionIter, error) { 2702 return &informationSchemaPartitionIter{informationSchemaPartition: informationSchemaPartition{partitionKey(t.Name())}}, nil 2703 } 2704 2705 // PartitionRows implements the sql.PartitionRows interface. 2706 func (t *informationSchemaTable) PartitionRows(ctx *Context, partition Partition) (RowIter, error) { 2707 if !bytes.Equal(partition.Key(), partitionKey(t.Name())) { 2708 return nil, ErrPartitionNotFound.New(partition.Key()) 2709 } 2710 if t.reader == nil { 2711 return RowsToRowIter(), nil 2712 } 2713 if t.catalog == nil { 2714 return nil, fmt.Errorf("nil catalog for info schema table %s", t.name) 2715 } 2716 return t.reader(ctx, t.catalog) 2717 } 2718 2719 // PartitionCount implements the sql.PartitionCounter interface. 2720 func (t *informationSchemaTable) String() string { 2721 return printTable(t.Name(), t.Schema()) 2722 } 2723 2724 // Key implements Partition interface 2725 func (p *informationSchemaPartition) Key() []byte { return p.key } 2726 2727 // Next implements single PartitionIter interface 2728 func (pit *informationSchemaPartitionIter) Next(ctx *Context) (Partition, error) { 2729 if pit.pos == 0 { 2730 pit.pos++ 2731 return pit, nil 2732 } 2733 return nil, io.EOF 2734 } 2735 2736 // Close implements single PartitionIter interface 2737 func (pit *informationSchemaPartitionIter) Close(_ *Context) error { 2738 pit.pos = 0 2739 return nil 2740 } 2741 2742 func NewDefaultStats() *defaultStatsTable { 2743 return &defaultStatsTable{ 2744 informationSchemaTable: &informationSchemaTable{ 2745 name: StatisticsTableName, 2746 schema: statisticsSchema, 2747 reader: statisticsRowIter, 2748 }, 2749 } 2750 } 2751 2752 // defaultStatsTable is a statistics table implementation 2753 // with a cache to save ANALYZE results. RowCount defers to 2754 // the underlying table in the absence of a cached statistic. 2755 type defaultStatsTable struct { 2756 *informationSchemaTable 2757 } 2758 2759 func (n *defaultStatsTable) AssignCatalog(cat Catalog) Table { 2760 n.catalog = cat 2761 return n 2762 } 2763 2764 func printTable(name string, tableSchema Schema) string { 2765 p := NewTreePrinter() 2766 _ = p.WriteNode("Table(%s)", name) 2767 var schema = make([]string, len(tableSchema)) 2768 for i, col := range tableSchema { 2769 schema[i] = fmt.Sprintf( 2770 "Column(%s, %s, nullable=%v)", 2771 col.Name, 2772 col.Type.String(), 2773 col.Nullable, 2774 ) 2775 } 2776 _ = p.WriteChildren(schema...) 2777 return p.String() 2778 } 2779 2780 func partitionKey(tableName string) []byte { 2781 return []byte(InformationSchemaDatabaseName + "." + tableName) 2782 } 2783 2784 func getColumnNamesFromIndex(idx Index, table Table) []string { 2785 var indexCols []string 2786 for _, expr := range idx.Expressions() { 2787 col := plan.GetColumnFromIndexExpr(expr, table) 2788 if col != nil { 2789 indexCols = append(indexCols, col.Name) 2790 } 2791 } 2792 2793 return indexCols 2794 } 2795 2796 // viewsInDatabase returns all views defined on the database given, consulting both the database itself as well as any 2797 // views defined in session memory. Typically there will not be both types of views on a single database, but the 2798 // interfaces do make it possible. 2799 func viewsInDatabase(ctx *Context, db Database) ([]ViewDefinition, error) { 2800 var views []ViewDefinition 2801 dbName := db.Name() 2802 2803 if vdb, ok := db.(ViewDatabase); ok { 2804 dbViews, err := vdb.AllViews(ctx) 2805 if err != nil { 2806 return nil, err 2807 } 2808 2809 views = append(views, dbViews...) 2810 } 2811 2812 for _, view := range ctx.GetViewRegistry().ViewsInDatabase(dbName) { 2813 views = append(views, ViewDefinition{ 2814 Name: view.Name(), 2815 TextDefinition: view.TextDefinition(), 2816 CreateViewStatement: view.CreateStatement(), 2817 }) 2818 } 2819 2820 return views, nil 2821 } 2822 2823 func removeBackticks(s string) string { 2824 return strings.Replace(s, "`", "", -1) 2825 } 2826 2827 // getGlobalPrivsRowsFromPrivSet returns USER_PRIVILEGES rows using given global privilege set and grantee name string. 2828 func getGlobalPrivsRowsFromPrivSet(privSet PrivilegeSet, grantee string) []Row { 2829 var rows []Row 2830 hasGrantOpt := privSet.Has(PrivilegeType_GrantOption) 2831 for _, priv := range privSet.ToSlice() { 2832 if priv == PrivilegeType_GrantOption { 2833 continue 2834 } 2835 isGrantable := "NO" 2836 if hasGrantOpt { 2837 isGrantable = "YES" 2838 } 2839 rows = append(rows, Row{ 2840 grantee, // grantee 2841 "def", // table_catalog 2842 priv.String(), // privilege_type 2843 isGrantable, // is_grantable 2844 }) 2845 } 2846 return rows 2847 } 2848 2849 // getSchemaPrivsRowsFromPrivDbSet returns SCHEMA_PRIVILEGES rows using given Database privilege set and grantee string. 2850 func getSchemaPrivsRowsFromPrivDbSet(privSetDb PrivilegeSetDatabase, grantee string) []Row { 2851 var rows []Row 2852 hasGrantOpt := privSetDb.Has(PrivilegeType_GrantOption) 2853 for _, privType := range privSetDb.ToSlice() { 2854 if privType == PrivilegeType_GrantOption { 2855 continue 2856 } 2857 isGrantable := "NO" 2858 if hasGrantOpt { 2859 isGrantable = "YES" 2860 } 2861 rows = append(rows, Row{ 2862 grantee, // grantee 2863 "def", // table_catalog 2864 privSetDb.Name(), // table_schema 2865 privType.String(), // privilege_type 2866 isGrantable, // is_grantable 2867 }) 2868 } 2869 return rows 2870 } 2871 2872 // getTablePrivsRowsFromPrivTblSet returns TABLE_PRIVILEGES rows using given Table privilege set and grantee and database name strings. 2873 func getTablePrivsRowsFromPrivTblSet(privSetTbl PrivilegeSetTable, grantee, dbName string) []Row { 2874 var rows []Row 2875 hasGrantOpt := privSetTbl.Has(PrivilegeType_GrantOption) 2876 for _, privType := range privSetTbl.ToSlice() { 2877 if privType == PrivilegeType_GrantOption { 2878 continue 2879 } 2880 isGrantable := "NO" 2881 if hasGrantOpt { 2882 isGrantable = "YES" 2883 } 2884 rows = append(rows, Row{ 2885 grantee, // grantee 2886 "def", // table_catalog 2887 dbName, // table_schema 2888 privSetTbl.Name(), // table_name 2889 privType.String(), // privilege_type 2890 isGrantable, // is_grantable 2891 }) 2892 } 2893 return rows 2894 }