2000-07-31 21:29:14 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
2000-08-14 13:27:19 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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.
|
2000-08-14 13:27:19 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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.
|
2000-08-14 13:27:19 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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 */
|
|
|
|
|
|
|
|
|
2005-05-26 12:09:14 +02:00
|
|
|
#ifdef USE_PRAGMA_IMPLEMENTATION
|
2000-07-31 21:29:14 +02:00
|
|
|
#pragma implementation // gcc: Class implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mysql_priv.h"
|
|
|
|
#include <m_ctype.h>
|
|
|
|
#include "ha_myisammrg.h"
|
|
|
|
#ifndef MASTER
|
2001-10-08 03:58:07 +02:00
|
|
|
#include "../srclib/myisammrg/myrg_def.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#else
|
2005-04-27 04:04:36 +02:00
|
|
|
#include "../storage/myisammrg/myrg_def.h"
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** MyISAM MERGE tables
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
static handler *myisammrg_create_handler(TABLE_SHARE *table);
|
2005-11-07 16:25:06 +01:00
|
|
|
|
2005-07-19 20:21:12 +02:00
|
|
|
/* MyISAM MERGE handlerton */
|
|
|
|
|
2005-09-19 21:06:23 +02:00
|
|
|
handlerton myisammrg_hton= {
|
2005-12-21 19:18:40 +01:00
|
|
|
MYSQL_HANDLERTON_INTERFACE_VERSION,
|
2005-09-19 21:06:23 +02:00
|
|
|
"MRG_MYISAM",
|
2005-10-03 04:44:28 +02:00
|
|
|
SHOW_OPTION_YES,
|
|
|
|
"Collection of identical MyISAM tables",
|
|
|
|
DB_TYPE_MRG_MYISAM,
|
|
|
|
NULL,
|
2005-07-19 20:21:12 +02:00
|
|
|
0, /* slot */
|
|
|
|
0, /* savepoint size. */
|
2005-07-20 18:02:36 +02:00
|
|
|
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 */
|
2005-11-07 16:25:06 +01:00
|
|
|
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 */
|
2006-01-17 08:40:00 +01:00
|
|
|
NULL, /* Partition flags */
|
|
|
|
NULL, /* Alter table flags */
|
2006-01-11 11:35:25 +01:00
|
|
|
NULL, /* Alter Tablespace */
|
2006-01-28 04:16:23 +01:00
|
|
|
NULL, /* Fill Files Table */
|
WL#2977 and WL#2712 global and session-level variable to set the binlog format (row/statement),
and new binlog format called "mixed" (which is statement-based except if only row-based is correct,
in this cset it means if UDF or UUID is used; more cases could be added in later 5.1 release):
SET GLOBAL|SESSION BINLOG_FORMAT=row|statement|mixed|default;
the global default is statement unless cluster is enabled (then it's row) as in 5.1-alpha.
It's not possible to use SET on this variable if a session is currently in row-based mode and has open temporary tables (because CREATE
TEMPORARY TABLE was not binlogged so temp table is not known on slave), or if NDB is enabled (because
NDB does not support such change on-the-fly, though it will later), of if in a stored function (see below).
The added tests test the possibility or impossibility to SET, their effects, and the mixed mode,
including in prepared statements and in stored procedures and functions.
Caveats:
a) The mixed mode will not work for stored functions: in mixed mode, a stored function will
always be binlogged as one call and in a statement-based way (e.g. INSERT VALUES(myfunc()) or SELECT myfunc()).
b) for the same reason, changing the thread's binlog format inside a stored function is
refused with an error message.
c) the same problems apply to triggers; implementing b) for triggers will be done later (will ask
Dmitri).
Additionally, as the binlog format is now changeable by each user for his session, I remove the implication
which was done at startup, where row-based automatically set log-bin-trust-routine-creators to 1
(not possible anymore as a user can now switch to stmt-based and do nasty things again), and automatically
set --innodb-locks-unsafe-for-binlog to 1 (was anyway theoretically incorrect as it disabled
phantom protection).
Plus fixes for compiler warnings.
2006-02-25 22:21:03 +01:00
|
|
|
HTON_CAN_RECREATE,
|
|
|
|
NULL, /* binlog_func */
|
2006-03-29 13:27:36 +02:00
|
|
|
NULL, /* binlog_log_query */
|
|
|
|
NULL /* release_temporary_latches */
|
2005-07-19 20:21:12 +02:00
|
|
|
};
|
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
static handler *myisammrg_create_handler(TABLE_SHARE *table)
|
2005-11-07 16:25:06 +01:00
|
|
|
{
|
|
|
|
return new ha_myisammrg(table);
|
|
|
|
}
|
|
|
|
|
2005-07-19 20:21:12 +02:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
ha_myisammrg::ha_myisammrg(TABLE_SHARE *table_arg)
|
2005-07-19 20:21:12 +02:00
|
|
|
:handler(&myisammrg_hton, table_arg), file(0)
|
|
|
|
{}
|
|
|
|
|
2005-04-27 11:25:08 +02:00
|
|
|
static const char *ha_myisammrg_exts[] = {
|
|
|
|
".MRG",
|
|
|
|
NullS
|
|
|
|
};
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
const char **ha_myisammrg::bas_ext() const
|
2005-04-27 11:25:08 +02:00
|
|
|
{
|
|
|
|
return ha_myisammrg_exts;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-11-23 22:57:04 +01:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2000-09-25 23:33:25 +02:00
|
|
|
int ha_myisammrg::open(const char *name, int mode, uint test_if_locked)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
char name_buff[FN_REFLEN];
|
2003-11-18 12:47:27 +01:00
|
|
|
|
2001-12-02 13:34:01 +01:00
|
|
|
DBUG_PRINT("info", ("ha_myisammrg::open"));
|
2005-12-31 06:01:26 +01:00
|
|
|
if (!(file=myrg_open(fn_format(name_buff,name,"","",
|
|
|
|
MY_UNPACK_FILENAME|MY_APPEND_EXT),
|
|
|
|
mode, test_if_locked)))
|
2001-12-02 13:34:01 +01:00
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("ha_myisammrg::open exit %d", my_errno));
|
2002-11-11 22:43:07 +01:00
|
|
|
return (my_errno ? my_errno : -1);
|
2001-12-02 13:34:01 +01:00
|
|
|
}
|
2006-02-14 22:36:11 +01:00
|
|
|
DBUG_PRINT("info", ("ha_myisammrg::open myrg_extrafunc..."));
|
2002-03-22 21:55:08 +01:00
|
|
|
myrg_extrafunc(file, query_cache_invalidate_by_MyISAM_filename_ref);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!(test_if_locked == HA_OPEN_WAIT_IF_LOCKED ||
|
|
|
|
test_if_locked == HA_OPEN_ABORT_IF_LOCKED))
|
2002-07-23 17:31:22 +02:00
|
|
|
myrg_extra(file,HA_EXTRA_NO_WAIT_LOCK,0);
|
2000-07-31 21:29:14 +02:00
|
|
|
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
|
|
|
|
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED))
|
2002-07-23 17:31:22 +02:00
|
|
|
myrg_extra(file,HA_EXTRA_WAIT_LOCK,0);
|
2002-09-30 13:54:16 +02:00
|
|
|
|
2005-01-06 12:00:13 +01:00
|
|
|
if (table->s->reclength != mean_rec_length && mean_rec_length)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
DBUG_PRINT("error",("reclength: %d mean_rec_length: %d",
|
2005-01-06 12:00:13 +01:00
|
|
|
table->s->reclength, mean_rec_length));
|
2002-09-30 13:54:16 +02:00
|
|
|
goto err;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-09-30 13:54:16 +02:00
|
|
|
#if !defined(BIG_TABLES) || SIZEOF_OFF_T == 4
|
|
|
|
/* Merge table has more than 2G rows */
|
2005-01-06 12:00:13 +01:00
|
|
|
if (table->s->crashed)
|
2002-09-30 13:54:16 +02:00
|
|
|
goto err;
|
|
|
|
#endif
|
2002-11-11 22:43:07 +01:00
|
|
|
return (0);
|
2002-09-30 13:54:16 +02:00
|
|
|
err:
|
|
|
|
myrg_close(file);
|
|
|
|
file=0;
|
2003-01-28 17:42:08 +01:00
|
|
|
return (my_errno= HA_ERR_WRONG_MRG_TABLE_DEF);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::close(void)
|
|
|
|
{
|
2002-11-11 22:43:07 +01:00
|
|
|
return myrg_close(file);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::write_row(byte * buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
|
2004-10-01 16:54:06 +02:00
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
|
|
|
|
table->timestamp_field->set_time();
|
2001-09-22 16:40:57 +02:00
|
|
|
if (table->next_number_field && buf == table->record[0])
|
2002-07-21 23:55:32 +02:00
|
|
|
update_auto_increment();
|
2002-11-11 22:43:07 +01:00
|
|
|
return myrg_write(file,buf);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::update_row(const byte * old_data, byte * new_data)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
|
2004-10-01 16:54:06 +02:00
|
|
|
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
|
|
|
|
table->timestamp_field->set_time();
|
2002-11-11 22:43:07 +01:00
|
|
|
return myrg_update(file,old_data,new_data);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::delete_row(const byte * buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
|
2002-11-11 22:43:07 +01:00
|
|
|
return myrg_delete(file,buf);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::index_read(byte * buf, const byte * key,
|
|
|
|
uint key_len, enum ha_rkey_function find_flag)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_key_count,
|
|
|
|
&LOCK_status);
|
2000-08-14 13:27:19 +02:00
|
|
|
int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key,
|
|
|
|
uint key_len, enum ha_rkey_function find_flag)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_key_count,
|
|
|
|
&LOCK_status);
|
2000-08-14 13:27:19 +02:00
|
|
|
int error=myrg_rkey(file,buf,index, key, key_len, find_flag);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-01-12 14:42:54 +01:00
|
|
|
int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_key_count,
|
|
|
|
&LOCK_status);
|
2002-01-12 14:42:54 +01:00
|
|
|
int error=myrg_rkey(file,buf,active_index, key, key_len,
|
|
|
|
HA_READ_PREFIX_LAST);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2002-01-12 14:42:54 +01:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_myisammrg::index_next(byte * buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_next_count,
|
|
|
|
&LOCK_status);
|
2000-08-14 13:27:19 +02:00
|
|
|
int error=myrg_rnext(file,buf,active_index);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::index_prev(byte * buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_prev_count,
|
|
|
|
&LOCK_status);
|
2000-08-14 13:27:19 +02:00
|
|
|
int error=myrg_rprev(file,buf, active_index);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2000-08-14 13:27:19 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_myisammrg::index_first(byte * buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_first_count,
|
2004-09-13 15:48:01 +02:00
|
|
|
&LOCK_status);
|
2000-08-14 13:27:19 +02:00
|
|
|
int error=myrg_rfirst(file, buf, active_index);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::index_last(byte * buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_last_count,
|
|
|
|
&LOCK_status);
|
2000-08-14 13:27:19 +02:00
|
|
|
int error=myrg_rlast(file, buf, active_index);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-11-25 22:18:44 +01:00
|
|
|
int ha_myisammrg::index_next_same(byte * buf,
|
|
|
|
const byte *key __attribute__((unused)),
|
|
|
|
uint length __attribute__((unused)))
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_next_count,
|
|
|
|
&LOCK_status);
|
2002-11-25 22:18:44 +01:00
|
|
|
int error=myrg_rnext_same(file,buf);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_myisammrg::rnd_init(bool scan)
|
|
|
|
{
|
2002-11-11 22:43:07 +01:00
|
|
|
return myrg_extra(file,HA_EXTRA_RESET,0);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::rnd_next(byte *buf)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
|
2004-09-13 15:48:01 +02:00
|
|
|
&LOCK_status);
|
2000-07-31 21:29:14 +02:00
|
|
|
int error=myrg_rrnd(file, buf, HA_OFFSET_ERROR);
|
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ha_myisammrg::rnd_pos(byte * buf, byte *pos)
|
|
|
|
{
|
2004-11-12 18:04:35 +01:00
|
|
|
statistic_increment(table->in_use->status_var.ha_read_rnd_count,
|
|
|
|
&LOCK_status);
|
2004-11-07 22:39:27 +01:00
|
|
|
int error=myrg_rrnd(file, buf, my_get_ptr(pos,ref_length));
|
2000-07-31 21:29:14 +02:00
|
|
|
table->status=error ? STATUS_NOT_FOUND: 0;
|
2002-11-11 22:43:07 +01:00
|
|
|
return error;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ha_myisammrg::position(const byte *record)
|
|
|
|
{
|
|
|
|
ulonglong position= myrg_position(file);
|
2004-11-07 22:39:27 +01:00
|
|
|
my_store_ptr(ref, ref_length, (my_off_t) position);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2004-05-16 13:48:32 +02:00
|
|
|
|
|
|
|
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);
|
2002-11-17 18:54:23 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2004-05-16 13:48:32 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
void ha_myisammrg::info(uint flag)
|
|
|
|
{
|
|
|
|
MYMERGE_INFO info;
|
|
|
|
(void) myrg_status(file,&info,flag);
|
2002-09-30 13:54:16 +02:00
|
|
|
/*
|
|
|
|
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))
|
2005-01-06 12:00:13 +01:00
|
|
|
table->s->crashed= 1;
|
2002-09-30 13:54:16 +02:00
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
data_file_length=info.data_file_length;
|
|
|
|
errkey = info.errkey;
|
2005-01-06 12:00:13 +01:00
|
|
|
table->s->keys_in_use.set_prefix(table->s->keys);
|
|
|
|
table->s->db_options_in_use= info.options;
|
|
|
|
mean_rec_length= info.reclength;
|
2006-02-11 19:51:43 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
The handler::block_size is used all over the code in index scan cost
|
|
|
|
calculations. It is used to get number of disk seeks required to
|
|
|
|
retrieve a number of index tuples.
|
|
|
|
If the merge table has N underlying tables, then (assuming underlying
|
|
|
|
tables have equal size, the only "simple" approach we can use)
|
|
|
|
retrieving X index records from a merge table will require N times more
|
|
|
|
disk seeks compared to doing the same on a MyISAM table with equal
|
|
|
|
number of records.
|
|
|
|
In the edge case (file_tables > myisam_block_size) we'll get
|
|
|
|
block_size==0, and index calculation code will act as if we need one
|
|
|
|
disk seek to retrieve one index tuple.
|
|
|
|
|
|
|
|
TODO: In 5.2 index scan cost calculation will be factored out into a
|
|
|
|
virtual function in class handler and we'll be able to remove this hack.
|
|
|
|
*/
|
|
|
|
block_size= 0;
|
|
|
|
if (file->tables)
|
|
|
|
block_size= myisam_block_size / file->tables;
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
update_time=0;
|
2001-11-03 14:18:09 +01:00
|
|
|
#if SIZEOF_OFF_T > 4
|
2000-07-31 21:29:14 +02:00
|
|
|
ref_length=6; // Should be big enough
|
2001-11-03 14:18:09 +01:00
|
|
|
#else
|
|
|
|
ref_length=4; // Can't be > than my_off_t
|
|
|
|
#endif
|
2002-12-10 00:06:05 +01:00
|
|
|
if (flag & HA_STATUS_CONST)
|
|
|
|
{
|
2005-01-06 12:00:13 +01:00
|
|
|
if (table->s->key_parts && info.rec_per_key)
|
2002-12-10 00:06:05 +01:00
|
|
|
memcpy((char*) table->key_info[0].rec_per_key,
|
|
|
|
(char*) info.rec_per_key,
|
2005-01-06 12:00:13 +01:00
|
|
|
sizeof(table->key_info[0].rec_per_key)*table->s->key_parts);
|
2002-12-10 00:06:05 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ha_myisammrg::extra(enum ha_extra_function operation)
|
|
|
|
{
|
2001-09-27 20:45:48 +02:00
|
|
|
/* 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)
|
2002-11-11 22:43:07 +01:00
|
|
|
return 0;
|
|
|
|
return myrg_extra(file,operation,0);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2002-12-12 20:01:32 +01:00
|
|
|
if ((specialflag & SPECIAL_SAFE_MODE) && operation == HA_EXTRA_WRITE_CACHE)
|
2002-11-11 22:43:07 +01:00
|
|
|
return 0;
|
|
|
|
return myrg_extra(file, operation, (void*) &cache_size);
|
2002-07-23 17:31:22 +02:00
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_myisammrg::external_lock(THD *thd, int lock_type)
|
|
|
|
{
|
2002-11-11 22:43:07 +01:00
|
|
|
return myrg_lock_database(file,lock_type);
|
2000-08-14 13:27:19 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
uint ha_myisammrg::lock_count(void) const
|
|
|
|
{
|
2002-11-11 22:43:07 +01:00
|
|
|
return file->tables;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
THR_LOCK_DATA **ha_myisammrg::store_lock(THD *thd,
|
|
|
|
THR_LOCK_DATA **to,
|
|
|
|
enum thr_lock_type lock_type)
|
|
|
|
{
|
2002-11-07 02:54:00 +01:00
|
|
|
MYRG_TABLE *open_table;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2002-11-07 02:54:00 +01:00
|
|
|
for (open_table=file->open_tables ;
|
|
|
|
open_table != file->end_table ;
|
|
|
|
open_table++)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2002-11-07 02:54:00 +01:00
|
|
|
*(to++)= &open_table->table->lock;
|
|
|
|
if (lock_type != TL_IGNORE && open_table->table->lock.type == TL_UNLOCK)
|
|
|
|
open_table->table->lock.type=lock_type;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2002-11-11 22:43:07 +01:00
|
|
|
return to;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-06-27 15:29:10 +02:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2003-11-20 21:06:25 +01:00
|
|
|
uint dir_length, prefix_length;
|
2003-06-27 15:29:10 +02:00
|
|
|
char buff[FN_REFLEN];
|
|
|
|
|
|
|
|
db->length= 0;
|
2003-11-20 21:06:25 +01:00
|
|
|
strmake(buff, file_name, sizeof(buff)-1);
|
2003-06-27 15:29:10 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-06 14:24:08 +01:00
|
|
|
void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
|
|
|
|
{
|
2002-11-11 22:43:07 +01:00
|
|
|
DBUG_ENTER("ha_myisammrg::update_create_info");
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2001-03-06 14:24:08 +01:00
|
|
|
if (!(create_info->used_fields & HA_CREATE_USED_UNION))
|
|
|
|
{
|
2002-11-07 02:54:00 +01:00
|
|
|
MYRG_TABLE *open_table;
|
2001-03-06 14:24:08 +01:00
|
|
|
THD *thd=current_thd;
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2001-03-06 14:24:08 +01:00
|
|
|
create_info->merge_list.next= &create_info->merge_list.first;
|
2001-08-10 16:05:54 +02:00
|
|
|
create_info->merge_list.elements=0;
|
2001-03-06 14:24:08 +01:00
|
|
|
|
2002-11-07 02:54:00 +01:00
|
|
|
for (open_table=file->open_tables ;
|
|
|
|
open_table != file->end_table ;
|
|
|
|
open_table++)
|
2001-03-06 14:24:08 +01:00
|
|
|
{
|
|
|
|
TABLE_LIST *ptr;
|
2003-06-27 15:29:10 +02:00
|
|
|
LEX_STRING db, name;
|
|
|
|
|
2001-03-06 14:24:08 +01:00
|
|
|
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
|
|
|
|
goto err;
|
2003-06-27 15:29:10 +02:00
|
|
|
split_file_name(open_table->table->filename, &db, &name);
|
2005-01-06 12:00:13 +01:00
|
|
|
if (!(ptr->table_name= thd->strmake(name.str, name.length)))
|
2003-06-27 15:29:10 +02:00
|
|
|
goto err;
|
|
|
|
if (db.length && !(ptr->db= thd->strmake(db.str, db.length)))
|
2001-03-06 14:24:08 +01:00
|
|
|
goto err;
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2001-08-10 16:05:54 +02:00
|
|
|
create_info->merge_list.elements++;
|
2001-03-06 14:24:08 +01:00
|
|
|
(*create_info->merge_list.next) = (byte*) ptr;
|
2004-07-16 00:15:55 +02:00
|
|
|
create_info->merge_list.next= (byte**) &ptr->next_local;
|
2001-03-06 14:24:08 +01:00
|
|
|
}
|
|
|
|
*create_info->merge_list.next=0;
|
|
|
|
}
|
2001-09-22 16:40:57 +02:00
|
|
|
if (!(create_info->used_fields & HA_CREATE_USED_INSERT_METHOD))
|
|
|
|
{
|
|
|
|
create_info->merge_insert_method = file->merge_insert_method;
|
|
|
|
}
|
2001-03-06 14:24:08 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
|
|
|
|
err:
|
|
|
|
create_info->merge_list.elements=0;
|
|
|
|
create_info->merge_list.first=0;
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
int ha_myisammrg::create(const char *name, register TABLE *form,
|
|
|
|
HA_CREATE_INFO *create_info)
|
|
|
|
{
|
2005-01-06 12:00:13 +01:00
|
|
|
char buff[FN_REFLEN];
|
|
|
|
const char **table_names, **pos;
|
2000-09-14 01:39:07 +02:00
|
|
|
TABLE_LIST *tables= (TABLE_LIST*) create_info->merge_list.first;
|
2003-06-27 15:29:10 +02:00
|
|
|
THD *thd= current_thd;
|
2005-04-28 18:28:50 +02:00
|
|
|
uint dirlgt= dirname_length(name);
|
2000-09-14 01:39:07 +02:00
|
|
|
DBUG_ENTER("ha_myisammrg::create");
|
|
|
|
|
2005-01-06 12:00:13 +01:00
|
|
|
if (!(table_names= (const char**)
|
|
|
|
thd->alloc((create_info->merge_list.elements+1) * sizeof(char*))))
|
2003-12-30 12:14:21 +01:00
|
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
2004-07-16 00:15:55 +02:00
|
|
|
for (pos= table_names; tables; tables= tables->next_local)
|
2002-11-05 00:00:51 +01:00
|
|
|
{
|
2005-01-06 12:00:13 +01:00
|
|
|
const char *table_name;
|
2005-11-23 21:45:02 +01:00
|
|
|
TABLE *tbl= 0;
|
2002-11-05 00:00:51 +01:00
|
|
|
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
|
2005-11-23 21:45:02 +01:00
|
|
|
tbl= find_temporary_table(thd, tables);
|
2003-06-27 15:29:10 +02:00
|
|
|
if (!tbl)
|
2002-11-05 00:00:51 +01:00
|
|
|
{
|
2005-04-28 18:28:50 +02:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2005-12-31 06:01:26 +01:00
|
|
|
uint length= build_table_filename(buff, sizeof(buff),
|
|
|
|
tables->db, tables->table_name, "");
|
2005-04-28 18:28:50 +02:00
|
|
|
/*
|
|
|
|
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))
|
2005-04-29 10:59:34 +02:00
|
|
|
table_name= tables->table_name;
|
2005-04-28 18:28:50 +02:00
|
|
|
else
|
|
|
|
if (! (table_name= thd->strmake(buff, length)))
|
|
|
|
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
|
2002-11-05 00:00:51 +01:00
|
|
|
}
|
|
|
|
else
|
2005-11-23 21:45:02 +01:00
|
|
|
table_name= tbl->s->path.str;
|
2002-11-05 00:00:51 +01:00
|
|
|
*pos++= table_name;
|
|
|
|
}
|
2000-09-14 01:39:07 +02:00
|
|
|
*pos=0;
|
2005-12-31 06:01:26 +01:00
|
|
|
DBUG_RETURN(myrg_create(fn_format(buff,name,"","",
|
|
|
|
MY_RESOLVE_SYMLINKS|
|
|
|
|
MY_UNPACK_FILENAME|MY_APPEND_EXT),
|
2005-01-06 12:00:13 +01:00
|
|
|
table_names,
|
2001-09-22 16:40:57 +02:00
|
|
|
create_info->merge_insert_method,
|
|
|
|
(my_bool) 0));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2001-02-17 18:04:33 +01:00
|
|
|
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2001-02-17 18:04:33 +01:00
|
|
|
void ha_myisammrg::append_create_info(String *packet)
|
|
|
|
{
|
2003-06-27 15:29:10 +02:00
|
|
|
const char *current_db;
|
|
|
|
uint db_length;
|
|
|
|
THD *thd= current_thd;
|
2005-11-23 21:45:02 +01:00
|
|
|
MYRG_TABLE *open_table, *first;
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2001-09-22 16:40:57 +02:00
|
|
|
if (file->merge_insert_method != MERGE_INSERT_DISABLED)
|
|
|
|
{
|
2005-11-20 19:47:07 +01:00
|
|
|
packet->append(STRING_WITH_LEN(" INSERT_METHOD="));
|
2001-09-27 20:45:48 +02:00
|
|
|
packet->append(get_type(&merge_insert_method,file->merge_insert_method-1));
|
2001-09-22 16:40:57 +02:00
|
|
|
}
|
2005-11-20 19:47:07 +01:00
|
|
|
packet->append(STRING_WITH_LEN(" UNION=("));
|
2001-02-17 18:04:33 +01:00
|
|
|
|
2005-11-23 21:45:02 +01:00
|
|
|
current_db= table->s->db.str;
|
|
|
|
db_length= table->s->db.length;
|
2003-06-27 15:29:10 +02:00
|
|
|
|
2002-11-07 02:54:00 +01:00
|
|
|
for (first=open_table=file->open_tables ;
|
|
|
|
open_table != file->end_table ;
|
|
|
|
open_table++)
|
2001-02-17 18:04:33 +01:00
|
|
|
{
|
2003-06-27 15:29:10 +02:00
|
|
|
LEX_STRING db, name;
|
|
|
|
split_file_name(open_table->table->filename, &db, &name);
|
2002-11-07 02:54:00 +01:00
|
|
|
if (open_table != first)
|
2001-02-17 18:04:33 +01:00
|
|
|
packet->append(',');
|
2003-06-27 15:29:10 +02:00
|
|
|
/* 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);
|
2001-02-17 18:04:33 +01:00
|
|
|
}
|
|
|
|
packet->append(')');
|
|
|
|
}
|
2005-07-22 22:43:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|