summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2006-03-30 00:20:13 +0400
committerunknown <konstantin@mysql.com>2006-03-30 00:20:13 +0400
commit87e9178114a00d34fa77673844f728008dbb3f31 (patch)
tree83ff09555ad8faa189a27ec3b62c92e69796bfdd /sql
parentc5ab0159e19d607246d73951e14cf3d42479c7b9 (diff)
parent1b458888549010439c591f0c5fff895b49c34dfd (diff)
downloadmariadb-git-87e9178114a00d34fa77673844f728008dbb3f31.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/opt/local/work/mysql-5.0-15683 sql/sql_load.cc: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/field.h6
-rw-r--r--sql/sp.cc6
-rw-r--r--sql/sql_insert.cc23
-rw-r--r--sql/sql_load.cc5
-rw-r--r--sql/sql_select.cc6
-rw-r--r--sql/sql_view.cc1
6 files changed, 36 insertions, 11 deletions
diff --git a/sql/field.h b/sql/field.h
index e8dd7f05f99..f53227e5fd6 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -320,6 +320,12 @@ public:
/* convert decimal to longlong with overflow check */
longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
int *err);
+ /* The max. number of characters */
+ inline uint32 Field::char_length() const
+ {
+ return field_length / charset()->mbmaxlen;
+ }
+
friend bool reopen_table(THD *,struct st_table *,bool);
friend int cre_myisam(my_string name, register TABLE *form, uint options,
ulonglong auto_increment_value);
diff --git a/sql/sp.cc b/sql/sp.cc
index 0446bf94e53..cfcf011032d 100644
--- a/sql/sp.cc
+++ b/sql/sp.cc
@@ -534,7 +534,11 @@ db_create_routine(THD *thd, int type, sp_head *sp)
ret= SP_GET_FIELD_FAILED;
goto done;
}
- if (sp->m_name.length > table->field[MYSQL_PROC_FIELD_NAME]->field_length)
+
+ if (system_charset_info->cset->numchars(system_charset_info,
+ sp->m_name.str,
+ sp->m_name.str+sp->m_name.length) >
+ table->field[MYSQL_PROC_FIELD_NAME]->char_length())
{
ret= SP_BAD_IDENTIFIER;
goto done;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index b6ff0ecc216..ad9606acb83 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -405,11 +405,15 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
let's *try* to start bulk inserts. It won't necessary
start them as values_list.elements should be greater than
some - handler dependent - threshold.
+ We should not start bulk inserts if this statement uses
+ functions or invokes triggers since they may access
+ to the same table and therefore should not see its
+ inconsistent state created by this optimization.
So we call start_bulk_insert to perform nesessary checks on
values_list.elements, and - if nothing else - to initialize
the code to make the call of end_bulk_insert() below safe.
*/
- if (lock_type != TL_WRITE_DELAYED)
+ if (lock_type != TL_WRITE_DELAYED && !thd->prelocked_mode)
table->file->start_bulk_insert(values_list.elements);
thd->no_trans_update= 0;
@@ -535,7 +539,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
else
#endif
{
- if (table->file->end_bulk_insert() && !error)
+ if (!thd->prelocked_mode && table->file->end_bulk_insert() && !error)
{
table->file->print_error(my_errno,MYF(0));
error=1;
@@ -2190,7 +2194,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
lex->current_select->options|= OPTION_BUFFER_RESULT;
lex->current_select->join->select_options|= OPTION_BUFFER_RESULT;
}
- else
+ else if (!thd->prelocked_mode)
{
/*
We must not yet prepare the result table if it is the same as one of the
@@ -2198,6 +2202,8 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
indexes on the result table, which may be used during the select, if it
is the same table (Bug #6034). Do the preparation after the select phase
in select_insert::prepare2().
+ We won't start bulk inserts at all if this statement uses functions or
+ should invoke triggers since they may access to the same table too.
*/
table->file->start_bulk_insert((ha_rows) 0);
}
@@ -2238,7 +2244,8 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
int select_insert::prepare2(void)
{
DBUG_ENTER("select_insert::prepare2");
- if (thd->lex->current_select->options & OPTION_BUFFER_RESULT)
+ if (thd->lex->current_select->options & OPTION_BUFFER_RESULT &&
+ !thd->prelocked_mode)
table->file->start_bulk_insert((ha_rows) 0);
DBUG_RETURN(0);
}
@@ -2341,7 +2348,8 @@ void select_insert::send_error(uint errcode,const char *err)
*/
DBUG_VOID_RETURN;
}
- table->file->end_bulk_insert();
+ if (!thd->prelocked_mode)
+ table->file->end_bulk_insert();
/*
If at least one row has been inserted/modified and will stay in the table
(the table doesn't have transactions) (example: we got a duplicate key
@@ -2376,7 +2384,7 @@ bool select_insert::send_eof()
int error,error2;
DBUG_ENTER("select_insert::send_eof");
- error=table->file->end_bulk_insert();
+ error= (!thd->prelocked_mode) ? table->file->end_bulk_insert():0;
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
/*
@@ -2459,7 +2467,8 @@ select_create::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
- table->file->start_bulk_insert((ha_rows) 0);
+ if (!thd->prelocked_mode)
+ table->file->start_bulk_insert((ha_rows) 0);
thd->no_trans_update= 0;
thd->abort_on_warning= (!info.ignore &&
(thd->variables.sql_mode &
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index cc724c102a4..0a667c887ef 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -356,7 +356,8 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
if (ignore ||
handle_duplicates == DUP_REPLACE)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
- table->file->start_bulk_insert((ha_rows) 0);
+ if (!thd->prelocked_mode)
+ table->file->start_bulk_insert((ha_rows) 0);
table->copy_blobs=1;
thd->no_trans_update= 0;
@@ -373,7 +374,7 @@ bool mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list,
error= read_sep_field(thd, info, table_list, fields_vars,
set_fields, set_values, read_info,
*enclosed, skip_lines, ignore);
- if (table->file->end_bulk_insert() && !error)
+ if (!thd->prelocked_mode && table->file->end_bulk_insert() && !error)
{
table->file->print_error(my_errno, MYF(0));
error= 1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 6e530b58d74..2e60bdb96f0 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -12333,7 +12333,11 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
Item **select_item; /* The corresponding item from the SELECT clause. */
Field *from_field; /* The corresponding field from the FROM clause. */
- if (order_item->type() == Item::INT_ITEM)
+ /*
+ Local SP variables may be int but are expressions, not positions.
+ (And they can't be used before fix_fields is called for them).
+ */
+ if (order_item->type() == Item::INT_ITEM && order_item->basic_const_item())
{ /* Order by position */
uint count= (uint) order_item->val_int();
if (!count || count > fields.elements)
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 2832adc1f8f..39d1ae5c9fb 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -938,6 +938,7 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table)
tbl->skip_temporary= 1;
tbl->belong_to_view= top_view;
tbl->referencing_view= table;
+ tbl->prelocking_placeholder= table->prelocking_placeholder;
/*
First we fill want_privilege with SELECT_ACL (this is needed for the
tables which belongs to view subqueries and temporary table views,