github.com/matrixorigin/matrixone@v1.2.0/pkg/util/sysview/predefined.go (about)

     1  // Copyright 2024 Matrix Origin
     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 sysview
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/catalog"
    21  )
    22  
    23  // `mysql` database system tables
    24  // They are all Tenant level system tables
    25  var (
    26  	MysqlUserDDL = `CREATE TABLE mysql.user (
    27  			Host char(255)  NOT NULL DEFAULT '',
    28  			User char(32)  NOT NULL DEFAULT '',
    29  			Select_priv varchar(10) NOT NULL DEFAULT 'N',
    30  			Insert_priv varchar(10) NOT NULL DEFAULT 'N',
    31  			Update_priv varchar(10) NOT NULL DEFAULT 'N',
    32  			Delete_priv varchar(10) NOT NULL DEFAULT 'N',
    33  			Create_priv varchar(10) NOT NULL DEFAULT 'N',
    34  			Drop_priv varchar(10)  NOT NULL DEFAULT 'N',
    35  			Reload_priv varchar(10)  NOT NULL DEFAULT 'N',
    36  			Shutdown_priv varchar(10)  NOT NULL DEFAULT 'N',
    37  			Process_priv varchar(10)  NOT NULL DEFAULT 'N',
    38  			File_priv varchar(10)  NOT NULL DEFAULT 'N',
    39  			Grant_priv varchar(10)  NOT NULL DEFAULT 'N',
    40  			References_priv varchar(10)  NOT NULL DEFAULT 'N',
    41  			Index_priv varchar(10)  NOT NULL DEFAULT 'N',
    42  			Alter_priv varchar(10)  NOT NULL DEFAULT 'N',
    43  			Show_db_priv varchar(10)  NOT NULL DEFAULT 'N',
    44  			Super_priv varchar(10)  NOT NULL DEFAULT 'N',
    45  			Create_tmp_table_priv varchar(10)  NOT NULL DEFAULT 'N',
    46  			Lock_tables_priv varchar(10)  NOT NULL DEFAULT 'N',
    47  			Execute_priv varchar(10)  NOT NULL DEFAULT 'N',
    48  			Repl_slave_priv varchar(10)  NOT NULL DEFAULT 'N',
    49  			Repl_client_priv varchar(10)  NOT NULL DEFAULT 'N',
    50  			Create_view_priv varchar(10)  NOT NULL DEFAULT 'N',
    51  			Show_view_priv varchar(10)  NOT NULL DEFAULT 'N',
    52  			Create_routine_priv varchar(10)  NOT NULL DEFAULT 'N',
    53  			Alter_routine_priv varchar(10)  NOT NULL DEFAULT 'N',
    54  			Create_user_priv varchar(10)  NOT NULL DEFAULT 'N',
    55  			Event_priv varchar(10)  NOT NULL DEFAULT 'N',
    56  			Trigger_priv varchar(10)  NOT NULL DEFAULT 'N',
    57  			Create_tablespace_priv varchar(10)  NOT NULL DEFAULT 'N',
    58  			ssl_type varchar(10)  NOT NULL DEFAULT '',
    59  			ssl_cipher blob NOT NULL,
    60  			x509_issuer blob NOT NULL,
    61  			x509_subject blob NOT NULL,
    62  			max_questions int unsigned NOT NULL DEFAULT '0',
    63  			max_updates int unsigned NOT NULL DEFAULT '0',
    64  			max_connections int unsigned NOT NULL DEFAULT '0',
    65  			max_user_connections int unsigned NOT NULL DEFAULT '0',
    66  			plugin char(64)  NOT NULL DEFAULT 'caching_sha2_password',
    67  			authentication_string text ,
    68  			password_expired varchar(10)  NOT NULL DEFAULT 'N',
    69  			password_last_changed timestamp NULL DEFAULT NULL,
    70  			password_lifetime smallint unsigned DEFAULT NULL,
    71  			account_locked varchar(10)  NOT NULL DEFAULT 'N',
    72  			Create_role_priv varchar(10)  NOT NULL DEFAULT 'N',
    73  			Drop_role_priv varchar(10)  NOT NULL DEFAULT 'N',
    74  			Password_reuse_history smallint unsigned DEFAULT NULL,
    75  			Password_reuse_time smallint unsigned DEFAULT NULL,
    76  			Password_require_current varchar(10)  DEFAULT NULL,
    77  			User_attributes json DEFAULT NULL,
    78  			PRIMARY KEY (Host,User)
    79  		  )`
    80  
    81  	MysqlDbDDL = `CREATE TABLE mysql.db (
    82  			Host char(255) NOT NULL DEFAULT '',
    83  			Db char(64)  NOT NULL DEFAULT '',
    84  			User char(32)  NOT NULL DEFAULT '',
    85  			Select_priv varchar(10)  NOT NULL DEFAULT 'N',
    86  			Insert_priv varchar(10)  NOT NULL DEFAULT 'N',
    87  			Update_priv varchar(10)  NOT NULL DEFAULT 'N',
    88  			Delete_priv varchar(10)  NOT NULL DEFAULT 'N',
    89  			Create_priv varchar(10)  NOT NULL DEFAULT 'N',
    90  			Drop_priv varchar(10)  NOT NULL DEFAULT 'N',
    91  			Grant_priv varchar(10)  NOT NULL DEFAULT 'N',
    92  			References_priv varchar(10)  NOT NULL DEFAULT 'N',
    93  			Index_priv varchar(10)  NOT NULL DEFAULT 'N',
    94  			Alter_priv varchar(10)  NOT NULL DEFAULT 'N',
    95  			Create_tmp_table_priv varchar(10)  NOT NULL DEFAULT 'N',
    96  			Lock_tables_priv varchar(10)  NOT NULL DEFAULT 'N',
    97  			Create_view_priv varchar(10)  NOT NULL DEFAULT 'N',
    98  			Show_view_priv varchar(10)  NOT NULL DEFAULT 'N',
    99  			Create_routine_priv varchar(10)  NOT NULL DEFAULT 'N',
   100  			Alter_routine_priv varchar(10)  NOT NULL DEFAULT 'N',
   101  			Execute_priv varchar(10)  NOT NULL DEFAULT 'N',
   102  			Event_priv varchar(10)  NOT NULL DEFAULT 'N',
   103  			Trigger_priv varchar(10)  NOT NULL DEFAULT 'N',
   104  			PRIMARY KEY (Host,Db,User),
   105  			KEY User (User)
   106  		  )`
   107  
   108  	MysqlProcsPrivDDL = `CREATE TABLE mysql.procs_priv (
   109  			Host char(255)  NOT NULL DEFAULT '',
   110  			Db char(64)  NOT NULL DEFAULT '',
   111  			User char(32)  NOT NULL DEFAULT '',
   112  			Routine_name char(64)  NOT NULL DEFAULT '',
   113  			Routine_type varchar(10)  NOT NULL,
   114  			Grantor varchar(288)  NOT NULL DEFAULT '',
   115  			Proc_priv varchar(10)  NOT NULL DEFAULT '',
   116  			Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   117  			PRIMARY KEY (Host,Db,User,Routine_name,Routine_type),
   118  			KEY Grantor (Grantor)
   119  		  )`
   120  
   121  	MysqlColumnsPrivDDL = `CREATE TABLE mysql.columns_priv (
   122  			Host char(255)  NOT NULL DEFAULT '',
   123  			Db char(64)  NOT NULL DEFAULT '',
   124  			User char(32)  NOT NULL DEFAULT '',
   125  			Table_name char(64)  NOT NULL DEFAULT '',
   126  			Column_name char(64)  NOT NULL DEFAULT '',
   127  			Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   128  			Column_priv varchar(10) NOT NULL DEFAULT '',
   129  			PRIMARY KEY (Host,Db,User,Table_name,Column_name)
   130  		  )`
   131  
   132  	MysqlTablesPrivDDL = `CREATE TABLE mysql.tables_priv (
   133  			Host char(255)  NOT NULL DEFAULT '',
   134  			Db char(64)  NOT NULL DEFAULT '',
   135  			User char(32)  NOT NULL DEFAULT '',
   136  			Table_name char(64)  NOT NULL DEFAULT '',
   137  			Grantor varchar(288)  NOT NULL DEFAULT '',
   138  			Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   139  			Table_priv varchar(10) NOT NULL DEFAULT '',
   140  			Column_priv varchar(10) NOT NULL DEFAULT '',
   141  			PRIMARY KEY (Host,Db,User,Table_name),
   142  			KEY Grantor (Grantor)
   143  		  )`
   144  
   145  	MysqlRoleEdgesDDL = `CREATE TABLE mysql.role_edges (
   146  			FROM_HOST char(255) NOT NULL DEFAULT '',
   147  			FROM_USER char(32) NOT NULL DEFAULT '',
   148  			TO_HOST char(255) NOT NULL DEFAULT '',
   149  			TO_USER char(32) NOT NULL DEFAULT '',
   150  			WITH_ADMIN_OPTION enum('N','Y') NOT NULL DEFAULT 'N',
   151  			PRIMARY KEY (FROM_HOST,FROM_USER,TO_HOST,TO_USER)
   152  		)`
   153  )
   154  
   155  // `information_schema` database
   156  // They are all Tenant level system tables/system views
   157  var (
   158  	InformationSchemaKeyColumnUsageDDL = "CREATE TABLE information_schema.KEY_COLUMN_USAGE (" +
   159  		"CONSTRAINT_CATALOG varchar(64)," +
   160  		"CONSTRAINT_SCHEMA varchar(64)," +
   161  		"CONSTRAINT_NAME varchar(64)," +
   162  		"TABLE_CATALOG varchar(64)," +
   163  		"TABLE_SCHEMA varchar(64)," +
   164  		"TABLE_NAME varchar(64)," +
   165  		"COLUMN_NAME varchar(64)," +
   166  		"ORDINAL_POSITION int unsigned," +
   167  		"POSITION_IN_UNIQUE_CONSTRAINT int unsigned," +
   168  		"REFERENCED_TABLE_SCHEMA varchar(64)," +
   169  		"REFERENCED_TABLE_NAME varchar(64)," +
   170  		"REFERENCED_COLUMN_NAME varchar(64)" +
   171  		")"
   172  
   173  	InformationSchemaColumnsDDL = fmt.Sprintf("CREATE VIEW information_schema.COLUMNS AS select "+
   174  		"'def' as TABLE_CATALOG,"+
   175  		"att_database as TABLE_SCHEMA,"+
   176  		"att_relname AS TABLE_NAME,"+
   177  		"attname AS COLUMN_NAME,"+
   178  		"attnum AS ORDINAL_POSITION,"+
   179  		"mo_show_visible_bin(att_default,1) as COLUMN_DEFAULT,"+
   180  		"(case when attnotnull != 0 then 'NO' else 'YES' end) as IS_NULLABLE,"+
   181  		"mo_show_visible_bin(atttyp,2) as DATA_TYPE,"+
   182  		"internal_char_length(atttyp) AS CHARACTER_MAXIMUM_LENGTH,"+
   183  		"internal_char_size(atttyp) AS CHARACTER_OCTET_LENGTH,"+
   184  		"internal_numeric_precision(atttyp) AS NUMERIC_PRECISION,"+
   185  		"internal_numeric_scale(atttyp) AS NUMERIC_SCALE,"+
   186  		"internal_datetime_scale(atttyp) AS DATETIME_PRECISION,"+
   187  		"(case internal_column_character_set(atttyp) WHEN 0 then 'utf8' WHEN 1 then 'utf8' else NULL end) AS CHARACTER_SET_NAME,"+
   188  		"(case internal_column_character_set(atttyp) WHEN 0 then 'utf8_bin' WHEN 1 then 'utf8_bin' else NULL end) AS COLLATION_NAME,"+
   189  		"mo_show_visible_bin(atttyp,3) as COLUMN_TYPE,"+
   190  		"case when att_constraint_type = 'p' then 'PRI' else '' end as COLUMN_KEY,"+
   191  		"case when att_is_auto_increment = 1 then 'auto_increment' else '' end as EXTRA,"+
   192  		"'select,insert,update,references' as `PRIVILEGES`,"+
   193  		"att_comment as COLUMN_COMMENT,"+
   194  		"cast('' as varchar(500)) as GENERATION_EXPRESSION,"+
   195  		"if(true, NULL, 0) as SRS_ID "+
   196  		"from mo_catalog.mo_columns "+
   197  		"where account_id = current_account_id() "+
   198  		"and att_relname!='%s' and att_relname not like '%s' and attname != '%s' and att_relname not like '%s'",
   199  		catalog.MOAutoIncrTable, catalog.PrefixPriColName+"%", catalog.Row_ID, catalog.PartitionSubTableWildcard)
   200  
   201  	InformationSchemaProfilingDDL = "CREATE TABLE information_schema.PROFILING (" +
   202  		"QUERY_ID int NOT NULL DEFAULT '0'," +
   203  		"SEQ int NOT NULL DEFAULT '0'," +
   204  		"STATE varchar(30) NOT NULL DEFAULT ''," +
   205  		"DURATION decimal(9,6) NOT NULL DEFAULT '0.000000'," +
   206  		"CPU_USER decimal(9,6) DEFAULT NULL," +
   207  		"CPU_SYSTEM decimal(9,6) DEFAULT NULL," +
   208  		"CONTEXT_VOLUNTARY int DEFAULT NULL," +
   209  		"CONTEXT_INVOLUNTARY int DEFAULT NULL," +
   210  		"BLOCK_OPS_IN int DEFAULT NULL," +
   211  		"BLOCK_OPS_OUT int DEFAULT NULL," +
   212  		"MESSAGES_SENT int DEFAULT NULL," +
   213  		"MESSAGES_RECEIVED int DEFAULT NULL," +
   214  		"PAGE_FAULTS_MAJOR int DEFAULT NULL," +
   215  		"PAGE_FAULTS_MINOR int DEFAULT NULL," +
   216  		"SWAPS int DEFAULT NULL," +
   217  		"SOURCE_FUNCTION varchar(30) DEFAULT NULL," +
   218  		"SOURCE_FILE varchar(20) DEFAULT NULL," +
   219  		"SOURCE_LINE int DEFAULT NULL" +
   220  		")"
   221  
   222  	InformationSchemaProcesslistDDL = fmt.Sprintf("CREATE VIEW %s.PROCESSLIST AS "+
   223  		"select node_id, conn_id, session_id, account, user, host, db, "+
   224  		"session_start, command, info, txn_id, statement_id, statement_type, "+
   225  		"query_type, sql_source_type, query_start, client_host, role, proxy_host "+
   226  		"from PROCESSLIST() A", InformationDBConst)
   227  
   228  	InformationSchemaUserPrivilegesDDL = "CREATE TABLE information_schema.USER_PRIVILEGES (" +
   229  		"GRANTEE varchar(292) NOT NULL DEFAULT ''," +
   230  		"TABLE_CATALOG varchar(512) NOT NULL DEFAULT ''," +
   231  		"PRIVILEGE_TYPE varchar(64) NOT NULL DEFAULT ''," +
   232  		"IS_GRANTABLE varchar(3) NOT NULL DEFAULT ''" +
   233  		")"
   234  
   235  	InformationSchemaSchemataDDL = "CREATE VIEW information_schema.SCHEMATA AS SELECT " +
   236  		"dat_catalog_name AS CATALOG_NAME," +
   237  		"datname AS SCHEMA_NAME," +
   238  		"'utf8mb4' AS DEFAULT_CHARACTER_SET_NAME," +
   239  		"'utf8mb4_0900_ai_ci' AS DEFAULT_COLLATION_NAME," +
   240  		"if(true, NULL, '') AS SQL_PATH," +
   241  		"cast('NO' as varchar(3)) AS DEFAULT_ENCRYPTION " +
   242  		"FROM mo_catalog.mo_database where account_id = current_account_id() or (account_id = 0 and datname in ('mo_catalog'))"
   243  
   244  	InformationSchemaCharacterSetsDDL = "CREATE TABLE information_schema.CHARACTER_SETS (" +
   245  		"CHARACTER_SET_NAME varchar(64)," +
   246  		"DEFAULT_COLLATE_NAME varchar(64)," +
   247  		"DESCRIPTION varchar(2048)," +
   248  		"MAXLEN int unsigned" +
   249  		")"
   250  
   251  	InformationSchemaTriggersDDL = "CREATE TABLE information_schema.TRIGGERS (" +
   252  		"TRIGGER_CATALOG varchar(64)," +
   253  		"TRIGGER_SCHEMA varchar(64)," +
   254  		"TRIGGER_NAME varchar(64)," +
   255  		"EVENT_MANIPULATION varchar(10)," +
   256  		"EVENT_OBJECT_CATALOG varchar(64)," +
   257  		"EVENT_OBJECT_SCHEMA varchar(64)," +
   258  		"EVENT_OBJECT_TABLE varchar(64)," +
   259  		"ACTION_ORDER int unsigned," +
   260  		"ACTION_CONDITION binary(0)," +
   261  		"ACTION_STATEMENT longtext," +
   262  		"ACTION_ORIENTATION varchar(3)," +
   263  		"ACTION_TIMING varchar(10)," +
   264  		"ACTION_REFERENCE_OLD_TABLE binary(0)," +
   265  		"ACTION_REFERENCE_NEW_TABLE binary(0)," +
   266  		"ACTION_REFERENCE_OLD_ROW varchar(3)," +
   267  		"ACTION_REFERENCE_NEW_ROW varchar(3)," +
   268  		"CREATED timestamp(2)," +
   269  		"SQL_MODE varchar(10)," +
   270  		"DEFINER varchar(288)," +
   271  		"CHARACTER_SET_CLIENT varchar(64)," +
   272  		"COLLATION_CONNECTION varchar(64)," +
   273  		"DATABASE_COLLATION varchar(64)" +
   274  		")"
   275  
   276  	InformationSchemaTablesDDL = fmt.Sprintf("CREATE VIEW information_schema.TABLES AS "+
   277  		"SELECT 'def' AS TABLE_CATALOG,"+
   278  		"reldatabase AS TABLE_SCHEMA,"+
   279  		"relname AS TABLE_NAME,"+
   280  		"(case when relkind = 'v' and (reldatabase='mo_catalog' or reldatabase='information_schema') then 'SYSTEM VIEW' "+
   281  		"when relkind = 'v'  then 'VIEW' "+
   282  		"when relkind = 'e' then 'EXTERNAL TABLE' "+
   283  		"when relkind = 'r' then 'BASE TABLE' "+
   284  		"else 'INTERNAL TABLE' end) AS TABLE_TYPE,"+
   285  		"if(relkind = 'r','Tae',NULL) AS ENGINE,"+
   286  		"if(relkind = 'v',NULL,10) AS VERSION,"+
   287  		"'Compressed' AS ROW_FORMAT,"+
   288  		"if(relkind = 'v', NULL, 0) AS TABLE_ROWS,"+
   289  		"if(relkind = 'v', NULL, 0) AS AVG_ROW_LENGTH,"+
   290  		"if(relkind = 'v', NULL, 0) AS DATA_LENGTH,"+
   291  		"if(relkind = 'v', NULL, 0) AS MAX_DATA_LENGTH,"+
   292  		"if(relkind = 'v', NULL, 0) AS INDEX_LENGTH,"+
   293  		"if(relkind = 'v', NULL, 0) AS DATA_FREE,"+
   294  		"if(relkind = 'v', NULL, internal_auto_increment(reldatabase, relname)) AS `AUTO_INCREMENT`,"+
   295  		"created_time AS CREATE_TIME,"+
   296  		"if(relkind = 'v', NULL, created_time) AS UPDATE_TIME,"+
   297  		"if(relkind = 'v', NULL, created_time) AS CHECK_TIME,"+
   298  		"'utf8mb4_0900_ai_ci' AS TABLE_COLLATION,"+
   299  		"if(relkind = 'v', NULL, 0) AS CHECKSUM,"+
   300  		"if(relkind = 'v', NULL, if(partitioned = 0, '', cast('partitioned' as varchar(256)))) AS CREATE_OPTIONS,"+
   301  		"cast(rel_comment as text) AS TABLE_COMMENT "+
   302  		"FROM mo_catalog.mo_tables tbl "+
   303  		"WHERE tbl.account_id = current_account_id() and tbl.relname not like '%s' and tbl.relkind != '%s'", catalog.IndexTableNamePrefix+"%", catalog.SystemPartitionRel)
   304  
   305  	InformationSchemaPartitionsDDL = "CREATE VIEW information_schema.`PARTITIONS` AS " +
   306  		"SELECT " +
   307  		"'def' AS `TABLE_CATALOG`," +
   308  		"`tbl`.`reldatabase` AS `TABLE_SCHEMA`," +
   309  		"`tbl`.`relname` AS `TABLE_NAME`," +
   310  		"`part`.`name` AS `PARTITION_NAME`," +
   311  		"NULL AS `SUBPARTITION_NAME`," +
   312  		"`part`.`number` AS `PARTITION_ORDINAL_POSITION`," +
   313  		"NULL AS `SUBPARTITION_ORDINAL_POSITION`," +
   314  		"(case `part`.`partition_type` when 'HASH' then 'HASH' " +
   315  		"when 'RANGE' then 'RANGE' " +
   316  		"when 'LIST' then 'LIST' " +
   317  		"when 'AUTO' then 'AUTO' " +
   318  		"when 'KEY_51' then 'KEY' " +
   319  		"when 'KEY_55' then 'KEY' " +
   320  		"when 'LINEAR_KEY_51' then 'LINEAR KEY' " +
   321  		"when 'LINEAR_KEY_55' then 'LINEAR KEY' " +
   322  		"when 'LINEAR_HASH' then 'LINEAR HASH' " +
   323  		"when 'RANGE_COLUMNS' then 'RANGE COLUMNS' " +
   324  		"when 'LIST_COLUMNS' then 'LIST COLUMNS' else NULL end) AS `PARTITION_METHOD`," +
   325  		"NULL AS `SUBPARTITION_METHOD`," +
   326  		"`part`.`partition_expression` AS `PARTITION_EXPRESSION`," +
   327  		"NULL AS `SUBPARTITION_EXPRESSION`," +
   328  		"`part`.`description_utf8` AS `PARTITION_DESCRIPTION`," +
   329  		"mo_table_rows(`tbl`.`reldatabase`, `part`.`partition_table_name`) AS `TABLE_ROWS`," +
   330  		"0 AS `AVG_ROW_LENGTH`," +
   331  		"mo_table_size(`tbl`.`reldatabase`, `part`.`partition_table_name`) AS `DATA_LENGTH`," +
   332  		"0 AS `MAX_DATA_LENGTH`," +
   333  		"0 AS `INDEX_LENGTH`," +
   334  		"0 AS `DATA_FREE`," +
   335  		"`tbl`.`created_time` AS `CREATE_TIME`," +
   336  		"NULL AS `UPDATE_TIME`," +
   337  		"NULL AS `CHECK_TIME`," +
   338  		"NULL AS `CHECKSUM`," +
   339  		"ifnull(`part`.`comment`,'')  AS `PARTITION_COMMENT`," +
   340  		"'default' AS `NODEGROUP`," +
   341  		"NULL AS `TABLESPACE_NAME` " +
   342  		"FROM `mo_catalog`.`mo_tables` `tbl` LEFT JOIN `mo_catalog`.`mo_table_partitions` `part` " +
   343  		"ON `part`.`table_id` = `tbl`.`rel_id` " +
   344  		"WHERE `tbl`.`account_id` = current_account_id() and `tbl`.`partitioned` = 1"
   345  
   346  	InformationSchemaViewsDDL = "CREATE VIEW information_schema.VIEWS AS " +
   347  		"SELECT 'def' AS `TABLE_CATALOG`," +
   348  		"tbl.reldatabase AS `TABLE_SCHEMA`," +
   349  		"tbl.relname AS `TABLE_NAME`," +
   350  		"tbl.rel_createsql AS `VIEW_DEFINITION`," +
   351  		"'NONE' AS `CHECK_OPTION`," +
   352  		"'YES' AS `IS_UPDATABLE`," +
   353  		"usr.user_name + '@' + usr.user_host AS `DEFINER`," +
   354  		"'DEFINER' AS `SECURITY_TYPE`," +
   355  		"'utf8mb4' AS `CHARACTER_SET_CLIENT`," +
   356  		"'utf8mb4_0900_ai_ci' AS `COLLATION_CONNECTION` " +
   357  		"FROM mo_catalog.mo_tables tbl LEFT JOIN mo_catalog.mo_user usr ON tbl.creator = usr.user_id " +
   358  		"WHERE tbl.account_id = current_account_id() and tbl.relkind = 'v' and tbl.reldatabase != 'information_schema'"
   359  
   360  	InformationSchemaStatisticsDDL = "CREATE VIEW information_schema.`STATISTICS` AS " +
   361  		"select 'def' AS `TABLE_CATALOG`," +
   362  		"`tbl`.`reldatabase` AS `TABLE_SCHEMA`," +
   363  		"`tbl`.`relname` AS `TABLE_NAME`," +
   364  		"if(((`idx`.`type` = 'PRIMARY') or (`idx`.`type` = 'UNIQUE')),0,1) AS `NON_UNIQUE`," +
   365  		"`tbl`.`reldatabase` AS `INDEX_SCHEMA`," +
   366  		"`idx`.`name` AS `INDEX_NAME`," +
   367  		"`idx`.`ordinal_position` AS `SEQ_IN_INDEX`," +
   368  		"`idx`.`column_name` AS `COLUMN_NAME`," +
   369  		"'A' AS `COLLATION`," +
   370  		"0 AS `CARDINALITY`," +
   371  		"NULL AS `SUB_PART`," +
   372  		"NULL AS `PACKED`," +
   373  		"if((`tcl`.`attnotnull` = 0),'YES','') AS `NULLABLE`," +
   374  		"NULL AS `INDEX_TYPE`," +
   375  		"if(((`idx`.`type` = 'PRIMARY') or (`idx`.`type` = 'UNIQUE')),'','') AS `COMMENT`," +
   376  		"`idx`.`comment` AS `INDEX_COMMENT`," +
   377  		"if(`idx`.`is_visible`,'YES','NO') AS `IS_VISIBLE`," +
   378  		"NULL AS `EXPRESSION`" +
   379  		"from (`mo_catalog`.`mo_indexes` `idx` " +
   380  		"join `mo_catalog`.`mo_tables` `tbl` on (`idx`.`table_id` = `tbl`.`rel_id`))" +
   381  		"join `mo_catalog`.`mo_columns` `tcl` on (`idx`.`table_id` = `tcl`.`att_relname_id` and `idx`.`column_name` = `tcl`.`attname`)"
   382  
   383  	InformationSchemaReferentialConstraintsDDL = "CREATE VIEW information_schema.REFERENTIAL_CONSTRAINTS AS " +
   384  		"SELECT DISTINCT " +
   385  		"'def' AS CONSTRAINT_CATALOG, " +
   386  		"fk.db_name AS CONSTRAINT_SCHEMA, " +
   387  		"fk.constraint_name AS CONSTRAINT_NAME, " +
   388  		"'def' AS UNIQUE_CONSTRAINT_CATALOG, " +
   389  		"fk.refer_db_name AS UNIQUE_CONSTRAINT_SCHEMA, " +
   390  		"idx.type AS UNIQUE_CONSTRAINT_NAME," +
   391  		"'NONE' AS MATCH_OPTION, " +
   392  		"fk.on_update AS UPDATE_RULE, " +
   393  		"fk.on_delete AS DELETE_RULE, " +
   394  		"fk.table_name AS TABLE_NAME, " +
   395  		"fk.refer_table_name AS REFERENCED_TABLE_NAME " +
   396  		"FROM mo_catalog.mo_foreign_keys fk " +
   397  		"JOIN mo_catalog.mo_indexes idx ON (fk.refer_column_name = idx.column_name)"
   398  
   399  	InformationSchemaEnginesDDL = "CREATE TABLE information_schema.ENGINES (" +
   400  		"ENGINE varchar(64)," +
   401  		"SUPPORT varchar(8)," +
   402  		"COMMENT varchar(160)," +
   403  		"TRANSACTIONS varchar(3)," +
   404  		"XA varchar(3)," +
   405  		"SAVEPOINTS varchar(3)" +
   406  		")"
   407  
   408  	InformationSchemaRoutinesDDL = "CREATE TABLE information_schema.ROUTINES (" +
   409  		"SPECIFIC_NAME varchar(64)," +
   410  		"ROUTINE_CATALOG varchar(64)," +
   411  		"ROUTINE_SCHEMA varchar(64)," +
   412  		"ROUTINE_NAME varchar(64)," +
   413  		"ROUTINE_TYPE varchar(10)," +
   414  		"DATA_TYPE  longtext," +
   415  		"CHARACTER_MAXIMUM_LENGTH bigint," +
   416  		"CHARACTER_OCTET_LENGTH bigint," +
   417  		"NUMERIC_PRECISION int unsigned," +
   418  		"NUMERIC_SCALE int unsigned," +
   419  		"DATETIME_PRECISION int unsigned," +
   420  		"CHARACTER_SET_NAME varchar(64)," +
   421  		"COLLATION_NAME varchar(64)," +
   422  		"DTD_IDENTIFIER longtext," +
   423  		"ROUTINE_BODY varchar(3)," +
   424  		"ROUTINE_DEFINITION longtext," +
   425  		"EXTERNAL_NAME binary(0)," +
   426  		"EXTERNAL_LANGUAGE varchar(64)," +
   427  		"PARAMETER_STYLE varchar(3)," +
   428  		"IS_DETERMINISTIC varchar(3)," +
   429  		"SQL_DATA_ACCESS varchar(10)," +
   430  		"SQL_PATH varchar(1000)," +
   431  		"SECURITY_TYPE varchar(10)," +
   432  		"CREATED timestamp," +
   433  		"LAST_ALTERED timestamp," +
   434  		"SQL_MODE varchar(1000)," +
   435  		"ROUTINE_COMMENT text," +
   436  		"DEFINER varchar(288)," +
   437  		"CHARACTER_SET_CLIENT varchar(64)," +
   438  		"COLLATION_CONNECTION varchar(64)," +
   439  		"DATABASE_COLLATION  varchar(64)" +
   440  		")"
   441  
   442  	InformationSchemaParametersDDL = "CREATE TABLE information_schema.PARAMETERS (" +
   443  		"SPECIFIC_CATALOG varchar(64)," +
   444  		"SPECIFIC_SCHEMA varchar(64)," +
   445  		"SPECIFIC_NAME varchar(64)," +
   446  		"ORDINAL_POSITION bigint unsigned," +
   447  		"PARAMETER_MODE varchar(5)," +
   448  		"PARAMETER_NAME varchar(64)," +
   449  		"DATA_TYPE longtext," +
   450  		"CHARACTER_MAXIMUM_LENGTH bigint," +
   451  		"CHARACTER_OCTET_LENGTH bigint," +
   452  		"NUMERIC_PRECISION int unsigned," +
   453  		"NUMERIC_SCALE bigint," +
   454  		"DATETIME_PRECISION int unsigned," +
   455  		"CHARACTER_SET_NAME varchar(64)," +
   456  		"COLLATION_NAME varchar(64)," +
   457  		"DTD_IDENTIFIER mediumtext," +
   458  		"ROUTINE_TYPE  varchar(64)" +
   459  		")"
   460  
   461  	InformationSchemaKeywordsDDL = "CREATE TABLE information_schema.KEYWORDS (" +
   462  		"WORD varchar(64)," +
   463  		"RESERVED int unsigned" +
   464  		")"
   465  
   466  	InformationSchemaSchemaPrivilegesDDL = "CREATE TABLE information_schema.`SCHEMA_PRIVILEGES` (" +
   467  		"`GRANTEE` varchar(292) NOT NULL DEFAULT ''," +
   468  		"`TABLE_CATALOG` varchar(512) NOT NULL DEFAULT ''," +
   469  		"`TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT ''," +
   470  		"`PRIVILEGE_TYPE` varchar(64) NOT NULL DEFAULT ''," +
   471  		"`IS_GRANTABLE` varchar(3) NOT NULL DEFAULT ''" +
   472  		")"
   473  
   474  	InformationSchemaTablePrivilegesDDL = "CREATE TABLE information_schema.`TABLE_PRIVILEGES` (" +
   475  		"`GRANTEE` varchar(292) NOT NULL DEFAULT ''," +
   476  		"`TABLE_CATALOG` varchar(512) NOT NULL DEFAULT ''," +
   477  		"`TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT ''," +
   478  		"`TABLE_NAME` varchar(64) NOT NULL DEFAULT ''," +
   479  		"`PRIVILEGE_TYPE` varchar(64) NOT NULL DEFAULT ''," +
   480  		"`IS_GRANTABLE` varchar(3) NOT NULL DEFAULT ''" +
   481  		")"
   482  
   483  	InformationSchemaColumnPrivilegesDDL = "CREATE TABLE information_schema.`COLUMN_PRIVILEGES` (" +
   484  		"`GRANTEE` varchar(292) NOT NULL DEFAULT ''," +
   485  		"`TABLE_CATALOG` varchar(512) NOT NULL DEFAULT ''," +
   486  		"`TABLE_SCHEMA` varchar(64) NOT NULL DEFAULT ''," +
   487  		"`TABLE_NAME` varchar(64) NOT NULL DEFAULT ''," +
   488  		"`COLUMN_NAME` varchar(64) NOT NULL DEFAULT ''," +
   489  		"`PRIVILEGE_TYPE` varchar(64) NOT NULL DEFAULT ''," +
   490  		"`IS_GRANTABLE` varchar(3) NOT NULL DEFAULT ''" +
   491  		")"
   492  
   493  	InformationSchemaCollationsDDL = "CREATE TABLE information_schema.COLLATIONS (" +
   494  		"COLLATION_NAME varchar(64) NOT NULL," +
   495  		"CHARACTER_SET_NAME varchar(64) NOT NULL," +
   496  		"ID bigint unsigned NOT NULL DEFAULT 0," +
   497  		"IS_DEFAULT varchar(3) NOT NULL DEFAULT ''," +
   498  		"IS_COMPILED varchar(3) NOT NULL DEFAULT ''," +
   499  		"SORTLEN int unsigned NOT NULL," +
   500  		"PAD_ATTRIBUTE enum('PAD SPACE','NO PAD') NOT NULL" +
   501  		")"
   502  
   503  	InformationSchemaTableConstraintsDDL = "CREATE TABLE information_schema.TABLE_CONSTRAINTS (" +
   504  		"CONSTRAINT_CATALOG varchar(64)," +
   505  		"CONSTRAINT_SCHEMA varchar(64)," +
   506  		"CONSTRAINT_NAME varchar(64)," +
   507  		"TABLE_SCHEMA varchar(64)," +
   508  		"TABLE_NAME varchar(64)," +
   509  		"CONSTRAINT_TYPE varchar(11) NOT NULL DEFAULT ''," +
   510  		"ENFORCED varchar(3) NOT NULL DEFAULT ''" +
   511  		")"
   512  
   513  	InformationSchemaEventsDDL = "CREATE TABLE information_schema.EVENTS (" +
   514  		"EVENT_CATALOG varchar(64)," +
   515  		"EVENT_SCHEMA varchar(64)," +
   516  		"EVENT_NAME varchar(64) NOT NULL," +
   517  		"`DEFINER` varchar(288) NOT NULL," +
   518  		"TIME_ZONE varchar(64) NOT NULL," +
   519  		"EVENT_BODY varchar(3) NOT NULL DEFAULT ''," +
   520  		"EVENT_DEFINITION longtext NOT NULL," +
   521  		"EVENT_TYPE varchar(9) NOT NULL DEFAULT ''," +
   522  		"EXECUTE_AT datetime," +
   523  		"INTERVAL_VALUE varchar(256)," +
   524  		"INTERVAL_FIELD enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND')," +
   525  		"SQL_MODE varchar(64) NOT NULL," +
   526  		"STARTS datetime," +
   527  		"ENDS datetime," +
   528  		"STATUS varchar(21) NOT NULL DEFAULT ''," +
   529  		"ON_COMPLETION varchar(12) NOT NULL DEFAULT ''," +
   530  		"CREATED timestamp NOT NULL," +
   531  		"LAST_ALTERED timestamp NOT NULL," +
   532  		"LAST_EXECUTED datetime," +
   533  		"EVENT_COMMENT varchar(2048) NOT NULL," +
   534  		"ORIGINATOR int unsigned NOT NULL," +
   535  		"CHARACTER_SET_CLIENT varchar(64) NOT NULL," +
   536  		"COLLATION_CONNECTION varchar(64) NOT NULL," +
   537  		"DATABASE_COLLATION varchar(64) NOT NULL" +
   538  		")"
   539  )