1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00
This commit is contained in:
tomas@poseidon.ndb.mysql.com
2005-10-06 10:54:07 +02:00
449 changed files with 13079 additions and 6107 deletions

View File

@ -25,43 +25,111 @@
#include "ha_heap.h"
#include "ha_myisam.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
#include "ha_berkeley.h"
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
#ifdef HAVE_BLACKHOLE_DB
#include "ha_blackhole.h"
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
#ifdef HAVE_EXAMPLE_DB
#include "examples/ha_example.h"
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
#ifdef HAVE_PARTITION_DB
#include "ha_partition.h"
#endif
#ifdef HAVE_ARCHIVE_DB
#include "examples/ha_archive.h"
#include "ha_archive.h"
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
#ifdef HAVE_CSV_DB
#include "examples/ha_tina.h"
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
#ifdef HAVE_INNOBASE_DB
#include "ha_innodb.h"
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
#ifdef HAVE_NDBCLUSTER_DB
#include "ha_ndbcluster.h"
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
#ifdef HAVE_FEDERATED_DB
#include "ha_federated.h"
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
#include <myisampack.h>
#include <errno.h>
/* static functions defined in this file */
extern handlerton myisam_hton;
extern handlerton myisammrg_hton;
extern handlerton heap_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;
/* list of all available storage engines (of their handlertons) */
handlerton *handlertons[MAX_HA]={0};
/* number of entries in handlertons[] */
ulong total_ha;
/* number of storage engines (from handlertons[]) that support 2pc */
@ -69,46 +137,35 @@ ulong total_ha_2pc;
/* size of savepoint storage area (see ha_init) */
ulong savepoint_alloc_size;
struct show_table_type_st sys_table_types[]=
/*
This array is used for processing compiled in engines.
*/
handlerton *sys_table_types[]=
{
{"MyISAM", &have_yes,
"Default engine as of MySQL 3.23 with great performance", DB_TYPE_MYISAM},
{"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},
{"ISAM", &have_isam,
"Obsolete storage engine, now replaced by MyISAM", DB_TYPE_ISAM},
{"MRG_ISAM", &have_isam,
"Obsolete storage engine, now replaced by MERGE", DB_TYPE_MRG_ISAM},
{"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},
{"NDBCLUSTER", &have_ndbcluster,
"Clustered, fault-tolerant, memory-based tables", DB_TYPE_NDBCLUSTER},
{"NDB", &have_ndbcluster,
"Alias for NDBCLUSTER", DB_TYPE_NDBCLUSTER},
{"EXAMPLE",&have_example_db,
"Example storage engine", DB_TYPE_EXAMPLE_DB},
{"ARCHIVE",&have_archive_db,
"Archive storage engine", DB_TYPE_ARCHIVE_DB},
{"CSV",&have_csv_db,
"CSV storage engine", DB_TYPE_CSV_DB},
{"FEDERATED",&have_federated_db,
"Federated MySQL storage engine", DB_TYPE_FEDERATED_DB},
{"BLACKHOLE",&have_blackhole_db,
"/dev/null storage engine (anything you write to it disappears)",
DB_TYPE_BLACKHOLE_DB},
{NullS, NULL, NullS, DB_TYPE_UNKNOWN}
&myisam_hton,
&heap_hton,
&innobase_hton,
&berkeley_hton,
&blackhole_hton,
&example_hton,
&archive_hton,
&tina_hton,
&ndbcluster_hton,
&federated_hton,
&myisammrg_hton,
&binlog_hton,
&isam_hton,
NULL
};
struct show_table_alias_st sys_table_aliases[]=
{
{"INNOBASE", "InnoDB"},
{"NDB", "NDBCLUSTER"},
{"BDB", "BERKELEYDB"},
{"HEAP", "MEMORY"},
{"MERGE", "MRG_MYISAM"},
{NullS, NullS}
};
const char *ha_row_type[] = {
@ -127,46 +184,78 @@ uint known_extensions_id= 0;
enum db_type ha_resolve_by_name(const char *name, uint namelen)
{
THD *thd= current_thd;
if (thd && !my_strcasecmp(&my_charset_latin1, name, "DEFAULT")) {
show_table_alias_st *table_alias;
handlerton **types;
const char *ptr= name;
if (thd && !my_strcasecmp(&my_charset_latin1, ptr, "DEFAULT"))
return (enum db_type) thd->variables.table_type;
retest:
for (types= sys_table_types; *types; types++)
{
if (!my_strcasecmp(&my_charset_latin1, ptr, (*types)->name))
return (enum db_type) (*types)->db_type;
}
show_table_type_st *types;
for (types= sys_table_types; types->type; types++)
/*
We check for the historical aliases.
*/
for (table_alias= sys_table_aliases; table_alias->type; table_alias++)
{
if (!my_strcasecmp(&my_charset_latin1, name, types->type))
return (enum db_type) types->db_type;
if (!my_strcasecmp(&my_charset_latin1, ptr, table_alias->alias))
{
ptr= table_alias->type;
goto retest;
}
}
return DB_TYPE_UNKNOWN;
}
const char *ha_get_storage_engine(enum db_type db_type)
{
show_table_type_st *types;
for (types= sys_table_types; types->type; types++)
handlerton **types;
for (types= sys_table_types; *types; types++)
{
if (db_type == types->db_type)
return types->type;
if (db_type == (*types)->db_type)
return (*types)->name;
}
return "none";
}
bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag)
{
handlerton **types;
for (types= sys_table_types; *types; types++)
{
if (db_type == (*types)->db_type)
{
if ((*types)->flags & flag)
return TRUE;
else
return FALSE;
}
}
return FALSE;
}
my_bool ha_storage_engine_is_enabled(enum db_type database_type)
{
show_table_type_st *types;
for (types= sys_table_types; types->type; types++)
handlerton **types;
for (types= sys_table_types; *types; types++)
{
if ((database_type == types->db_type) &&
(*types->value == SHOW_OPTION_YES))
if ((database_type == (*types)->db_type) &&
((*types)->state == SHOW_OPTION_YES))
return TRUE;
}
return FALSE;
}
/* Use other database handler if databasehandler is not incompiled */
/* Use other database handler if databasehandler is not compiled in */
enum db_type ha_checktype(THD *thd, enum db_type database_type,
bool no_substitute, bool report_error)
@ -372,8 +461,8 @@ static int ha_init_errors(void)
SETMSG(HA_ERR_READ_ONLY_TRANSACTION, ER(ER_READ_ONLY_TRANSACTION));
SETMSG(HA_ERR_LOCK_DEADLOCK, ER(ER_LOCK_DEADLOCK));
SETMSG(HA_ERR_CANNOT_ADD_FOREIGN, ER(ER_CANNOT_ADD_FOREIGN));
SETMSG(HA_ERR_NO_REFERENCED_ROW, ER(ER_NO_REFERENCED_ROW));
SETMSG(HA_ERR_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED));
SETMSG(HA_ERR_NO_REFERENCED_ROW, ER(ER_NO_REFERENCED_ROW_2));
SETMSG(HA_ERR_ROW_IS_REFERENCED, ER(ER_ROW_IS_REFERENCED_2));
SETMSG(HA_ERR_NO_SAVEPOINT, "No savepoint with that name");
SETMSG(HA_ERR_NON_UNIQUE_BLOCK_SIZE, "Non unique key block size");
SETMSG(HA_ERR_NO_SUCH_TABLE, "No such table: '%.64s'");
@ -422,81 +511,24 @@ static inline void ha_was_inited_ok(handlerton **ht)
int ha_init()
{
int error= 0;
handlerton **ht= handlertons;
handlerton **types;
show_table_alias_st *table_alias;
total_ha= savepoint_alloc_size= 0;
if (ha_init_errors())
return 1;
if (opt_bin_log)
/*
We now initialize everything here.
*/
for (types= sys_table_types; *types; 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
}
if (!(*types)->init || !(*types)->init())
ha_was_inited_ok(types);
else
ha_was_inited_ok(ht++);
(*types)->state= SHOW_OPTION_DISABLED;
}
#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++);
}
#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++);
}
#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++);
}
#endif
#ifdef HAVE_FEDERATED_DB
if (have_federated_db == SHOW_OPTION_YES)
{
if (federated_db_init())
{
have_federated_db= SHOW_OPTION_DISABLED;
error= 1;
}
}
#endif
#ifdef HAVE_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++);
}
#endif
DBUG_ASSERT(total_ha < MAX_HA);
/*
Check if there is a transaction-capable storage engine besides the
@ -543,6 +575,10 @@ int ha_panic(enum ha_panic_function flag)
#ifdef HAVE_ARCHIVE_DB
if (have_archive_db == SHOW_OPTION_YES)
error|= archive_db_end();
#endif
#ifdef HAVE_CSV_DB
if (have_csv_db == SHOW_OPTION_YES)
error|= tina_end();
#endif
if (ha_finish_errors())
error= 1;
@ -564,9 +600,10 @@ void ha_drop_database(char* path)
/* don't bother to rollback here, it's done already */
void ha_close_connection(THD* thd)
{
for (uint i=0; i < total_ha; i++)
if (thd->ha_data[i])
(*handlertons[i]->close_connection)(thd);
handlerton **types;
for (types= sys_table_types; *types; types++)
if (thd->ha_data[(*types)->slot])
(*types)->close_connection(thd);
}
/* ========================================================================
@ -877,13 +914,13 @@ int ha_autocommit_or_rollback(THD *thd, int error)
int ha_commit_or_rollback_by_xid(XID *xid, bool commit)
{
handlerton **ht= handlertons, **end_ht=ht+total_ha;
handlerton **types;
int res= 1;
for ( ; ht < end_ht ; ht++)
if ((*ht)->recover)
for (types= sys_table_types; *types; types++)
if ((*types)->state == SHOW_OPTION_YES && (*types)->recover)
res= res &&
(*(commit ? (*ht)->commit_by_xid : (*ht)->rollback_by_xid))(xid);
(*(commit ? (*types)->commit_by_xid : (*types)->rollback_by_xid))(xid);
return res;
}
@ -962,7 +999,7 @@ static char* xid_to_str(char *buf, XID *xid)
int ha_recover(HASH *commit_list)
{
int len, got, found_foreign_xids=0, found_my_xids=0;
handlerton **ht= handlertons, **end_ht=ht+total_ha;
handlerton **types;
XID *list=0;
bool dry_run=(commit_list==0 && tc_heuristic_recover==0);
DBUG_ENTER("ha_recover");
@ -998,14 +1035,14 @@ int ha_recover(HASH *commit_list)
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;
while ((got=(*(*ht)->recover)(list, len)) > 0 )
while ((got=(*(*types)->recover)(list, len)) > 0 )
{
sql_print_information("Found %d prepared transaction(s) in %s",
got, (*ht)->name);
got, (*types)->name);
for (int i=0; i < got; i ++)
{
my_xid x=list[i].get_my_xid();
@ -1033,7 +1070,7 @@ int ha_recover(HASH *commit_list)
char buf[XIDDATASIZE*4+6]; // see xid_to_str
sql_print_information("commit xid %s", xid_to_str(buf, list+i));
#endif
(*(*ht)->commit_by_xid)(list+i);
(*(*types)->commit_by_xid)(list+i);
}
else
{
@ -1041,7 +1078,7 @@ int ha_recover(HASH *commit_list)
char buf[XIDDATASIZE*4+6]; // see xid_to_str
sql_print_information("rollback xid %s", xid_to_str(buf, list+i));
#endif
(*(*ht)->rollback_by_xid)(list+i);
(*(*types)->rollback_by_xid)(list+i);
}
}
if (got < len)
@ -1401,11 +1438,9 @@ int handler::ha_open(const char *name, int mode, int test_if_locked)
table->db_stat|=HA_READ_ONLY;
(void) extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL
if (!alloc_root_inited(&table->mem_root)) // If temporary table
ref=(byte*) sql_alloc(ALIGN_SIZE(ref_length)*2);
else
ref=(byte*) alloc_root(&table->mem_root, ALIGN_SIZE(ref_length)*2);
if (!ref)
DBUG_ASSERT(alloc_root_inited(&table->mem_root));
if (!(ref= (byte*) alloc_root(&table->mem_root, ALIGN_SIZE(ref_length)*2)))
{
close();
error=HA_ERR_OUT_OF_MEM;
@ -1870,11 +1905,19 @@ void handler::print_error(int error, myf errflag)
textno=ER_CANNOT_ADD_FOREIGN;
break;
case HA_ERR_ROW_IS_REFERENCED:
textno=ER_ROW_IS_REFERENCED;
break;
{
String str;
get_error_message(error, &str);
my_error(ER_ROW_IS_REFERENCED_2, MYF(0), str.c_ptr_safe());
DBUG_VOID_RETURN;
}
case HA_ERR_NO_REFERENCED_ROW:
textno=ER_NO_REFERENCED_ROW;
break;
{
String str;
get_error_message(error, &str);
my_error(ER_NO_REFERENCED_ROW_2, MYF(0), str.c_ptr_safe());
DBUG_VOID_RETURN;
}
case HA_ERR_TABLE_DEF_CHANGED:
textno=ER_TABLE_DEF_CHANGED;
break;
@ -2585,7 +2628,7 @@ TYPELIB *ha_known_exts(void)
{
if (!known_extensions.type_names || mysys_usage_id != known_extensions_id)
{
show_table_type_st *types;
handlerton **types;
List<char> found_exts;
List_iterator_fast<char> it(found_exts);
const char **ext, *old_ext;
@ -2593,11 +2636,11 @@ TYPELIB *ha_known_exts(void)
known_extensions_id= mysys_usage_id;
found_exts.push_back((char*) triggers_file_ext);
found_exts.push_back((char*) trigname_file_ext);
for (types= sys_table_types; types->type; types++)
for (types= sys_table_types; *types; types++)
{
if (*types->value == SHOW_OPTION_YES)
if ((*types)->state == SHOW_OPTION_YES)
{
handler *file= get_new_handler(0,(enum db_type) types->db_type);
handler *file= get_new_handler(0,(enum db_type) (*types)->db_type);
for (ext= file->bas_ext(); *ext; ext++)
{
while ((old_ext= it++))