Commit 65a947e2 authored by unknown's avatar unknown

QUERY_NO_GOOD_INDEX_USED and QUERY_NO_INDEX_USED moved from...

QUERY_NO_GOOD_INDEX_USED and QUERY_NO_INDEX_USED moved from thd->lex.select_lex->options to thd->server_status


mysql-test/r/union.result:
  union and slow log tests
mysql-test/t/union.test:
  union and slow log tests
parent 0178804a
...@@ -124,6 +124,8 @@ enum enum_server_command ...@@ -124,6 +124,8 @@ enum enum_server_command
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */ #define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
#define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */ #define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */
#define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */ #define SERVER_MORE_RESULTS_EXISTS 8 /* Multi query - next query exists */
#define SERVER_QUERY_NO_GOOD_INDEX_USED 16
#define SERVER_QUERY_NO_INDEX_USED 32
#define MYSQL_ERRMSG_SIZE 512 #define MYSQL_ERRMSG_SIZE 512
#define NET_READ_TIMEOUT 30 /* Timeout on read */ #define NET_READ_TIMEOUT 30 /* Timeout on read */
......
...@@ -823,3 +823,41 @@ count(*) ...@@ -823,3 +823,41 @@ count(*)
13 13
drop table t1,t2; drop table t1,t2;
set local tmp_table_size=default; set local tmp_table_size=default;
create table t1 (a int, index (a), b int);
insert t1 values (1,1),(2,2),(3,3),(4,4),(5,5);
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
FLUSH STATUS;
show status like 'Slow_queries';
Variable_name Value
Slow_queries 0
select count(*) from t1 where a=7;
count(*)
26
show status like 'Slow_queries';
Variable_name Value
Slow_queries 0
select count(*) from t1 where b=13;
count(*)
10
show status like 'Slow_queries';
Variable_name Value
Slow_queries 1
select count(*) from t1 where b=13 union select count(*) from t1 where a=7;
count(*)
0
26
show status like 'Slow_queries';
Variable_name Value
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 3
drop table t1;
--log-slow-queries --log-long-format --log-queries-not-using-indexes
...@@ -416,9 +416,6 @@ create table t1 select _latin2"test" union select _latin2"testt" ; ...@@ -416,9 +416,6 @@ create table t1 select _latin2"test" union select _latin2"testt" ;
show create table t1; show create table t1;
drop table t1; drop table t1;
#
# conversion memory->disk table
#
# #
# conversion memory->disk table # conversion memory->disk table
# #
...@@ -436,3 +433,26 @@ select count(*) from t1; ...@@ -436,3 +433,26 @@ select count(*) from t1;
select count(*) from t2; select count(*) from t2;
drop table t1,t2; drop table t1,t2;
set local tmp_table_size=default; set local tmp_table_size=default;
#
# slow logging
#
create table t1 (a int, index (a), b int);
insert t1 values (1,1),(2,2),(3,3),(4,4),(5,5);
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
insert t1 select a+1, a+b from t1;
FLUSH STATUS;
show status like 'Slow_queries';
select count(*) from t1 where a=7;
show status like 'Slow_queries';
select count(*) from t1 where b=13;
show status like 'Slow_queries';
select count(*) from t1 where b=13 union select count(*) from t1 where a=7;
show status like 'Slow_queries';
select count(*) from t1 where a=7 union select count(*) from t1 where b=13;
show status like 'Slow_queries';
drop table t1;
...@@ -177,50 +177,45 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset; ...@@ -177,50 +177,45 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
#define TEST_SIGINT 1024 /* Allow sigint on threads */ #define TEST_SIGINT 1024 /* Allow sigint on threads */
/* options for select set by the yacc parser (stored in lex->options) */ /* options for select set by the yacc parser (stored in lex->options) */
#define SELECT_DISTINCT 1 #define SELECT_DISTINCT (1L << 0)
#define SELECT_STRAIGHT_JOIN 2 #define SELECT_STRAIGHT_JOIN (1L << 1)
#define SELECT_DESCRIBE 4 #define SELECT_DESCRIBE (1L << 2)
#define SELECT_SMALL_RESULT 8 #define SELECT_SMALL_RESULT (1L << 3)
#define SELECT_BIG_RESULT 16 #define SELECT_BIG_RESULT (1L << 4)
#define OPTION_FOUND_ROWS 32 #define OPTION_FOUND_ROWS (1L << 5)
#define OPTION_TO_QUERY_CACHE 64 #define OPTION_TO_QUERY_CACHE (1L << 6)
#define SELECT_NO_JOIN_CACHE 256 /* Intern */ #define SELECT_NO_JOIN_CACHE (1L << 7) /* Intern */
#define OPTION_BIG_TABLES (1L << 8) /* for SQL OPTION */
#define OPTION_BIG_TABLES 512 /* for SQL OPTION */ #define OPTION_BIG_SELECTS (1L << 9) /* for SQL OPTION */
#define OPTION_BIG_SELECTS 1024 /* for SQL OPTION */ #define OPTION_LOG_OFF (1L << 10)
#define OPTION_LOG_OFF 2048 #define OPTION_UPDATE_LOG (1L << 11) /* update log flag */
#define OPTION_UPDATE_LOG 4096 /* update log flag */ #define TMP_TABLE_ALL_COLUMNS (1L << 12)
#define TMP_TABLE_ALL_COLUMNS 8192 #define OPTION_WARNINGS (1L << 13)
#define OPTION_WARNINGS 16384 #define OPTION_AUTO_IS_NULL (1L << 14)
#define OPTION_AUTO_IS_NULL 32768 #define OPTION_FOUND_COMMENT (1L << 15)
#define OPTION_FOUND_COMMENT 65536L #define OPTION_SAFE_UPDATES (1L << 16)
#define OPTION_SAFE_UPDATES OPTION_FOUND_COMMENT*2 #define OPTION_BUFFER_RESULT (1L << 17)
#define OPTION_BUFFER_RESULT OPTION_SAFE_UPDATES*2 #define OPTION_BIN_LOG (1L << 18)
#define OPTION_BIN_LOG OPTION_BUFFER_RESULT*2 #define OPTION_NOT_AUTOCOMMIT (1L << 19)
#define OPTION_NOT_AUTOCOMMIT OPTION_BIN_LOG*2 #define OPTION_BEGIN (1L << 20)
#define OPTION_BEGIN OPTION_NOT_AUTOCOMMIT*2 #define OPTION_TABLE_LOCK (1L << 21)
#define OPTION_TABLE_LOCK OPTION_BEGIN*2 #define OPTION_QUICK (1L << 22)
#define OPTION_QUICK OPTION_TABLE_LOCK*2 #define OPTION_QUOTE_SHOW_CREATE (1L << 23)
#define OPTION_QUOTE_SHOW_CREATE OPTION_QUICK*2 #define OPTION_INTERNAL_SUBTRANSACTIONS (1L << 24)
#define OPTION_INTERNAL_SUBTRANSACTIONS OPTION_QUOTE_SHOW_CREATE*2
/* options for UNION set by the yacc parser (stored in unit->union_option) */
#define UNION_ALL 1
/* Set if we are updating a non-transaction safe table */ /* Set if we are updating a non-transaction safe table */
#define OPTION_STATUS_NO_TRANS_UPDATE OPTION_INTERNAL_SUBTRANSACTIONS*2 #define OPTION_STATUS_NO_TRANS_UPDATE (1L << 25)
/* The following is set when parsing the query */
#define QUERY_NO_INDEX_USED OPTION_STATUS_NO_TRANS_UPDATE*2
#define QUERY_NO_GOOD_INDEX_USED QUERY_NO_INDEX_USED*2
/* The following can be set when importing tables in a 'wrong order' /* The following can be set when importing tables in a 'wrong order'
to suppress foreign key checks */ to suppress foreign key checks */
#define OPTION_NO_FOREIGN_KEY_CHECKS QUERY_NO_GOOD_INDEX_USED*2 #define OPTION_NO_FOREIGN_KEY_CHECKS (1L << 26)
/* The following speeds up inserts to InnoDB tables by suppressing unique /* The following speeds up inserts to InnoDB tables by suppressing unique
key checks in some cases */ key checks in some cases */
#define OPTION_RELAXED_UNIQUE_CHECKS OPTION_NO_FOREIGN_KEY_CHECKS*2 #define OPTION_RELAXED_UNIQUE_CHECKS (1L << 27)
#define SELECT_NO_UNLOCK ((ulong) OPTION_RELAXED_UNIQUE_CHECKS*2) #define SELECT_NO_UNLOCK (1L << 28)
/* NOTE: we have now used up all 32 bits of the OPTION flag! */
/* options for UNION set by the yacc parser (stored in unit->union_option) */
#define UNION_ALL 1
/* Bits for different SQL modes modes (including ANSI mode) */ /* Bits for different SQL modes modes (including ANSI mode) */
#define MODE_REAL_AS_FLOAT 1 #define MODE_REAL_AS_FLOAT 1
......
...@@ -104,7 +104,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, ...@@ -104,7 +104,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order,
/* If running in safe sql mode, don't allow updates without keys */ /* If running in safe sql mode, don't allow updates without keys */
if (table->quick_keys.is_clear_all()) if (table->quick_keys.is_clear_all())
{ {
thd->lex.select_lex.options|=QUERY_NO_INDEX_USED; thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
if (safe_update && !using_limit) if (safe_update && !using_limit)
{ {
delete select; delete select;
......
...@@ -1203,7 +1203,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1203,7 +1203,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thread_running++; thread_running++;
VOID(pthread_mutex_unlock(&LOCK_thread_count)); VOID(pthread_mutex_unlock(&LOCK_thread_count));
thd->lex.select_lex.options=0; // We store status here thd->server_status&=
~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
switch (command) { switch (command) {
case COM_INIT_DB: case COM_INIT_DB:
{ {
...@@ -1635,8 +1636,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1635,8 +1636,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if ((ulong) (thd->start_time - thd->time_after_lock) > if ((ulong) (thd->start_time - thd->time_after_lock) >
thd->variables.long_query_time || thd->variables.long_query_time ||
((thd->lex.select_lex.options & ((thd->server_status &
(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED)) && (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) &&
(specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES))) (specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES)))
{ {
long_query_count++; long_query_count++;
...@@ -3730,6 +3731,7 @@ mysql_init_query(THD *thd) ...@@ -3730,6 +3731,7 @@ mysql_init_query(THD *thd)
lex->select_lex.prev= &lex->unit.slave; lex->select_lex.prev= &lex->unit.slave;
lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0; lex->select_lex.link_next= lex->select_lex.slave= lex->select_lex.next= 0;
lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list); lex->select_lex.link_prev= (st_select_lex_node**)&(lex->all_selects_list);
lex->select_lex.options=0;
lex->describe= 0; lex->describe= 0;
lex->derived_tables= FALSE; lex->derived_tables= FALSE;
lex->lock_option= TL_READ; lex->lock_option= TL_READ;
......
...@@ -3619,7 +3619,7 @@ make_join_readinfo(JOIN *join, uint options) ...@@ -3619,7 +3619,7 @@ make_join_readinfo(JOIN *join, uint options)
/* These init changes read_record */ /* These init changes read_record */
if (tab->use_quick == 2) if (tab->use_quick == 2)
{ {
select_lex->options|=QUERY_NO_GOOD_INDEX_USED; join->thd->server_status|=SERVER_QUERY_NO_GOOD_INDEX_USED;
tab->read_first_record= join_init_quick_read_record; tab->read_first_record= join_init_quick_read_record;
statistic_increment(select_range_check_count, &LOCK_status); statistic_increment(select_range_check_count, &LOCK_status);
} }
...@@ -3634,7 +3634,7 @@ make_join_readinfo(JOIN *join, uint options) ...@@ -3634,7 +3634,7 @@ make_join_readinfo(JOIN *join, uint options)
} }
else else
{ {
select_lex->options|=QUERY_NO_INDEX_USED; join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
statistic_increment(select_scan_count, &LOCK_status); statistic_increment(select_scan_count, &LOCK_status);
} }
} }
...@@ -3646,7 +3646,7 @@ make_join_readinfo(JOIN *join, uint options) ...@@ -3646,7 +3646,7 @@ make_join_readinfo(JOIN *join, uint options)
} }
else else
{ {
select_lex->options|=QUERY_NO_INDEX_USED; join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
statistic_increment(select_full_join_count, &LOCK_status); statistic_increment(select_full_join_count, &LOCK_status);
} }
} }
...@@ -8926,7 +8926,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, ...@@ -8926,7 +8926,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
(ulong)join->select_lex, join->select_lex->type, (ulong)join->select_lex, join->select_lex->type,
message ? message : "NULL")); message ? message : "NULL"));
/* Don't log this into the slow query log */ /* Don't log this into the slow query log */
select_lex->options&= ~(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED); thd->server_status&= ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
join->unit->offset_limit_cnt= 0; join->unit->offset_limit_cnt= 0;
if (message) if (message)
......
...@@ -166,7 +166,7 @@ int mysql_update(THD *thd, ...@@ -166,7 +166,7 @@ int mysql_update(THD *thd,
/* If running in safe sql mode, don't allow updates without keys */ /* If running in safe sql mode, don't allow updates without keys */
if (table->quick_keys.is_clear_all()) if (table->quick_keys.is_clear_all())
{ {
thd->lex.select_lex.options|=QUERY_NO_INDEX_USED; thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
if (safe_update && !using_limit) if (safe_update && !using_limit)
{ {
my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE, my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_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