1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Merge bk-internal.mysql.com:/home/bk/mysql-4.1

into mysql.com:/home/my/mysql-4.1
This commit is contained in:
monty@mysql.com
2004-08-26 18:27:33 +03:00
28 changed files with 254 additions and 164 deletions

View File

@ -1753,7 +1753,7 @@ void Field_medium::sql_type(String &res) const
int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
{
long tmp;
int error= 0, cuted_fields= 0;
int error= 0;
char *end;
tmp= cs->cset->scan(cs, from, from+len, MY_SEQ_SPACES);
@ -1781,7 +1781,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
#if SIZEOF_LONG > 4
if (unsigned_flag)
{
if (tmp > UINT_MAX32)
if ((ulong) tmp > UINT_MAX32)
{
tmp= UINT_MAX32;
error= 1;
@ -4277,27 +4277,17 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
int Field_str::store(double nr)
{
bool use_scientific_notation=TRUE;
char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
uint length;
if (field_length < 32 && nr > 1) // TODO: negative numbers
{
if (ceiling == 0)
{
static double e[]= {1e1, 1e2, 1e4, 1e8, 1e16 };
double p= 1;
for (int i= sizeof(e)/sizeof(e[0]), j= 1<<i ; j; i--, j>>= 1 )
{
if (field_length & j)
p*= e[i];
}
ceiling= p-1;
}
use_scientific_notation= (ceiling < nr);
}
length= (uint)sprintf(buff, "%-.*g",
use_scientific_notation ? max(0,(int)field_length-5) : field_length,
nr);
bool use_scientific_notation= TRUE;
use_scientific_notation= TRUE;
if (field_length < 32 && fabs(nr) < log_10[field_length]-1)
use_scientific_notation= FALSE;
length= (uint) my_sprintf(buff, (buff, "%-.*g",
(use_scientific_notation ?
max(0, (int)field_length-5) :
field_length),
nr));
/*
+1 below is because "precision" in %g above means the
max. number of significant digits, not the output width.
@ -4310,6 +4300,7 @@ int Field_str::store(double nr)
return store((const char *)buff, min(length, field_length), charset());
}
int Field_string::store(longlong nr)
{
char buff[64];
@ -4403,9 +4394,8 @@ char *Field_string::pack(char *to, const char *from, uint max_length)
char *Field_string::pack_key(char *to, const char *from, uint max_length)
{
int length=min(field_length,max_length);
uint char_length= (field_charset->mbmaxlen > 1) ?
max_length/field_charset->mbmaxlen : max_length;
uint length= min(field_length,max_length);
uint char_length= max_length/field_charset->mbmaxlen;
if (length > char_length)
char_length= my_charpos(field_charset, from, from+length, char_length);
set_if_smaller(length, char_length);

View File

@ -336,14 +336,13 @@ public:
class Field_str :public Field {
protected:
CHARSET_INFO *field_charset;
double ceiling; // for ::store(double nr)
public:
Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const char *field_name_arg,
struct st_table *table_arg,CHARSET_INFO *charset)
:Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
unireg_check_arg, field_name_arg, table_arg), ceiling(0.0)
unireg_check_arg, field_name_arg, table_arg)
{
field_charset=charset;
if (charset->state & MY_CS_BINSORT)

View File

@ -1732,8 +1732,8 @@ bool Item_func_in::nulls_in_row()
static int srtcmp_in(CHARSET_INFO *cs, const String *x,const String *y)
{
return cs->coll->strnncollsp(cs,
(unsigned char *) x->ptr(),x->length(),
(unsigned char *) y->ptr(),y->length());
(uchar *) x->ptr(),x->length(),
(uchar *) y->ptr(),y->length());
}

View File

@ -39,7 +39,8 @@ C_MODE_END
String my_empty_string("",default_charset_info);
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname)
static void my_coll_agg_error(DTCollation &c1, DTCollation &c2,
const char *fname)
{
my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
c1.collation->name,c1.derivation_name(),
@ -62,8 +63,9 @@ double Item_str_func::val()
{
DBUG_ASSERT(fixed == 1);
int err;
String *res;
res=val_str(&str_value);
char buff[64];
String *res, tmp(buff,sizeof(buff), &my_charset_bin);
res= val_str(&tmp);
return res ? my_strntod(res->charset(), (char*) res->ptr(),res->length(),
NULL, &err) : 0.0;
}
@ -72,8 +74,9 @@ longlong Item_str_func::val_int()
{
DBUG_ASSERT(fixed == 1);
int err;
String *res;
res=val_str(&str_value);
char buff[22];
String *res, tmp(buff,sizeof(buff), &my_charset_bin);
res= val_str(&tmp);
return (res ?
my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
&err) :
@ -986,10 +989,7 @@ String *Item_func_left::val_str(String *str)
if (res->length() <= (uint) length ||
res->length() <= (char_pos= res->charpos(length)))
return res;
if (&str_value == res)
str_value.length(char_pos);
else
str_value.set(*res, 0, char_pos);
str_value.set(*res, 0, char_pos);
return &str_value;
}
@ -2200,7 +2200,8 @@ String *Item_func_conv_charset::val_str(String *str)
null_value=1;
return 0;
}
null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(),conv_charset);
null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(),
conv_charset);
return null_value ? 0 : &str_value;
}

View File

@ -1945,13 +1945,12 @@ void Item_func_group_concat::reset_field()
bool
Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
{
uint i; /* for loop variable */
DBUG_ASSERT(fixed == 0);
if (save_args_for_prepared_statement(thd))
return 1;
uint i; /* for loop variable */
if (!thd->allow_sum_func)
{
my_error(ER_INVALID_GROUP_FUNC_USE,MYF(0));
@ -1971,7 +1970,7 @@ Item_func_group_concat::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if (args[i]->fix_fields(thd, tables, args + i) || args[i]->check_cols(1))
return 1;
if (i < arg_count_field)
maybe_null |= args[i]->maybe_null;
maybe_null|= args[i]->maybe_null;
}
result_field= 0;
@ -2048,7 +2047,8 @@ bool Item_func_group_concat::setup(THD *thd)
of a record instead of a pointer of one.
*/
if (!(table=create_tmp_table(thd, tmp_table_param, all_fields,
(ORDER*) 0, 0, TRUE,select_lex->options | thd->options,
(ORDER*) 0, 0, TRUE,
select_lex->options | thd->options,
HA_POS_ERROR,(char *) "")))
DBUG_RETURN(1);
table->file->extra(HA_EXTRA_NO_ROWS);

View File

@ -200,7 +200,7 @@ net_printf(THD *thd, uint errcode, ...)
2+SQLSTATE_LENGTH+1 : 2) : 0);
#ifndef EMBEDDED_LIBRARY
text_pos=(char*) net->buff + head_length + offset + 1;
length=(char*)net->buff_end-text_pos;
length= (uint) ((char*)net->buff_end - text_pos);
#else
length=sizeof(text_pos)-1;
#endif

View File

@ -551,21 +551,19 @@ static ulong get_sort(uint count,...)
uint chars= 0;
uint wild_pos= 0; /* first wildcard position */
if (start= str)
if ((start= str))
{
for (; *str ; str++)
{
if (*str == wild_many || *str == wild_one || *str == wild_prefix)
{
wild_pos= str - start + 1;
wild_pos= (uint) (str - start) + 1;
break;
}
else
chars++;
chars= 128; // Marker that chars existed
}
}
sort= (sort << 8) + (wild_pos ? (wild_pos > 127 ? 127 : wild_pos) :
(chars ? 128 : 0));
sort= (sort << 8) + (wild_pos ? min(wild_pos, 127) : chars);
}
va_end(args);
return sort;

View File

@ -833,7 +833,8 @@ JOIN::optimize()
((group_list && const_tables != tables &&
(!simple_group ||
!test_if_skip_sort_order(&join_tab[const_tables], group_list,
unit->select_limit_cnt, 0))) || select_distinct) &&
unit->select_limit_cnt, 0))) ||
select_distinct) &&
tmp_table_param.quick_group && !procedure)
{
need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort
@ -2163,22 +2164,32 @@ add_key_field(KEY_FIELD **key_fields,uint and_level, COND *cond,
number. cmp_type() is checked to allow compare of dates to numbers.
eq_func is NEVER true when num_values > 1
*/
if (!eq_func ||
field->result_type() == STRING_RESULT &&
(*value)->result_type() != STRING_RESULT &&
field->cmp_type() != (*value)->result_type())
return;
/*
We can't use indexes if the effective collation
of the operation differ from the field collation.
*/
if (field->result_type() == STRING_RESULT &&
(*value)->result_type() == STRING_RESULT &&
field->cmp_type() == STRING_RESULT &&
((Field_str*)field)->charset() != cond->compare_collation())
return;
if (!eq_func)
return;
if (field->result_type() == STRING_RESULT)
{
if ((*value)->result_type() != STRING_RESULT)
{
if (field->cmp_type() != (*value)->result_type())
return;
}
else
{
/*
We can't use indexes if the effective collation
of the operation differ from the field collation.
We can also not used index on a text column, as the column may
contain 'x' 'x\t' 'x ' and 'read_next_same' will stop after
'x' when searching for WHERE col='x '
*/
if (field->cmp_type() == STRING_RESULT &&
(((Field_str*)field)->charset() != cond->compare_collation() ||
((*value)->type() != Item::NULL_ITEM &&
(field->flags & BLOB_FLAG) && !field->binary())))
return;
}
}
}
}
DBUG_ASSERT(num_values == 1);
@ -5564,9 +5575,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
table->file->info(HA_STATUS_VARIABLE); /* update table->file->records */
new_table.file->start_bulk_insert(table->file->records);
#else
/*
HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it explicitly.
*/
/* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */
new_table.file->extra(HA_EXTRA_WRITE_CACHE);
#endif
@ -7234,9 +7243,9 @@ test_if_skip_sort_order(JOIN_TAB *tab,ORDER *order,ha_rows select_limit,
keys.merge(table->used_keys);
/*
We are adding here also the index speified in FORCE INDEX clause,
We are adding here also the index specified in FORCE INDEX clause,
if any.
This is to allow users to use index in ORDER BY.
This is to allow users to use index in ORDER BY.
*/
if (table->force_index)
keys.merge(table->keys_in_use_for_query);

View File

@ -2158,20 +2158,21 @@ my_tz_find(const String * name, TABLE_LIST *tz_tables)
if (!(result_tz= new (&tz_storage) Time_zone_offset(offset)) ||
my_hash_insert(&offset_tzs, (const byte *) result_tz))
{
result_tz= 0;
sql_print_error("Fatal error: Out of memory "
"while setting new time zone");
result_tz= 0;
}
}
} else {
}
else
{
result_tz= 0;
if ((tmp_tzname= (TZ_NAMES_ENTRY *)hash_search(&tz_names,
(const byte *)name->ptr(),
name->length())))
result_tz= tmp_tzname->tz;
else if(time_zone_tables_exist)
else if (time_zone_tables_exist)
result_tz= tz_load_from_open_tables(name, tz_tables);
else
result_tz= 0;
}
VOID(pthread_mutex_unlock(&tz_LOCK));