Merge bk-internal.mysql.com:/home/bk/mysql-5.1

into  mysql.com:/home/my/mysql-5.1


mysql-test/extra/rpl_tests/rpl_log.test:
  Auto merged
mysql-test/r/rpl_ndb_log.result:
  Auto merged
mysql-test/r/rpl_row_log.result:
  Auto merged
mysql-test/r/rpl_row_log_innodb.result:
  Auto merged
sql/ha_ndbcluster.cc:
  Auto merged
sql/log_event.cc:
  Auto merged
sql/sql_class.cc:
  Auto merged
sql/sql_class.h:
  Auto merged
sql/sql_lex.cc:
  Auto merged
sql/sql_parse.cc:
  Auto merged
sql/sql_show.cc:
  Auto merged
sql/mysql_priv.h:
  SCCS merged
This commit is contained in:
unknown 2006-06-22 12:21:41 +03:00
commit 0f9ec6d6e8
40 changed files with 546 additions and 321 deletions

View File

@ -547,7 +547,6 @@ extern File my_open(const char *FileName,int Flags,myf MyFlags);
extern File my_register_filename(File fd, const char *FileName,
enum file_type type_of_file,
uint error_message_number, myf MyFlags);
extern void my_print_open_files(void);
extern File my_create(const char *FileName,int CreateFlags,
int AccessFlags, myf MyFlags);
extern int my_close(File Filedes,myf MyFlags);
@ -638,7 +637,7 @@ extern void allow_break(void);
#endif
#ifdef EXTRA_DEBUG
void my_print_open_files();
void my_print_open_files(void);
#else
#define my_print_open_files()
#endif
@ -672,13 +671,15 @@ extern my_string my_path(my_string to,const char *progname,
const char *own_pathname_part);
extern my_string my_load_path(my_string to, const char *path,
const char *own_path_prefix);
extern int wild_compare(const char *str,const char *wildstr,pbool str_is_pattern);
extern int wild_compare(const char *str,const char *wildstr,
pbool str_is_pattern);
extern WF_PACK *wf_comp(my_string str);
extern int wf_test(struct wild_file_pack *wf_pack,const char *name);
extern void wf_end(struct wild_file_pack *buffer);
extern size_s strip_sp(my_string str);
extern void get_date(my_string to,int timeflag,time_t use_time);
extern void soundex(CHARSET_INFO *, my_string out_pntr, my_string in_pntr,pbool remove_garbage);
extern void soundex(CHARSET_INFO *, my_string out_pntr, my_string in_pntr,
pbool remove_garbage);
extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file,
uint reclength,enum cache_type type,
pbool use_async_io);

View File

@ -60,7 +60,7 @@ Variable_name Value
Qcache_hits 0
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 5
Qcache_not_cached 0
select "user1";
user1
user1
@ -72,7 +72,7 @@ Variable_name Value
Qcache_hits 0
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 9
Qcache_not_cached 1
select * from t1;
a b c
1 1 1
@ -85,7 +85,7 @@ Variable_name Value
Qcache_hits 1
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 12
Qcache_not_cached 1
select a from t1 ;
a
1
@ -98,7 +98,7 @@ Variable_name Value
Qcache_hits 2
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 15
Qcache_not_cached 1
select c from t1;
c
1
@ -111,7 +111,7 @@ Variable_name Value
Qcache_hits 3
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 18
Qcache_not_cached 1
show grants for current_user();
Grants for @localhost
GRANT USAGE ON *.* TO ''@'localhost'
@ -144,7 +144,7 @@ Variable_name Value
Qcache_hits 7
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 22
Qcache_not_cached 2
select "user3";
user3
user3
@ -168,7 +168,7 @@ Variable_name Value
Qcache_hits 7
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 30
Qcache_not_cached 7
select "user4";
user4
user4
@ -198,7 +198,7 @@ Variable_name Value
Qcache_hits 8
show status like "Qcache_not_cached";
Variable_name Value
Qcache_not_cached 34
Qcache_not_cached 8
set names binary;
delete from mysql.user where user in ("mysqltest_1","mysqltest_2","mysqltest_3");
delete from mysql.db where user in ("mysqltest_1","mysqltest_2","mysqltest_3");

View File

@ -199,6 +199,8 @@ select table_name, column_name, privileges from information_schema.columns
where table_schema = 'mysqltest' and table_name = 'v1';
table_name column_name privileges
v1 c select
explain select * from v1;
ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table
drop view v1, mysqltest.v1;
drop tables mysqltest.t4, mysqltest.t1, t2, t3, t5;
drop database mysqltest;

View File

@ -1050,6 +1050,7 @@ Qcache_hits 1
drop table t1;
create table t1 (a int);
insert into t1 values (1),(2);
drop procedure if exists p1;
CREATE PROCEDURE `p1`()
begin
Declare c1 cursor for select a from t1;

View File

@ -23,6 +23,32 @@ select 1;
show status like 'last_query_cost';
Variable_name Value
Last_query_cost 0.000000
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
select * from t1 where a=6;
a
6
6
6
6
6
show status like 'last_query_cost';
Variable_name Value
Last_query_cost 12.084449
show status like 'last_query_cost';
Variable_name Value
Last_query_cost 12.084449
select 1;
1
1
show status like 'last_query_cost';
Variable_name Value
Last_query_cost 0.000000
drop table t1;
FLUSH STATUS;
SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
@ -43,3 +69,27 @@ SHOW STATUS LIKE 'max_used_connections';
Variable_name Value
Max_used_connections 5
SET GLOBAL thread_cache_size=@save_thread_cache_size;
show status like 'com_show_status';
Variable_name Value
Com_show_status 3
show status like 'hand%write%';
Variable_name Value
Handler_write 0
show status like '%tmp%';
Variable_name Value
Created_tmp_disk_tables 0
Created_tmp_files 0
Created_tmp_tables 0
show status like 'hand%write%';
Variable_name Value
Handler_write 0
show status like '%tmp%';
Variable_name Value
Created_tmp_disk_tables 0
Created_tmp_files 0
Created_tmp_tables 0
show status like 'com_show_status';
Variable_name Value
Com_show_status 8
rnd_diff tmp_table_diff
20 8

View File

@ -98,7 +98,7 @@ d
show status like "created_tmp%tables";
Variable_name Value
Created_tmp_disk_tables 0
Created_tmp_tables 2
Created_tmp_tables 1
drop table t1;
create temporary table v1 as select 'This is temp. table' A;
create view v1 as select 'This is view' A;

View File

@ -836,27 +836,27 @@ count(*)
26
show status like 'Slow_queries';
Variable_name Value
Slow_queries 1
Slow_queries 0
select count(*) from t1 where b=13;
count(*)
10
show status like 'Slow_queries';
Variable_name Value
Slow_queries 3
Slow_queries 1
select count(*) from t1 where b=13 union select count(*) from t1 where a=7;
count(*)
10
26
show status like 'Slow_queries';
Variable_name Value
Slow_queries 5
Slow_queries 2
select count(*) from t1 where a=7 union select count(*) from t1 where b=13;
count(*)
26
10
show status like 'Slow_queries';
Variable_name Value
Slow_queries 7
Slow_queries 3
flush status;
select a from t1 where b not in (1,2,3) union select a from t1 where b not in (4,5,6);
a

View File

@ -1,4 +1,7 @@
--disable_warnings
create database if not exists events_test;
--enable_warnings
use events_test;
--error ER_NOT_SUPPORTED_YET

View File

@ -80,6 +80,8 @@ connect (user4,localhost,mysqltest_3,,mysqltest);
connection user4;
select table_name, column_name, privileges from information_schema.columns
where table_schema = 'mysqltest' and table_name = 'v1';
--error 1345
explain select * from v1;
connection default;
drop view v1, mysqltest.v1;

