mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Merge with 4.1
This commit is contained in:
158
sql/sql_table.cc
158
sql/sql_table.cc
@@ -29,12 +29,6 @@
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#define tmp_disable_binlog(A) \
|
||||
ulong save_options= (A)->options; \
|
||||
(A)->options&= ~OPTION_BIN_LOG;
|
||||
|
||||
#define reenable_binlog(A) (A)->options= save_options;
|
||||
|
||||
const char *primary_key_name="PRIMARY";
|
||||
|
||||
static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);
|
||||
@@ -281,7 +275,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
|
||||
if (!error)
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length,
|
||||
tmp_table_deleted && !some_tables_deleted);
|
||||
tmp_table_deleted && !some_tables_deleted,
|
||||
FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
}
|
||||
@@ -390,6 +385,41 @@ void check_duplicates_in_interval(const char *set_or_name,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Check TYPELIB (set or enum) max and total lengths
|
||||
|
||||
SYNOPSIS
|
||||
calculate_interval_lengths()
|
||||
cs charset+collation pair of the interval
|
||||
typelib list of values for the column
|
||||
max_length length of the longest item
|
||||
tot_length sum of the item lengths
|
||||
|
||||
DESCRIPTION
|
||||
After this function call:
|
||||
- ENUM uses max_length
|
||||
- SET uses tot_length.
|
||||
|
||||
RETURN VALUES
|
||||
void
|
||||
*/
|
||||
void calculate_interval_lengths(CHARSET_INFO *cs, TYPELIB *interval,
|
||||
uint32 *max_length, uint32 *tot_length)
|
||||
{
|
||||
const char **pos;
|
||||
uint *len;
|
||||
*max_length= *tot_length= 0;
|
||||
for (pos= interval->type_names, len= interval->type_lengths;
|
||||
*pos ; pos++, len++)
|
||||
{
|
||||
uint length= cs->cset->numchars(cs, *pos, *pos + *len);
|
||||
*tot_length+= length;
|
||||
set_if_bigger(*max_length, (uint32)length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Preparation for table creation
|
||||
|
||||
@@ -453,6 +483,91 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
if ((sql_field->sql_type == FIELD_TYPE_SET ||
|
||||
sql_field->sql_type == FIELD_TYPE_ENUM) && !sql_field->interval)
|
||||
{
|
||||
uint32 dummy;
|
||||
CHARSET_INFO *cs= sql_field->charset;
|
||||
TYPELIB *interval;
|
||||
|
||||
/*
|
||||
Create typelib from interval_list, and if necessary
|
||||
convert strings from client character set to the
|
||||
column character set.
|
||||
*/
|
||||
|
||||
interval= sql_field->interval= typelib(sql_field->interval_list);
|
||||
List_iterator<String> it(sql_field->interval_list);
|
||||
String conv, *tmp;
|
||||
for (uint i= 0; (tmp= it++); i++)
|
||||
{
|
||||
if (String::needs_conversion(tmp->length(), tmp->charset(), cs, &dummy))
|
||||
{
|
||||
uint cnv_errs;
|
||||
conv.copy(tmp->ptr(), tmp->length(), tmp->charset(), cs, &cnv_errs);
|
||||
char *buf= (char*) sql_alloc(conv.length()+1);
|
||||
memcpy(buf, conv.ptr(), conv.length());
|
||||
buf[conv.length()]= '\0';
|
||||
interval->type_names[i]= buf;
|
||||
interval->type_lengths[i]= conv.length();
|
||||
}
|
||||
|
||||
// Strip trailing spaces.
|
||||
uint lengthsp= cs->cset->lengthsp(cs, interval->type_names[i],
|
||||
interval->type_lengths[i]);
|
||||
interval->type_lengths[i]= lengthsp;
|
||||
((uchar *)interval->type_names[i])[lengthsp]= '\0';
|
||||
}
|
||||
sql_field->interval_list.empty(); // Don't need interval_list anymore
|
||||
|
||||
|
||||
/*
|
||||
Convert the default value from client character
|
||||
set into the column character set if necessary.
|
||||
*/
|
||||
if (sql_field->def)
|
||||
{
|
||||
sql_field->def=
|
||||
sql_field->def->safe_charset_converter(cs);
|
||||
}
|
||||
|
||||
if (sql_field->sql_type == FIELD_TYPE_SET)
|
||||
{
|
||||
if (sql_field->def)
|
||||
{
|
||||
char *not_used;
|
||||
uint not_used2;
|
||||
bool not_found= 0;
|
||||
String str, *def= sql_field->def->val_str(&str);
|
||||
def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
|
||||
(void) find_set(interval, def->ptr(), def->length(),
|
||||
cs, ¬_used, ¬_used2, ¬_found);
|
||||
if (not_found)
|
||||
{
|
||||
my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
calculate_interval_lengths(cs, interval, &dummy, &sql_field->length);
|
||||
sql_field->length+= (interval->count - 1);
|
||||
}
|
||||
else /* FIELD_TYPE_ENUM */
|
||||
{
|
||||
if (sql_field->def)
|
||||
{
|
||||
String str, *def= sql_field->def->val_str(&str);
|
||||
def->length(cs->cset->lengthsp(cs, def->ptr(), def->length()));
|
||||
if (!find_type2(interval, def->ptr(), def->length(), cs))
|
||||
{
|
||||
my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
calculate_interval_lengths(cs, interval, &sql_field->length, &dummy);
|
||||
}
|
||||
set_if_smaller(sql_field->length, MAX_FIELD_WIDTH-1);
|
||||
}
|
||||
|
||||
sql_field->create_length_to_internal_length();
|
||||
|
||||
/* Don't pack keys in old tables if the user has requested this */
|
||||
@@ -816,8 +931,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (key_info->algorithm == HA_KEY_ALG_RTREE)
|
||||
else if (key_info->algorithm == HA_KEY_ALG_RTREE)
|
||||
{
|
||||
#ifdef HAVE_RTREE_KEYS
|
||||
if ((key_info->key_parts & 1) == 1)
|
||||
@@ -839,6 +953,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
CHARSET_INFO *ft_key_charset=0; // for FULLTEXT
|
||||
for (uint column_nr=0 ; (column=cols++) ; column_nr++)
|
||||
{
|
||||
key_part_spec *dup_column;
|
||||
|
||||
it.rewind();
|
||||
field=0;
|
||||
while ((sql_field=it++) &&
|
||||
@@ -851,9 +967,8 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
for (uint dup_nr= 0; dup_nr < column_nr; dup_nr++)
|
||||
while ((dup_column= cols2++) != column)
|
||||
{
|
||||
key_part_spec *dup_column= cols2++;
|
||||
if (!my_strcasecmp(system_charset_info,
|
||||
column->field_name, dup_column->field_name))
|
||||
{
|
||||
@@ -864,12 +979,6 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
}
|
||||
}
|
||||
cols2.rewind();
|
||||
/* for fulltext keys keyseg length is 1 for blobs (it's ignored in
|
||||
ft code anyway, and 0 (set to column width later) for char's.
|
||||
it has to be correct col width for char's, as char data are not
|
||||
prefixed with length (unlike blobs, where ft code takes data length
|
||||
from a data prefix, ignoring column->length).
|
||||
*/
|
||||
if (key->type == Key::FULLTEXT)
|
||||
{
|
||||
if ((sql_field->sql_type != FIELD_TYPE_STRING &&
|
||||
@@ -1296,10 +1405,12 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length,
|
||||
test(create_info->options &
|
||||
HA_LEX_CREATE_TMP_TABLE));
|
||||
HA_LEX_CREATE_TMP_TABLE),
|
||||
FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
error= FALSE;
|
||||
|
||||
end:
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
start_waiting_global_read_lock(thd);
|
||||
@@ -2274,7 +2385,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length,
|
||||
test(create_info->options &
|
||||
HA_LEX_CREATE_TMP_TABLE));
|
||||
HA_LEX_CREATE_TMP_TABLE),
|
||||
FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
res= FALSE;
|
||||
@@ -2384,7 +2496,7 @@ mysql_discard_or_import_tablespace(THD *thd,
|
||||
goto err;
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0);
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
err:
|
||||
@@ -2773,7 +2885,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0);
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
if (do_send_ok)
|
||||
@@ -3189,7 +3301,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0);
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
goto end_temporary;
|
||||
@@ -3323,7 +3435,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
if (mysql_bin_log.is_open())
|
||||
{
|
||||
thd->clear_error();
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0);
|
||||
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
|
||||
mysql_bin_log.write(&qinfo);
|
||||
}
|
||||
VOID(pthread_cond_broadcast(&COND_refresh));
|
||||
|
||||
Reference in New Issue
Block a user