Commit 10e15762 authored by unknown's avatar unknown

Don't enable HA_EXTRA_WRITE_CACHE if too few rows

Revert main parts of patch for online index builds. Should be done differently
Added support for %lx in my_snprintf()


sql/ha_myisam.cc:
  Don't enable HA_EXTRA_WRITE_CACHE if too few rows
sql/handler.h:
  Indentaion fix
sql/mysql_priv.h:
  Removed real_alter_table, mysql_add_column and mysql_drop_column
sql/sql_class.cc:
  After merge fix
sql/sql_insert.cc:
  Don't user bulk_insert if only one row (common case)
sql/sql_parse.cc:
  Added mysql_create_index() and mysql_drop_index() as these are only wrappers for mysql_alter_table()
sql/sql_table.cc:
  Revert main parts of patch for online index builds
  Changed back to use tabs to make merges possible between trees
sql/unireg.cc:
  Added comments and minor cleanup
strings/my_vsnprintf.c:
  Added support for %lx.
  Proper long support
parent 46bd7be2
......@@ -867,7 +867,9 @@ void ha_myisam::start_bulk_insert(ha_rows rows)
THD *thd=current_thd;
ulong size= min(thd->variables.read_buff_size, table->avg_row_length*rows);
mi_extra(file, HA_EXTRA_WRITE_CACHE, (void*)&size);
/* don't enable row cache if too few rows */
if (!rows && rows > 10)
mi_extra(file, HA_EXTRA_WRITE_CACHE, (void*) &size);
can_enable_indexes= (file->s->state.key_map ==
set_bits(ulonglong, file->s->base.keys));
......
......@@ -509,19 +509,7 @@ int mysql_alter_table(THD *thd, char *new_db, char *new_name,
List<create_field> &fields,
List<Key> &keys,List<Alter_drop> &drop_list,
List<Alter_column> &alter_list,
uint order_num, ORDER *order, int alter_flags,
enum enum_duplicates handle_duplicates,
enum enum_enable_or_disable keys_onoff=LEAVE_AS_IS,
enum tablespace_op_type tablespace_op=NO_TABLESPACE_OP,
bool simple_alter=0);
int real_alter_table(THD *thd, char *new_db, char *new_name,
HA_CREATE_INFO *create_info,
TABLE_LIST *table_list,
TABLE *table,
List<create_field> &fields,
List<Key> &keys,List<Alter_drop> &drop_list,
List<Alter_column> &alter_list,
uint order_num, ORDER *order, int alter_flags,
uint order_num, ORDER *order, uint alter_flags,
enum enum_duplicates handle_duplicates,
enum enum_enable_or_disable keys_onoff=LEAVE_AS_IS,
enum tablespace_op_type tablespace_op=NO_TABLESPACE_OP,
......@@ -537,10 +525,6 @@ bool mysql_rename_table(enum db_type base,
int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys);
int mysql_drop_index(THD *thd, TABLE_LIST *table_list,
List<Alter_drop> &drop_list);
int mysql_add_column(THD *thd, TABLE_LIST *table_list,
List<create_field> &fields);
int mysql_drop_column(THD *thd, TABLE_LIST *table_list,
List<Alter_drop> &drop_list);
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
List<Item> &values,COND *conds,
uint order_num, ORDER *order, ha_rows limit,
......@@ -944,7 +928,8 @@ void unlock_table_names(THD *thd, TABLE_LIST *table_list,
void unireg_init(ulong options);
void unireg_end(void);
int mysql_create_frm(THD *thd, my_string file_name,HA_CREATE_INFO *create_info,
bool mysql_create_frm(THD *thd, my_string file_name,
HA_CREATE_INFO *create_info,
List<create_field> &create_field,
uint key_count,KEY *key_info,handler *db_type);
int rea_create_table(THD *thd, my_string file_name,HA_CREATE_INFO *create_info,
......
......@@ -86,8 +86,7 @@ extern "C" void free_user_var(user_var_entry *entry)
THD::THD():user_time(0), current_statement(0), is_fatal_error(0),
last_insert_id_used(0),
insert_id_used(0), rand_used(0), in_lock_tables(0),
global_read_lock(0), bootstrap(0),
no_table_fix_fields_cache(0)
global_read_lock(0), bootstrap(0)
{
host= user= priv_user= db= ip=0;
host_or_ip= "connecting host";
......
......@@ -260,7 +260,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
thd->proc_info="update";
if (duplic != DUP_ERROR)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
if (lock_type != TL_WRITE_DELAYED)
if (lock_type != TL_WRITE_DELAYED && values_list.elements != 1);
table->file->start_bulk_insert(values_list.elements);
while ((values= its++))
......
......@@ -4993,3 +4993,49 @@ Item * all_any_subquery_creator(Item *left_expr,
return it; /* ANY/SOME */
}
/*
CREATE INDEX and DROP INDEX are implemented by calling ALTER TABLE with
the proper arguments. This isn't very fast but it should work for most
cases.
In the future ALTER TABLE will notice that only added indexes
and create these one by one for the existing table without having to do
a full rebuild.
One should normally create all indexes with CREATE TABLE or ALTER TABLE.
*/
int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
{
List<create_field> fields;
List<Alter_drop> drop;
List<Alter_column> alter;
HA_CREATE_INFO create_info;
DBUG_ENTER("mysql_create_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.default_table_charset= thd->variables.collation_database;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, 0, (ORDER*)0,
ALTER_ADD_INDEX, DUP_ERROR));
}
int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop)
{
List<create_field> fields;
List<Key> keys;
List<Alter_column> alter;
HA_CREATE_INFO create_info;
DBUG_ENTER("mysql_drop_index");
bzero((char*) &create_info,sizeof(create_info));
create_info.db_type=DB_TYPE_DEFAULT;
create_info.default_table_charset= thd->variables.collation_database;
DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
&create_info, table_list,
fields, keys, drop, alter, 0, (ORDER*)0,
ALTER_DROP_INDEX, DUP_ERROR));
}
This diff is collapsed.
......@@ -46,8 +46,25 @@ static bool make_empty_rec(int file, enum db_type table_type,
List<create_field> &create_fields,
uint reclength,uint null_fields);
/*
Create a frm (table definition) file
SYNOPSIS
mysql_create_frm()
thd Thread handler
file_name Name of file (including database and .frm)
create_info create info parameters
create_fields Fields to create
keys number of keys to create
key_info Keys to create
db_file Handler to use. May be zero, in which case we use
create_info->db_type
RETURN
0 ok
1 error
*/
int mysql_create_frm(THD *thd, my_string file_name,
bool mysql_create_frm(THD *thd, my_string file_name,
HA_CREATE_INFO *create_info,
List<create_field> &create_fields,
uint keys, KEY *key_info,
......@@ -166,9 +183,29 @@ err:
err2:
VOID(my_close(file,MYF(MY_WME)));
err3:
my_delete(file_name,MYF(0));
DBUG_RETURN(1);
} /* mysql_create_frm */
/*
Create a frm (table definition) file and the tables
SYNOPSIS
mysql_create_frm()
thd Thread handler
file_name Name of file (including database and .frm)
create_info create info parameters
create_fields Fields to create
keys number of keys to create
key_info Keys to create
db_file Handler to use. May be zero, in which case we use
create_info->db_type
RETURN
0 ok
1 error
*/
int rea_create_table(THD *thd, my_string file_name,
HA_CREATE_INFO *create_info,
List<create_field> &create_fields,
......@@ -179,12 +216,8 @@ int rea_create_table(THD *thd, my_string file_name,
if (mysql_create_frm(thd, file_name, create_info,
create_fields, keys, key_info, NULL) ||
ha_create_table(file_name,create_info,0))
goto err;
DBUG_RETURN(0);
err:
my_delete(file_name,MYF(0));
DBUG_RETURN(1);
DBUG_RETURN(0);
} /* rea_create_table */
......
......@@ -25,8 +25,9 @@
IMPLEMENTION:
Supports following formats:
%#d
%#u
%#[l]d
%#[l]u
%#[l]x
%#.#s Note #.# is skiped
RETURN
......@@ -47,7 +48,7 @@ int my_snprintf(char* to, size_t n, const char* fmt, ...)
int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
{
char *start=to, *end=to+n-1;
uint length, num_state, pre_zero;
uint length, num_state, pre_zero, have_long;
for (; *fmt ; fmt++)
{
......@@ -62,7 +63,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
/* Read max fill size (only used with %d and %u) */
if (*fmt == '-')
fmt++;
length= num_state= pre_zero= 0;
length= num_state= pre_zero= have_long= 0;
for (;; fmt++)
{
if (my_isdigit(&my_charset_latin1,*fmt))
......@@ -80,7 +81,10 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
num_state= 1;
}
if (*fmt == 'l')
{
fmt++;
have_long= 1;
}
if (*fmt == 's') /* String parameter */
{
reg2 char *par = va_arg(ap, char *);
......@@ -92,20 +96,29 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
to=strnmov(to,par,plen);
continue;
}
else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */
else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x') /* Integer parameter */
{
register int iarg;
register long larg;
uint res_length, to_length;
char *store_start= to, *store_end;
char buff[16];
char buff[32];
if ((to_length= (uint) (end-to)) < 16 || length)
store_start= buff;
iarg = va_arg(ap, int);
if (have_long)
larg = va_arg(ap, long);
else
if (*fmt == 'd')
store_end= int10_to_str((long) iarg, store_start, -10);
larg = va_arg(ap, int);
else
larg= (long) (uint) va_arg(ap, int);
if (*fmt == 'd')
store_end= int10_to_str(larg, store_start, -10);
else
if (*fmt== 'u')
store_end= int10_to_str(larg, store_start, 10);
else
store_end= int10_to_str((long) (uint) iarg, store_start, 10);
store_end= int2str(larg, store_start, 16);
if ((res_length= (uint) (store_end - store_start)) > to_length)
break; /* num doesn't fit in output */
/* If %#d syntax was used, we have to pre-zero/pre-space the string */
......@@ -146,7 +159,7 @@ static void my_printf(const char * fmt, ...)
n = my_vsnprintf(buf, sizeof(buf)-1,fmt, ar);
printf(buf);
printf("n=%d, strlen=%d\n", n, strlen(buf));
if (buf[sizeof(buf)-1] != OVERRUN_SENTRY)
if ((uchar) buf[sizeof(buf)-1] != OVERRUN_SENTRY)
{
fprintf(stderr, "Buffer overrun\n");
abort();
......@@ -167,6 +180,7 @@ int main()
my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack");
my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1);
my_printf("Hello %u\n", 1);
my_printf("Hex: %lx '%6lx'\n", 32, 65);
my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\
`%-.64s' (%-.64s)", 1, 0,0,0,0);
return 0;
......
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