mirror of
https://github.com/MariaDB/server.git
synced 2025-01-26 00:34:18 +01:00
19bbb7cc85
Optimised version of ADD/DROP/REORGANIZE partitions for non-NDB storage engines. New syntax to handle REBUILD/OPTIMIZE/ANALYZE/CHECK/REPAIR partitions Quite a few bug fixes include/thr_lock.h: New method to downgrade locks from TL_WRITE_ONLY Possibility to upgrade lock while aborting locks mysql-test/r/ndb_autodiscover.result: Fix for lowercase and that all NDB tables are now partitioned mysql-test/r/ndb_bitfield.result: Fix for lowercase and that all NDB tables are now partitioned mysql-test/r/ndb_gis.result: Fix for lowercase and that all NDB tables are now partitioned mysql-test/r/ndb_partition_key.result: New test case mysql-test/r/partition.result: New test case mysql-test/r/partition_error.result: New test case mysql-test/r/partition_mgm_err.result: Fix of test case results mysql-test/t/disabled.def: partition_03ndb still has bug mysql-test/t/ndb_partition_key.test: New test cases for new functionality and bugs mysql-test/t/partition.test: New test cases for new functionality and bugs mysql-test/t/partition_error.test: New test cases for new functionality and bugs mysql-test/t/partition_mgm_err.test: New test cases for new functionality and bugs mysys/thr_lock.c: New method to downgrade TL_WRITE_ONLY locks Possibility to specify if locks are to be upgraded at abort locks sql/ha_archive.cc: New handlerton methods sql/ha_berkeley.cc: New handlerton methods sql/ha_blackhole.cc: New handlerton methods sql/ha_federated.cc: New handlerton methods sql/ha_heap.cc: New handlerton methods sql/ha_innodb.cc: New handlerton methods sql/ha_myisam.cc: New handlerton methods sql/ha_myisammrg.cc: New handlerton methods sql/ha_ndbcluster.cc: New handlerton methods Moved out packfrm and unpackfrm methods Adapted many parts to use table_share instead of table->s Ensured that .ndb file uses filename and not tablename according to new encoding of names (WL 1324) All NDB tables are partitioned and set up partition info Fixed such that tablenames use tablenames and not filenames in NDB NDB uses auto partitioning for ENGINE=NDB tables Warning for very large tables Set RANGE data Set LIST data New method to set-up partition info Set Default number of partitions flag Set linear hash flag Set node group array Set number of fragments Set max rows Set tablespace names New method to get number of partitions of table to use at open table sql/ha_ndbcluster.h: Removed partition_flags and alter_table_flags from handler class A couple of new and changed method headers sql/ha_ndbcluster_binlog.cc: Use new method headers sql/ha_partition.cc: New handlerton methods Lots of new function headers Use #P# as separator between table name and partition name and #SP# as separator between partition name and subpartition name Use filename encoding for files both of table name part and of partition name parts New method to drop partitions based on partition state New method to rename partitions based on partition state New methods to optimize, analyze, check and repair partitions New methods to optimize, analyze, check and repair table Helper method to create new partition, open it and external lock it, not needed to lock it internally since no one else knows about it yet. Cleanup method at error for new partitions New methods to perform bulk of work at ADD/REORGANIZE partitions (change_partitions, copy_partitions) sql/ha_partition.h: New methods and variables A few dropped ones and a few changed ones sql/handler.cc: Handlerton interface changes New flag to open_table_from_share sql/handler.h: New alter_table_flags New partition flags New partition states More states for default handling Lots of new, dropped and changed interfaces sql/lex.h: Added REBUILD and changed name of REORGANISE to REORGANIZE sql/lock.cc: Method to downgrade locks Able to specify if locks upgraded on abort locks sql/log.cc: New handlerton methods sql/mysql_priv.h: Lots of new interfaces sql/share/errmsg.txt: Lots of new, dropped and changed error messages sql/sql_base.cc: Adapted to new method headers New method to abort and upgrade lock New method to close open tables and downgrade lock New method to wait for completed table sql/sql_lex.h: New flags sql/sql_partition.cc: Return int instead of bool in get_partition_id More defaults handling Make use of new mem_alloc_error method More work on function headers Changes to generate partition syntax to cater for intermediate partition states Lots of new code with large comments describing new features for Partition Management: ADD/DROP/REORGANIZE/OPTIMIZE/ANALYZE/CHECK/REPAIR partitions sql/sql_show.cc: Minors sql/sql_table.cc: Moved a couple of methods New methods to copy create lists and key lists for use with mysql_prepare_table New method to write frm file New handling of handlers with auto partitioning Fix CREATE TABLE LIKE Moved code for ADD/DROP/REORGANIZE partitions Use handlerton method for alter_table_flags sql/sql_yacc.yy: More memory alloc error checks New syntax for REBUILD, ANALYZE, CHECK, OPTIMIZE, REPAIR partitions sql/table.cc: Fix length of extra part to be 4 bytes Partition state introduced in frm file sql/table.h: Partition state introduced sql/unireg.cc: Partition state introduced Default partition storage/csv/ha_tina.cc: New handlerton methods storage/example/ha_example.cc: New handlerton methods storage/ndb/include/kernel/ndb_limits.h: RANGE DATA storage/ndb/include/kernel/signaldata/AlterTable.hpp: New interfaces in ALTER TABLE towards NDB kernel storage/ndb/include/kernel/signaldata/DiAddTab.hpp: New section storage/ndb/include/kernel/signaldata/DictTabInfo.hpp: Lots of new parts of table description storage/ndb/include/kernel/signaldata/LqhFrag.hpp: tablespace id specified in LQHFRAGREQ storage/ndb/include/ndbapi/NdbDictionary.hpp: Lots of new methods in NDB dictionary storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp: Lots of new variables in table description storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Lots of new variables in table description storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp: Lots of new variables in table description storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp: New error insertion storage/ndb/src/kernel/blocks/dbtup/DbtupMeta.cpp: a few extra jam's storage/ndb/src/ndbapi/NdbBlob.cpp: Changes to definition of blob tables storage/ndb/src/ndbapi/NdbDictionary.cpp: Lots of new stuff in NDB dictionary storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp: Lots of new stuff in NDB dictionary storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp: Lots of new stuff in NDB dictionary storage/ndb/test/ndbapi/test_event.cpp: removed use of methods no longer in existence storage/ndb/tools/restore/Restore.cpp: Renamed variable
551 lines
16 KiB
C++
551 lines
16 KiB
C++
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
|
#pragma implementation // gcc: Class implementation
|
|
#endif
|
|
|
|
#include "mysql_priv.h"
|
|
#include <m_ctype.h>
|
|
#include "ha_myisammrg.h"
|
|
#ifndef MASTER
|
|
#include "../srclib/myisammrg/myrg_def.h"
|
|
#else
|
|
#include "../storage/myisammrg/myrg_def.h"
|
|
#endif
|
|
|
|
/*****************************************************************************
|
|
** MyISAM MERGE tables
|
|
*****************************************************************************/
|
|
|
|
static handler *myisammrg_create_handler(TABLE_SHARE *table);
|
|
|
|
/* MyISAM MERGE handlerton */
|
|
|
|
handlerton myisammrg_hton= {
|
|
MYSQL_HANDLERTON_INTERFACE_VERSION,
|
|
"MRG_MYISAM",
|
|
SHOW_OPTION_YES,
|
|
"Collection of identical MyISAM tables",
|
|
DB_TYPE_MRG_MYISAM,
|
|
NULL,
|
|
0, /* slot */
|
|
0, /* savepoint size. */
|
|
NULL, /* close_connection */
|
|
NULL, /* savepoint */
|
|
NULL, /* rollback to savepoint */
|
|
NULL, /* release savepoint */
|
|
NULL, /* commit */
|
|
NULL, /* rollback */
|
|
NULL, /* prepare */
|
|
NULL, /* recover */
|
|
NULL, /* commit_by_xid */
|
|
NULL, /* rollback_by_xid */
|
|
NULL, /* create_cursor_read_view */
|
|
NULL, /* set_cursor_read_view */
|
|
NULL, /* close_cursor_read_view */
|
|
myisammrg_create_handler, /* Create a new handler */
|
|
NULL, /* Drop a database */
|
|
myrg_panic, /* Panic call */
|
|
NULL, /* Start Consistent Snapshot */
|
|
NULL, /* Flush logs */
|
|
NULL, /* Show status */
|
|
NULL, /* Partition flags */
|
|
NULL, /* Alter table flags */
|
|
NULL, /* Alter Tablespace */
|
|
HTON_CAN_RECREATE
|
|
};
|
|
|
|
static handler *myisammrg_create_handler(TABLE_SHARE *table)
|
|
{
|
|
return new ha_myisammrg(table);
|
|
}
|
|
|
|
|
|
ha_myisammrg::ha_myisammrg(TABLE_SHARE *table_arg)
|
|
:handler(&myisammrg_hton, table_arg), file(0)
|
|
{}
|
|
|
|
static const char *ha_myisammrg_exts[] = {
|
|
".MRG",
|
|
NullS
|
|
};
|
|
|
|
const char **ha_myisammrg::bas_ext() const
|
|
{
|
|
return ha_myisammrg_exts;
|
|
}
|
|
|
|
|
|
const char *ha_myisammrg::index_type(uint key_number)
|
|
{
|
|
return ((table->key_info[key_number].flags & HA_FULLTEXT) ?
|
|
"FULLTEXT" :
|
|
(table->key_info[key_number].flags & HA_SPATIAL) ?
|
|
"SPATIAL" :
|
|
(table->key_info[key_number].algorithm == HA_KEY_ALG_RTREE) ?
|
|
"RTREE" :
|
|
"BTREE");
|
|
}
|
|
|
|
|
|
int ha_myisammrg::open(const char *name, int mode, uint test_if_locked)
|
|
{
|
|
char name_buff[FN_REFLEN];
|
|
|
|
DBUG_PRINT("info", ("ha_myisammrg::open"));
|
|
if (!(file=myrg_open(fn_format(name_buff,name,"","",
|
|
MY_UNPACK_FILENAME|MY_APPEND_EXT),
|
|
mode, test_if_locked)))
|
|
{
|
|
DBUG_PRINT("info", ("ha_myisammrg::open exit %d", my_errno));
|
|
return (my_errno ? my_errno : -1);
|
|
}
|
|
DBUG_PRINT("info", ("ha_myisammrg::open myrg_extrafunc..."))
|
|
myrg_extrafunc(file, query_cache_invalidate_by_MyISAM_filename_ref);
|
|
if (!(test_if_locked == HA_OPEN_WAIT_IF_LOCKED ||
|
|
test_if_locked == HA_OPEN_ABORT_IF_LOCKED))
|
|
myrg_extra(file,HA_EXTRA_NO_WAIT_LOCK,0);
|
|
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
|
|
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
|
|
myrg_extra(file,HA_EXTRA_WAIT_LOCK,0);
|
|
|
|
if (table->s->reclength != mean_rec_length && mean_rec_length)
|
|
{
|
|
DBUG_PRINT("error",("reclength: %d mean_rec_length: %d",
|
|
table->s->reclength, mean_rec_length));
|
|
goto err;
|
|
}
|
|
#if !defined(BIG_TABLES) || SIZEOF_OFF_T == 4
|
|
/* Merge table has more than 2G rows */
|
|
if (table->s->crashed)
|
|
goto err;
|
|
#endif
|
|
return (0);
|
|
err:
|
|
myrg_close(file);
|
|
file=0;
|
|
return (my_errno= HA_ERR_WRONG_MRG_TABLE_DEF);
|
|
}
|
|
|
|
int ha_myisammrg::close(void)
|
|
{
|
|
return myrg_close(file);
|
|
}
|
|
|
|
int ha_myisammrg::write_row(byte * buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
|
|
table->timestamp_field->set_time();
|
|
if (table->next_number_field && buf == table->record[0])
|
|
update_auto_increment();
|
|
return myrg_write(file,buf);
|
|
}
|
|
|
|
int ha_myisammrg::update_row(const byte * old_data, byte * new_data)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
|
|
table->timestamp_field->set_time();
|
|
return myrg_update(file,old_data,new_data);
|
|
}
|
|
|
|
int ha_myisammrg::delete_row(const byte * buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
|
|
return myrg_delete(file,buf);
|
|
}
|
|
|
|
int ha_myisammrg::index_read(byte * buf, const byte * key,
|
|
uint key_len, enum ha_rkey_function find_flag)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_key_count,
|
|
&LOCK_status);
|
|
int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key,
|
|
uint key_len, enum ha_rkey_function find_flag)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_key_count,
|
|
&LOCK_status);
|
|
int error=myrg_rkey(file,buf,index, key, key_len, find_flag);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_key_count,
|
|
&LOCK_status);
|
|
int error=myrg_rkey(file,buf,active_index, key, key_len,
|
|
HA_READ_PREFIX_LAST);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_next(byte * buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_next_count,
|
|
&LOCK_status);
|
|
int error=myrg_rnext(file,buf,active_index);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_prev(byte * buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_prev_count,
|
|
&LOCK_status);
|
|
int error=myrg_rprev(file,buf, active_index);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_first(byte * buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_first_count,
|
|
&LOCK_status);
|
|
int error=myrg_rfirst(file, buf, active_index);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_last(byte * buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_last_count,
|
|
&LOCK_status);
|
|
int error=myrg_rlast(file, buf, active_index);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::index_next_same(byte * buf,
|
|
const byte *key __attribute__((unused)),
|
|
uint length __attribute__((unused)))
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_next_count,
|
|
&LOCK_status);
|
|
int error=myrg_rnext_same(file,buf);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::rnd_init(bool scan)
|
|
{
|
|
return myrg_extra(file,HA_EXTRA_RESET,0);
|
|
}
|
|
|
|
int ha_myisammrg::rnd_next(byte *buf)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
|
|
&LOCK_status);
|
|
int error=myrg_rrnd(file, buf, HA_OFFSET_ERROR);
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
int ha_myisammrg::rnd_pos(byte * buf, byte *pos)
|
|
{
|
|
statistic_increment(table->in_use->status_var.ha_read_rnd_count,
|
|
&LOCK_status);
|
|
int error=myrg_rrnd(file, buf, my_get_ptr(pos,ref_length));
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
return error;
|
|
}
|
|
|
|
void ha_myisammrg::position(const byte *record)
|
|
{
|
|
ulonglong position= myrg_position(file);
|
|
my_store_ptr(ref, ref_length, (my_off_t) position);
|
|
}
|
|
|
|
|
|
ha_rows ha_myisammrg::records_in_range(uint inx, key_range *min_key,
|
|
key_range *max_key)
|
|
{
|
|
return (ha_rows) myrg_records_in_range(file, (int) inx, min_key, max_key);
|
|
}
|
|
|
|
|
|
void ha_myisammrg::info(uint flag)
|
|
{
|
|
MYMERGE_INFO info;
|
|
(void) myrg_status(file,&info,flag);
|
|
/*
|
|
The following fails if one has not compiled MySQL with -DBIG_TABLES
|
|
and one has more than 2^32 rows in the merge tables.
|
|
*/
|
|
records = (ha_rows) info.records;
|
|
deleted = (ha_rows) info.deleted;
|
|
#if !defined(BIG_TABLES) || SIZEOF_OFF_T == 4
|
|
if ((info.records >= (ulonglong) 1 << 32) ||
|
|
(info.deleted >= (ulonglong) 1 << 32))
|
|
table->s->crashed= 1;
|
|
#endif
|
|
data_file_length=info.data_file_length;
|
|
errkey = info.errkey;
|
|
table->s->keys_in_use.set_prefix(table->s->keys);
|
|
table->s->db_options_in_use= info.options;
|
|
mean_rec_length= info.reclength;
|
|
block_size=0;
|
|
update_time=0;
|
|
#if SIZEOF_OFF_T > 4
|
|
ref_length=6; // Should be big enough
|
|
#else
|
|
ref_length=4; // Can't be > than my_off_t
|
|
#endif
|
|
if (flag & HA_STATUS_CONST)
|
|
{
|
|
if (table->s->key_parts && info.rec_per_key)
|
|
memcpy((char*) table->key_info[0].rec_per_key,
|
|
(char*) info.rec_per_key,
|
|
sizeof(table->key_info[0].rec_per_key)*table->s->key_parts);
|
|
}
|
|
}
|
|
|
|
|
|
int ha_myisammrg::extra(enum ha_extra_function operation)
|
|
{
|
|
/* As this is just a mapping, we don't have to force the underlying
|
|
tables to be closed */
|
|
if (operation == HA_EXTRA_FORCE_REOPEN ||
|
|
operation == HA_EXTRA_PREPARE_FOR_DELETE)
|
|
return 0;
|
|
return myrg_extra(file,operation,0);
|
|
}
|
|
|
|
|
|
/* To be used with WRITE_CACHE, EXTRA_CACHE and BULK_INSERT_BEGIN */
|
|
|
|
int ha_myisammrg::extra_opt(enum ha_extra_function operation, ulong cache_size)
|
|
{
|
|
if ((specialflag & SPECIAL_SAFE_MODE) && operation == HA_EXTRA_WRITE_CACHE)
|
|
return 0;
|
|
return myrg_extra(file, operation, (void*) &cache_size);
|
|
}
|
|
|
|
int ha_myisammrg::external_lock(THD *thd, int lock_type)
|
|
{
|
|
return myrg_lock_database(file,lock_type);
|
|
}
|
|
|
|
uint ha_myisammrg::lock_count(void) const
|
|
{
|
|
return file->tables;
|
|
}
|
|
|
|
|
|
THR_LOCK_DATA **ha_myisammrg::store_lock(THD *thd,
|
|
THR_LOCK_DATA **to,
|
|
enum thr_lock_type lock_type)
|
|
{
|
|
MYRG_TABLE *open_table;
|
|
|
|
for (open_table=file->open_tables ;
|
|
open_table != file->end_table ;
|
|
open_table++)
|
|
{
|
|
*(to++)= &open_table->table->lock;
|
|
if (lock_type != TL_IGNORE && open_table->table->lock.type == TL_UNLOCK)
|
|
open_table->table->lock.type=lock_type;
|
|
}
|
|
return to;
|
|
}
|
|
|
|
|
|
/* Find out database name and table name from a filename */
|
|
|
|
static void split_file_name(const char *file_name,
|
|
LEX_STRING *db, LEX_STRING *name)
|
|
{
|
|
uint dir_length, prefix_length;
|
|
char buff[FN_REFLEN];
|
|
|
|
db->length= 0;
|
|
strmake(buff, file_name, sizeof(buff)-1);
|
|
dir_length= dirname_length(buff);
|
|
if (dir_length > 1)
|
|
{
|
|
/* Get database */
|
|
buff[dir_length-1]= 0; // Remove end '/'
|
|
prefix_length= dirname_length(buff);
|
|
db->str= (char*) file_name+ prefix_length;
|
|
db->length= dir_length - prefix_length -1;
|
|
}
|
|
name->str= (char*) file_name+ dir_length;
|
|
name->length= (uint) (fn_ext(name->str) - name->str);
|
|
}
|
|
|
|
|
|
void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
|
|
{
|
|
DBUG_ENTER("ha_myisammrg::update_create_info");
|
|
|
|
if (!(create_info->used_fields & HA_CREATE_USED_UNION))
|
|
{
|
|
MYRG_TABLE *open_table;
|
|
THD *thd=current_thd;
|
|
|
|
create_info->merge_list.next= &create_info->merge_list.first;
|
|
create_info->merge_list.elements=0;
|
|
|
|
for (open_table=file->open_tables ;
|
|
open_table != file->end_table ;
|
|
open_table++)
|
|
{
|
|
TABLE_LIST *ptr;
|
|
LEX_STRING db, name;
|
|
|
|
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
|
|
goto err;
|
|
split_file_name(open_table->table->filename, &db, &name);
|
|
if (!(ptr->table_name= thd->strmake(name.str, name.length)))
|
|
goto err;
|
|
if (db.length && !(ptr->db= thd->strmake(db.str, db.length)))
|
|
goto err;
|
|
|
|
create_info->merge_list.elements++;
|
|
(*create_info->merge_list.next) = (byte*) ptr;
|
|
create_info->merge_list.next= (byte**) &ptr->next_local;
|
|
}
|
|
*create_info->merge_list.next=0;
|
|
}
|
|
if (!(create_info->used_fields & HA_CREATE_USED_INSERT_METHOD))
|
|
{
|
|
create_info->merge_insert_method = file->merge_insert_method;
|
|
}
|
|
DBUG_VOID_RETURN;
|
|
|
|
err:
|
|
create_info->merge_list.elements=0;
|
|
create_info->merge_list.first=0;
|
|
DBUG_VOID_RETURN;
|
|
}
|
|
|
|
|
|
int ha_myisammrg::create(const char *name, register TABLE *form,
|
|
HA_CREATE_INFO *create_info)
|
|
{
|
|
char buff[FN_REFLEN];
|
|
const char **table_names, **pos;
|
|
TABLE_LIST *tables= (TABLE_LIST*) create_info->merge_list.first;
|
|
THD *thd= current_thd;
|
|
uint dirlgt= dirname_length(name);
|
|
DBUG_ENTER("ha_myisammrg::create");
|
|
|
|
if (!(table_names= (const char**)
|
|
thd->alloc((create_info->merge_list.elements+1) * sizeof(char*))))
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
for (pos= table_names; tables; tables= tables->next_local)
|
|
{
|
|
const char *table_name;
|
|
TABLE *tbl= 0;
|
|
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
|
|
tbl= find_temporary_table(thd, tables);
|
|
if (!tbl)
|
|
{
|
|
/*
|
|
Construct the path to the MyISAM table. Try to meet two conditions:
|
|
1.) Allow to include MyISAM tables from different databases, and
|
|
2.) allow for moving DATADIR around in the file system.
|
|
The first means that we need paths in the .MRG file. The second
|
|
means that we should not have absolute paths in the .MRG file.
|
|
The best, we can do, is to use 'mysql_data_home', which is '.'
|
|
in mysqld and may be an absolute path in an embedded server.
|
|
This means that it might not be possible to move the DATADIR of
|
|
an embedded server without changing the paths in the .MRG file.
|
|
*/
|
|
uint length= build_table_filename(buff, sizeof(buff),
|
|
tables->db, tables->table_name, "");
|
|
/*
|
|
If a MyISAM table is in the same directory as the MERGE table,
|
|
we use the table name without a path. This means that the
|
|
DATADIR can easily be moved even for an embedded server as long
|
|
as the MyISAM tables are from the same database as the MERGE table.
|
|
*/
|
|
if ((dirname_length(buff) == dirlgt) && ! memcmp(buff, name, dirlgt))
|
|
table_name= tables->table_name;
|
|
else
|
|
if (! (table_name= thd->strmake(buff, length)))
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
|
}
|
|
else
|
|
table_name= tbl->s->path.str;
|
|
*pos++= table_name;
|
|
}
|
|
*pos=0;
|
|
DBUG_RETURN(myrg_create(fn_format(buff,name,"","",
|
|
MY_RESOLVE_SYMLINKS|
|
|
MY_UNPACK_FILENAME|MY_APPEND_EXT),
|
|
table_names,
|
|
create_info->merge_insert_method,
|
|
(my_bool) 0));
|
|
}
|
|
|
|
|
|
void ha_myisammrg::append_create_info(String *packet)
|
|
{
|
|
const char *current_db;
|
|
uint db_length;
|
|
THD *thd= current_thd;
|
|
MYRG_TABLE *open_table, *first;
|
|
|
|
if (file->merge_insert_method != MERGE_INSERT_DISABLED)
|
|
{
|
|
packet->append(STRING_WITH_LEN(" INSERT_METHOD="));
|
|
packet->append(get_type(&merge_insert_method,file->merge_insert_method-1));
|
|
}
|
|
packet->append(STRING_WITH_LEN(" UNION=("));
|
|
|
|
current_db= table->s->db.str;
|
|
db_length= table->s->db.length;
|
|
|
|
for (first=open_table=file->open_tables ;
|
|
open_table != file->end_table ;
|
|
open_table++)
|
|
{
|
|
LEX_STRING db, name;
|
|
split_file_name(open_table->table->filename, &db, &name);
|
|
if (open_table != first)
|
|
packet->append(',');
|
|
/* Report database for mapped table if it isn't in current database */
|
|
if (db.length &&
|
|
(db_length != db.length ||
|
|
strncmp(current_db, db.str, db.length)))
|
|
{
|
|
append_identifier(thd, packet, db.str, db.length);
|
|
packet->append('.');
|
|
}
|
|
append_identifier(thd, packet, name.str, name.length);
|
|
}
|
|
packet->append(')');
|
|
}
|
|
|
|
|
|
bool ha_myisammrg::check_if_incompatible_data(HA_CREATE_INFO *info,
|
|
uint table_changes)
|
|
{
|
|
/*
|
|
For myisammrg, we should always re-generate the mapping file as this
|
|
is trivial to do
|
|
*/
|
|
return COMPATIBLE_DATA_NO;
|
|
}
|