Commit 3c7745ff authored by unknown's avatar unknown

Merge mysql.com:/home/mydev/mysql-4.0

into mysql.com:/home/mydev/mysql-4.0-lock

parents 83bee61e f1257b3f
......@@ -1190,6 +1190,22 @@ a
A
a
drop table t1;
create table t1(
pk1 text not null, pk2 text not null, pk3 char(4),
key1 int, key2 int,
primary key(pk1(4), pk2(4), pk3), key(key1), key(key2)
) engine=bdb;
insert into t1 values (concat('aaa-', repeat('A', 4000)),
concat('eee-', repeat('e', 4000)), 'a++a', 1, 1);
insert into t1 values (concat('bbb-', repeat('B', 4000)),
concat('ggg-', repeat('G', 4000)), 'b++b', 1, 1);
select substring(pk1, 1, 4), substring(pk1, 4001),
substring(pk2, 1, 4), substring(pk2, 4001), pk3, key1, key2
from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
substring(pk1, 1, 4) substring(pk1, 4001) substring(pk2, 1, 4) substring(pk2, 4001) pk3 key1 key2
aaa- AAAA eee- eeee a++a 1 1
bbb- BBBB ggg- GGGG b++b 1 1
drop table t1;
create table t1 (
pk1 varchar(8) not null default '',
pk2 varchar(4) not null default '',
......
drop table if exists t1;
create table t1 (a int not null auto_increment primary key);
insert into t1 values(0);
lock table t1 read;
flush table t1;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
drop database if exists test_test;
create database test_test;
use test_test;
create table t1(table_id char(20) primary key);
insert into t1 values ('test_test.t1');
insert into t1 values ('');
handler t1 open;
handler t1 read first limit 9;
table_id
test_test.t1
create table t2(table_id char(20) primary key);
insert into t2 values ('test_test.t2');
insert into t2 values ('');
handler t2 open;
handler t2 read first limit 9;
table_id
test_test.t2
use test;
drop table if exists t1;
create table t1(table_id char(20) primary key);
insert into t1 values ('test.t1');
insert into t1 values ('');
handler t1 open;
handler t1 read first limit 9;
table_id
test.t1
use test;
handler test.t1 read first limit 9;
table_id
test.t1
handler test.t2 read first limit 9;
Unknown table 't2' in HANDLER
handler test_test.t1 read first limit 9;
table_id
test_test.t1
handler test_test.t2 read first limit 9;
table_id
test_test.t2
handler test_test.t1 close;
drop table test_test.t1;
handler test_test.t2 close;
drop table test_test.t2;
drop database test_test;
use test;
handler test.t1 close;
drop table test.t1;
drop table if exists t1;
drop table if exists t2;
create table t1(table_id char(20) primary key);
create table t2(table_id char(20) primary key);
insert into t1 values ('test.t1');
insert into t1 values ('');
insert into t2 values ('test.t2');
insert into t2 values ('');
handler t1 open as a1;
handler t1 open as a2;
handler t2 open;
handler a1 read first limit 9;
table_id
test.t1
handler a2 read first limit 9;
table_id
test.t1
handler t2 read first limit 9;
table_id
test.t2
flush tables;
handler a1 read first limit 9;
Unknown table 'a1' in HANDLER
handler a2 read first limit 9;
Unknown table 'a2' in HANDLER
handler t2 read first limit 9;
Unknown table 't2' in HANDLER
handler t1 open as a1;
handler t1 open as a2;
handler t2 open;
handler a1 read first limit 9;
table_id
test.t1
handler a2 read first limit 9;
table_id
test.t1
handler t2 read first limit 9;
table_id
test.t2
flush table t1;
handler a1 read first limit 9;
Unknown table 'a1' in HANDLER
handler a2 read first limit 9;
Unknown table 'a2' in HANDLER
handler t2 read first limit 9;
table_id
test.t2
flush table t2;
handler t2 close;
Unknown table 't2' in HANDLER
drop table t1;
drop table t2;
......@@ -830,6 +830,25 @@ explain select a from t1;
select a from t1;
drop table t1;
#
# bug#2686 - index_merge select on BerkeleyDB table with varchar PK causes mysqld to crash
#
create table t1(
pk1 text not null, pk2 text not null, pk3 char(4),
key1 int, key2 int,
primary key(pk1(4), pk2(4), pk3), key(key1), key(key2)
) engine=bdb;
insert into t1 values (concat('aaa-', repeat('A', 4000)),
concat('eee-', repeat('e', 4000)), 'a++a', 1, 1);
insert into t1 values (concat('bbb-', repeat('B', 4000)),
concat('ggg-', repeat('G', 4000)), 'b++b', 1, 1);
select substring(pk1, 1, 4), substring(pk1, 4001),
substring(pk2, 1, 4), substring(pk2, 4001), pk3, key1, key2
from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
drop table t1;
#
# bug#2688 - Wrong index_merge query results for BDB table with variable length primary key
#
......
......@@ -4,10 +4,111 @@
# Test of flush table
#
#drop table if exists t1;
#create table t1 (a int not null auto_increment primary key);
#insert into t1 values(0);
#lock table t1 read;
#flush table t1;
#check table t1;
#drop table t1;
drop table if exists t1;
create table t1 (a int not null auto_increment primary key);
insert into t1 values(0);
lock table t1 read;
flush table t1;
check table t1;
drop table t1;
#
# Check if two database names beginning the same are seen as different.
#
# This database begins like the usual 'test' database.
#
--disable_warnings
drop database if exists test_test;
--enable_warnings
create database test_test;
use test_test;
create table t1(table_id char(20) primary key);
insert into t1 values ('test_test.t1');
insert into t1 values ('');
handler t1 open;
handler t1 read first limit 9;
create table t2(table_id char(20) primary key);
insert into t2 values ('test_test.t2');
insert into t2 values ('');
handler t2 open;
handler t2 read first limit 9;
#
# This is the usual 'test' database.
#
use test;
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1(table_id char(20) primary key);
insert into t1 values ('test.t1');
insert into t1 values ('');
handler t1 open;
handler t1 read first limit 9;
#
# Check accesibility of all the tables.
#
use test;
handler test.t1 read first limit 9;
--error 1109;
handler test.t2 read first limit 9;
handler test_test.t1 read first limit 9;
handler test_test.t2 read first limit 9;
#
# Cleanup.
#
handler test_test.t1 close;
drop table test_test.t1;
handler test_test.t2 close;
drop table test_test.t2;
drop database test_test;
#
use test;
handler test.t1 close;
drop table test.t1;
#
# In the following test FLUSH TABLES produces a deadlock
# (hang forever) if the fix for bug#3565 is missing.
#
--disable_warnings
drop table if exists t1;
drop table if exists t2;
--enable_warnings
create table t1(table_id char(20) primary key);
create table t2(table_id char(20) primary key);
insert into t1 values ('test.t1');
insert into t1 values ('');
insert into t2 values ('test.t2');
insert into t2 values ('');
handler t1 open as a1;
handler t1 open as a2;
handler t2 open;
handler a1 read first limit 9;
handler a2 read first limit 9;
handler t2 read first limit 9;
flush tables;
--error 1109;
handler a1 read first limit 9;
--error 1109;
handler a2 read first limit 9;
--error 1109;
handler t2 read first limit 9;
#
handler t1 open as a1;
handler t1 open as a2;
handler t2 open;
handler a1 read first limit 9;
handler a2 read first limit 9;
handler t2 read first limit 9;
flush table t1;
--error 1109;
handler a1 read first limit 9;
--error 1109;
handler a2 read first limit 9;
handler t2 read first limit 9;
flush table t2;
--error 1109;
handler t2 close;
drop table t1;
drop table t2;
......@@ -4167,6 +4167,42 @@ uint32 Field_blob::get_length(const char *pos)
}
/*
Put a blob length field into a record buffer.
SYNOPSIS
Field_blob::put_length()
pos Pointer into the record buffer.
length The length value to put.
DESCRIPTION
Depending on the maximum length of a blob, its length field is
put into 1 to 4 bytes. This is a property of the blob object,
described by 'packlength'.
RETURN
nothing
*/
void Field_blob::put_length(char *pos, uint32 length)
{
switch (packlength) {
case 1:
*pos= (char) length;
break;
case 2:
int2store(pos, length);
break;
case 3:
int3store(pos, length);
break;
case 4:
int4store(pos, length);
break;
}
}
void Field_blob::store(const char *from,uint len)
{
if (!len)
......@@ -4525,6 +4561,50 @@ char *Field_blob::pack_key(char *to, const char *from, uint max_length)
return to+length;
}
/*
Unpack a blob key into a record buffer.
SYNOPSIS
Field_blob::unpack_key()
to Pointer into the record buffer.
from Pointer to the packed key.
max_length Key length limit from key description.
DESCRIPTION
A blob key has a maximum size of 64K-1.
In its packed form, the length field is one or two bytes long,
depending on 'max_length'.
Depending on the maximum length of a blob, its length field is
put into 1 to 4 bytes. This is a property of the blob object,
described by 'packlength'.
Blobs are internally stored apart from the record buffer, which
contains a pointer to the blob buffer.
RETURN
Pointer into 'from' past the last byte copied from packed key.
*/
const char *Field_blob::unpack_key(char *to, const char *from, uint max_length)
{
/* get length of the blob key */
uint32 length= *((uchar*) from++);
if (max_length > 255)
length+= (*((uchar*) from++)) << 8;
/* put the length into the record buffer */
put_length(to, length);
/* put the address of the blob buffer or NULL */
if (length)
memcpy_fixed(to + packlength, &from, sizeof(from));
else
bzero(to + packlength, sizeof(from));
/* point to first byte of next field in 'from' */
return from + length;
}
/* Create a packed key that will be used for storage from a MySQL key */
char *Field_blob::pack_key_from_key_image(char *to, const char *from,
......
......@@ -189,6 +189,10 @@ public:
{
return pack(to,from,max_length);
}
virtual const char *unpack_key(char* to, const char *from, uint max_length)
{
return unpack(to,from);
}
virtual uint packed_col_length(const char *to, uint length)
{ return length;}
virtual uint max_packed_col_length(uint max_length)
......@@ -890,6 +894,7 @@ public:
inline uint32 get_length(uint row_offset=0)
{ return get_length(ptr+row_offset); }
uint32 get_length(const char *ptr);
void put_length(char *pos, uint32 length);
bool binary() const { return binary_flag; }
inline void get_ptr(char **str)
{
......@@ -923,6 +928,7 @@ public:
const char *unpack(char *to, const char *from);
char *pack_key(char *to, const char *from, uint max_length);
char *pack_key_from_key_image(char* to, const char *from, uint max_length);
const char *unpack_key(char* to, const char *from, uint max_length);
int pack_cmp(const char *a, const char *b, uint key_length);
int pack_cmp(const char *b, uint key_length);
uint packed_col_length(const char *col_ptr, uint length);
......
......@@ -720,8 +720,8 @@ void ha_berkeley::unpack_key(char *record, DBT *key, uint index)
}
record[key_part->null_offset]&= ~key_part->null_bit;
}
pos= (char*) key_part->field->unpack(record + key_part->field->offset(),
pos);
pos= (char*) key_part->field->unpack_key(record + key_part->field->offset(),
pos, key_part->length);
}
}
......
......@@ -538,8 +538,9 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
/* sql_handler.cc */
int mysql_ha_open(THD *thd, TABLE_LIST *tables);
int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok=0);
int mysql_ha_closeall(THD *thd, TABLE_LIST *tables);
int mysql_ha_close(THD *thd, TABLE_LIST *tables,
bool dont_send_ok=0, bool dont_lock=0, bool no_alias=0);
int mysql_ha_close_list(THD *thd, TABLE_LIST *tables, bool flushed=0);
int mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
......@@ -587,7 +588,6 @@ void free_io_cache(TABLE *entry);
void intern_close_table(TABLE *entry);
bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_thread_tables(THD *thd,bool locked=0);
bool close_thread_table(THD *thd, TABLE **table_ptr);
void close_temporary_tables(THD *thd);
TABLE **find_temporary_table(THD *thd, const char *db, const char *table_name);
bool close_temporary_table(THD *thd, const char *db, const char *table_name);
......
......@@ -389,6 +389,7 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
thd->proc_info="Flushing tables";
close_old_data_files(thd,thd->open_tables,1,1);
mysql_ha_close_list(thd, tables);
bool found=1;
/* Wait until all threads has closed all the tables we had locked */
DBUG_PRINT("info", ("Waiting for others threads to close their open tables"));
......@@ -857,6 +858,9 @@ TABLE *open_table(THD *thd,const char *db,const char *table_name,
DBUG_RETURN(0);
}
/* close handler tables which are marked for flush */
mysql_ha_close_list(thd, (TABLE_LIST*) NULL, /*flushed*/ 1);
for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ;
table && table->in_use ;
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
......@@ -1222,6 +1226,7 @@ bool wait_for_tables(THD *thd)
{
thd->some_tables_deleted=0;
close_old_data_files(thd,thd->open_tables,0,dropping_tables != 0);
mysql_ha_close_list(thd, (TABLE_LIST*) NULL, /*flushed*/ 1);
if (!table_is_used(thd->open_tables,1))
break;
(void) pthread_cond_wait(&COND_refresh,&LOCK_open);
......
......@@ -44,7 +44,9 @@
thd->handler_tables=tmp; }
static TABLE **find_table_ptr_by_name(THD *thd,const char *db,
const char *table_name, bool is_alias);
const char *table_name,
bool is_alias, bool dont_lock,
bool *was_flushed);
int mysql_ha_open(THD *thd, TABLE_LIST *tables)
{
......@@ -66,23 +68,59 @@ int mysql_ha_open(THD *thd, TABLE_LIST *tables)
return 0;
}
int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok)
/*
Close a HANDLER table.
SYNOPSIS
mysql_ha_close()
thd Thread identifier.
tables A list of tables with the first entry to close.
dont_send_ok Suppresses the commands' ok message and
error message and error return.
dont_lock Suppresses the normal locking of LOCK_open.
DESCRIPTION
Though this function takes a list of tables, only the first list entry
will be closed. Broadcasts a COND_refresh condition.
If mysql_ha_close() is not called from the parser, 'dont_send_ok'
must be set.
If the caller did already lock LOCK_open, it must set 'dont_lock'.
IMPLEMENTATION
find_table_ptr_by_name() closes the table, if a FLUSH TABLE is outstanding.
It returns a NULL pointer in this case, but flags the situation in
'was_flushed'. In that case the normal ER_UNKNOWN_TABLE error messages
is suppressed.
RETURN
0 ok
-1 error
*/
int mysql_ha_close(THD *thd, TABLE_LIST *tables,
bool dont_send_ok, bool dont_lock, bool no_alias)
{
TABLE **ptr=find_table_ptr_by_name(thd, tables->db, tables->alias, 1);
TABLE **table_ptr;
bool was_flushed;
if (*ptr)
table_ptr= find_table_ptr_by_name(thd, tables->db, tables->alias,
!no_alias, dont_lock, &was_flushed);
if (*table_ptr)
{
if (!dont_lock)
VOID(pthread_mutex_lock(&LOCK_open));
if (close_thread_table(thd, ptr))
if (close_thread_table(thd, table_ptr))
{
/* Tell threads waiting for refresh that something has happened */
VOID(pthread_cond_broadcast(&COND_refresh));
}
if (!dont_lock)
VOID(pthread_mutex_unlock(&LOCK_open));
}
else
else if (!was_flushed && !dont_send_ok)
{
my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0),
my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0),
tables->alias, "HANDLER");
return -1;
}
......@@ -91,14 +129,65 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok)
return 0;
}
int mysql_ha_closeall(THD *thd, TABLE_LIST *tables)
/*
Close a list of HANDLER tables.
SYNOPSIS
mysql_ha_close_list()
thd Thread identifier.
tables The list of tables to close. If NULL,
close all HANDLER tables.
flushed Close only tables which are marked flushed.
Used only if tables is NULL.
DESCRIPTION
The list of HANDLER tables may be NULL, in which case all HANDLER
tables are closed. Broadcasts a COND_refresh condition, for
every table closed. If 'tables' is NULL and 'flushed' is set,
all HANDLER tables marked for flush are closed.
The caller must lock LOCK_open.
IMPLEMENTATION
find_table_ptr_by_name() closes the table, if it is marked for flush.
It returns a NULL pointer in this case, but flags the situation in
'was_flushed'. In that case the normal ER_UNKNOWN_TABLE error messages
is suppressed.
RETURN
0 ok
*/
int mysql_ha_close_list(THD *thd, TABLE_LIST *tables, bool flushed)
{
TABLE **ptr=find_table_ptr_by_name(thd, tables->db, tables->real_name, 0);
if (*ptr && close_thread_table(thd, ptr))
TABLE_LIST *tl_item;
TABLE **table_ptr;
if (tables)
{
for (tl_item= tables ; tl_item; tl_item= tl_item->next)
{
mysql_ha_close(thd, tl_item, /*dont_send_ok*/ 1,
/*dont_lock*/ 1, /*no_alias*/ 1);
}
}
else
{
table_ptr= &(thd->handler_tables);
while (*table_ptr)
{
if (! flushed || ((*table_ptr)->version != refresh_version))
{
if (close_thread_table(thd, table_ptr))
{
/* Tell threads waiting for refresh that something has happened */
VOID(pthread_cond_broadcast(&COND_refresh));
}
continue;
}
table_ptr= &((*table_ptr)->next);
}
}
return 0;
}
......@@ -112,7 +201,10 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
ha_rows select_limit,ha_rows offset_limit)
{
int err, keyno=-1;
TABLE *table=*find_table_ptr_by_name(thd, tables->db, tables->alias, 1);
bool was_flushed;
TABLE *table= *find_table_ptr_by_name(thd, tables->db, tables->alias,
/*is_alias*/ 1, /*dont_lock*/ 0,
&was_flushed);
if (!table)
{
my_printf_error(ER_UNKNOWN_TABLE,ER(ER_UNKNOWN_TABLE),MYF(0),
......@@ -278,36 +370,76 @@ err0:
return -1;
}
/*
Find a HANDLER table by name.
SYNOPSIS
find_table_ptr_by_name()
thd Thread identifier.
db Database (schema) name.
table_name Table name ;-).
is_alias Table name may be an alias name.
dont_lock Suppresses the normal locking of LOCK_open.
DESCRIPTION
Find the table 'db'.'table_name' in the list of HANDLER tables of the
thread 'thd'. If the table has been marked by FLUSH TABLE(S), close it,
flag this situation in '*was_flushed' and broadcast a COND_refresh
condition.
An empty database (schema) name matches all database (schema) names.
If the caller did already lock LOCK_open, it must set 'dont_lock'.
IMPLEMENTATION
Just in case that the table is twice in 'thd->handler_tables' (!?!),
the loop does not break when the table was flushed. If another table
by that name was found and not flushed, '*was_flushed' is cleared again,
since a pointer to an open HANDLER table is returned.
RETURN
*was_flushed Table has been closed due to FLUSH TABLE.
NULL A HANDLER Table by that name does not exist (any more).
!= NULL Pointer to the TABLE structure.
*/
static TABLE **find_table_ptr_by_name(THD *thd, const char *db,
const char *table_name, bool is_alias)
const char *table_name,
bool is_alias, bool dont_lock,
bool *was_flushed)
{
int dblen;
TABLE **ptr;
TABLE **table_ptr;
DBUG_ASSERT(db);
dblen=*db ? strlen(db)+1 : 0;
ptr=&(thd->handler_tables);
dblen= *db ? strlen(db)+1 : 0;
table_ptr= &(thd->handler_tables);
*was_flushed= FALSE;
for (TABLE *table=*ptr; table ; table=*ptr)
for (TABLE *table=*table_ptr; table ; table=*table_ptr)
{
if ((!dblen || !memcmp(table->table_cache_key, db, dblen)) &&
!my_strcasecmp((is_alias ? table->table_name : table->real_name),table_name))
!my_strcasecmp((is_alias ? table->table_name : table->real_name),
table_name))
{
if (table->version != refresh_version)
{
if (!dont_lock)
VOID(pthread_mutex_lock(&LOCK_open));
if (close_thread_table(thd, ptr))
if (close_thread_table(thd, table_ptr))
{
/* Tell threads waiting for refresh that something has happened */
VOID(pthread_cond_broadcast(&COND_refresh));
}
if (!dont_lock)
VOID(pthread_mutex_unlock(&LOCK_open));
*was_flushed= TRUE;
continue;
}
*was_flushed= FALSE;
break;
}
ptr=&(table->next);
table_ptr=&(table->next);
}
return ptr;
return table_ptr;
}
......@@ -176,7 +176,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;
mysql_ha_closeall(thd, table);
mysql_ha_close(thd, table, /*dont_send_ok*/ 1, /*dont_lock*/ 1);
if (!close_temporary_table(thd, db, table->real_name))
{
tmp_table_deleted=1;
......@@ -1230,7 +1230,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
if (send_fields(thd, field_list, 1))
DBUG_RETURN(-1);
mysql_ha_closeall(thd, tables);
mysql_ha_close(thd, tables, /*dont_send_ok*/ 1, /*dont_lock*/ 1);
for (table = tables; table; table = table->next)
{
char table_name[NAME_LEN*2+2];
......@@ -1492,7 +1492,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
used_fields=create_info->used_fields;
mysql_ha_closeall(thd, table_list);
mysql_ha_close(thd, table_list, /*dont_send_ok*/ 1, /*dont_lock*/ 1);
if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ)))
DBUG_RETURN(-1);
......
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