Commit c36f4fd0 authored by monty@donna.mysql.fi's avatar monty@donna.mysql.fi

Added tests if a user variable is changed in the same query.

parent d0722d73
...@@ -597,7 +597,7 @@ Replication in MySQL ...@@ -597,7 +597,7 @@ Replication in MySQL
* Replication Options:: Replication Options in my.cnf * Replication Options:: Replication Options in my.cnf
* Replication SQL:: SQL Commands related to replication * Replication SQL:: SQL Commands related to replication
* Replication FAQ:: Frequently Asked Questions about replication * Replication FAQ:: Frequently Asked Questions about replication
* Troubleshooting Replication:: Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. * Replication Problems:: Troubleshooting Replication.
Getting Maximum Performance from MySQL Getting Maximum Performance from MySQL
...@@ -23616,9 +23616,24 @@ Change to not use page locks at all when we are scanning tables. ...@@ -23616,9 +23616,24 @@ Change to not use page locks at all when we are scanning tables.
@node BDB errors, , BDB TODO, BDB @node BDB errors, , BDB TODO, BDB
@subsection Errors You May Get When Using BDB Tables @subsection Errors You May Get When Using BDB Tables
@itemize @bullet
@item
If you get the following error in the @code{hostname.err log} when
starting @code{mysqld}:
@example
bdb: Ignoring log file: .../log.XXXXXXXXXX: unsupported log version #}
@end example
it means that the new @code{BDB} version doesn't support the old log
file format. In this case you have to delete all @code{BDB} log BDB
from your database directory (the files that has the format
@code{log.XXXXXXXXXX} ) and restart @code{mysqld}. We would also
recommend you to do a @code{mysqldump --opt} of your old @code{BDB}
tables, delete the old table and restore the dump.
@item
If you are running in not @code{auto_commit} mode and delete a table you If you are running in not @code{auto_commit} mode and delete a table you
are using you may get the following error messages in the @strong{MySQL} are using by another thread you may get the following error messages in
error file: the @strong{MySQL} error file:
@example @example
001119 23:43:56 bdb: Missing log fileid entry 001119 23:43:56 bdb: Missing log fileid entry
...@@ -23628,6 +23643,7 @@ error file: ...@@ -23628,6 +23643,7 @@ error file:
This is not fatal but we don't recommend that you delete tables if you are This is not fatal but we don't recommend that you delete tables if you are
not in @code{auto_commit} mode, until this problem is fixed (the fix is not in @code{auto_commit} mode, until this problem is fixed (the fix is
not trivial). not trivial).
@end itemize
@cindex tables, @code{GEMINI} @cindex tables, @code{GEMINI}
@node GEMINI, INNOBASE, BDB, Table types @node GEMINI, INNOBASE, BDB, Table types
...@@ -26676,7 +26692,7 @@ tables}. ...@@ -26676,7 +26692,7 @@ tables}.
* Replication Options:: Replication Options in my.cnf * Replication Options:: Replication Options in my.cnf
* Replication SQL:: SQL Commands related to replication * Replication SQL:: SQL Commands related to replication
* Replication FAQ:: Frequently Asked Questions about replication * Replication FAQ:: Frequently Asked Questions about replication
* Troubleshooting Replication:: Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. Troubleshooting Replication. * Replication Problems:: Troubleshooting Replication.
@end menu @end menu
@node Replication Intro, Replication Implementation, Replication, Replication @node Replication Intro, Replication Implementation, Replication, Replication
...@@ -26884,7 +26900,7 @@ Replication will be done correctly with @code{AUTO_INCREMENT}, ...@@ -26884,7 +26900,7 @@ Replication will be done correctly with @code{AUTO_INCREMENT},
@code{LAST_INSERT_ID}, and @code{TIMESTAMP} values. @code{LAST_INSERT_ID}, and @code{TIMESTAMP} values.
@item @item
@code{RAND()} in updates does not replicate properly. Use @code{RAND()} in updates does not replicate properly. Use
@code{RAND(some_non_rand_expr)} if you are replcating updates with @code{RAND(some_non_rand_expr)} if you are replcating updates with
@code{RAND()}. You can, for example, use @code{UNIX_TIMESTAMP()} for the @code{RAND()}. You can, for example, use @code{UNIX_TIMESTAMP()} for the
argument to @code{RAND()}. argument to @code{RAND()}.
@item @item
...@@ -26894,6 +26910,14 @@ propagation. @code{LOAD LOCAL DATA INFILE} will be skipped. ...@@ -26894,6 +26910,14 @@ propagation. @code{LOAD LOCAL DATA INFILE} will be skipped.
@item @item
Update queries that use user variables are not replication-safe (yet). Update queries that use user variables are not replication-safe (yet).
@item @item
@code{FLUSH} commands are not stored in the binary log and are because
of this not replicated to the slaves. This is not normally a problem as
@code{FLUSH} doesn't change anything. This does however mean that if you
update the @code{MySQL} privilege tables directly without using
@code{GRANT} statement and you replicate the @code{MySQL} privilege
database, you must do a @code{FLUSH PRIVILEGES} on your slaves to put
the new privileges into effect.
@item
Temporary tables starting in 3.23.29 are replicated properly with the Temporary tables starting in 3.23.29 are replicated properly with the
exception of the case when you shut down slave server ( not just slave thread), exception of the case when you shut down slave server ( not just slave thread),
you have some temporary tables open, and the are used in subsequent updates. you have some temporary tables open, and the are used in subsequent updates.
...@@ -27240,7 +27264,7 @@ last log on the list), backup all the logs you are about to delete ...@@ -27240,7 +27264,7 @@ last log on the list), backup all the logs you are about to delete
@end multitable @end multitable
@node Replication FAQ, Troubleshooting Replication, Replication SQL, Replication @node Replication FAQ, Replication Problems, Replication SQL, Replication
@section Replication FAQ @section Replication FAQ
@cindex @code{Binlog_Dump} @cindex @code{Binlog_Dump}
...@@ -27493,7 +27517,7 @@ We are currently working on intergrating an automatic master election ...@@ -27493,7 +27517,7 @@ We are currently working on intergrating an automatic master election
system into @strong{MySQL}, but until it is ready, you will have to system into @strong{MySQL}, but until it is ready, you will have to
create your own monitoring tools. create your own monitoring tools.
@node Troubleshooting Replication, , Replication FAQ, Replication @node Replication Problems, , Replication FAQ, Replication
@section Troubleshooting Replication @section Troubleshooting Replication
If you have followed the instructions, and your replication setup is not If you have followed the instructions, and your replication setup is not
...@@ -6,3 +6,11 @@ i ...@@ -6,3 +6,11 @@ i
i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3 i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3
1 1 0 1 2 1 1 0 1 2
2 1 0 0 1 2 1 0 0 1
table type possible_keys key key_len ref rows Extra
t1 ref i i 4 const 1 where used
table type possible_keys key key_len ref rows Extra
t1 ALL NULL NULL NULL NULL 3 where used
table type possible_keys key key_len ref rows Extra
t1 index NULL i 4 NULL 3 where used; Using index
table type possible_keys key key_len ref rows Extra
t1 ref i i 4 const 1 where used
...@@ -12,4 +12,8 @@ create table t2 (i int not null, unique (i)); ...@@ -12,4 +12,8 @@ create table t2 (i int not null, unique (i));
insert into t2 select distinct i from t1; insert into t2 select distinct i from t1;
select * from t2; select * from t2;
select distinct t2.i,@vv1:=if(sv1.i,1,0),@vv2:=if(sv2.i,1,0),@vv3:=if(sv3.i,1,0), @vv1+@vv2+@vv3 from t2 left join t1 as sv1 on sv1.i=t2.i and sv1.v=1 left join t1 as sv2 on sv2.i=t2.i and sv2.v=2 left join t1 as sv3 on sv3.i=t2.i and sv3.v=3; select distinct t2.i,@vv1:=if(sv1.i,1,0),@vv2:=if(sv2.i,1,0),@vv3:=if(sv3.i,1,0), @vv1+@vv2+@vv3 from t2 left join t1 as sv1 on sv1.i=t2.i and sv1.v=1 left join t1 as sv2 on sv2.i=t2.i and sv2.v=2 left join t1 as sv3 on sv3.i=t2.i and sv3.v=3;
explain select * from t1 where i=@vv1;
explain select * from t1 where @vv1:=@vv1+1 and i=@vv1;
explain select @vv1:=i from t1 where i=@vv1;
explain select * from t1 where i=@vv1;
drop table t1,t2; drop table t1,t2;
...@@ -1606,6 +1606,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, ...@@ -1606,6 +1606,7 @@ static user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
entry->name.length=name.length; entry->name.length=name.length;
entry->value=0; entry->value=0;
entry->length=0; entry->length=0;
entry->update_query_id=0;
entry->type=STRING_RESULT; entry->type=STRING_RESULT;
memcpy(entry->name.str, name.str, name.length+1); memcpy(entry->name.str, name.str, name.length+1);
if (hash_insert(hash,(byte*) entry)) if (hash_insert(hash,(byte*) entry))
...@@ -1625,6 +1626,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd,TABLE_LIST *tables) ...@@ -1625,6 +1626,7 @@ bool Item_func_set_user_var::fix_fields(THD *thd,TABLE_LIST *tables)
if (Item_func::fix_fields(thd,tables) || if (Item_func::fix_fields(thd,tables) ||
!(entry= get_variable(&thd->user_vars, name, 1))) !(entry= get_variable(&thd->user_vars, name, 1)))
return 1; return 1;
entry->update_query_id=thd->query_id;
return 0; return 0;
} }
...@@ -1809,10 +1811,12 @@ longlong Item_func_get_user_var::val_int() ...@@ -1809,10 +1811,12 @@ longlong Item_func_get_user_var::val_int()
void Item_func_get_user_var::fix_length_and_dec() void Item_func_get_user_var::fix_length_and_dec()
{ {
THD *thd=current_thd;
maybe_null=1; maybe_null=1;
decimals=NOT_FIXED_DEC; decimals=NOT_FIXED_DEC;
max_length=MAX_BLOB_WIDTH; max_length=MAX_BLOB_WIDTH;
entry= get_variable(&current_thd->user_vars, name, 0); if ((entry= get_variable(&thd->user_vars, name, 0)))
const_var_flag= thd->query_id != entry->update_query_id;
} }
......
...@@ -825,9 +825,11 @@ class Item_func_get_user_var :public Item_func ...@@ -825,9 +825,11 @@ class Item_func_get_user_var :public Item_func
{ {
LEX_STRING name; LEX_STRING name;
user_var_entry *entry; user_var_entry *entry;
bool const_var_flag;
public: public:
Item_func_get_user_var(LEX_STRING a): Item_func(), name(a) {} Item_func_get_user_var(LEX_STRING a):
Item_func(), name(a), const_var_flag(1) {}
user_var_entry *get_entry(); user_var_entry *get_entry();
double val(); double val();
longlong val_int(); longlong val_int();
...@@ -835,8 +837,9 @@ public: ...@@ -835,8 +837,9 @@ public:
void fix_length_and_dec(); void fix_length_and_dec();
enum Item_result result_type() const; enum Item_result result_type() const;
const char *func_name() const { return "get_user_var"; } const char *func_name() const { return "get_user_var"; }
bool const_item() const { return 0; } bool const_item() const { return const_var_flag; }
table_map used_tables() const { return RAND_TABLE_BIT; } table_map used_tables() const
{ return const_var_flag ? 0 : RAND_TABLE_BIT; }
}; };
class Item_func_inet_aton : public Item_int_func class Item_func_inet_aton : public Item_int_func
......
...@@ -550,7 +550,7 @@ class user_var_entry ...@@ -550,7 +550,7 @@ class user_var_entry
public: public:
LEX_STRING name; LEX_STRING name;
char *value; char *value;
ulong length; ulong length, update_query_id;
Item_result type; Item_result type;
}; };
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