Commit a58c0e7d authored by jonas@eel.(none)'s avatar jonas@eel.(none)

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

into  eel.(none):/home/jonas/src/mysql-4.1-push
parents 3aede000 d9e3ad09
......@@ -1054,3 +1054,5 @@ vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
ndb/tools/ndb_config
support-files/MacOSX/postflight
support-files/MacOSX/preflight
......@@ -80,7 +80,7 @@ int hp_rb_delete_key(HP_INFO *info, register HP_KEYDEF *keyinfo,
custom_arg.search_flag= SEARCH_SAME;
old_allocated= keyinfo->rb_tree.allocated;
res= tree_delete(&keyinfo->rb_tree, info->recbuf, &custom_arg);
info->s->index_length+= (keyinfo->rb_tree.allocated-old_allocated);
info->s->index_length-= (old_allocated - keyinfo->rb_tree.allocated);
return res;
}
......
......@@ -788,7 +788,6 @@ extern my_bool init_compiled_charsets(myf flags);
extern void add_compiled_collation(CHARSET_INFO *cs);
extern ulong escape_string_for_mysql(CHARSET_INFO *charset_info, char *to,
const char *from, ulong length);
extern char *bare_str_to_hex(char *to, const char *from, uint len);
#ifdef __WIN__
#define BACKSLASH_MBTAIL
/* File system character set */
......
......@@ -8576,6 +8576,23 @@ FC4B
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
RESET MASTER;
CREATE TABLE t1(f1 blob);
PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)';
SET @var1= x'8300';
EXECUTE stmt1 USING @var1;
SHOW BINLOG EVENTS;
Log_name Pos Event_type Server_id Orig_log_pos Info
master-bin.000001 # Start 1 # Server ver: 4.1.15-debug-log, Binlog ver: 3
master-bin.000001 # Query 1 # use `test`; SET ONE_SHOT CHARACTER_SET_CLIENT=95,COLLATION_CONNECTION=95,COLLATION_DATABASE=95,COLLATION_SERVER=8
master-bin.000001 # Query 1 # use `test`; CREATE TABLE t1(f1 blob)
master-bin.000001 # Query 1 # use `test`; SET ONE_SHOT CHARACTER_SET_CLIENT=95,COLLATION_CONNECTION=95,COLLATION_DATABASE=95,COLLATION_SERVER=8
master-bin.000001 # User var 1 # @`var1`=_binary 0x8300 COLLATE binary
master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES(@'var1')
SELECT HEX(f1) FROM t1;
HEX(f1)
8300
DROP table t1;
SET collation_connection='cp932_japanese_ci';
create table t1 select repeat('a',4000) a;
delete from t1;
......
......@@ -464,3 +464,43 @@ SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
html prod
1 0.00
drop table t1;
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
SELECT DISTINCT a, 1 FROM t1;
a 1
1 1
2 1
3 1
4 1
5 1
SELECT DISTINCT 1, a FROM t1;
1 a
1 1
1 2
1 3
1 4
1 5
CREATE TABLE t2 (a int, b int);
INSERT INTO t2 VALUES (1,1),(2,2),(2,3),(2,4),(3,5);
SELECT DISTINCT a, b, 2 FROM t2;
a b 2
1 1 2
2 2 2
2 3 2
2 4 2
3 5 2
SELECT DISTINCT 2, a, b FROM t2;
2 a b
2 1 1
2 2 2
2 2 3
2 2 4
2 3 5
SELECT DISTINCT a, 2, b FROM t2;
a 2 b
1 2 1
2 2 2
2 2 3
2 2 4
3 2 5
DROP TABLE t1,t2;
This diff is collapsed.
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
create table t1 (n int not null primary key);
insert into t1 values (1);
create table t2 (n int);
insert into t2 values (1);
insert ignore into t1 select * from t2;
insert into t1 values (2);
select * from t1;
n
1
2
drop table t1,t2;
......@@ -401,6 +401,28 @@ DROP TABLE t2;
DROP TABLE t3;
#DROP TABLE t4;
# Test prepared statement with 0x8300 sequence in parameter while
# running with cp932 client character set.
RESET MASTER;
CREATE TABLE t1(f1 blob);
PREPARE stmt1 FROM 'INSERT INTO t1 VALUES(?)';
SET @var1= x'8300';
# TODO: Note that this doesn't actually test the code which was added for
# bug#11338 because this syntax for prepared statements causes the PS to
# be replicated differently than if we executed the PS from C or Java.
# Using this syntax, variable names are inserted into the binlog instead
# of values. The real goal of this test is to check the code that was
# added to Item_param::query_val_str() in order to do hex encoding of
# PS parameters when the client character set is cp932;
# Bug#11338 has an example java program which can be used to verify this
# code (and I have used it to test the fix) until there is some way to
# exercise this code from mysql-test-run.
EXECUTE stmt1 USING @var1;
--replace_column 2 # 5 #
SHOW BINLOG EVENTS;
SELECT HEX(f1) FROM t1;
DROP table t1;
# end test for bug#11338
SET collation_connection='cp932_japanese_ci';
-- source include/ctype_filesort.inc
......
......@@ -333,4 +333,21 @@ INSERT INTO t1 VALUES ('1',1,0);
SELECT DISTINCT html,SUM(out)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
drop table t1;
#
# Test cases for #12625: DISTINCT for a list with constants
#
CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
SELECT DISTINCT a, 1 FROM t1;
SELECT DISTINCT 1, a FROM t1;
CREATE TABLE t2 (a int, b int);
INSERT INTO t2 VALUES (1,1),(2,2),(2,3),(2,4),(3,5);
SELECT DISTINCT a, b, 2 FROM t2;
SELECT DISTINCT 2, a, b FROM t2;
SELECT DISTINCT a, 2, b FROM t2;
DROP TABLE t1,t2;
# End of 4.1 tests
# test case for BUG#4680 -- if there are extra files in the db directory
# dropping the db on the master causes replication problems
-- source include/master-slave.inc
connection master;
--disable_warnings
drop database if exists d1;
--enable_warnings
create database d1;
create table d1.t1 (n int);
insert into d1.t1 values (1);
select * from d1.t1 into outfile 'd1/f1.txt';
create table d1.t2 (n int);
create table d1.t3 (n int);
--error 1010
drop database d1;
use d1;
show tables;
# test the branch of the code that deals with the query buffer overflow
let $1=1000;
while ($1)
{
eval create table d1.t$1(n int);
dec $1;
}
--error 1010
drop database d1;
use d1;
show tables;
use test;
create table t1 (n int);
insert into t1 values (1234);
sync_slave_with_master;
connection slave;
use d1;
show tables;
use test;
select * from t1;
connection master;
drop table t1;
sync_slave_with_master;
#cleanup
connection slave;
stop slave;
system rm -rf var/master-data/d1;
# Testcase for BUG#10456 - INSERT INTO ... SELECT violating a primary key
# breaks replication
-- source include/master-slave.inc
connection master;
create table t1 (n int not null primary key);
insert into t1 values (1);
create table t2 (n int);
insert into t2 values (1);
insert ignore into t1 select * from t2;
insert into t1 values (2);
sync_slave_with_master;
connection slave;
select * from t1;
connection master;
drop table t1,t2;
sync_slave_with_master;
......@@ -663,21 +663,3 @@ CHARSET_INFO *fs_character_set()
return fs_cset_cache;
}
#endif
/*
Transforms a string into hex form.
*/
char *bare_str_to_hex(char *to, const char *from, uint len)
{
char *p= to;
uint i;
for (i= 0; i < len; i++, p+= 2)
{
/* val[i] is char. Casting to uchar helps greatly if val[i] < 0 */
uint tmp= (uint) (uchar) from[i];
p[0]= _dig_vec_upper[tmp >> 4];
p[1]= _dig_vec_upper[tmp & 15];
}
*p= 0;
return p; // pointer to end 0 of 'to'
}
......@@ -1230,7 +1230,7 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
CHARSET_INFO *tocs= thd->variables.collation_connection;
uint32 dummy_offset;
value.cs_info.character_set_client= fromcs;
value.cs_info.character_set_of_placeholder= fromcs;
/*
Setup source and destination character sets so that they
are different only if conversion is necessary: this will
......@@ -1443,7 +1443,7 @@ String *Item_param::val_str(String* str)
and avoid one more memcpy/alloc between str and log string.
*/
const String *Item_param::query_val_str(String* str, THD *thd) const
const String *Item_param::query_val_str(String* str) const
{
switch (state) {
case INT_VALUE:
......@@ -1482,18 +1482,17 @@ const String *Item_param::query_val_str(String* str, THD *thd) const
buf= str->c_ptr_quick();
ptr= buf;
if (thd->charset()->escape_with_backslash_is_dangerous)
if (value.cs_info.character_set_client->escape_with_backslash_is_dangerous)
{
ptr= strmov(ptr, "x\'");
ptr= bare_str_to_hex(ptr, str_value.ptr(), str_value.length());
ptr= str_to_hex(ptr, str_value.ptr(), str_value.length());
}
else
{
*ptr++= '\'';
ptr+= escape_string_for_mysql(str_value.charset(), ptr,
str_value.ptr(), str_value.length());
}
*ptr++='\'';
}
str->length(ptr - buf);
break;
}
......@@ -1523,10 +1522,10 @@ bool Item_param::convert_str_value(THD *thd)
here only if conversion is really necessary.
*/
if (value.cs_info.final_character_set_of_str_value !=
value.cs_info.character_set_client)
value.cs_info.character_set_of_placeholder)
{
rc= thd->convert_string(&str_value,
value.cs_info.character_set_client,
value.cs_info.character_set_of_placeholder,
value.cs_info.final_character_set_of_str_value);
}
else
......
......@@ -532,6 +532,7 @@ class Item_param :public Item
struct CONVERSION_INFO
{
CHARSET_INFO *character_set_client;
CHARSET_INFO *character_set_of_placeholder;
/*
This points at character set of connection if conversion
to it is required (i. e. if placeholder typecode is not BLOB).
......@@ -591,7 +592,7 @@ class Item_param :public Item
*/
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
const String *query_val_str(String *str, THD *thd) const;
const String *query_val_str(String *str) const;
bool convert_str_value(THD *thd);
......
......@@ -207,7 +207,7 @@ static inline int read_str(char * &buf, char *buf_end, char * &str,
/*
Transforms a string into "" or its expression in 0x... form.
*/
static char *str_to_hex(char *to, char *from, uint len)
char *str_to_hex(char *to, const char *from, uint len)
{
char *p= to;
if (len)
......
......@@ -1069,5 +1069,5 @@ class Unknown_log_event: public Log_event
bool is_valid() { return 1; }
};
#endif
char *str_to_hex(char *to, const char *from, uint len);
#endif /* _log_event_h */
......@@ -4328,7 +4328,7 @@ Disable with --skip-bdb (will save memory).",
(gptr*) &default_collation_name, (gptr*) &default_collation_name,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{"default-storage-engine", OPT_STORAGE_ENGINE,
"Set the default storage engine (table tyoe) for tables.", 0, 0,
"Set the default storage engine (table type) for tables.", 0, 0,
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default-table-type", OPT_STORAGE_ENGINE,
"(deprecated) Use --default-storage-engine.", 0, 0,
......
......@@ -25,13 +25,19 @@
#include <direct.h>
#endif
#define MAX_DROP_TABLE_Q_LEN 1024
const char *del_exts[]= {".frm", ".BAK", ".TMD",".opt", NullS};
static TYPELIB deletable_extentions=
{array_elements(del_exts)-1,"del_exts", del_exts, NULL};
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp,
const char *db, const char *path,
uint level);
const char *db, const char *path, uint level,
TABLE_LIST** dropped_tables);
static inline void write_to_binlog(THD* thd, char* query, uint q_len,
char* db, uint db_len);
/* Database options hash */
static HASH dboptions;
......@@ -57,6 +63,19 @@ static byte* dboptions_get_key(my_dbopt_t *opt, uint *length,
return (byte*) opt->name;
}
/*
Helper function to write a query to binlog used by mysql_rm_db()
*/
static inline void write_to_binlog(THD* thd, char* query, uint q_len,
char* db, uint db_len)
{
Query_log_event qinfo(thd, query, q_len, 0, 0);
qinfo.error_code= 0;
qinfo.db= db;
qinfo.db_len= db_len;
mysql_bin_log.write(&qinfo);
}
/*
Function to free dboptions hash element
......@@ -585,6 +604,7 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
char path[FN_REFLEN+16], tmp_db[NAME_LEN+1];
MY_DIR *dirp;
uint length;
TABLE_LIST* dropped_tables= 0;
DBUG_ENTER("mysql_rm_db");
VOID(pthread_mutex_lock(&LOCK_mysql_create_db));
......@@ -621,8 +641,10 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
remove_db_from_cache(db);
pthread_mutex_unlock(&LOCK_open);
error= -1;
if ((deleted= mysql_rm_known_files(thd, dirp, db, path, 0)) >= 0)
if ((deleted= mysql_rm_known_files(thd, dirp, db, path, 0,
&dropped_tables)) >= 0)
{
ha_drop_database(path);
query_cache_invalidate1(db);
......@@ -672,6 +694,45 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
send_ok(thd, (ulong) deleted);
thd->server_status&= ~SERVER_STATUS_DB_DROPPED;
}
else if (mysql_bin_log.is_open())
{
char* query= thd->alloc(MAX_DROP_TABLE_Q_LEN);
if (!query)
goto exit; /* not much else we can do */
char* p= strmov(query,"drop table ");
char* p_end= query + MAX_DROP_TABLE_Q_LEN;
TABLE_LIST* tbl;
bool last_query_needs_write= 0;
uint db_len= strlen(db);
for (tbl= dropped_tables;tbl;tbl= tbl->next)
{
if (!tbl->was_dropped)
continue;
/* 3 for the quotes and the comma*/
uint tbl_name_len= strlen(tbl->real_name) + 3;
if (p + tbl_name_len + 1 >= p_end)
{
*--p= 0; /* kill , */
write_to_binlog(thd, query, p - query, db, db_len);
p= query + 11; /* reuse the initial "drop table" */
}
*p++ = '`';
p= strmov(p,tbl->real_name);
*p++ = '`';
*p++ = ',';
last_query_needs_write= 1;
}
if (last_query_needs_write)
{
*--p= 0;
write_to_binlog(thd, query, p - query, db, db_len);
}
}
exit:
start_waiting_global_read_lock(thd);
......@@ -716,7 +777,7 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent)
*/
static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
const char *org_path, uint level)
const char *org_path, uint level, TABLE_LIST** dropped_tables)
{
long deleted=0;
ulong found_other_files=0;
......@@ -758,7 +819,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
if ((new_dirp = my_dir(newpath,MYF(MY_DONT_SORT))))
{
DBUG_PRINT("my",("New subdir found: %s", newpath));
if ((mysql_rm_known_files(thd, new_dirp, NullS, newpath,1)) < 0)
if ((mysql_rm_known_files(thd, new_dirp, NullS, newpath,1,0)) < 0)
goto err;
if (!(copy_of_path= thd->memdup(newpath, length+1)) ||
!(dir= new (thd->mem_root) String(copy_of_path, length,
......@@ -818,6 +879,9 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db,
}
my_dirend(dirp);
if (dropped_tables)
*dropped_tables= tot_list;
/*
If the directory is a symbolic link, remove the link first, then
remove the directory the symbolic link pointed at
......
......@@ -528,7 +528,9 @@ static void setup_one_conversion_function(THD *thd, Item_param *param,
case MYSQL_TYPE_LONG_BLOB:
case MYSQL_TYPE_BLOB:
param->set_param_func= set_param_str;
param->value.cs_info.character_set_client= &my_charset_bin;
param->value.cs_info.character_set_of_placeholder= &my_charset_bin;
param->value.cs_info.character_set_client=
thd->variables.character_set_client;
param->value.cs_info.final_character_set_of_str_value= &my_charset_bin;
param->item_type= Item::STRING_ITEM;
param->item_result_type= STRING_RESULT;
......@@ -544,6 +546,7 @@ static void setup_one_conversion_function(THD *thd, Item_param *param,
CHARSET_INFO *tocs= thd->variables.collation_connection;
uint32 dummy_offset;
param->value.cs_info.character_set_of_placeholder= fromcs;
param->value.cs_info.character_set_client= fromcs;
/*
......@@ -601,7 +604,7 @@ static bool insert_params_withlog(Prepared_statement *stmt, uchar *null_array,
param->set_param_func(param, &read_pos, data_end - read_pos);
}
}
res= param->query_val_str(&str, thd);
res= param->query_val_str(&str);
if (param->convert_str_value(thd))
DBUG_RETURN(1); /* out of memory */
......@@ -749,7 +752,7 @@ static bool emb_insert_params_withlog(Prepared_statement *stmt, String *query)
client_param->buffer_length);
}
}
res= param->query_val_str(&str, thd);
res= param->query_val_str(&str);
if (param->convert_str_value(thd))
DBUG_RETURN(1); /* out of memory */
......
......@@ -8517,9 +8517,7 @@ create_distinct_group(THD *thd, Item **ref_pointer_array,
li.rewind();
while ((item=li++))
{
if (item->const_item() || item->with_sum_func)
continue;
if (!item->marker)
if (!item->const_item() && !item->with_sum_func && !item->marker)
{
ORDER *ord=(ORDER*) thd->calloc(sizeof(ORDER));
if (!ord)
......
......@@ -220,6 +220,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
for (table=tables ; table ; table=table->next)
{
char *db=table->db;
table->was_dropped= 0;
mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL);
if (!close_temporary_table(thd, db, table->real_name))
{
......@@ -280,6 +281,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
wrong_tables.append(',');
wrong_tables.append(String(table->real_name,system_charset_info));
}
else
table->was_dropped= 1;
}
thd->tmp_table_used= tmp_table_deleted;
error= 0;
......
......@@ -235,6 +235,9 @@ typedef struct st_table_list
bool cacheable_table; /* stop PS caching */
/* used in multi-upd privelege check */
bool table_in_update_from_clause;
/* used for proper partially successful DROP DATABASE binlogging */
bool was_dropped;
} TABLE_LIST;
typedef struct st_changed_table_list
......
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