diff options
-rw-r--r-- | sql/examples/ha_archive.cc | 2 | ||||
-rw-r--r-- | sql/examples/ha_example.cc | 2 | ||||
-rw-r--r-- | sql/examples/ha_tina.cc | 2 | ||||
-rw-r--r-- | sql/ha_berkeley.cc | 2 | ||||
-rw-r--r-- | sql/ha_blackhole.cc | 2 | ||||
-rw-r--r-- | sql/ha_federated.cc | 2 | ||||
-rw-r--r-- | sql/ha_heap.cc | 2 | ||||
-rw-r--r-- | sql/ha_innodb.cc | 2 | ||||
-rw-r--r-- | sql/ha_myisam.cc | 2 | ||||
-rw-r--r-- | sql/ha_myisammrg.cc | 4 | ||||
-rw-r--r-- | sql/ha_ndbcluster.cc | 2 | ||||
-rw-r--r-- | sql/handler.cc | 276 | ||||
-rw-r--r-- | sql/handler.h | 21 |
13 files changed, 222 insertions, 99 deletions
diff --git a/sql/examples/ha_archive.cc b/sql/examples/ha_archive.cc index 85104405024..7a0c957e5c3 100644 --- a/sql/examples/ha_archive.cc +++ b/sql/examples/ha_archive.cc @@ -136,7 +136,7 @@ static HASH archive_open_tables; #define ARCHIVE_CHECK_HEADER 254 // The number we use to determine corruption /* dummy handlerton - only to have something to return from archive_db_init */ -static handlerton archive_hton = { +handlerton archive_hton = { "archive", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/examples/ha_example.cc b/sql/examples/ha_example.cc index dfc2fa7a260..cc4ad3eb535 100644 --- a/sql/examples/ha_example.cc +++ b/sql/examples/ha_example.cc @@ -73,7 +73,7 @@ #include "ha_example.h" -static handlerton example_hton= { +handlerton example_hton= { "CSV", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/examples/ha_tina.cc b/sql/examples/ha_tina.cc index 5c3cbdcf2ca..e01cc7cc980 100644 --- a/sql/examples/ha_tina.cc +++ b/sql/examples/ha_tina.cc @@ -54,7 +54,7 @@ pthread_mutex_t tina_mutex; static HASH tina_open_tables; static int tina_init= 0; -static handlerton tina_hton= { +handlerton tina_hton= { "CSV", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index b8a779c08cf..2f47b03de9d 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -107,7 +107,7 @@ static int berkeley_close_connection(THD *thd); static int berkeley_commit(THD *thd, bool all); static int berkeley_rollback(THD *thd, bool all); -static handlerton berkeley_hton = { +handlerton berkeley_hton = { "BerkeleyDB", 0, /* slot */ 0, /* savepoint size */ diff --git a/sql/ha_blackhole.cc b/sql/ha_blackhole.cc index a287d6e446b..f089b67d678 100644 --- a/sql/ha_blackhole.cc +++ b/sql/ha_blackhole.cc @@ -26,7 +26,7 @@ /* Blackhole storage engine handlerton */ -static handlerton blackhole_hton= { +handlerton blackhole_hton= { "BLACKHOLE", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index 83224649842..aac43647e15 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -690,7 +690,7 @@ error: /* Federated storage engine handlerton */ -static handlerton federated_hton= { +handlerton federated_hton= { "FEDERATED", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 94ee3f8e656..fafd597e858 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -23,7 +23,7 @@ #include <myisampack.h> #include "ha_heap.h" -static handlerton heap_hton= { +handlerton heap_hton= { "MEMORY", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 4ed5fadb603..491aaf5a226 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -206,7 +206,7 @@ static int innobase_rollback_to_savepoint(THD* thd, void *savepoint); static int innobase_savepoint(THD* thd, void *savepoint); static int innobase_release_savepoint(THD* thd, void *savepoint); -static handlerton innobase_hton = { +handlerton innobase_hton = { "InnoDB", 0, /* slot */ sizeof(trx_named_savept_t), /* savepoint size. TODO: use it */ diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 8f3970d69e6..bd4717eb02f 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -46,7 +46,7 @@ TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"", /* MyISAM handlerton */ -static handlerton myisam_hton= { +handlerton myisam_hton= { "MyISAM", 0, /* slot */ 0, /* savepoint size. */ diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index f92717e11eb..8347dcdaa3e 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -34,8 +34,8 @@ /* MyISAM MERGE handlerton */ -static handlerton myisammrg_hton= { - "MRG_MyISAM", +handlerton myisammrg_hton= { + "MRG_MYISAM", 0, /* slot */ 0, /* savepoint size. */ NULL, /* close_connection */ diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index ff631ac9db8..f069db09382 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -49,7 +49,7 @@ static int ndbcluster_close_connection(THD *thd); static int ndbcluster_commit(THD *thd, bool all); static int ndbcluster_rollback(THD *thd, bool all); -static handlerton ndbcluster_hton = { +handlerton ndbcluster_hton = { "ndbcluster", 0, /* slot */ 0, /* savepoint size */ diff --git a/sql/handler.cc b/sql/handler.cc index b3754891d05..543d4a5877c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -27,31 +27,44 @@ #include "ha_myisammrg.h" #ifdef HAVE_BERKELEY_DB #include "ha_berkeley.h" +extern handlerton berkeley_hton; #endif #ifdef HAVE_BLACKHOLE_DB #include "ha_blackhole.h" +extern handlerton blackhole_hton; #endif #ifdef HAVE_EXAMPLE_DB #include "examples/ha_example.h" +extern handlerton example_hton; #endif #ifdef HAVE_ARCHIVE_DB #include "examples/ha_archive.h" +extern handlerton archive_hton; #endif #ifdef HAVE_CSV_DB #include "examples/ha_tina.h" +extern handlerton tina_hton; #endif #ifdef HAVE_INNOBASE_DB #include "ha_innodb.h" +extern handlerton innobase_hton; #endif #ifdef HAVE_NDBCLUSTER_DB #include "ha_ndbcluster.h" +extern handlerton ndbcluster_hton; #endif #ifdef HAVE_FEDERATED_DB #include "ha_federated.h" +extern handlerton federated_hton; #endif #include <myisampack.h> #include <errno.h> +extern handlerton myisam_hton; +extern handlerton myisammrg_hton; +extern handlerton heap_hton; + + /* static functions defined in this file */ static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES; @@ -66,46 +79,53 @@ ulong total_ha_2pc; /* size of savepoint storage area (see ha_init) */ ulong savepoint_alloc_size; +/* + This structure will go away with loadable storeage engines, we will instead + build it dynamically from the configure script. +*/ struct show_table_type_st sys_table_types[]= { {"MyISAM", &have_yes, - "Default engine as of MySQL 3.23 with great performance", DB_TYPE_MYISAM}, + "Default engine as of MySQL 3.23 with great performance", DB_TYPE_MYISAM, + NULL}, {"MEMORY", &have_yes, - "Hash based, stored in memory, useful for temporary tables", DB_TYPE_HEAP}, - {"HEAP", &have_yes, - "Alias for MEMORY", DB_TYPE_HEAP}, - {"MERGE", &have_yes, - "Collection of identical MyISAM tables", DB_TYPE_MRG_MYISAM}, - {"MRG_MYISAM",&have_yes, - "Alias for MERGE", DB_TYPE_MRG_MYISAM}, + "Hash based, stored in memory, useful for temporary tables", DB_TYPE_HEAP, + NULL}, + {"MRG_MYISAM", &have_yes, + "Collection of identical MyISAM tables", DB_TYPE_MRG_MYISAM, NULL}, {"ISAM", &have_isam, - "Obsolete storage engine, now replaced by MyISAM", DB_TYPE_ISAM}, + "Obsolete storage engine, now replaced by MyISAM", DB_TYPE_ISAM, NULL}, {"MRG_ISAM", &have_isam, - "Obsolete storage engine, now replaced by MERGE", DB_TYPE_MRG_ISAM}, + "Obsolete storage engine, now replaced by MERGE", DB_TYPE_MRG_ISAM, NULL}, {"InnoDB", &have_innodb, - "Supports transactions, row-level locking, and foreign keys", DB_TYPE_INNODB}, - {"INNOBASE", &have_innodb, - "Alias for INNODB", DB_TYPE_INNODB}, - {"BDB", &have_berkeley_db, - "Supports transactions and page-level locking", DB_TYPE_BERKELEY_DB}, - {"BERKELEYDB",&have_berkeley_db, - "Alias for BDB", DB_TYPE_BERKELEY_DB}, + "Supports transactions, row-level locking, and foreign keys", DB_TYPE_INNODB, + NULL}, + {"BERKELEYDB", &have_berkeley_db, + "Supports transactions and page-level locking", DB_TYPE_BERKELEY_DB, NULL}, {"NDBCLUSTER", &have_ndbcluster, - "Clustered, fault-tolerant, memory-based tables", DB_TYPE_NDBCLUSTER}, - {"NDB", &have_ndbcluster, - "Alias for NDBCLUSTER", DB_TYPE_NDBCLUSTER}, + "Clustered, fault-tolerant, memory-based tables", DB_TYPE_NDBCLUSTER, NULL}, {"EXAMPLE",&have_example_db, - "Example storage engine", DB_TYPE_EXAMPLE_DB}, + "Example storage engine", DB_TYPE_EXAMPLE_DB, NULL}, {"ARCHIVE",&have_archive_db, - "Archive storage engine", DB_TYPE_ARCHIVE_DB}, + "Archive storage engine", DB_TYPE_ARCHIVE_DB, NULL}, {"CSV",&have_csv_db, - "CSV storage engine", DB_TYPE_CSV_DB}, + "CSV storage engine", DB_TYPE_CSV_DB, NULL}, {"FEDERATED",&have_federated_db, - "Federated MySQL storage engine", DB_TYPE_FEDERATED_DB}, + "Federated MySQL storage engine", DB_TYPE_FEDERATED_DB, NULL}, {"BLACKHOLE",&have_blackhole_db, "/dev/null storage engine (anything you write to it disappears)", - DB_TYPE_BLACKHOLE_DB}, - {NullS, NULL, NullS, DB_TYPE_UNKNOWN} + DB_TYPE_BLACKHOLE_DB, NULL}, + {NullS, NULL, NullS, DB_TYPE_UNKNOWN, NULL} +}; + +struct show_table_alias_st sys_table_aliases[]= +{ + {"INNOBASE", "InnoDB", NULL }, + {"NDB", "NDBCLUSTER", NULL}, + {"BDB", "BERKELEYDB", NULL}, + {"HEAP", "MEMORY", NULL}, + {"MERGE", "MRG_MYISAM", NULL}, + {NullS, NullS, NULL} }; const char *ha_row_type[] = { @@ -124,16 +144,27 @@ uint known_extensions_id= 0; enum db_type ha_resolve_by_name(const char *name, uint namelen) { THD *thd= current_thd; + show_table_alias_st *table_alias; + show_table_type_st *types; + if (thd && !my_strcasecmp(&my_charset_latin1, name, "DEFAULT")) { return (enum db_type) thd->variables.table_type; } - show_table_type_st *types; for (types= sys_table_types; types->type; types++) { if (!my_strcasecmp(&my_charset_latin1, name, types->type)) return (enum db_type) types->db_type; } + + /* + We check for the historical aliases next. + */ + for (table_alias= sys_table_aliases; table_alias->type; table_alias++) + { + if (!my_strcasecmp(&my_charset_latin1, name, table_alias->alias) && table_alias->st) + return (enum db_type) table_alias->st->db_type; + } return DB_TYPE_UNKNOWN; } @@ -361,80 +392,165 @@ int ha_init() { int error= 0; handlerton **ht= handlertons; + show_table_type_st *types; + show_table_alias_st *table_alias; total_ha= savepoint_alloc_size= 0; if (ha_init_errors()) return 1; - if (opt_bin_log) + for (types= sys_table_types; types->type; types++) { - if (!(*ht= binlog_init())) // Always succeed - { - mysql_bin_log.close(LOG_CLOSE_INDEX); // Never used - opt_bin_log= 0; // Never used - error= 1; // Never used - } - else - ha_was_inited_ok(ht++); - } + switch (types->db_type) { + case DB_TYPE_HEAP: + types->ht= &heap_hton; + for (table_alias= sys_table_aliases; table_alias->type; table_alias++) + { + if (!my_strcasecmp(&my_charset_latin1, types->ht->name, table_alias->type)) + table_alias->st= types; + } + break; + case DB_TYPE_MYISAM: + types->ht= &myisam_hton; + break; + case DB_TYPE_MRG_MYISAM: + types->ht= &myisammrg_hton; + for (table_alias= sys_table_aliases; table_alias->type; table_alias++) + { + if (!my_strcasecmp(&my_charset_latin1, types->ht->name, table_alias->type)) + table_alias->st= types; + } + break; #ifdef HAVE_BERKELEY_DB - if (have_berkeley_db == SHOW_OPTION_YES) - { - if (!(*ht= berkeley_init())) - { - have_berkeley_db= SHOW_OPTION_DISABLED; // If we couldn't use handler - error= 1; - } - else - ha_was_inited_ok(ht++); - } + case DB_TYPE_BERKELEY_DB: + if (have_berkeley_db == SHOW_OPTION_YES) + { + if (!(*ht= berkeley_init())) + { + have_berkeley_db= SHOW_OPTION_DISABLED; // If we couldn't use handler + error= 1; + } + else + { + types->ht= &berkeley_hton; + for (table_alias= sys_table_aliases; table_alias->type; table_alias++) + { + if (!my_strcasecmp(&my_charset_latin1, types->ht->name, table_alias->type)) + table_alias->st= types; + } + ha_was_inited_ok(ht++); + } + } + break; #endif #ifdef HAVE_INNOBASE_DB - if (have_innodb == SHOW_OPTION_YES) - { - if (!(*ht= innobase_init())) - { - have_innodb= SHOW_OPTION_DISABLED; // If we couldn't use handler - error= 1; - } - else - ha_was_inited_ok(ht++); - } + case DB_TYPE_INNODB: + if (have_innodb == SHOW_OPTION_YES) + { + if (!(*ht= innobase_init())) + { + have_innodb= SHOW_OPTION_DISABLED; // If we couldn't use handler + error= 1; + } + else + { + ha_was_inited_ok(ht++); + types->ht= &innobase_hton; + for (table_alias= sys_table_aliases; table_alias->type; table_alias++) + { + if (!my_strcasecmp(&my_charset_latin1, types->ht->name, table_alias->type)) + table_alias->st= types; + } + } + } + break; #endif #ifdef HAVE_NDBCLUSTER_DB - if (have_ndbcluster == SHOW_OPTION_YES) - { - if (!(*ht= ndbcluster_init())) - { - have_ndbcluster= SHOW_OPTION_DISABLED; - error= 1; - } - else - ha_was_inited_ok(ht++); - } + case DB_TYPE_NDBCLUSTER: + if (have_ndbcluster == SHOW_OPTION_YES) + { + if (!(*ht= ndbcluster_init())) + { + have_ndbcluster= SHOW_OPTION_DISABLED; + error= 1; + } + else + { + ha_was_inited_ok(ht++); + types->ht= &ndbcluster_hton; + for (table_alias= sys_table_aliases; table_alias->type; table_alias++) + { + if (!my_strcasecmp(&my_charset_latin1, types->ht->name, table_alias->type)) + table_alias->st= types; + } + } + } + break; +#endif +#ifdef HAVE_EXAMPLE_DB + case DB_TYPE_EXAMPLE_DB: + types->ht= &example_hton; + break; +#endif +#ifdef HAVE_ARCHIVE_DB + case DB_TYPE_ARCHIVE_DB: + if (have_archive_db == SHOW_OPTION_YES) + { + if (!(*ht= archive_db_init())) + { + have_archive_db= SHOW_OPTION_DISABLED; + error= 1; + } + else + { + ha_was_inited_ok(ht++); + types->ht= &archive_hton; + } + } + break; +#endif +#ifdef HAVE_CSV_DB + case DB_TYPE_CSV_DB,: + types->ht= &tina_hton; + break; #endif #ifdef HAVE_FEDERATED_DB - if (have_federated_db == SHOW_OPTION_YES) - { - if (federated_db_init()) - { - have_federated_db= SHOW_OPTION_DISABLED; - error= 1; + case DB_TYPE_FEDERATED_DB: + if (have_federated_db == SHOW_OPTION_YES) + { + if (federated_db_init()) + { + have_federated_db= SHOW_OPTION_DISABLED; + error= 1; + } + else + { + types->ht= &federated_hton; + } + } + break; +#endif +#ifdef HAVE_BLACKHOLE_DB + case DB_TYPE_BLACKHOLE_DB: + types->ht= &blackhole_hton; + break; +#endif + default: + types->ht= NULL; } } -#endif -#ifdef HAVE_ARCHIVE_DB - if (have_archive_db == SHOW_OPTION_YES) + + if (opt_bin_log) { - if (!(*ht= archive_db_init())) + if (!(*ht= binlog_init())) // Always succeed { - have_archive_db= SHOW_OPTION_DISABLED; - error= 1; + mysql_bin_log.close(LOG_CLOSE_INDEX); // Never used + opt_bin_log= 0; // Never used + error= 1; // Never used } else ha_was_inited_ok(ht++); } -#endif DBUG_ASSERT(total_ha < MAX_HA); /* Check if there is a transaction-capable storage engine besides the diff --git a/sql/handler.h b/sql/handler.h index f1f9ab904d1..bd558894a27 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -177,13 +177,6 @@ enum db_type DB_TYPE_DEFAULT // Must be last }; -struct show_table_type_st { - const char *type; - SHOW_COMP_OPTION *value; - const char *comment; - enum db_type db_type; -}; - enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED, ROW_TYPE_DYNAMIC, ROW_TYPE_COMPRESSED, ROW_TYPE_REDUNDANT, ROW_TYPE_COMPACT }; @@ -363,6 +356,20 @@ typedef struct uint32 flags; /* global handler flags */ } handlerton; +struct show_table_type_st { + const char *type; + SHOW_COMP_OPTION *value; + const char *comment; + enum db_type db_type; + handlerton *ht; +}; + +struct show_table_alias_st { + const char *alias; + const char *type; + show_table_type_st *st; +}; + /* Possible flags of a handlerton */ #define HTON_NO_FLAGS 0 #define HTON_CLOSE_CURSORS_AT_COMMIT 1 |