summaryrefslogtreecommitdiff
path: root/sql/ha_myisammrg.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/ha_myisammrg.cc')
-rw-r--r--sql/ha_myisammrg.cc135
1 files changed, 88 insertions, 47 deletions
diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc
index f65c9afc786..9aa6d039efb 100644
--- a/sql/ha_myisammrg.cc
+++ b/sql/ha_myisammrg.cc
@@ -35,9 +35,11 @@
const char **ha_myisammrg::bas_ext() const
{ static const char *ext[]= { ".MRG", NullS }; return ext; }
+
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,"","",2 | 4), mode,
test_if_locked)))
@@ -80,8 +82,8 @@ int ha_myisammrg::close(void)
int ha_myisammrg::write_row(byte * buf)
{
statistic_increment(ha_write_count,&LOCK_status);
- if (table->time_stamp)
- update_timestamp(buf+table->time_stamp-1);
+ if (table->timestamp_default_now)
+ update_timestamp(buf+table->timestamp_default_now-1);
if (table->next_number_field && buf == table->record[0])
update_auto_increment();
return myrg_write(file,buf);
@@ -90,8 +92,8 @@ int ha_myisammrg::write_row(byte * buf)
int ha_myisammrg::update_row(const byte * old_data, byte * new_data)
{
statistic_increment(ha_update_count,&LOCK_status);
- if (table->time_stamp)
- update_timestamp(new_data+table->time_stamp-1);
+ if (table->timestamp_on_update_now)
+ update_timestamp(new_data+table->timestamp_on_update_now);
return myrg_update(file,old_data,new_data);
}
@@ -160,6 +162,16 @@ int ha_myisammrg::index_last(byte * buf)
return error;
}
+int ha_myisammrg::index_next_same(byte * buf,
+ const byte *key __attribute__((unused)),
+ uint length __attribute__((unused)))
+{
+ statistic_increment(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);
@@ -187,20 +199,14 @@ void ha_myisammrg::position(const byte *record)
ha_store_ptr(ref, ref_length, (my_off_t) position);
}
-ha_rows ha_myisammrg::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)
+
+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,
- inx,
- start_key,start_key_len,
- start_search_flag,
- end_key,end_key_len,
- end_search_flag);
+ return (ha_rows) myrg_records_in_range(file, (int) inx, min_key, max_key);
}
+
void ha_myisammrg::info(uint flag)
{
MYMERGE_INFO info;
@@ -218,7 +224,7 @@ void ha_myisammrg::info(uint flag)
#endif
data_file_length=info.data_file_length;
errkey = info.errkey;
- table->keys_in_use= set_bits(key_map, table->keys);
+ table->keys_in_use.set_prefix(table->keys);
table->db_options_in_use = info.options;
table->is_view=1;
mean_rec_length=info.reclength;
@@ -259,12 +265,6 @@ int ha_myisammrg::extra_opt(enum ha_extra_function operation, ulong cache_size)
return myrg_extra(file, operation, (void*) &cache_size);
}
-
-int ha_myisammrg::reset(void)
-{
- return myrg_extra(file,HA_EXTRA_RESET,0);
-}
-
int ha_myisammrg::external_lock(THD *thd, int lock_type)
{
return myrg_lock_database(file,lock_type);
@@ -293,14 +293,40 @@ THR_LOCK_DATA **ha_myisammrg::store_lock(THD *thd,
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)
{
- // [phi] auto_increment stuff is missing (but currently not needed)
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;
@@ -308,14 +334,17 @@ void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
open_table != file->end_table ;
open_table++)
{
- char *name=open_table->table->filename;
- char buff[FN_REFLEN];
TABLE_LIST *ptr;
+ LEX_STRING db, name;
+
if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
goto err;
- fn_format(buff,name,"","",3);
- if (!(ptr->real_name=thd->strdup(buff)))
+ split_file_name(open_table->table->filename, &db, &name);
+ if (!(ptr->real_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;
@@ -334,37 +363,34 @@ err:
DBUG_VOID_RETURN;
}
+
int ha_myisammrg::create(const char *name, register TABLE *form,
HA_CREATE_INFO *create_info)
{
char buff[FN_REFLEN],**table_names,**pos;
TABLE_LIST *tables= (TABLE_LIST*) create_info->merge_list.first;
+ THD *thd= current_thd;
DBUG_ENTER("ha_myisammrg::create");
- if (!(table_names= (char**) sql_alloc((create_info->merge_list.elements+1)*
- sizeof(char*))))
+ if (!(table_names= (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)
{
char *table_name;
+ TABLE **tbl= 0;
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
+ tbl= find_temporary_table(thd, tables->db, tables->real_name);
+ if (!tbl)
{
- TABLE **tbl=find_temporary_table(current_thd,
- tables->db, tables->real_name);
- if (!tbl)
- {
- table_name=sql_alloc(1+
- my_snprintf(buff,FN_REFLEN,"%s/%s/%s",mysql_real_data_home,
- tables->db, tables->real_name));
- if (!table_name)
- DBUG_RETURN(HA_ERR_OUT_OF_MEM);
- strcpy(table_name, buff);
- }
- else
- table_name=(*tbl)->path;
+ uint length= my_snprintf(buff,FN_REFLEN,"%s%s/%s",
+ mysql_real_data_home,
+ tables->db, tables->real_name);
+ if (!(table_name= thd->strmake(buff, length)))
+ DBUG_RETURN(HA_ERR_OUT_OF_MEM);
}
else
- table_name=tables->real_name;
+ table_name=(*tbl)->path;
*pos++= table_name;
}
*pos=0;
@@ -374,9 +400,13 @@ int ha_myisammrg::create(const char *name, register TABLE *form,
(my_bool) 0));
}
+
void ha_myisammrg::append_create_info(String *packet)
{
- char buff[FN_REFLEN];
+ const char *current_db;
+ uint db_length;
+ THD *thd= current_thd;
+
if (file->merge_insert_method != MERGE_INSERT_DISABLED)
{
packet->append(" INSERT_METHOD=",15);
@@ -385,15 +415,26 @@ void ha_myisammrg::append_create_info(String *packet)
packet->append(" UNION=(",8);
MYRG_TABLE *open_table,*first;
+ current_db= table->table_cache_key;
+ db_length= strlen(current_db);
+
for (first=open_table=file->open_tables ;
open_table != file->end_table ;
open_table++)
{
- char *name= open_table->table->filename;
- fn_format(buff,name,"","",3);
+ LEX_STRING db, name;
+ split_file_name(open_table->table->filename, &db, &name);
if (open_table != first)
packet->append(',');
- packet->append(buff,(uint) strlen(buff));
+ /* 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(')');
}