Commit be269e56 authored by monty@mysql.com's avatar monty@mysql.com

SHOW STATUS does not anymore change local status variables (except...

SHOW STATUS does not anymore change local status variables (except com_show_status). Global status variables are still updated.
SHOW STATUS are not anymore put in slow query log because of no index usage.

Implemntation done by removing orig_sql_command and moving logic of SHOW STATUS to mysql_excute_command()
This simplifies code and allows us to remove some if statements all over the code.

Upgraded uc_update_queries[] to sql_command_flags and added more bitmaps to better categorize commands.
This allowed some overall simplifaction when testing sql_command.

Fixes bugs:
Bug#10210: running SHOW STATUS increments counters it shouldn't
Bug#19764: SHOW commands end up in the slow log as table scans
parent 49a33348
......@@ -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");
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
......@@ -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;
......
......@@ -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
......
--disable_warnings
create database if not exists events_test;
--enable_warnings
use events_test;
--error ER_NOT_SUPPORTED_YET
......
......@@ -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;
......
......@@ -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
......
......@@ -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
......@@ -1582,6 +1582,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[];
/* optional things, have_* variables */
......
......@@ -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)
{
......
......@@ -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
......@@ -1306,6 +1306,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);
......@@ -1952,8 +1956,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 */
......@@ -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;
......
......@@ -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;
......
This diff is collapsed.
......@@ -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()));
......
......@@ -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;
}
......
......@@ -2143,7 +2143,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;
......@@ -2332,10 +2332,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))
......@@ -2414,12 +2413,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);
/*
......@@ -2442,8 +2435,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()
......@@ -2474,13 +2475,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
......@@ -2521,7 +2522,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)
{
......@@ -2565,8 +2567,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
......@@ -2876,7 +2880,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
......@@ -2927,7 +2931,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;
......@@ -2972,7 +2976,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
......@@ -3242,16 +3246,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))
......@@ -3362,7 +3368,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
......@@ -4153,7 +4159,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);
......@@ -4383,7 +4389,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,
......@@ -4411,7 +4417,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);
......@@ -4477,7 +4483,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);
}
......@@ -4670,7 +4676,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
*/
......@@ -4994,7 +5000,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);
......
......@@ -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))
......
......@@ -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. */
......
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