summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2003-12-06 23:21:09 +0100
committerunknown <serg@serg.mylan>2003-12-06 23:21:09 +0100
commitf3bf35ec03e683815be4656ec93722e248eb56a0 (patch)
tree63c4006a74c5d36672d3bce9c6978cb1a831bdbe
parentafbeb64e936f4282661e7e904fa9a886f89a653c (diff)
downloadmariadb-git-f3bf35ec03e683815be4656ec93722e248eb56a0.tar.gz
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
-rw-r--r--include/mysql_com.h2
-rw-r--r--mysql-test/r/union.result38
-rw-r--r--mysql-test/t/union-master.opt1
-rw-r--r--mysql-test/t/union.test26
-rw-r--r--sql/mysql_priv.h69
-rw-r--r--sql/sql_delete.cc2
-rw-r--r--sql/sql_parse.cc8
-rw-r--r--sql/sql_select.cc8
-rw-r--r--sql/sql_update.cc2
9 files changed, 107 insertions, 49 deletions
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 39e9c48146d..2036b3d0ac2 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -124,6 +124,8 @@ enum enum_server_command
#define SERVER_STATUS_AUTOCOMMIT 2 /* Server in auto_commit mode */
#define SERVER_STATUS_MORE_RESULTS 4 /* More results on server */
#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 NET_READ_TIMEOUT 30 /* Timeout on read */
diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result
index 241b9847c02..642c07904b5 100644
--- a/mysql-test/r/union.result
+++ b/mysql-test/r/union.result
@@ -823,3 +823,41 @@ count(*)
13
drop table t1,t2;
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;
diff --git a/mysql-test/t/union-master.opt b/mysql-test/t/union-master.opt
new file mode 100644
index 00000000000..3eb98fc3d6b
--- /dev/null
+++ b/mysql-test/t/union-master.opt
@@ -0,0 +1 @@
+--log-slow-queries --log-long-format --log-queries-not-using-indexes
diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test
index e302378e117..a5cb1ce6b6e 100644
--- a/mysql-test/t/union.test
+++ b/mysql-test/t/union.test
@@ -419,9 +419,6 @@ drop table t1;
#
# conversion memory->disk table
#
-#
-# conversion memory->disk table
-#
create table t1 (s char(200));
insert into t1 values (repeat("1",200));
create table t2 select * from t1;
@@ -436,3 +433,26 @@ select count(*) from t1;
select count(*) from t2;
drop table t1,t2;
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;
+
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 4e2be96b9c7..62494da45d4 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -177,50 +177,45 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
#define TEST_SIGINT 1024 /* Allow sigint on threads */
/* options for select set by the yacc parser (stored in lex->options) */
-#define SELECT_DISTINCT 1
-#define SELECT_STRAIGHT_JOIN 2
-#define SELECT_DESCRIBE 4
-#define SELECT_SMALL_RESULT 8
-#define SELECT_BIG_RESULT 16
-#define OPTION_FOUND_ROWS 32
-#define OPTION_TO_QUERY_CACHE 64
-#define SELECT_NO_JOIN_CACHE 256 /* Intern */
-
-#define OPTION_BIG_TABLES 512 /* for SQL OPTION */
-#define OPTION_BIG_SELECTS 1024 /* for SQL OPTION */
-#define OPTION_LOG_OFF 2048
-#define OPTION_UPDATE_LOG 4096 /* update log flag */
-#define TMP_TABLE_ALL_COLUMNS 8192
-#define OPTION_WARNINGS 16384
-#define OPTION_AUTO_IS_NULL 32768
-#define OPTION_FOUND_COMMENT 65536L
-#define OPTION_SAFE_UPDATES OPTION_FOUND_COMMENT*2
-#define OPTION_BUFFER_RESULT OPTION_SAFE_UPDATES*2
-#define OPTION_BIN_LOG OPTION_BUFFER_RESULT*2
-#define OPTION_NOT_AUTOCOMMIT OPTION_BIN_LOG*2
-#define OPTION_BEGIN OPTION_NOT_AUTOCOMMIT*2
-#define OPTION_TABLE_LOCK OPTION_BEGIN*2
-#define OPTION_QUICK OPTION_TABLE_LOCK*2
-#define OPTION_QUOTE_SHOW_CREATE OPTION_QUICK*2
-#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
+#define SELECT_DISTINCT (1L << 0)
+#define SELECT_STRAIGHT_JOIN (1L << 1)
+#define SELECT_DESCRIBE (1L << 2)
+#define SELECT_SMALL_RESULT (1L << 3)
+#define SELECT_BIG_RESULT (1L << 4)
+#define OPTION_FOUND_ROWS (1L << 5)
+#define OPTION_TO_QUERY_CACHE (1L << 6)
+#define SELECT_NO_JOIN_CACHE (1L << 7) /* Intern */
+#define OPTION_BIG_TABLES (1L << 8) /* for SQL OPTION */
+#define OPTION_BIG_SELECTS (1L << 9) /* for SQL OPTION */
+#define OPTION_LOG_OFF (1L << 10)
+#define OPTION_UPDATE_LOG (1L << 11) /* update log flag */
+#define TMP_TABLE_ALL_COLUMNS (1L << 12)
+#define OPTION_WARNINGS (1L << 13)
+#define OPTION_AUTO_IS_NULL (1L << 14)
+#define OPTION_FOUND_COMMENT (1L << 15)
+#define OPTION_SAFE_UPDATES (1L << 16)
+#define OPTION_BUFFER_RESULT (1L << 17)
+#define OPTION_BIN_LOG (1L << 18)
+#define OPTION_NOT_AUTOCOMMIT (1L << 19)
+#define OPTION_BEGIN (1L << 20)
+#define OPTION_TABLE_LOCK (1L << 21)
+#define OPTION_QUICK (1L << 22)
+#define OPTION_QUOTE_SHOW_CREATE (1L << 23)
+#define OPTION_INTERNAL_SUBTRANSACTIONS (1L << 24)
/* 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'
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
key checks in some cases */
-#define OPTION_RELAXED_UNIQUE_CHECKS OPTION_NO_FOREIGN_KEY_CHECKS*2
-#define SELECT_NO_UNLOCK ((ulong) OPTION_RELAXED_UNIQUE_CHECKS*2)
-/* NOTE: we have now used up all 32 bits of the OPTION flag! */
+#define OPTION_RELAXED_UNIQUE_CHECKS (1L << 27)
+#define SELECT_NO_UNLOCK (1L << 28)
+
+/* 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) */
#define MODE_REAL_AS_FLOAT 1
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 4bab7be255c..94ae1743fd9 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -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 (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)
{
delete select;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c50bfc43862..6442bbc1e1d 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1203,7 +1203,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thread_running++;
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) {
case COM_INIT_DB:
{
@@ -1635,8 +1636,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if ((ulong) (thd->start_time - thd->time_after_lock) >
thd->variables.long_query_time ||
- ((thd->lex.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)) &&
(specialflag & SPECIAL_LOG_QUERIES_NOT_USING_INDEXES)))
{
long_query_count++;
@@ -3730,6 +3731,7 @@ mysql_init_query(THD *thd)
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_prev= (st_select_lex_node**)&(lex->all_selects_list);
+ lex->select_lex.options=0;
lex->describe= 0;
lex->derived_tables= FALSE;
lex->lock_option= TL_READ;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 69e8ea8ccff..3d2a572c3a9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -3619,7 +3619,7 @@ make_join_readinfo(JOIN *join, uint options)
/* These init changes read_record */
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;
statistic_increment(select_range_check_count, &LOCK_status);
}
@@ -3634,7 +3634,7 @@ make_join_readinfo(JOIN *join, uint options)
}
else
{
- select_lex->options|=QUERY_NO_INDEX_USED;
+ join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
statistic_increment(select_scan_count, &LOCK_status);
}
}
@@ -3646,7 +3646,7 @@ make_join_readinfo(JOIN *join, uint options)
}
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);
}
}
@@ -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,
message ? message : "NULL"));
/* 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;
if (message)
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index d623ea66dfb..95dff107350 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -166,7 +166,7 @@ int mysql_update(THD *thd,
/* If running in safe sql mode, don't allow updates without keys */
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)
{
my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,