View File

@ -765,6 +765,9 @@ drop table t1;
create table t1 (a int);
insert into t1 values (1),(2);
--disable_warnings
drop procedure if exists p1;
--enable_warnings
delimiter //;
CREATE PROCEDURE `p1`()
begin

View File

@ -48,6 +48,19 @@ connection default;
select 1;
show status like 'last_query_cost';
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
select * from t1 where a=6;
show status like 'last_query_cost';
# Ensure value dosn't change by second status call
show status like 'last_query_cost';
select 1;
show status like 'last_query_cost';
drop table t1;
#
# Test for Bug #15933 max_used_connections is wrong after FLUSH STATUS
@ -144,3 +157,24 @@ disconnect con2;
disconnect con1;
# End of 5.0 tests
#
# Ensure that SHOW STATUS only changes global status variables
#
connect (con1,localhost,root,,);
let $rnd_next = `show global status like 'handler_read_rnd_next'`;
let $tmp_table = `show global status like 'Created_tmp_tables'`;
show status like 'com_show_status';
show status like 'hand%write%';
show status like '%tmp%';
show status like 'hand%write%';
show status like '%tmp%';
show status like 'com_show_status';
let $rnd_next2 = `show global status like 'handler_read_rnd_next'`;
let $tmp_table2 = `show global status like 'Created_tmp_tables'`;
--disable_query_log
eval select substring_index('$rnd_next2',0x9,-1)-substring_index('$rnd_next',0x9,-1) as rnd_diff, substring_index('$tmp_table2',0x9,-1)-substring_index('$tmp_table',0x9,-1) as tmp_table_diff;
--enable_query_log
# End of 5.1 tests

View File

@ -470,8 +470,10 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
uint age_threshold)
{
int blocks;
#ifdef THREAD
struct st_my_thread_var *thread;
KEYCACHE_WQUEUE *wqueue;
#endif
DBUG_ENTER("resize_key_cache");
if (!keycache->key_cache_inited)
@ -1102,8 +1104,12 @@ static void unreg_request(KEY_CACHE *keycache,
static inline void remove_reader(BLOCK_LINK *block)
{
#ifdef THREAD
if (! --block->hash_link->requests && block->condvar)
keycache_pthread_cond_signal(block->condvar);
#else
--block->hash_link->requests;
#endif
}
@ -1112,7 +1118,8 @@ static inline void remove_reader(BLOCK_LINK *block)
signals on its termination
*/
static inline void wait_for_readers(KEY_CACHE *keycache, BLOCK_LINK *block)
static inline void wait_for_readers(KEY_CACHE *keycache __attribute__((unused)),
BLOCK_LINK *block)
{
#ifdef THREAD
struct st_my_thread_var *thread= my_thread_var;
@ -1209,7 +1216,6 @@ static HASH_LINK *get_hash_link(KEY_CACHE *keycache,
int file, my_off_t filepos)
{
reg1 HASH_LINK *hash_link, **start;
KEYCACHE_PAGE page;
#if defined(KEYCACHE_DEBUG)
int cnt;
#endif
@ -1264,6 +1270,7 @@ restart:
#ifdef THREAD
/* Wait for a free hash link */
struct st_my_thread_var *thread= my_thread_var;
KEYCACHE_PAGE page;
KEYCACHE_DBUG_PRINT("get_hash_link", ("waiting"));
page.file= file;
page.filepos= filepos;
@ -1588,8 +1595,10 @@ restart:
/* Remove the hash link for this page from the hash table */
unlink_hash(keycache, block->hash_link);
/* All pending requests for this page must be resubmitted */
#ifdef THREAD
if (block->wqueue[COND_FOR_SAVED].last_thread)
release_queue(&block->wqueue[COND_FOR_SAVED]);
#endif
}
link_to_file_list(keycache, block, file,
(my_bool)(block->hash_link ? 1 : 0));
@ -1669,7 +1678,7 @@ restart:
portion is less than read_length, but not less than min_length.
*/
static void read_block(KEY_CACHE *keycache,
static void read_block(KEY_CACHE *keycache __attribute__((unused)),
BLOCK_LINK *block, uint read_length,
uint min_length, my_bool primary)
{
@ -1707,8 +1716,10 @@ static void read_block(KEY_CACHE *keycache,
KEYCACHE_DBUG_PRINT("read_block",
("primary request: new page in cache"));
/* Signal that all pending requests for this page now can be processed */
#ifdef THREAD
if (block->wqueue[COND_FOR_REQUESTED].last_thread)
release_queue(&block->wqueue[COND_FOR_REQUESTED]);
#endif
}
else
{
@ -1973,9 +1984,11 @@ int key_cache_insert(KEY_CACHE *keycache,
block->length= read_length+offset;
KEYCACHE_DBUG_PRINT("key_cache_insert",
("primary request: new page in cache"));
#ifdef THREAD
/* Signal that all pending requests for this now can be processed. */
if (block->wqueue[COND_FOR_REQUESTED].last_thread)
release_queue(&block->wqueue[COND_FOR_REQUESTED]);
#endif
}
remove_reader(block);
@ -2219,9 +2232,11 @@ static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block)
/* Keep track of the number of currently unused blocks. */
keycache->blocks_unused++;
#ifdef THREAD
/* All pending requests for this page must be resubmitted. */
if (block->wqueue[COND_FOR_SAVED].last_thread)
release_queue(&block->wqueue[COND_FOR_SAVED]);
#endif
}
@ -2275,12 +2290,14 @@ static int flush_cached_blocks(KEY_CACHE *keycache,
if (!last_errno)
last_errno= errno ? errno : -1;
}
#ifdef THREAD
/*
Let to proceed for possible waiting requests to write to the block page.
It might happen only during an operation to resize the key cache.
*/
if (block->wqueue[COND_FOR_SAVED].last_thread)
release_queue(&block->wqueue[COND_FOR_SAVED]);
#endif
/* type will never be FLUSH_IGNORE_CHANGED here */
if (! (type == FLUSH_KEEP || type == FLUSH_FORCE_WRITE))
{

View File

@ -53,8 +53,10 @@ static struct my_err_head
int meh_first; /* error number matching array slot 0 */
int meh_last; /* error number matching last slot */
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST};
static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
/*
Error message to user
@ -76,7 +78,6 @@ int my_error(int nr, myf MyFlags, ...)
va_list args;
char ebuff[ERRMSGSIZE + 20];
DBUG_ENTER("my_error");
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno));
/* Search for the error messages array, which could contain the message. */
@ -102,6 +103,7 @@ int my_error(int nr, myf MyFlags, ...)
DBUG_RETURN((*error_handler_hook)(nr, ebuff, MyFlags));
}
/*
Error as printf

View File

@ -1,4 +1,21 @@
#include "my_base.h"
/* Copyright (C) 2000 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <my_global.h>
#include <m_string.h>
/*
my_memmem, port of a GNU extension.

View File

@ -205,8 +205,8 @@ LEX_STRING interval_type_to_name[] = {
int sortcmp_lex_string(LEX_STRING s, LEX_STRING t, CHARSET_INFO *cs)
{
return cs->coll->strnncollsp(cs, (unsigned char *) s.str,s.length,
(unsigned char *) t.str,t.length, 0);
return cs->coll->strnncollsp(cs, (uchar *) s.str,s.length,
(uchar *) t.str,t.length, 0);
}

View File

@ -5212,7 +5212,7 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
else if (nr > 1900)
nr-= 1900;
}
*ptr= (char) (unsigned char) nr;
*ptr= (char) (uchar) nr;
return error;
}
@ -5244,7 +5244,7 @@ int Field_year::store(longlong nr, bool unsigned_val)
else if (nr > 1900)
nr-= 1900;
}
*ptr= (char) (unsigned char) nr;
*ptr= (char) (uchar) nr;
return 0;
}
@ -6203,8 +6203,8 @@ int Field_string::cmp(const char *a_ptr, const char *b_ptr)
void Field_string::sort_string(char *to,uint length)
{
uint tmp= my_strnxfrm(field_charset,
(unsigned char *) to, length,
(unsigned char *) ptr, field_length);
(uchar*) to, length,
(uchar*) ptr, field_length);
DBUG_ASSERT(tmp == length);
}

View File

@ -712,14 +712,14 @@ static void make_sortkey(register SORTPARAM *param,
{
char *from=(char*) res->ptr();
uint tmp_length;
if ((unsigned char *)from == to)
if ((uchar*) from == to)
{
set_if_smaller(length,sort_field->length);
memcpy(param->tmp_buffer,from,length);
from=param->tmp_buffer;
}
tmp_length= my_strnxfrm(cs,to,sort_field->length,
(unsigned char *) from, length);
(uchar*) from, length);
DBUG_ASSERT(tmp_length == sort_field->length);
}
else

View File

@ -119,7 +119,7 @@ int ndbcluster_util_inited= 0;
static Ndb* g_ndb= NULL;
Ndb_cluster_connection* g_ndb_cluster_connection= NULL;
unsigned char g_node_id_map[max_ndb_nodes];
uchar g_node_id_map[max_ndb_nodes];
// Handler synchronization
pthread_mutex_t ndbcluster_mutex;
@ -1006,7 +1006,7 @@ static int fix_unique_index_attr_order(NDB_INDEX_DATA &data,
if (data.unique_index_attrid_map)
my_free((char*)data.unique_index_attrid_map, MYF(0));
data.unique_index_attrid_map= (unsigned char*)my_malloc(sz,MYF(MY_WME));
data.unique_index_attrid_map= (uchar*)my_malloc(sz,MYF(MY_WME));
KEY_PART_INFO* key_part= key_info->key_part;
KEY_PART_INFO* end= key_part+key_info->key_parts;

View File

@ -138,7 +138,7 @@ static void print_records(TABLE *table, const char *record)
for (int i= 0; i < n && pos < 20; i++)
{
pos+= sprintf(&buf[pos]," %x", (int) (unsigned char) field_ptr[i]);
pos+= sprintf(&buf[pos]," %x", (int) (uchar) field_ptr[i]);
}
buf[pos]= 0;
DBUG_PRINT("info",("[%u]field_ptr[0->%d]: %s", j, n, buf));
@ -871,11 +871,11 @@ int ndbcluster_setup_binlog_table_shares(THD *thd)
struct Cluster_schema
{
unsigned char db_length;
uchar db_length;
char db[64];
unsigned char name_length;
uchar name_length;
char name[64];
unsigned char slock_length;
uchar slock_length;
uint32 slock[SCHEMA_SLOCK_SIZE/4];
unsigned short query_length;
char *query;
@ -974,7 +974,7 @@ static char *ndb_pack_varchar(const NDBCOL *col, char *buf,
memcpy(buf, str, sz);
break;
case NDBCOL::ArrayTypeShortVar:
*(unsigned char*)buf= (unsigned char)sz;
*(uchar*)buf= (uchar)sz;
memcpy(buf + 1, str, sz);
break;
case NDBCOL::ArrayTypeMediumVar:

View File

@ -127,11 +127,11 @@ String *Item_func_md5::val_str(String *str)
if (sptr)
{
my_MD5_CTX context;
unsigned char digest[16];
uchar digest[16];
null_value=0;
my_MD5Init (&context);
my_MD5Update (&context,(unsigned char *) sptr->ptr(), sptr->length());
my_MD5Update (&context,(uchar *) sptr->ptr(), sptr->length());
my_MD5Final (digest, &context);
if (str->alloc(32)) // Ensure that memory is free
{
@ -178,7 +178,7 @@ String *Item_func_sha::val_str(String *str)
mysql_sha1_reset(&context); /* We do not have to check for error here */
/* No need to check error as the only case would be too long message */
mysql_sha1_input(&context,
(const unsigned char *) sptr->ptr(), sptr->length());
(const uchar *) sptr->ptr(), sptr->length());
/* Ensure that memory is free and we got result */
if (!( str->alloc(SHA1_HASH_SIZE*2) ||
(mysql_sha1_result(&context,digest))))

View File

@ -5682,7 +5682,7 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid,
/* If malloc fails, catched in is_valid() */
if ((m_memory= my_malloc(m_colcnt, MYF(MY_WME))))
{
m_coltype= reinterpret_cast<unsigned char*>(m_memory);
m_coltype= reinterpret_cast<uchar*>(m_memory);
for (unsigned int i= 0 ; i < m_table->s->fields ; ++i)
m_coltype[i]= m_table->field[i]->type();
}
@ -5738,11 +5738,11 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len,
/* Extract the length of the various parts from the buffer */
byte const* const ptr_dblen= (byte const*)vpart + 0;
m_dblen= *(unsigned char*) ptr_dblen;
m_dblen= *(uchar*) ptr_dblen;
/* Length of database name + counter + terminating null */
byte const* const ptr_tbllen= ptr_dblen + m_dblen + 2;
m_tbllen= *(unsigned char*) ptr_tbllen;
m_tbllen= *(uchar*) ptr_tbllen;
/* Length of table name + counter + terminating null */
byte const* const ptr_colcnt= ptr_tbllen + m_tbllen + 2;

View File

@ -1588,6 +1588,7 @@ extern TABLE *unused_tables;
extern const char* any_db;
extern struct my_option my_long_options[];
extern const LEX_STRING view_type;
extern uint sql_command_flags[];
extern TYPELIB log_output_typelib;
/* optional things, have_* variables */

View File

@ -5164,8 +5164,8 @@ get_mm_parts(RANGE_OPT_PARAM *param, COND *cond_func, Field *field,
static SEL_ARG *
get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field, KEY_PART *key_part,
Item_func::Functype type,Item *value)
get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field,
KEY_PART *key_part, Item_func::Functype type,Item *value)
{
uint maybe_null=(uint) field->real_maybe_null();
bool optimize_range;
@ -9126,10 +9126,10 @@ get_constant_key_infix(KEY *index_info, SEL_ARG *index_range_tree,
uint field_length= cur_part->store_length;
if ((cur_range->maybe_null &&
cur_range->min_value[0] && cur_range->max_value[0])
||
(memcmp(cur_range->min_value, cur_range->max_value, field_length) == 0))
{ /* cur_range specifies 'IS NULL' or an equality condition. */
cur_range->min_value[0] && cur_range->max_value[0]) ||
!memcmp(cur_range->min_value, cur_range->max_value, field_length))
{
/* cur_range specifies 'IS NULL' or an equality condition. */
memcpy(key_ptr, cur_range->min_value, field_length);
key_ptr+= field_length;
*key_infix_len+= field_length;

View File

@ -516,6 +516,31 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
/* it doesn't make sense to add last_query_cost values */
}
/*
Add the difference between two status variable arrays to another one.
SYNOPSIS
add_diff_to_status
to_var add to this array
from_var from this array
dec_var minus this array
NOTE
This function assumes that all variables are long/ulong.
*/
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
STATUS_VAR *dec_var)
{
ulong *end= (ulong*) ((byte*) to_var + offsetof(STATUS_VAR,
last_system_status_var) +
sizeof(ulong));
ulong *to= (ulong*) to_var, *from= (ulong*) from_var, *dec= (ulong*) dec_var;
while (to != end)
*(to++)+= *(from++) - *(dec++);
}
void THD::awake(THD::killed_state state_to_set)
{

View File

@ -343,7 +343,6 @@ typedef struct system_status_var
#define last_system_status_var com_stmt_close
#ifdef MYSQL_SERVER
void free_tmp_table(THD *thd, TABLE *entry);
@ -833,6 +832,7 @@ public:
struct rand_struct rand; // used for authentication
struct system_variables variables; // Changeable local variables
struct system_status_var status_var; // Per thread statistic vars
struct system_status_var *initial_status_var; /* used by show status */
THR_LOCK_INFO lock_info; // Locking info of this thread
THR_LOCK_OWNER main_lock_id; // To use for conventional queries
THR_LOCK_OWNER *lock_id; // If not main_lock_id, points to
@ -1310,6 +1310,10 @@ public:
{
return !stmt_arena->is_stmt_prepare() && !lex->only_view_structure();
}
inline bool fill_information_schema_tables()
{
return !stmt_arena->is_stmt_prepare();
}
inline gptr trans_alloc(unsigned int size)
{
return alloc_root(&transaction.mem_root,size);
@ -1966,8 +1970,16 @@ public:
void cleanup();
};
/* Bits in sql_command_flags */
#define CF_CHANGES_DATA 1
#define CF_HAS_ROW_COUNT 2
#define CF_STATUS_COMMAND 4
#define CF_SHOW_TABLE_COMMAND 8
/* Functions in sql_class.cc */
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
STATUS_VAR *dec_var);
#endif /* MYSQL_SERVER */

View File

@ -52,7 +52,7 @@ void SQL_CRYPT::crypt_init(ulong *rand_nr)
decode_buff[+i]=a;
}
for (i=0 ; i <= 255 ; i++)
encode_buff[(unsigned char) decode_buff[i]]=i;
encode_buff[(uchar) decode_buff[i]]=i;
org_rand=rand;
shift=0;
}
@ -75,7 +75,7 @@ void SQL_CRYPT::decode(char *str,uint length)
for (uint i=0; i < length; i++)
{
shift^=(uint) (my_rnd(&rand)*255.0);
uint idx= (uint) ((unsigned char) str[0] ^ shift);
uint idx= (uint) ((uchar) str[0] ^ shift);
*str = decode_buff[idx];
shift^= (uint) (uchar) *str++;
}

View File

@ -168,7 +168,7 @@ void lex_start(THD *thd, const uchar *buf, uint length)
lex->select_lex.group_list.empty();
lex->select_lex.order_list.empty();
lex->ignore_space=test(thd->variables.sql_mode & MODE_IGNORE_SPACE);
lex->sql_command= lex->orig_sql_command= SQLCOM_END;
lex->sql_command= SQLCOM_END;
lex->duplicates= DUP_ERROR;
lex->ignore= 0;
lex->sphead= NULL;

View File

@ -934,7 +934,7 @@ typedef struct st_lex : public Query_tables_list
the variable can contain 0 or 1 for each nest level.
*/
nesting_map allow_sum_func;
enum_sql_command sql_command, orig_sql_command;
enum_sql_command sql_command;
thr_lock_type lock_option;
enum SSL_type ssl_type; /* defined in violite.h */
enum my_lex_states next_state;

View File

@ -68,6 +68,7 @@ static void decrease_user_connections(USER_CONN *uc);
static bool check_db_used(THD *thd,TABLE_LIST *tables);
static bool check_multi_update_lock(THD *thd);
static void remove_escape(char *name);
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
const char *any_db="*any*"; // Special symbol for check_access
@ -626,50 +627,79 @@ void free_max_user_conn(void)
sql_command is actually set to SQLCOM_END sometimes
so we need the +1 to include it in the array.
numbers are:
0 - read-only query
!= 0 - query that may change a table
See COMMAND_FLAG_xxx for different type of commands
2 - query that returns meaningful ROW_COUNT() -
a number of modified rows
*/
char uc_update_queries[SQLCOM_END+1];
uint sql_command_flags[SQLCOM_END+1];
void init_update_queries(void)
{
bzero((gptr) &uc_update_queries, sizeof(uc_update_queries));
bzero((gptr) &sql_command_flags, sizeof(sql_command_flags));
uc_update_queries[SQLCOM_CREATE_TABLE]=1;
uc_update_queries[SQLCOM_CREATE_INDEX]=1;
uc_update_queries[SQLCOM_ALTER_TABLE]=1;
uc_update_queries[SQLCOM_UPDATE]=2;
uc_update_queries[SQLCOM_UPDATE_MULTI]=2;
uc_update_queries[SQLCOM_INSERT]=2;
uc_update_queries[SQLCOM_INSERT_SELECT]=2;
uc_update_queries[SQLCOM_DELETE]=2;
uc_update_queries[SQLCOM_DELETE_MULTI]=2;
uc_update_queries[SQLCOM_TRUNCATE]=1;
uc_update_queries[SQLCOM_DROP_TABLE]=1;
uc_update_queries[SQLCOM_LOAD]=1;
uc_update_queries[SQLCOM_CREATE_DB]=1;
uc_update_queries[SQLCOM_DROP_DB]=1;
uc_update_queries[SQLCOM_REPLACE]=2;
uc_update_queries[SQLCOM_REPLACE_SELECT]=2;
uc_update_queries[SQLCOM_RENAME_TABLE]=1;
uc_update_queries[SQLCOM_BACKUP_TABLE]=1;
uc_update_queries[SQLCOM_RESTORE_TABLE]=1;
uc_update_queries[SQLCOM_DROP_INDEX]=1;
uc_update_queries[SQLCOM_CREATE_VIEW]=1;
uc_update_queries[SQLCOM_DROP_VIEW]=1;
uc_update_queries[SQLCOM_CREATE_EVENT]=1;
uc_update_queries[SQLCOM_ALTER_EVENT]=1;
uc_update_queries[SQLCOM_DROP_EVENT]=1;
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_ALTER_TABLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_TRUNCATE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_TABLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_LOAD]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_CREATE_DB]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_DB]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_RENAME_TABLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_BACKUP_TABLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_RESTORE_TABLE]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_CREATE_VIEW]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_VIEW]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_CREATE_EVENT]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_ALTER_EVENT]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_DROP_EVENT]= CF_CHANGES_DATA;
sql_command_flags[SQLCOM_UPDATE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_UPDATE_MULTI]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_INSERT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_INSERT_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_DELETE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_DELETE_MULTI]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_SHOW_STATUS_PROC]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_STATUS_FUNC]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_STATUS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_DATABASES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_TRIGGERS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_EVENTS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_OPEN_TABLES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_PLUGINS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_FIELDS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_KEYS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_VARIABLES]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_CHARSETS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_COLLATIONS]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_STATUS_PROC]= CF_STATUS_COMMAND;
sql_command_flags[SQLCOM_SHOW_TABLES]= (CF_STATUS_COMMAND |
CF_SHOW_TABLE_COMMAND);
sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]= (CF_STATUS_COMMAND |
CF_SHOW_TABLE_COMMAND);
/*
The following is used to preserver CF_ROW_COUNT during the
a CALL or EXECUTE statement, so the value generated by the
last called (or executed) statement is preserved.
See mysql_execute_command() for how CF_ROW_COUNT is used.
*/
sql_command_flags[SQLCOM_CALL]= CF_HAS_ROW_COUNT;
sql_command_flags[SQLCOM_EXECUTE]= CF_HAS_ROW_COUNT;
}
bool is_update_query(enum enum_sql_command command)
{
DBUG_ASSERT(command >= 0 && command <= SQLCOM_END);
return uc_update_queries[command] != 0;
return (sql_command_flags[command] & CF_CHANGES_DATA) != 0;
}
/*
@ -733,7 +763,8 @@ static bool check_mqh(THD *thd, uint check_command)
if (check_command < (uint) SQLCOM_END)
{
/* Check that we have not done too many updates / hour */
if (uc->user_resources.updates && uc_update_queries[check_command] &&
if (uc->user_resources.updates &&
(sql_command_flags[check_command] & CF_CHANGES_DATA) &&
uc->updates++ >= uc->user_resources.updates)
{
net_printf_error(thd, ER_USER_LIMIT_REACHED, uc->user, "max_updates",
@ -2290,8 +2321,6 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
table_list->schema_select_lex= sel;
table_list->schema_table_reformed= 1;
statistic_increment(thd->status_var.com_stat[lex->orig_sql_command],
&LOCK_status);
DBUG_RETURN(0);
}
@ -2458,7 +2487,7 @@ mysql_execute_command(THD *thd)
*/
if (opt_readonly &&
!(thd->security_ctx->master_access & SUPER_ACL) &&
uc_update_queries[lex->sql_command] &&
(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA) &&
!((lex->sql_command == SQLCOM_CREATE_TABLE) &&
(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE)) &&
((lex->sql_command != SQLCOM_UPDATE_MULTI) &&
@ -2470,7 +2499,6 @@ mysql_execute_command(THD *thd)
#ifdef HAVE_REPLICATION
} /* endif unlikely slave */
#endif
if(lex->orig_sql_command == SQLCOM_END)
statistic_increment(thd->status_var.com_stat[lex->sql_command],
&LOCK_status);
@ -2480,77 +2508,61 @@ mysql_execute_command(THD *thd)
#endif /*HAVE_ROW_BASED_REPLICATION*/
switch (lex->sql_command) {
case SQLCOM_SELECT:
case SQLCOM_SHOW_EVENTS:
if ((res= check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0,
is_schema_db(thd->lex->select_lex.db))))
break;
/* fall through */
case SQLCOM_SHOW_STATUS_PROC:
case SQLCOM_SHOW_STATUS_FUNC:
res= execute_sqlcom_select(thd, all_tables);
break;
case SQLCOM_SHOW_STATUS:
{
/* assign global limit variable if limit is not given */
{
SELECT_LEX *param= lex->unit.global_parameters;
if (!param->explicit_limit)
param->select_limit=
new Item_int((ulonglong)thd->variables.select_limit);
system_status_var old_status_var= thd->status_var;
thd->initial_status_var= &old_status_var;
res= execute_sqlcom_select(thd, all_tables);
/* Don't log SHOW STATUS commands to slow query log */
thd->server_status&= ~(SERVER_QUERY_NO_INDEX_USED |
SERVER_QUERY_NO_GOOD_INDEX_USED);
/*
restore status variables, as we don't want 'show status' to cause
changes
*/
pthread_mutex_lock(&LOCK_status);
add_diff_to_status(&global_status_var, &thd->status_var,
&old_status_var);
thd->status_var= old_status_var;
pthread_mutex_unlock(&LOCK_status);
break;
}
select_result *result=lex->result;
case SQLCOM_SHOW_DATABASES:
case SQLCOM_SHOW_TABLES:
case SQLCOM_SHOW_TRIGGERS:
case SQLCOM_SHOW_TABLE_STATUS:
case SQLCOM_SHOW_OPEN_TABLES:
case SQLCOM_SHOW_PLUGINS:
case SQLCOM_SHOW_FIELDS:
case SQLCOM_SHOW_KEYS:
case SQLCOM_SHOW_VARIABLES:
case SQLCOM_SHOW_CHARSETS:
case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SELECT:
thd->status_var.last_query_cost= 0.0;
if (all_tables)
{
if (lex->orig_sql_command != SQLCOM_SHOW_STATUS_PROC &&
lex->orig_sql_command != SQLCOM_SHOW_STATUS_FUNC &&
lex->orig_sql_command != SQLCOM_SHOW_EVENTS)
res= check_table_access(thd,
lex->exchange ? SELECT_ACL | FILE_ACL :
SELECT_ACL,
all_tables, 0);
else if (lex->orig_sql_command == SQLCOM_SHOW_EVENTS)
res= check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0,
is_schema_db(thd->lex->select_lex.db));
}
else
res= check_access(thd,
lex->exchange ? SELECT_ACL | FILE_ACL : SELECT_ACL,
any_db, 0, 0, 0, 0);
if (res)
goto error;
if (!(res= open_and_lock_tables(thd, all_tables)))
{
if (lex->describe)
{
/*
We always use select_send for EXPLAIN, even if it's an EXPLAIN
for SELECT ... INTO OUTFILE: a user application should be able
to prepend EXPLAIN to any query and receive output for it,
even if the query itself redirects the output.
*/
if (!(result= new select_send()))
goto error;
else
thd->send_explain_fields(result);
res= mysql_explain_union(thd, &thd->lex->unit, result);
if (lex->describe & DESCRIBE_EXTENDED)
{
char buff[1024];
String str(buff,(uint32) sizeof(buff), system_charset_info);
str.length(0);
thd->lex->unit.print(&str);
str.append('\0');
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_YES, str.ptr());
}
result->send_eof();
delete result;
}
else
{
if (!result && !(result= new select_send()))
goto error;
query_cache_store_query(thd, all_tables);
res= handle_select(thd, lex, result, 0);
if (result != lex->result)
delete result;
}
}
if (!res)
res= execute_sqlcom_select(thd, all_tables);
break;
}
case SQLCOM_PREPARE:
{
mysql_sql_stmt_prepare(thd);
@ -4826,6 +4838,7 @@ end_with_restore_list:
}
break;
}
#ifdef NOT_USED
case SQLCOM_SHOW_STATUS_PROC:
{
res= sp_show_status_procedure(thd, (lex->wild ?
@ -4838,6 +4851,7 @@ end_with_restore_list:
lex->wild->ptr() : NullS));
break;
}
#endif
#ifndef DBUG_OFF
case SQLCOM_SHOW_PROC_CODE:
case SQLCOM_SHOW_FUNC_CODE:
@ -5162,13 +5176,10 @@ end:
/*
The return value for ROW_COUNT() is "implementation dependent" if the
statement is not DELETE, INSERT or UPDATE, but -1 is what JDBC and ODBC
wants.
We do not change the value for a CALL or EXECUTE statement, so the value
generated by the last called (or executed) statement is preserved.
wants. We also keep the last value in case of SQLCOM_CALL or
SQLCOM_EXECUTE.
*/
if (lex->sql_command != SQLCOM_CALL && lex->sql_command != SQLCOM_EXECUTE &&
uc_update_queries[lex->sql_command]<2)
if (!(sql_command_flags[lex->sql_command] & CF_HAS_ROW_COUNT))
thd->row_count_func= -1;
DBUG_RETURN(res || thd->net.report_error);
@ -5178,6 +5189,59 @@ error:
}
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
{
LEX *lex= thd->lex;
select_result *result=lex->result;
bool res;
/* assign global limit variable if limit is not given */
{
SELECT_LEX *param= lex->unit.global_parameters;
if (!param->explicit_limit)
param->select_limit=
new Item_int((ulonglong) thd->variables.select_limit);
}
if (!(res= open_and_lock_tables(thd, all_tables)))
{
if (lex->describe)
{
/*
We always use select_send for EXPLAIN, even if it's an EXPLAIN
for SELECT ... INTO OUTFILE: a user application should be able
to prepend EXPLAIN to any query and receive output for it,
even if the query itself redirects the output.
*/
if (!(result= new select_send()))
return 1;
thd->send_explain_fields(result);
res= mysql_explain_union(thd, &thd->lex->unit, result);
if (lex->describe & DESCRIBE_EXTENDED)
{
char buff[1024];
String str(buff,(uint32) sizeof(buff), system_charset_info);
str.length(0);
thd->lex->unit.print(&str);
str.append('\0');
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
ER_YES, str.ptr());
}
result->send_eof();
delete result;
}
else
{
if (!result && !(result= new select_send()))
return 1;
query_cache_store_query(thd, all_tables);
res= handle_select(thd, lex, result, 0);
if (result != lex->result)
delete result;
}
}
return res;
}
/*
Check grants for commands which work only with one table and all other
tables belonging to subselects or implicitly opened tables.
@ -6283,7 +6347,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name);
if (!schema_table ||
(schema_table->hidden &&
lex->orig_sql_command == SQLCOM_END)) // not a 'show' command
(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0))
{
my_error(ER_UNKNOWN_TABLE, MYF(0),
ptr->table_name, information_schema_name.str);

View File

@ -1727,22 +1727,17 @@ static bool check_prepared_statement(Prepared_statement *stmt,
res= mysql_test_insert_select(stmt, tables);
break;
case SQLCOM_SHOW_DATABASES:
/*
Note that we don't need to have cases in this list if they are
marked with CF_STATUS_COMMAND in sql_command_flags
*/
case SQLCOM_SHOW_PROCESSLIST:
case SQLCOM_SHOW_STORAGE_ENGINES:
case SQLCOM_SHOW_PRIVILEGES:
case SQLCOM_SHOW_COLUMN_TYPES:
case SQLCOM_SHOW_STATUS:
case SQLCOM_SHOW_VARIABLES:
case SQLCOM_SHOW_ENGINE_LOGS:
case SQLCOM_SHOW_ENGINE_STATUS:
case SQLCOM_SHOW_ENGINE_MUTEX:
case SQLCOM_SHOW_TABLES:
case SQLCOM_SHOW_OPEN_TABLES:
case SQLCOM_SHOW_CHARSETS:
case SQLCOM_SHOW_COLLATIONS:
case SQLCOM_SHOW_FIELDS:
case SQLCOM_SHOW_KEYS:
case SQLCOM_SHOW_CREATE_DB:
case SQLCOM_SHOW_GRANTS:
case SQLCOM_DROP_TABLE:
@ -1762,10 +1757,18 @@ static bool check_prepared_statement(Prepared_statement *stmt,
break;
default:
/*
Trivial check of all status commands. This is easier than having
things in the above case list, as it's less chance for mistakes.
*/
if (!(sql_command_flags[sql_command] & CF_STATUS_COMMAND))
{
/* All other statements are not supported yet. */
my_message(ER_UNSUPPORTED_PS, ER(ER_UNSUPPORTED_PS), MYF(0));
goto error;
}
break;
}
if (res == 0)
DBUG_RETURN(text_protocol? FALSE : (send_prep_stmt(stmt, 0) ||
thd->protocol->flush()));

View File

@ -551,9 +551,6 @@ JOIN::optimize()
DBUG_RETURN(0);
optimized= 1;
if (thd->lex->orig_sql_command != SQLCOM_SHOW_STATUS)
thd->status_var.last_query_cost= 0.0;
row_limit= ((select_distinct || order || group_list) ? HA_POS_ERROR :
unit->select_limit_cnt);
/* select_limit is used to decide if we are likely to scan the whole table */
@ -3875,9 +3872,7 @@ choose_plan(JOIN *join, table_map join_tables)
/*
Store the cost of this query into a user variable
Don't update last_query_cost for 'show status' command
*/
if (join->thd->lex->orig_sql_command != SQLCOM_SHOW_STATUS)
join->thd->status_var.last_query_cost= join->best_read;
DBUG_VOID_RETURN;
}

View File

@ -2148,7 +2148,7 @@ bool schema_table_store_record(THD *thd, TABLE *table)
void get_index_field_values(LEX *lex, INDEX_FIELD_VALUES *index_field_values)
{
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
switch (lex->orig_sql_command) {
switch (lex->sql_command) {
case SQLCOM_SHOW_DATABASES:
index_field_values->db_value= wild;
break;
@ -2337,10 +2337,9 @@ int make_db_list(THD *thd, List<char> *files,
/*
This part of code is for SHOW TABLES, SHOW TABLE STATUS commands.
idx_field_vals->db_value can't be 0 (see get_index_field_values()
function). lex->orig_sql_command can be not equal to SQLCOM_END
only in case of executing of SHOW commands.
function).
*/
if (lex->orig_sql_command != SQLCOM_END)
if (sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)
{
if (!my_strcasecmp(system_charset_info, information_schema_name.str,
idx_field_vals->db_value))
@ -2419,12 +2418,6 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
LINT_INIT(end);
LINT_INIT(len);
/*
Let us set fake sql_command so views won't try to merge
themselves into main statement.
*/
lex->sql_command= SQLCOM_SHOW_FIELDS;
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
/*
@ -2447,8 +2440,16 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
I_S tables will be done.
*/
thd->temporary_tables= open_tables_state_backup.temporary_tables;
/*
Let us set fake sql_command so views won't try to merge
themselves into main statement. If we don't do this,
SELECT * from information_schema.xxxx will cause problems.
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
*/
lex->sql_command= SQLCOM_SHOW_FIELDS;
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
lex->sql_command= save_sql_command;
/*
get_all_tables() returns 1 on failure and 0 on success thus
return only these and not the result code of ::process_table()
@ -2479,13 +2480,13 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
partial_cond= make_cond_for_info_schema(cond, tables);
it.rewind(); /* To get access to new elements in basis list */
while ((orig_base_name= base_name= it++) ||
/*
generate error for non existing database.
Below we generate error for non existing database.
(to save old behaviour for SHOW TABLES FROM db)
*/
((lex->orig_sql_command == SQLCOM_SHOW_TABLES ||
lex->orig_sql_command == SQLCOM_SHOW_TABLE_STATUS) &&
while ((orig_base_name= base_name= it++) ||
((sql_command_flags[save_sql_command] & CF_SHOW_TABLE_COMMAND) &&
(base_name= select_lex->db) && !bases.elements))
{
#ifndef NO_EMBEDDED_ACCESS_CHECKS
@ -2526,7 +2527,8 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
{
if (schema_table_idx == SCH_TABLE_NAMES)
{
if (lex->verbose || lex->orig_sql_command == SQLCOM_END)
if (lex->verbose ||
(sql_command_flags[save_sql_command] & CF_STATUS_COMMAND) == 0)
{
if (with_i_schema)
{
@ -2570,8 +2572,10 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
lex->all_selects_list= &sel;
lex->derived_tables= 0;
lex->sql_command= SQLCOM_SHOW_FIELDS;
res= open_normal_and_derived_tables(thd, show_table_list,
MYSQL_LOCK_IGNORE_FLUSH);
lex->sql_command= save_sql_command;
/*
We should use show_table_list->alias instead of
show_table_list->table_name because table_name
@ -2881,7 +2885,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
if (res)
{
if (lex->orig_sql_command != SQLCOM_SHOW_FIELDS)
if (lex->sql_command != SQLCOM_SHOW_FIELDS)
{
/*
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
@ -2932,7 +2936,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
col_access= get_column_grant(thd, &tables->grant,
base_name, file_name,
field->field_name) & COL_ACLS;
if (lex->orig_sql_command != SQLCOM_SHOW_FIELDS &&
if (lex->sql_command != SQLCOM_SHOW_FIELDS &&
!tables->schema_table && !col_access)
continue;
end= tmp;
@ -2977,7 +2981,7 @@ static int get_schema_column_record(THD *thd, struct st_table_list *tables,
table->field[5]->set_notnull();
}
else if (field->unireg_check == Field::NEXT_NUMBER ||
lex->orig_sql_command != SQLCOM_SHOW_FIELDS ||
lex->sql_command != SQLCOM_SHOW_FIELDS ||
field->maybe_null())
table->field[5]->set_null(); // Null as default
else
@ -3247,16 +3251,18 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
get_field(thd->mem_root, proc_table->field[11], &definer);
if (!full_access)
full_access= !strcmp(sp_user, definer.ptr());
if (!full_access && check_some_routine_access(thd, sp_db.ptr(), sp_name.ptr(),
proc_table->field[2]->val_int() ==
if (!full_access && check_some_routine_access(thd, sp_db.ptr(),
sp_name.ptr(),
proc_table->field[2]->
val_int() ==
TYPE_ENUM_PROCEDURE))
return 0;
if (lex->orig_sql_command == SQLCOM_SHOW_STATUS_PROC &&
if (lex->sql_command == SQLCOM_SHOW_STATUS_PROC &&
proc_table->field[2]->val_int() == TYPE_ENUM_PROCEDURE ||
lex->orig_sql_command == SQLCOM_SHOW_STATUS_FUNC &&
lex->sql_command == SQLCOM_SHOW_STATUS_FUNC &&
proc_table->field[2]->val_int() == TYPE_ENUM_FUNCTION ||
lex->orig_sql_command == SQLCOM_END)
(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND) == 0)
{
restore_record(table, s->default_values);
if (!wild || !wild[0] || !wild_compare(sp_name.ptr(), wild, 0))
@ -3367,7 +3373,7 @@ static int get_schema_stat_record(THD *thd, struct st_table_list *tables,
DBUG_ENTER("get_schema_stat_record");
if (res)
{
if (thd->lex->orig_sql_command != SQLCOM_SHOW_KEYS)
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
{
/*
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
@ -4158,7 +4164,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table)
optimized. It's guaranteed in case of SHOW EVENTS that the user
has access.
*/
if (thd->lex->orig_sql_command != SQLCOM_SHOW_EVENTS &&
if (thd->lex->sql_command != SQLCOM_SHOW_EVENTS &&
check_access(thd, EVENT_ACL, et.dbname.str, 0, 0, 1,
is_schema_db(et.dbname.str)))
DBUG_RETURN(0);
@ -4388,7 +4394,7 @@ int fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
If it's SHOW EVENTS then thd->lex->select_lex.db is guaranteed not to
be NULL. Let's do an assert anyway.
*/
if (thd->lex->orig_sql_command == SQLCOM_SHOW_EVENTS)
if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS)
{
DBUG_ASSERT(thd->lex->select_lex.db);
if (check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0,
@ -4416,7 +4422,7 @@ int fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
will save use from doing a table scan and comparing
every single row's `db` with the schema which we show.
*/
if (thd->lex->orig_sql_command == SQLCOM_SHOW_EVENTS)
if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS)
ret= events_table_index_read_for_db(thd, schema_table, event_table);
else
ret= events_table_scan_all(thd, schema_table, event_table);
@ -4482,7 +4488,7 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
(SHOW_VAR *)all_status_vars.buffer,
OPT_GLOBAL,
(lex->option_type == OPT_GLOBAL ?
&tmp: &thd->status_var), "",tables->table);
&tmp: thd->initial_status_var), "",tables->table);
pthread_mutex_unlock(&LOCK_status);
DBUG_RETURN(res);
}
@ -4675,7 +4681,7 @@ TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
schema_table pointer to 'schema_tables' element
RETURN
-1 errror
1 error
0 success
*/
@ -4999,7 +5005,7 @@ bool get_schema_tables_result(JOIN *join)
break;
TABLE_LIST *table_list= tab->table->pos_in_table_list;
if (table_list->schema_table && thd->fill_derived_tables())
if (table_list->schema_table && thd->fill_information_schema_tables())
{
bool is_subselect= (&lex->unit != lex->current_select->master_unit() &&
lex->current_select->master_unit()->item);

View File

@ -710,8 +710,8 @@ void String::qs_append(uint i)
int sortcmp(const String *s,const String *t, CHARSET_INFO *cs)
{
return cs->coll->strnncollsp(cs,
(unsigned char *) s->ptr(),s->length(),
(unsigned char *) t->ptr(),t->length(), 0);
(uchar *) s->ptr(),s->length(),
(uchar *) t->ptr(),t->length(), 0);
}
@ -724,7 +724,7 @@ int sortcmp(const String *s,const String *t, CHARSET_INFO *cs)
t Second string
NOTE:
Strings are compared as a stream of unsigned chars
Strings are compared as a stream of uchars
RETURN
< 0 s < t

View File

@ -2058,16 +2058,19 @@ sp_cursor_stmt:
{
Lex->sphead->reset_lex(YYTHD);
/* We use statement here just be able to get a better
/*
We use statement here just be able to get a better
error message. Using 'select' works too, but will then
result in a generic "syntax error" if a non-select
statement is given. */
statement is given.
*/
}
statement
{
LEX *lex= Lex;
if (lex->sql_command != SQLCOM_SELECT)
if (lex->sql_command != SQLCOM_SELECT &&
!(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND))
{
my_message(ER_SP_BAD_CURSOR_QUERY, ER(ER_SP_BAD_CURSOR_QUERY),
MYF(0));
@ -8062,16 +8065,14 @@ show_param:
DATABASES wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_DATABASES;
lex->sql_command= SQLCOM_SHOW_DATABASES;
if (prepare_schema_table(YYTHD, lex, 0, SCH_SCHEMATA))
YYABORT;
}
| opt_full TABLES opt_db wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_TABLES;
lex->sql_command= SQLCOM_SHOW_TABLES;
lex->select_lex.db= $3;
if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLE_NAMES))
YYABORT;
@ -8079,8 +8080,7 @@ show_param:
| opt_full TRIGGERS_SYM opt_db wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_TRIGGERS;
lex->sql_command= SQLCOM_SHOW_TRIGGERS;
lex->select_lex.db= $3;
if (prepare_schema_table(YYTHD, lex, 0, SCH_TRIGGERS))
YYABORT;
@ -8088,8 +8088,7 @@ show_param:
| EVENTS_SYM opt_db wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_EVENTS;
lex->sql_command= SQLCOM_SHOW_EVENTS;
lex->select_lex.db= $2;
if (prepare_schema_table(YYTHD, lex, 0, SCH_EVENTS))
YYABORT;
@ -8106,8 +8105,7 @@ show_param:
| TABLE_SYM STATUS_SYM opt_db wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_TABLE_STATUS;
lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
lex->select_lex.db= $3;
if (prepare_schema_table(YYTHD, lex, 0, SCH_TABLES))
YYABORT;
@ -8115,8 +8113,7 @@ show_param:
| OPEN_SYM TABLES opt_db wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_OPEN_TABLES;
lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
lex->select_lex.db= $3;
if (prepare_schema_table(YYTHD, lex, 0, SCH_OPEN_TABLES))
YYABORT;
@ -8125,16 +8122,14 @@ show_param:
{
LEX *lex= Lex;
WARN_DEPRECATED(yythd, "5.2", "SHOW PLUGIN", "'SHOW PLUGINS'");
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_PLUGINS;
lex->sql_command= SQLCOM_SHOW_PLUGINS;
if (prepare_schema_table(YYTHD, lex, 0, SCH_PLUGINS))
YYABORT;
}
| PLUGINS_SYM
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_PLUGINS;
lex->sql_command= SQLCOM_SHOW_PLUGINS;
if (prepare_schema_table(YYTHD, lex, 0, SCH_PLUGINS))
YYABORT;
}
@ -8147,8 +8142,7 @@ show_param:
| opt_full COLUMNS from_or_in table_ident opt_db wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_FIELDS;
lex->sql_command= SQLCOM_SHOW_FIELDS;
if ($5)
$4->change_db($5);
if (prepare_schema_table(YYTHD, lex, $4, SCH_COLUMNS))
@ -8180,8 +8174,7 @@ show_param:
| keys_or_index from_or_in table_ident opt_db where_clause
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_KEYS;
lex->sql_command= SQLCOM_SHOW_KEYS;
if ($4)
$3->change_db($4);
if (prepare_schema_table(YYTHD, lex, $3, SCH_STATISTICS))
@ -8202,7 +8195,6 @@ show_param:
{
LEX *lex=Lex;
lex->sql_command= SQLCOM_SHOW_STORAGE_ENGINES;
lex->orig_sql_command= SQLCOM_SHOW_AUTHORS;
if (prepare_schema_table(YYTHD, lex, 0, SCH_ENGINES))
YYABORT;
}
@ -8232,8 +8224,7 @@ show_param:
| opt_var_type STATUS_SYM wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_STATUS;
lex->sql_command= SQLCOM_SHOW_STATUS;
lex->option_type= $1;
if (prepare_schema_table(YYTHD, lex, 0, SCH_STATUS))
YYABORT;
@ -8267,8 +8258,7 @@ show_param:
| opt_var_type VARIABLES wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_VARIABLES;
lex->sql_command= SQLCOM_SHOW_VARIABLES;
lex->option_type= $1;
if (prepare_schema_table(YYTHD, lex, 0, SCH_VARIABLES))
YYABORT;
@ -8276,16 +8266,14 @@ show_param:
| charset wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_CHARSETS;
lex->sql_command= SQLCOM_SHOW_CHARSETS;
if (prepare_schema_table(YYTHD, lex, 0, SCH_CHARSETS))
YYABORT;
}
| COLLATION_SYM wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_COLLATIONS;
lex->sql_command= SQLCOM_SHOW_COLLATIONS;
if (prepare_schema_table(YYTHD, lex, 0, SCH_COLLATIONS))
YYABORT;
}
@ -8391,8 +8379,7 @@ show_param:
| PROCEDURE STATUS_SYM wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_STATUS_PROC;
lex->sql_command= SQLCOM_SHOW_STATUS_PROC;
if (!sp_add_to_query_tables(YYTHD, lex, "mysql", "proc", TL_READ))
YYABORT;
if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES))
@ -8401,8 +8388,7 @@ show_param:
| FUNCTION_SYM STATUS_SYM wild_and_where
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_STATUS_FUNC;
lex->sql_command= SQLCOM_SHOW_STATUS_FUNC;
if (!sp_add_to_query_tables(YYTHD, lex, "mysql", "proc", TL_READ))
YYABORT;
if (prepare_schema_table(YYTHD, lex, 0, SCH_PROCEDURES))
@ -8497,8 +8483,7 @@ describe:
lex->lock_option= TL_READ;
mysql_init_select(lex);
lex->current_select->parsing_place= SELECT_LIST;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_FIELDS;
lex->sql_command= SQLCOM_SHOW_FIELDS;
lex->select_lex.db= 0;
lex->verbose= 0;
if (prepare_schema_table(YYTHD, lex, $2, SCH_COLUMNS))

View File

@ -180,7 +180,7 @@ typedef struct user_resources {
uint questions;
/*
Maximum number of updating statements per hour (which statements are
updating is defined by uc_update_queries array).
updating is defined by sql_command_flags array).
*/
uint updates;
/* Maximum number of connections established per hour. */

View File

@ -107,7 +107,7 @@ typedef struct st_time_zone_info
uint revcnt; // Number of transition descr. for TIME->my_time_t conversion
/* The following are dynamical arrays are allocated in MEM_ROOT */
my_time_t *ats; // Times of transitions between time types
unsigned char *types; // Local time types for transitions
uchar *types; // Local time types for transitions
TRAN_TYPE_INFO *ttis; // Local time types descriptions
#ifdef ABBR_ARE_USED
/* Storage for local time types abbreviations. They are stored as ASCIIZ */
@ -222,7 +222,7 @@ tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage)
sp->ats= (my_time_t *)tzinfo_buf;
tzinfo_buf+= ALIGN_SIZE(sp->timecnt * sizeof(my_time_t));
sp->types= (unsigned char *)tzinfo_buf;
sp->types= (uchar *)tzinfo_buf;
tzinfo_buf+= ALIGN_SIZE(sp->timecnt);
sp->ttis= (TRAN_TYPE_INFO *)tzinfo_buf;
tzinfo_buf+= ALIGN_SIZE(sp->typecnt * sizeof(TRAN_TYPE_INFO));
@ -237,7 +237,7 @@ tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage)
for (i= 0; i < sp->timecnt; i++)
{
sp->types[i]= (unsigned char) *p++;
sp->types[i]= (uchar) *p++;
if (sp->types[i] >= sp->typecnt)
return 1;
}
@ -248,10 +248,10 @@ tz_load(const char *name, TIME_ZONE_INFO *sp, MEM_ROOT *storage)
ttisp= &sp->ttis[i];
ttisp->tt_gmtoff= int4net(p);
p+= 4;
ttisp->tt_isdst= (unsigned char) *p++;
ttisp->tt_isdst= (uchar) *p++;
if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1)
return 1;
ttisp->tt_abbrind= (unsigned char) *p++;
ttisp->tt_abbrind= (uchar) *p++;
if (ttisp->tt_abbrind > sp->charcnt)
return 1;
}
@ -1801,7 +1801,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
TIME_ZONE_INFO structure
*/
my_time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
uchar types[TZ_MAX_TIMES];
TRAN_TYPE_INFO ttis[TZ_MAX_TYPES];
#ifdef ABBR_ARE_USED
char chars[max(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))];
@ -2038,7 +2038,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
tz_info->ats= (my_time_t *)alloc_buff;
memcpy(tz_info->ats, ats, tz_info->timecnt * sizeof(my_time_t));
alloc_buff+= ALIGN_SIZE(sizeof(my_time_t) * tz_info->timecnt);
tz_info->types= (unsigned char *)alloc_buff;
tz_info->types= (uchar *)alloc_buff;
memcpy(tz_info->types, types, tz_info->timecnt);
alloc_buff+= ALIGN_SIZE(tz_info->timecnt);
#ifdef ABBR_ARE_USED

