Commit ed35cecd authored by unknown's avatar unknown

Final patch for 5.0 for simplifying storage engine code. We now have just one...

Final patch for 5.0 for simplifying storage engine code. We now have just one set of ifdefs. I may also remove the code for creating new handlers.
May changes were to simplify storage engine setup and support for legacy call to show storage engines.


mysql-test/r/ps_1general.result:
  Fixed test results for new listing order
sql/examples/ha_tina.cc:
  Removed dead code
sql/examples/ha_tina.h:
  Removed dead code
sql/ha_archive.cc:
  Capitalized sotrage engine name and moved disabled code.
sql/ha_berkeley.cc:
  Moved deisabled code
sql/ha_federated.cc:
  Removed disabled code
sql/ha_innodb.cc:
  Removed disabled message
sql/ha_ndbcluster.cc:
  Removed disabled message
sql/handler.cc:
  Added in legacy support for sotrage engine listing (ala Serg's request). Removed handlertons variables and we now have simplified ha_init code.
sql/handler.h:
  No longer need handlertons array.
parent cdb57192
...@@ -323,17 +323,17 @@ execute stmt4; ...@@ -323,17 +323,17 @@ execute stmt4;
Engine Support Comment Engine Support Comment
MyISAM YES/NO Default engine as of MySQL 3.23 with great performance MyISAM YES/NO Default engine as of MySQL 3.23 with great performance
MEMORY YES/NO Hash based, stored in memory, useful for temporary tables MEMORY YES/NO Hash based, stored in memory, useful for temporary tables
MRG_MYISAM YES/NO Collection of identical MyISAM tables
ISAM YES/NO Obsolete storage engine, now replaced by MyISAM
MRG_ISAM YES/NO Obsolete storage engine, now replaced by MERGE
InnoDB YES/NO Supports transactions, row-level locking, and foreign keys InnoDB YES/NO Supports transactions, row-level locking, and foreign keys
BERKELEYDB YES/NO Supports transactions and page-level locking BerkeleyDB YES/NO Supports transactions and page-level locking
NDBCLUSTER YES/NO Clustered, fault-tolerant, memory-based tables BLACKHOLE YES/NO /dev/null storage engine (anything you write to it disappears)
EXAMPLE YES/NO Example storage engine EXAMPLE YES/NO Example storage engine
ARCHIVE YES/NO Archive storage engine ARCHIVE YES/NO Archive storage engine
CSV YES/NO CSV storage engine CSV YES/NO CSV storage engine
ndbcluster YES/NO Clustered, fault-tolerant, memory-based tables
FEDERATED YES/NO Federated MySQL storage engine FEDERATED YES/NO Federated MySQL storage engine
BLACKHOLE YES/NO /dev/null storage engine (anything you write to it disappears) MRG_MYISAM YES/NO Collection of identical MyISAM tables
binlog YES/NO This is a meta storage engine to represent the binlog in a transaction
ISAM YES/NO Obsolete storage engine
drop table if exists t5; drop table if exists t5;
prepare stmt1 from ' drop table if exists t5 ' ; prepare stmt1 from ' drop table if exists t5 ' ;
execute stmt1 ; execute stmt1 ;
......
...@@ -861,21 +861,6 @@ THR_LOCK_DATA **ha_tina::store_lock(THD *thd, ...@@ -861,21 +861,6 @@ THR_LOCK_DATA **ha_tina::store_lock(THD *thd,
return to; return to;
} }
/*
Range optimizer calls this.
I need to update the information on this.
*/
ha_rows ha_tina::records_in_range(int inx,
const byte *start_key,uint start_key_len,
enum ha_rkey_function start_search_flag,
const byte *end_key,uint end_key_len,
enum ha_rkey_function end_search_flag)
{
DBUG_ENTER("ha_tina::records_in_range ");
DBUG_RETURN(records); // Good guess
}
/* /*
Create a table. You do not want to leave the table open after a call to Create a table. You do not want to leave the table open after a call to
this (the database will call ::open() if it needs to). this (the database will call ::open() if it needs to).
......
...@@ -78,7 +78,6 @@ class ha_tina: public handler ...@@ -78,7 +78,6 @@ class ha_tina: public handler
*/ */
virtual double scan_time() { return (double) (records+deleted) / 20.0+10; } virtual double scan_time() { return (double) (records+deleted) / 20.0+10; }
/* The next method will never be called */ /* The next method will never be called */
virtual double read_time(ha_rows rows) { DBUG_ASSERT(0); return((double) rows / 20.0+1); }
virtual bool fast_key_read() { return 1;} virtual bool fast_key_read() { return 1;}
/* /*
TODO: return actual upper bound of number of records in the table. TODO: return actual upper bound of number of records in the table.
...@@ -110,12 +109,6 @@ class ha_tina: public handler ...@@ -110,12 +109,6 @@ class ha_tina: public handler
int reset(void); int reset(void);
int external_lock(THD *thd, int lock_type); int external_lock(THD *thd, int lock_type);
int delete_all_rows(void); int delete_all_rows(void);
ha_rows records_in_range(int inx, const byte *start_key,uint start_key_len,
enum ha_rkey_function start_search_flag,
const byte *end_key,uint end_key_len,
enum ha_rkey_function end_search_flag);
// int delete_table(const char *from);
// int rename_table(const char * from, const char * to);
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
......
...@@ -137,7 +137,7 @@ static HASH archive_open_tables; ...@@ -137,7 +137,7 @@ static HASH archive_open_tables;
/* dummy handlerton - only to have something to return from archive_db_init */ /* dummy handlerton - only to have something to return from archive_db_init */
handlerton archive_hton = { handlerton archive_hton = {
"archive", "ARCHIVE",
SHOW_OPTION_YES, SHOW_OPTION_YES,
"Archive storage engine", "Archive storage engine",
DB_TYPE_ARCHIVE_DB, DB_TYPE_ARCHIVE_DB,
...@@ -201,7 +201,6 @@ bool archive_db_init() ...@@ -201,7 +201,6 @@ bool archive_db_init()
} }
error: error:
have_archive_db= SHOW_OPTION_DISABLED; // If we couldn't use handler have_archive_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
archive_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -210,7 +210,6 @@ bool berkeley_init(void) ...@@ -210,7 +210,6 @@ bool berkeley_init(void)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
error: error:
have_berkeley_db= SHOW_OPTION_DISABLED; // If we couldn't use handler have_berkeley_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
berkeley_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -428,7 +428,6 @@ bool federated_db_init() ...@@ -428,7 +428,6 @@ bool federated_db_init()
} }
error: error:
have_federated_db= SHOW_OPTION_DISABLED; // If we couldn't use handler have_federated_db= SHOW_OPTION_DISABLED; // If we couldn't use handler
federated_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -1423,7 +1423,6 @@ innobase_init(void) ...@@ -1423,7 +1423,6 @@ innobase_init(void)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
error: error:
have_innodb= SHOW_OPTION_DISABLED; // If we couldn't use handler have_innodb= SHOW_OPTION_DISABLED; // If we couldn't use handler
innobase_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -4837,7 +4837,6 @@ bool ndbcluster_init() ...@@ -4837,7 +4837,6 @@ bool ndbcluster_init()
delete g_ndb_cluster_connection; delete g_ndb_cluster_connection;
g_ndb_cluster_connection= NULL; g_ndb_cluster_connection= NULL;
have_ndbcluster= SHOW_OPTION_DISABLED; // If we couldn't use handler have_ndbcluster= SHOW_OPTION_DISABLED; // If we couldn't use handler
ndbcluster_hton.state= SHOW_OPTION_DISABLED;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -25,37 +25,87 @@ ...@@ -25,37 +25,87 @@
#include "ha_heap.h" #include "ha_heap.h"
#include "ha_myisam.h" #include "ha_myisam.h"
#include "ha_myisammrg.h" #include "ha_myisammrg.h"
/*
We have dummy hanldertons in case the handler has not been compiled
in. This will be removed in 5.1.
*/
#ifdef HAVE_BERKELEY_DB #ifdef HAVE_BERKELEY_DB
#include "ha_berkeley.h" #include "ha_berkeley.h"
extern handlerton berkeley_hton; extern handlerton berkeley_hton;
#else
handlerton berkeley_hton = { "BerkeleyDB", SHOW_OPTION_NO,
"Supports transactions and page-level locking", DB_TYPE_BERKELEY_DB, NULL,
0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_BLACKHOLE_DB #ifdef HAVE_BLACKHOLE_DB
#include "ha_blackhole.h" #include "ha_blackhole.h"
extern handlerton blackhole_hton; extern handlerton blackhole_hton;
#else
handlerton blackhole_hton = { "BLACKHOLE", SHOW_OPTION_NO,
"/dev/null storage engine (anything you write to it disappears)",
DB_TYPE_BLACKHOLE_DB, NULL, 0, 0, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_EXAMPLE_DB #ifdef HAVE_EXAMPLE_DB
#include "examples/ha_example.h" #include "examples/ha_example.h"
extern handlerton example_hton; extern handlerton example_hton;
#else
handlerton example_hton = { "EXAMPLE", SHOW_OPTION_NO,
"Example storage engine",
DB_TYPE_EXAMPLE_DB, NULL, 0, 0, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_ARCHIVE_DB #ifdef HAVE_ARCHIVE_DB
#include "ha_archive.h" #include "ha_archive.h"
extern handlerton archive_hton; extern handlerton archive_hton;
#else
handlerton archive_hton = { "ARCHIVE", SHOW_OPTION_NO,
"Archive storage engine", DB_TYPE_ARCHIVE_DB, NULL, 0, 0, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_CSV_DB #ifdef HAVE_CSV_DB
#include "examples/ha_tina.h" #include "examples/ha_tina.h"
extern handlerton tina_hton; extern handlerton tina_hton;
#else
handlerton tina_hton = { "CSV", SHOW_OPTION_NO, "CSV storage engine",
DB_TYPE_CSV_DB, NULL, 0, 0, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_INNOBASE_DB #ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h" #include "ha_innodb.h"
extern handlerton innobase_hton; extern handlerton innobase_hton;
#else
handlerton innobase_hton = { "InnoDB", SHOW_OPTION_NO,
"Supports transactions, row-level locking, and foreign keys",
DB_TYPE_INNODB, NULL, 0, 0, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_NDBCLUSTER_DB #ifdef HAVE_NDBCLUSTER_DB
#include "ha_ndbcluster.h" #include "ha_ndbcluster.h"
extern handlerton ndbcluster_hton; extern handlerton ndbcluster_hton;
#else
handlerton ndbcluster_hton = { "ndbcluster", SHOW_OPTION_NO,
"Clustered, fault-tolerant, memory-based tables",
DB_TYPE_NDBCLUSTER, NULL, 0, 0, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#ifdef HAVE_FEDERATED_DB #ifdef HAVE_FEDERATED_DB
#include "ha_federated.h" #include "ha_federated.h"
extern handlerton federated_hton; extern handlerton federated_hton;
#else
handlerton federated_hton = { "FEDERATED", SHOW_OPTION_NO,
"Federated MySQL storage engine", DB_TYPE_FEDERATED_DB, NULL, 0, 0, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
HTON_NO_FLAGS };
#endif #endif
#include <myisampack.h> #include <myisampack.h>
#include <errno.h> #include <errno.h>
...@@ -65,13 +115,17 @@ extern handlerton myisammrg_hton; ...@@ -65,13 +115,17 @@ extern handlerton myisammrg_hton;
extern handlerton heap_hton; extern handlerton heap_hton;
extern handlerton binlog_hton; extern handlerton binlog_hton;
/*
Obsolete
*/
handlerton isam_hton = { "ISAM", SHOW_OPTION_NO, "Obsolete storage engine",
DB_TYPE_ISAM, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, HTON_NO_FLAGS };
/* static functions defined in this file */
static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES; /* static functions defined in this file */
/* list of all available storage engines (of their handlertons) */ static SHOW_COMP_OPTION have_yes= SHOW_OPTION_YES;
handlerton *handlertons[MAX_HA]={0};
/* number of entries in handlertons[] */ /* number of entries in handlertons[] */
ulong total_ha; ulong total_ha;
...@@ -87,31 +141,17 @@ handlerton *sys_table_types[]= ...@@ -87,31 +141,17 @@ handlerton *sys_table_types[]=
{ {
&myisam_hton, &myisam_hton,
&heap_hton, &heap_hton,
#ifdef HAVE_INNOBASE_DB
&innobase_hton, &innobase_hton,
#endif
#ifdef HAVE_BERKELEY_DB
&berkeley_hton, &berkeley_hton,
#endif
#ifdef HAVE_BLACKHOLE_DB
&blackhole_hton, &blackhole_hton,
#endif
#ifdef HAVE_EXAMPLE_DB
&example_hton, &example_hton,
#endif
#ifdef HAVE_ARCHIVE_DB
&archive_hton, &archive_hton,
#endif
#ifdef HAVE_CSV_DB
&tina_hton, &tina_hton,
#endif
#ifdef HAVE_NDBCLUSTER_DB
&ndbcluster_hton, &ndbcluster_hton,
#endif
#ifdef HAVE_FEDERATED_DB
&federated_hton, &federated_hton,
#endif
&myisammrg_hton, &myisammrg_hton,
&binlog_hton,
&isam_hton,
NULL NULL
}; };
...@@ -183,12 +223,12 @@ const char *ha_get_storage_engine(enum db_type db_type) ...@@ -183,12 +223,12 @@ const char *ha_get_storage_engine(enum db_type db_type)
bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag) bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag)
{ {
show_table_type_st *types; handlerton **types;
for (types= sys_table_types; types->type; types++) for (types= sys_table_types; *types; types++)
{ {
if (db_type == types->db_type) if (db_type == (*types)->db_type)
{ {
if (types->ht->flags & flag) if ((*types)->flags & flag)
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
...@@ -409,7 +449,6 @@ static inline void ha_was_inited_ok(handlerton **ht) ...@@ -409,7 +449,6 @@ static inline void ha_was_inited_ok(handlerton **ht)
int ha_init() int ha_init()
{ {
int error= 0; int error= 0;
handlerton **ht= handlertons;
handlerton **types; handlerton **types;
show_table_alias_st *table_alias; show_table_alias_st *table_alias;
total_ha= savepoint_alloc_size= 0; total_ha= savepoint_alloc_size= 0;
...@@ -418,38 +457,16 @@ int ha_init() ...@@ -418,38 +457,16 @@ int ha_init()
return 1; return 1;
/* /*
This will go away soon. We now initialize everything here.
*/ */
for (types= sys_table_types; *types; types++) for (types= sys_table_types; *types; types++)
{ {
/* if (!(*types)->init || !(*types)->init())
FUTURE -
We need to collapse sys_table_types and handlertons variables into
one variable.
*/
*ht= *types;
ht++;
if ((*types)->init)
{
if (!(*types)->init())
ha_was_inited_ok(types); ha_was_inited_ok(types);
}
}
if (opt_bin_log)
{
if (0) // Should fail until binlog is a bit more se like
{
mysql_bin_log.close(LOG_CLOSE_INDEX); // Never used
opt_bin_log= 0; // Never used
error= 1; // Never used
}
else else
{ (*types)->state= SHOW_OPTION_DISABLED;
*types= &binlog_hton;
ha_was_inited_ok(types);
}
} }
DBUG_ASSERT(total_ha < MAX_HA); DBUG_ASSERT(total_ha < MAX_HA);
/* /*
Check if there is a transaction-capable storage engine besides the Check if there is a transaction-capable storage engine besides the
...@@ -521,9 +538,10 @@ void ha_drop_database(char* path) ...@@ -521,9 +538,10 @@ void ha_drop_database(char* path)
/* don't bother to rollback here, it's done already */ /* don't bother to rollback here, it's done already */
void ha_close_connection(THD* thd) void ha_close_connection(THD* thd)
{ {
for (uint i=0; i < total_ha; i++) handlerton **types;
if (thd->ha_data[i]) for (types= sys_table_types; *types; types++)
(*handlertons[i]->close_connection)(thd); if (thd->ha_data[(*types)->slot])
(*types)->close_connection(thd);
} }
/* ======================================================================== /* ========================================================================
...@@ -834,13 +852,13 @@ int ha_autocommit_or_rollback(THD *thd, int error) ...@@ -834,13 +852,13 @@ int ha_autocommit_or_rollback(THD *thd, int error)
int ha_commit_or_rollback_by_xid(XID *xid, bool commit) int ha_commit_or_rollback_by_xid(XID *xid, bool commit)
{ {
handlerton **ht= handlertons, **end_ht=ht+total_ha; handlerton **types;
int res= 1; int res= 1;
for ( ; ht < end_ht ; ht++) for (types= sys_table_types; *types; types++)
if ((*ht)->recover) if ((*types)->state == SHOW_OPTION_YES && (*types)->recover)
res= res && res= res &&
(*(commit ? (*ht)->commit_by_xid : (*ht)->rollback_by_xid))(xid); (*(commit ? (*types)->commit_by_xid : (*types)->rollback_by_xid))(xid);
return res; return res;
} }
...@@ -919,7 +937,7 @@ static char* xid_to_str(char *buf, XID *xid) ...@@ -919,7 +937,7 @@ static char* xid_to_str(char *buf, XID *xid)
int ha_recover(HASH *commit_list) int ha_recover(HASH *commit_list)
{ {
int len, got, found_foreign_xids=0, found_my_xids=0; int len, got, found_foreign_xids=0, found_my_xids=0;
handlerton **ht= handlertons, **end_ht=ht+total_ha; handlerton **types;
XID *list=0; XID *list=0;
bool dry_run=(commit_list==0 && tc_heuristic_recover==0); bool dry_run=(commit_list==0 && tc_heuristic_recover==0);
DBUG_ENTER("ha_recover"); DBUG_ENTER("ha_recover");
...@@ -955,14 +973,14 @@ int ha_recover(HASH *commit_list) ...@@ -955,14 +973,14 @@ int ha_recover(HASH *commit_list)
DBUG_RETURN(1); DBUG_RETURN(1);
} }
for ( ; ht < end_ht ; ht++) for (types= sys_table_types; *types; types++)
{ {
if (!(*ht)->recover) if ((*types)->state != SHOW_OPTION_YES || !(*types)->recover)
continue; continue;
while ((got=(*(*ht)->recover)(list, len)) > 0 ) while ((got=(*(*types)->recover)(list, len)) > 0 )
{ {
sql_print_information("Found %d prepared transaction(s) in %s", sql_print_information("Found %d prepared transaction(s) in %s",
got, (*ht)->name); got, (*types)->name);
for (int i=0; i < got; i ++) for (int i=0; i < got; i ++)
{ {
my_xid x=list[i].get_my_xid(); my_xid x=list[i].get_my_xid();
...@@ -990,7 +1008,7 @@ int ha_recover(HASH *commit_list) ...@@ -990,7 +1008,7 @@ int ha_recover(HASH *commit_list)
char buf[XIDDATASIZE*4+6]; // see xid_to_str char buf[XIDDATASIZE*4+6]; // see xid_to_str
sql_print_information("commit xid %s", xid_to_str(buf, list+i)); sql_print_information("commit xid %s", xid_to_str(buf, list+i));
#endif #endif
(*(*ht)->commit_by_xid)(list+i); (*(*types)->commit_by_xid)(list+i);
} }
else else
{ {
...@@ -998,7 +1016,7 @@ int ha_recover(HASH *commit_list) ...@@ -998,7 +1016,7 @@ int ha_recover(HASH *commit_list)
char buf[XIDDATASIZE*4+6]; // see xid_to_str char buf[XIDDATASIZE*4+6]; // see xid_to_str
sql_print_information("rollback xid %s", xid_to_str(buf, list+i)); sql_print_information("rollback xid %s", xid_to_str(buf, list+i));
#endif #endif
(*(*ht)->rollback_by_xid)(list+i); (*(*types)->rollback_by_xid)(list+i);
} }
} }
if (got < len) if (got < len)
......
...@@ -854,7 +854,6 @@ extern handlerton *sys_table_types[]; ...@@ -854,7 +854,6 @@ extern handlerton *sys_table_types[];
extern const char *ha_row_type[]; extern const char *ha_row_type[];
extern TYPELIB tx_isolation_typelib; extern TYPELIB tx_isolation_typelib;
extern TYPELIB myisam_stats_method_typelib; extern TYPELIB myisam_stats_method_typelib;
extern handlerton *handlertons[MAX_HA];
extern ulong total_ha, total_ha_2pc; extern ulong total_ha, total_ha_2pc;
/* Wrapper functions */ /* Wrapper functions */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment