Commit 5c9dee55 authored by joreland@mysql.com's avatar joreland@mysql.com

Merge mysql.com:/home/jonas/src/mysql-4.1

into mysql.com:/home/jonas/src/mysql-4.1-push
parents a5a13ea8 e23f2491
...@@ -3870,6 +3870,14 @@ int update_state_info(MI_CHECK *param, MI_INFO *info,uint update) ...@@ -3870,6 +3870,14 @@ int update_state_info(MI_CHECK *param, MI_INFO *info,uint update)
if (!share->state.create_time) if (!share->state.create_time)
share->state.create_time=share->state.check_time; share->state.create_time=share->state.check_time;
} }
/*
When tables are locked we haven't synched the share state and the
real state for a while so we better do it here before synching
the share state to disk. Only when table is write locked is it
necessary to perform this synch.
*/
if (info->lock_type == F_WRLCK)
share->state.state= *info->state;
if (mi_state_info_write(share->kfile,&share->state,1+2)) if (mi_state_info_write(share->kfile,&share->state,1+2))
goto err; goto err;
share->changed=0; share->changed=0;
......
...@@ -84,8 +84,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key, ...@@ -84,8 +84,7 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key,
pos= (byte*) record+keyseg->start; pos= (byte*) record+keyseg->start;
if (keyseg->flag & HA_SPACE_PACK) if (keyseg->flag & HA_SPACE_PACK)
{ {
FIX_LENGTH(cs, pos, length, char_length); end= pos + length;
end= pos + char_length;
if (type != HA_KEYTYPE_NUM) if (type != HA_KEYTYPE_NUM)
{ {
while (end > pos && end[-1] == ' ') while (end > pos && end[-1] == ' ')
...@@ -96,7 +95,8 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key, ...@@ -96,7 +95,8 @@ uint _mi_make_key(register MI_INFO *info, uint keynr, uchar *key,
while (pos < end && pos[0] == ' ') while (pos < end && pos[0] == ' ')
pos++; pos++;
} }
char_length= (uint) (end - pos); length=(uint) (end-pos);
FIX_LENGTH(cs, pos, length, char_length);
store_key_length_inc(key,char_length); store_key_length_inc(key,char_length);
memcpy((byte*) key,(byte*) pos,(size_t) char_length); memcpy((byte*) key,(byte*) pos,(size_t) char_length);
key+=char_length; key+=char_length;
......
...@@ -68,8 +68,8 @@ int mi_rnext_same(MI_INFO *info, byte *buf) ...@@ -68,8 +68,8 @@ int mi_rnext_same(MI_INFO *info, byte *buf)
info->lastkey_length,SEARCH_BIGGER, info->lastkey_length,SEARCH_BIGGER,
info->s->state.key_root[inx]))) info->s->state.key_root[inx])))
break; break;
if (ha_key_cmp(keyinfo->seg,info->lastkey2,info->lastkey, if (ha_key_cmp(keyinfo->seg, info->lastkey, info->lastkey2,
info->last_rkey_length, SEARCH_FIND, &not_used)) info->last_rkey_length, SEARCH_FIND, &not_used))
{ {
error=1; error=1;
my_errno=HA_ERR_END_OF_FILE; my_errno=HA_ERR_END_OF_FILE;
......
create table t1 (a bigint);
lock tables t1 write;
insert into t1 values(0);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
unlock tables;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
create table t1 (a bigint);
insert into t1 values(0);
lock tables t1 write;
delete from t1;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
unlock tables;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
create table t1 (a bigint);
insert into t1 values(0);
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
...@@ -901,4 +901,7 @@ insert into t1 values (2,'Durban'); ...@@ -901,4 +901,7 @@ insert into t1 values (2,'Durban');
select * from t1 where city = 'Durban'; select * from t1 where city = 'Durban';
id city id city
2 Durban 2 Durban
select * from t1 where city = 'Durban ';
id city
2 Durban
drop table t1; drop table t1;
...@@ -132,6 +132,22 @@ a b ...@@ -132,6 +132,22 @@ a b
handler t2 read last; handler t2 read last;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
handler t2 close; handler t2 close;
handler t1 open;
handler t1 read a next;
a b
14 aaa
handler t1 read a next;
a b
15 bbb
handler t1 close;
handler t1 open;
handler t1 read a prev;
a b
22 iii
handler t1 read a prev;
a b
21 hhh
handler t1 close;
handler t1 open as t2; handler t1 open as t2;
handler t2 read first; handler t2 read first;
a b a b
......
...@@ -468,13 +468,13 @@ execute stmt1; ...@@ -468,13 +468,13 @@ execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 3 N 1 31 8 def type 253 10 3 Y 0 31 8
def possible_keys 253 4096 0 Y 0 31 8 def possible_keys 253 4096 0 Y 0 31 8
def key 253 64 0 Y 0 31 8 def key 253 64 0 Y 0 31 8
def key_len 8 3 0 Y 32928 0 63 def key_len 8 3 0 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 14 N 1 31 8 def Extra 253 255 14 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort
...@@ -484,13 +484,13 @@ execute stmt1 using @arg00; ...@@ -484,13 +484,13 @@ execute stmt1 using @arg00;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 5 N 1 31 8 def type 253 10 5 Y 0 31 8
def possible_keys 253 4096 7 Y 0 31 8 def possible_keys 253 4096 7 Y 0 31 8
def key 253 64 7 Y 0 31 8 def key 253 64 7 Y 0 31 8
def key_len 8 3 1 Y 32928 0 63 def key_len 8 3 1 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 27 N 1 31 8 def Extra 253 255 27 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where; Using filesort 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where; Using filesort
......
...@@ -1151,13 +1151,13 @@ execute stmt1; ...@@ -1151,13 +1151,13 @@ execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 3 N 1 31 8 def type 253 10 3 Y 0 31 8
def possible_keys 253 4096 0 Y 0 31 8 def possible_keys 253 4096 0 Y 0 31 8
def key 253 64 0 Y 0 31 8 def key 253 64 0 Y 0 31 8
def key_len 8 3 0 Y 32928 0 63 def key_len 8 3 0 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 0 N 1 31 8 def Extra 253 255 0 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t9 ALL NULL NULL NULL NULL 2 1 SIMPLE t9 ALL NULL NULL NULL NULL 2
......
...@@ -1151,13 +1151,13 @@ execute stmt1; ...@@ -1151,13 +1151,13 @@ execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 3 N 1 31 8 def type 253 10 3 Y 0 31 8
def possible_keys 253 4096 0 Y 0 31 8 def possible_keys 253 4096 0 Y 0 31 8
def key 253 64 0 Y 0 31 8 def key 253 64 0 Y 0 31 8
def key_len 8 3 0 Y 32928 0 63 def key_len 8 3 0 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 0 N 1 31 8 def Extra 253 255 0 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t9 ALL NULL NULL NULL NULL 2 1 SIMPLE t9 ALL NULL NULL NULL NULL 2
......
...@@ -1152,13 +1152,13 @@ execute stmt1; ...@@ -1152,13 +1152,13 @@ execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 3 N 1 31 8 def type 253 10 3 Y 0 31 8
def possible_keys 253 4096 0 Y 0 31 8 def possible_keys 253 4096 0 Y 0 31 8
def key 253 64 0 Y 0 31 8 def key 253 64 0 Y 0 31 8
def key_len 8 3 0 Y 32928 0 63 def key_len 8 3 0 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 0 N 1 31 8 def Extra 253 255 0 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t9 ALL NULL NULL NULL NULL 2 1 SIMPLE t9 ALL NULL NULL NULL NULL 2
......
...@@ -1194,13 +1194,13 @@ execute stmt1; ...@@ -1194,13 +1194,13 @@ execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 3 N 1 31 8 def type 253 10 3 Y 0 31 8
def possible_keys 253 4096 0 Y 0 31 8 def possible_keys 253 4096 0 Y 0 31 8
def key 253 64 0 Y 0 31 8 def key 253 64 0 Y 0 31 8
def key_len 8 3 0 Y 32928 0 63 def key_len 8 3 0 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 0 N 1 31 8 def Extra 253 255 0 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t9 ALL NULL NULL NULL NULL 2 1 SIMPLE t9 ALL NULL NULL NULL NULL 2
...@@ -4208,13 +4208,13 @@ execute stmt1; ...@@ -4208,13 +4208,13 @@ execute stmt1;
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def id 8 3 1 N 32929 0 63 def id 8 3 1 N 32929 0 63
def select_type 253 19 6 N 1 31 8 def select_type 253 19 6 N 1 31 8
def table 253 64 2 N 1 31 8 def table 253 64 2 Y 0 31 8
def type 253 10 3 N 1 31 8 def type 253 10 3 Y 0 31 8
def possible_keys 253 4096 0 Y 0 31 8 def possible_keys 253 4096 0 Y 0 31 8
def key 253 64 0 Y 0 31 8 def key 253 64 0 Y 0 31 8
def key_len 8 3 0 Y 32928 0 63 def key_len 8 3 0 Y 32928 0 63
def ref 253 1024 0 Y 0 31 8 def ref 253 1024 0 Y 0 31 8
def rows 8 10 1 N 32929 0 63 def rows 8 10 1 Y 32928 0 63
def Extra 253 255 0 N 1 31 8 def Extra 253 255 0 N 1 31 8
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t9 ALL NULL NULL NULL NULL 2 1 SIMPLE t9 ALL NULL NULL NULL NULL 2
......
#
# Bug #10901 Analyze Table on new table destroys table
# This is minimal test case to get error
# The problem was that analyze table wrote the shared state to the file and this
# didn't include the inserts while locked. A check was needed to ensure that
# state information was not updated when executing analyze table for a locked table.
# The analyze table had to be within locks and check table had to be after unlocking
# since then it brings the wrong state from disk rather than from the currently
# correct internal state. The insert is needed since it changes the file state,
# number of records.
# The fix is to synchronise the state of the shared state and the current state before
# calling mi_state_info_write
#
create table t1 (a bigint);
lock tables t1 write;
insert into t1 values(0);
analyze table t1;
unlock tables;
check table t1;
drop table t1;
create table t1 (a bigint);
insert into t1 values(0);
lock tables t1 write;
delete from t1;
analyze table t1;
unlock tables;
check table t1;
drop table t1;
create table t1 (a bigint);
insert into t1 values(0);
analyze table t1;
check table t1;
drop table t1;
...@@ -744,4 +744,5 @@ create table t1 ( ...@@ -744,4 +744,5 @@ create table t1 (
insert into t1 values (1,'Durban North'); insert into t1 values (1,'Durban North');
insert into t1 values (2,'Durban'); insert into t1 values (2,'Durban');
select * from t1 where city = 'Durban'; select * from t1 where city = 'Durban';
select * from t1 where city = 'Durban ';
drop table t1; drop table t1;
...@@ -69,6 +69,16 @@ handler t2 read next; ...@@ -69,6 +69,16 @@ handler t2 read next;
handler t2 read last; handler t2 read last;
handler t2 close; handler t2 close;
handler t1 open;
handler t1 read a next; # this used to crash as a bug#5373
handler t1 read a next;
handler t1 close;
handler t1 open;
handler t1 read a prev; # this used to crash as a bug#5373
handler t1 read a prev;
handler t1 close;
handler t1 open as t2; handler t1 open as t2;
handler t2 read first; handler t2 read first;
alter table t1 engine=innodb; alter table t1 engine=innodb;
......
...@@ -158,32 +158,52 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) ...@@ -158,32 +158,52 @@ FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
DBUG_RETURN(fd); DBUG_RETURN(fd);
} /* my_fdopen */ } /* my_fdopen */
/*
make_ftype
Make a filehandler-open-typestring from ordinary inputflags
/* Make a filehandler-open-typestring from ordinary inputflags */ Note: This routine attempts to find the best possible match
between a numeric option and a string option that could be
fed to fopen. There is not a 1 to 1 mapping between the two.
r == O_RDONLY
w == O_WRONLY|O_TRUNC|O_CREAT
a == O_WRONLY|O_APPEND|O_CREAT
r+ == O_RDWR
w+ == O_RDWR|O_TRUNC|O_CREAT
a+ == O_RDWR|O_APPEND|O_CREAT
*/
static void make_ftype(register my_string to, register int flag) static void make_ftype(register my_string to, register int flag)
{ {
#if FILE_BINARY /* If we have binary-files */ #if FILE_BINARY
/* If we have binary-files */
reg3 int org_flag=flag; reg3 int org_flag=flag;
#endif #endif
flag&= ~FILE_BINARY; /* remove binary bit */ flag&= ~FILE_BINARY; /* remove binary bit */
if (flag == O_RDONLY)
*to++= 'r'; /* check some possible invalid combinations */
else if (flag == O_WRONLY) DBUG_ASSERT(flag & (O_TRUNC|O_APPEND) != O_TRUNC|O_APPEND);
*to++= 'w';
else if (flag & (O_RDONLY|O_WRONLY) == O_WRONLY)
{ /* Add '+' after theese */ *to++= (flag & O_TRUNC) ? 'w' : 'a';
if (flag == O_RDWR) else if (flag & O_RDWR)
{
/* Add '+' after theese */
if (flag & O_TRUNC)
*to++= 'w';
else if (flag & O_APPEND)
*to++= 'a';
else
*to++= 'r'; *to++= 'r';
else if (flag & O_APPEND) *to++= '+';
*to++= 'a'; }
else else
*to++= 'w'; /* Create file */ *to++= 'r';
*to++= '+';
} #if FILE_BINARY /* If we have binary-files */
#if FILE_BINARY /* If we have binary-files */ if (org_flag & FILE_BINARY)
if (org_flag & FILE_BINARY)
*to++='b'; *to++='b';
#endif #endif
*to='\0'; *to='\0';
} /* make_ftype */ } /* make_ftype */
...@@ -198,7 +198,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables) ...@@ -198,7 +198,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
ACL_HOST host; ACL_HOST host;
update_hostname(&host.host,get_field(&mem, table->field[0])); update_hostname(&host.host,get_field(&mem, table->field[0]));
host.db= get_field(&mem, table->field[1]); host.db= get_field(&mem, table->field[1]);
if (lower_case_table_names) if (lower_case_table_names && host.db)
{ {
/* /*
We make a temporary copy of the database, force it to lower case, We make a temporary copy of the database, force it to lower case,
...@@ -222,7 +222,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables) ...@@ -222,7 +222,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
{ {
sql_print_warning("'host' entry '%s|%s' " sql_print_warning("'host' entry '%s|%s' "
"ignored in --skip-name-resolve mode.", "ignored in --skip-name-resolve mode.",
host.host.hostname, host.db, host.host.hostname); host.host.hostname, host.db?host.db:"");
continue; continue;
} }
#ifndef TO_BE_REMOVED #ifndef TO_BE_REMOVED
...@@ -290,7 +290,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables) ...@@ -290,7 +290,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
{ {
sql_print_warning("'user' entry '%s@%s' " sql_print_warning("'user' entry '%s@%s' "
"ignored in --skip-name-resolve mode.", "ignored in --skip-name-resolve mode.",
user.user, user.host.hostname, user.host.hostname); user.user, user.host.hostname);
continue; continue;
} }
...@@ -393,7 +393,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables) ...@@ -393,7 +393,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables)
{ {
sql_print_warning("'db' entry '%s %s@%s' " sql_print_warning("'db' entry '%s %s@%s' "
"ignored in --skip-name-resolve mode.", "ignored in --skip-name-resolve mode.",
db.db, db.user, db.host.hostname, db.host.hostname); db.db, db.user, db.host.hostname);
continue; continue;
} }
db.access=get_access(table,3); db.access=get_access(table,3);
...@@ -2690,7 +2690,7 @@ my_bool grant_init(THD *org_thd) ...@@ -2690,7 +2690,7 @@ my_bool grant_init(THD *org_thd)
sql_print_warning("'tables_priv' entry '%s %s@%s' " sql_print_warning("'tables_priv' entry '%s %s@%s' "
"ignored in --skip-name-resolve mode.", "ignored in --skip-name-resolve mode.",
mem_check->tname, mem_check->user, mem_check->tname, mem_check->user,
mem_check->host, mem_check->host); mem_check->host);
continue; continue;
} }
} }
......
...@@ -667,8 +667,10 @@ int THD::send_explain_fields(select_result *result) ...@@ -667,8 +667,10 @@ int THD::send_explain_fields(select_result *result)
CHARSET_INFO *cs= system_charset_info; CHARSET_INFO *cs= system_charset_info;
field_list.push_back(new Item_return_int("id",3, MYSQL_TYPE_LONGLONG)); field_list.push_back(new Item_return_int("id",3, MYSQL_TYPE_LONGLONG));
field_list.push_back(new Item_empty_string("select_type", 19, cs)); field_list.push_back(new Item_empty_string("select_type", 19, cs));
field_list.push_back(new Item_empty_string("table", NAME_LEN, cs)); field_list.push_back(item= new Item_empty_string("table", NAME_LEN, cs));
field_list.push_back(new Item_empty_string("type", 10, cs)); item->maybe_null= 1;
field_list.push_back(item= new Item_empty_string("type", 10, cs));
item->maybe_null= 1;
field_list.push_back(item=new Item_empty_string("possible_keys", field_list.push_back(item=new Item_empty_string("possible_keys",
NAME_LEN*MAX_KEY, cs)); NAME_LEN*MAX_KEY, cs));
item->maybe_null=1; item->maybe_null=1;
...@@ -680,7 +682,9 @@ int THD::send_explain_fields(select_result *result) ...@@ -680,7 +682,9 @@ int THD::send_explain_fields(select_result *result)
field_list.push_back(item=new Item_empty_string("ref", field_list.push_back(item=new Item_empty_string("ref",
NAME_LEN*MAX_REF_PARTS, cs)); NAME_LEN*MAX_REF_PARTS, cs));
item->maybe_null=1; item->maybe_null=1;
field_list.push_back(new Item_return_int("rows", 10, MYSQL_TYPE_LONGLONG)); field_list.push_back(item= new Item_return_int("rows", 10,
MYSQL_TYPE_LONGLONG));
item->maybe_null= 1;
field_list.push_back(new Item_empty_string("Extra", 255, cs)); field_list.push_back(new Item_empty_string("Extra", 255, cs));
return (result->send_fields(field_list,1)); return (result->send_fields(field_list,1));
} }
......
...@@ -429,12 +429,10 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -429,12 +429,10 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
} }
tables->table=table; tables->table=table;
if (cond && ((!cond->fixed && if (cond && ((!cond->fixed &&
cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1))) cond->fix_fields(thd, tables, &cond)) || cond->check_cols(1)))
goto err0; goto err0;
table->file->init_table_handle_for_HANDLER(); // Only InnoDB requires it
if (keyname) if (keyname)
{ {
if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0) if ((keyno=find_type(keyname, &table->keynames, 1+2)-1)<0)
...@@ -443,8 +441,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -443,8 +441,6 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
keyname,tables->alias); keyname,tables->alias);
goto err0; goto err0;
} }
table->file->ha_index_or_rnd_end();
table->file->ha_index_init(keyno);
} }
if (insert_fields(thd,tables,tables->db,tables->alias,&it)) if (insert_fields(thd,tables,tables->db,tables->alias,&it))
...@@ -471,9 +467,22 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -471,9 +467,22 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
for (num_rows=0; num_rows < select_limit; ) for (num_rows=0; num_rows < select_limit; )
{ {
switch (mode) { switch (mode) {
case RNEXT:
if (table->file->inited != handler::NONE)
{
err=keyname ?
table->file->index_next(table->record[0]) :
table->file->rnd_next(table->record[0]);
break;
}
/* else fall through */
case RFIRST: case RFIRST:
if (keyname) if (keyname)
{
table->file->ha_index_or_rnd_end();
table->file->ha_index_init(keyno);
err=table->file->index_first(table->record[0]); err=table->file->index_first(table->record[0]);
}
else else
{ {
table->file->ha_index_or_rnd_end(); table->file->ha_index_or_rnd_end();
...@@ -482,20 +491,21 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -482,20 +491,21 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
} }
mode=RNEXT; mode=RNEXT;
break; break;
case RPREV:
DBUG_ASSERT(keyname != 0);
if (table->file->inited != handler::NONE)
{
err=table->file->index_prev(table->record[0]);
break;
}
/* else fall through */
case RLAST: case RLAST:
DBUG_ASSERT(keyname != 0); DBUG_ASSERT(keyname != 0);
table->file->ha_index_or_rnd_end();
table->file->ha_index_init(keyno);
err=table->file->index_last(table->record[0]); err=table->file->index_last(table->record[0]);
mode=RPREV; mode=RPREV;
break; break;
case RNEXT:
err=keyname ?
table->file->index_next(table->record[0]) :
table->file->rnd_next(table->record[0]);
break;
case RPREV:
DBUG_ASSERT(keyname != 0);
err=table->file->index_prev(table->record[0]);
break;
case RNEXT_SAME: case RNEXT_SAME:
/* Continue scan on "(keypart1,keypart2,...)=(c1, c2, ...) */ /* Continue scan on "(keypart1,keypart2,...)=(c1, c2, ...) */
DBUG_ASSERT(keyname != 0); DBUG_ASSERT(keyname != 0);
...@@ -517,7 +527,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -517,7 +527,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
for (key_len=0 ; (item=it_ke++) ; key_part++) for (key_len=0 ; (item=it_ke++) ; key_part++)
{ {
// 'item' can be changed by fix_fields() call // 'item' can be changed by fix_fields() call
if ((!item->fixed && if ((!item->fixed &&
item->fix_fields(thd, tables, it_ke.ref())) || item->fix_fields(thd, tables, it_ke.ref())) ||
(item= *it_ke.ref())->check_cols(1)) (item= *it_ke.ref())->check_cols(1))
goto err; goto err;
...@@ -535,6 +545,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -535,6 +545,8 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
goto err; goto err;
} }
key_copy(key, table, keyno, key_len); key_copy(key, table, keyno, key_len);
table->file->ha_index_or_rnd_end();
table->file->ha_index_init(keyno);
err=table->file->index_read(table->record[0], err=table->file->index_read(table->record[0],
key,key_len,ha_rkey_mode); key,key_len,ha_rkey_mode);
mode=rkey_to_rnext[(int)ha_rkey_mode]; mode=rkey_to_rnext[(int)ha_rkey_mode];
......
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