View File

@ -57,6 +57,7 @@ int heap_reset(HP_INFO *info)
info->current_record= (ulong) ~0L;
info->current_hash_ptr=0;
info->update=0;
info->next_block=0;
return 0;
}
@ -83,4 +84,3 @@ static void heap_extra_keyflag(register HP_INFO *info,
}
}
}

View File

@ -74,6 +74,7 @@ int main(int argc, char *argv[])
get_options(argc,argv);
bzero(&hp_create_info, sizeof(hp_create_info));
hp_create_info.max_table_size= 1024L*1024L;
write_count=update=opt_delete=0;
key_check=0;

View File

@ -31,8 +31,9 @@
int mi_rsame_with_pos(MI_INFO *info, byte *record, int inx, my_off_t filepos)
{
DBUG_ENTER("mi_rsame_with_pos");
DBUG_PRINT("enter",("index: %d filepos: %ld", inx, (long) filepos));
if (inx < -1 || ! mi_is_key_active(info->s->state.key_map, inx))
if (inx < -1 || inx >= 0 && ! mi_is_key_active(info->s->state.key_map, inx))
{
DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
}

View File

@ -1353,7 +1353,7 @@ int bin2decimal(char *from, decimal_t *to, int precision, int scale)
}
from+=i;
*buf=x ^ mask;
if (((uint32)*buf) >= powers10[intg0x+1])
if (((ulonglong)*buf) >= (ulonglong) powers10[intg0x+1])
goto err;
if (buf > to->buf || *buf != 0)
buf++;