diff options
author | unknown <monty@hundin.mysql.fi> | 2002-02-08 03:21:34 +0200 |
---|---|---|
committer | unknown <monty@hundin.mysql.fi> | 2002-02-08 03:21:34 +0200 |
commit | 0f9932a162bdd80d83fd0c4a3d6641d41ff3f1e3 (patch) | |
tree | 6fb2be8a25c87f580e5d7831b049ad0839a48237 | |
parent | 6340283614f9f5cc4b9212ec5affa177b3f71711 (diff) | |
download | mariadb-git-0f9932a162bdd80d83fd0c4a3d6641d41ff3f1e3.tar.gz |
Fix some bugs introduced with the new my_getopt
Added counting of rollback's and commits
Fixed bug in 'SELECT 0 LIMIT 0'
Fixed bug in 'SELECT SQL_CALC_FOUND_ROWS'
Docs/manual.texi:
Changelog
configure.in:
Cleanup
myisam/myisamchk.c:
Fix some bugs introduced with the new my_getopt
mysql-test/r/limit.result:
Test for bugfix
mysql-test/r/rpl000001.result:
fix wrong result
mysql-test/r/select.result:
Fix things after fixing ignore index()
mysql-test/r/select_found.result:
Test of bug in SQL_CALC_FOUND_ROWS
mysql-test/t/limit.test:
Test bug in LIMIT 0
mysql-test/t/rpl000001.test:
fix wrong result
mysql-test/t/select_found.test:
Test of bug in SQL_CALC_FOUND_ROWS
sql/handler.cc:
Added counting of rollback's and commits
sql/mysql_priv.h:
Added counting of rollback's and commits
sql/mysqld.cc:
Added counting of rollback's and commits
sql/sql_select.cc:
Fixed bug in 'SELECT 0 LIMIT 0'
Fixed bug in 'SELECT SQL_CALC_FOUND_ROWS'
-rw-r--r-- | Docs/manual.texi | 5 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | myisam/myisamchk.c | 101 | ||||
-rw-r--r-- | mysql-test/r/limit.result | 2 | ||||
-rw-r--r-- | mysql-test/r/rpl000001.result | 2 | ||||
-rw-r--r-- | mysql-test/r/select.result | 4 | ||||
-rw-r--r-- | mysql-test/r/select_found.result | 17 | ||||
-rw-r--r-- | mysql-test/t/limit.test | 2 | ||||
-rw-r--r-- | mysql-test/t/rpl000001.test | 1 | ||||
-rw-r--r-- | mysql-test/t/select_found.test | 12 | ||||
-rw-r--r-- | sql/handler.cc | 12 | ||||
-rw-r--r-- | sql/mysql_priv.h | 3 | ||||
-rw-r--r-- | sql/mysqld.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 11 |
14 files changed, 128 insertions, 48 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi index c060c0e4d21..bafc990f0e6 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -48385,6 +48385,11 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}. @itemize @bullet @item +Fixed a bug where @code{SQL_CALC_ROWS} returned a wrong value when used +with one table and @code{ORDER BY} and with InnoDB tables. +@item +Fixed that @code{SELECT 0 LIMIT 0} doesn't hang thread. +@item Fixed some problems with @code{USE KEYS} / @code{IGNORE KEYS} when using many keys with the same start column. @item diff --git a/configure.in b/configure.in index 50000a808b7..2b511c59bd5 100644 --- a/configure.in +++ b/configure.in @@ -188,7 +188,7 @@ AC_DEFINE(SPRINTF_RETURNS_INT) AC_MSG_RESULT("int"), # option, cache_name, variable, -# code to execute if yes, code to exectute if fal +# code to execute if yes, code to exectute if fail AC_DEFUN(AC_SYS_COMPILER_FLAG, [ AC_MSG_CHECKING($1) diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 20aaaf6ac8e..60ffbaeccdb 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -193,7 +193,7 @@ static struct my_option my_long_options[] = 0, 0, 0, GET_NO_ARG, NO_ARG, 'i', 0, 0, 0, 0, 0, 0}, {"keys-used", "Tell MyISAM to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts!", (gptr*) &check_param.keys_in_use, (gptr*) &check_param.keys_in_use, 0, - GET_LONG, REQUIRED_ARG, 'k', 0, 0, 0, 0, 0, 0}, + GET_LL, REQUIRED_ARG, 'k', -1LL, 0, 0, 0, 0, 0}, {"medium-check", "Faster than extended-check, but only finds 99.99% of all errors. Should be good enough for most cases.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'm', 0, 0, 0, 0, 0, 0}, @@ -384,8 +384,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { - uint old_testflag; - switch (optid) { case 'a': if (argument && *argument == '0') @@ -417,10 +415,7 @@ get_one_option(int optid, break; case 'C': if (argument && *argument == '0') - { - check_param.testflag&= ~T_CHECK; - check_param.testflag&= ~T_CHECK_ONLY_CHANGED; - } + check_param.testflag&= ~(T_CHECK | T_CHECK_ONLY_CHANGED); else check_param.testflag|= T_CHECK | T_CHECK_ONLY_CHANGED; break; @@ -429,11 +424,7 @@ get_one_option(int optid, break; case 's': /* silent */ if (argument && *argument == '0') - { - if (check_param.testflag & T_VERY_SILENT) - check_param.testflag&= ~T_VERY_SILENT; - check_param.testflag&= ~T_SILENT; - } + check_param.testflag&= ~(T_SILENT | T_VERY_SILENT); else { if (check_param.testflag & T_SILENT) @@ -467,8 +458,16 @@ get_one_option(int optid, check_param.testflag|= T_INFO; break; case 'f': - check_param.tmpfile_createflag= O_RDWR | O_TRUNC; - check_param.testflag|= T_FORCE_CREATE | T_UPDATE_STATE; + if (argument && *argument == '0') + { + check_param.tmpfile_createflag= O_RDWR | O_TRUNC | O_EXCL; + check_param.testflag&= ~(T_FORCE_CREATE | T_UPDATE_STATE); + } + else + { + check_param.tmpfile_createflag= O_RDWR | O_TRUNC; + check_param.testflag|= T_FORCE_CREATE | T_UPDATE_STATE; + } break; case 'F': if (argument && *argument == '0') @@ -486,61 +485,82 @@ get_one_option(int optid, check_param.testflag|= T_MEDIUM; /* Medium check */ break; case 'r': /* Repair table */ - check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; + if (argument && *argument == '0') + check_param.testflag&= ~(T_REP | T_REP_BY_SORT); + else + check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; break; case 'o': - check_param.testflag= (check_param.testflag & ~T_REP_BY_SORT) | T_REP; - check_param.force_sort=0; - my_disable_async_io=1; /* More safety */ + if (argument && *argument == '0') + { + check_param.testflag&= ~(T_REP | T_REP_BY_SORT); + check_param.force_sort= 0; + } + else + { + check_param.testflag= (check_param.testflag & ~T_REP_BY_SORT) | T_REP; + check_param.force_sort= 0; + my_disable_async_io= 1; /* More safety */ + } break; case 'n': - check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; - check_param.force_sort= 1; + if (argument && *argument == '0') + { + check_param.testflag&= ~(T_REP | T_REP_BY_SORT); + check_param.force_sort= 0; + } + else + { + check_param.testflag= (check_param.testflag & ~T_REP) | T_REP_BY_SORT; + check_param.force_sort= 1; + } break; case 'q': if (argument && *argument == '0') - check_param.opt_rep_quick--; + check_param.opt_rep_quick=0; else check_param.opt_rep_quick++; break; case 'u': if (argument && *argument == '0') - { - check_param.testflag&= ~T_UNPACK; - check_param.testflag&= ~T_REP_BY_SORT; - } + check_param.testflag&= ~(T_UNPACK | T_REP_BY_SORT); else check_param.testflag|= T_UNPACK | T_REP_BY_SORT; break; case 'v': /* Verbose */ if (argument && *argument == '0') + { check_param.testflag&= ~T_VERBOSE; + check_param.verbose=0; + } else + { check_param.testflag|= T_VERBOSE; - check_param.verbose++; + check_param.verbose++; + } break; case 'R': /* Sort records */ - old_testflag= check_param.testflag; - check_param.testflag|= T_SORT_RECORDS; - check_param.opt_sort_key= (uint) atoi(argument) - 1; - if (check_param.opt_sort_key >= MI_MAX_KEY) + if (argument && *argument == '0') + check_param.testflag&= ~T_SORT_RECORDS; + else { - fprintf(stderr, - "The value of the sort key is bigger than max key: %d.\n", - MI_MAX_KEY); - exit(1); + check_param.testflag|= T_SORT_RECORDS; + check_param.opt_sort_key= (uint) atoi(argument) - 1; + if (check_param.opt_sort_key >= MI_MAX_KEY) + { + fprintf(stderr, + "The value of the sort key is bigger than max key: %d.\n", + MI_MAX_KEY); + exit(1); + } } break; case 'S': /* Sort index */ - old_testflag= check_param.testflag; if (argument && *argument == '0') check_param.testflag&= ~T_SORT_INDEX; else check_param.testflag|= T_SORT_INDEX; break; - case 't': - check_param.tmpdir= argument; - break; case 'T': if (argument && *argument == '0') check_param.testflag&= ~T_READONLY; @@ -554,7 +574,10 @@ get_one_option(int optid, check_param.testflag|= T_UPDATE_STATE; break; case '#': - DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace"); + if (argument && *argument == '0') + DBUG_POP(); + else + DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace"); break; case 'V': print_version(); diff --git a/mysql-test/r/limit.result b/mysql-test/r/limit.result index f341eebb968..5a8edc99c12 100644 --- a/mysql-test/r/limit.result +++ b/mysql-test/r/limit.result @@ -48,3 +48,5 @@ i 2 1 drop table t1; +select 0 limit 0; +0 diff --git a/mysql-test/r/rpl000001.result b/mysql-test/r/rpl000001.result index 3dae52c6d3f..60a5db1de3a 100644 --- a/mysql-test/r/rpl000001.result +++ b/mysql-test/r/rpl000001.result @@ -7,7 +7,7 @@ use test; drop table if exists t1,t3; create table t1 (word char(20) not null); load data infile '../../std_data/words.dat' into table t1; -load data local infile '/home/sasha/bk/mysql-4.0/mysql-test/std_data/words.dat' into table t1; +load data local infile 'MYSQL_TEST_DIR/std_data/words.dat' into table t1; select * from t1; word Aarhus diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index ee057b268fd..051aeb43b43 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -1331,10 +1331,10 @@ table type possible_keys key key_len ref rows Extra t2 ref fld3 fld3 30 const 1 where used; Using index explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; table type possible_keys key key_len ref rows Extra -t2 index fld3 fld3 30 NULL 1199 where used; Using index +t2 index NULL fld3 30 NULL 1199 where used; Using index explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; table type possible_keys key key_len ref rows Extra -t2 index fld3 fld3 30 NULL 1199 where used; Using index +t2 index NULL fld3 30 NULL 1199 where used; Using index explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; table type possible_keys key key_len ref rows Extra t2 ref fld3 fld3 30 const 1 where used; Using index diff --git a/mysql-test/r/select_found.result b/mysql-test/r/select_found.result index 2fab1642cc5..3a84c3e52da 100644 --- a/mysql-test/r/select_found.result +++ b/mysql-test/r/select_found.result @@ -45,3 +45,20 @@ select found_rows(); FOUND_ROWS() 8 drop table t1; +create table t1 (a int not null primary key); +insert into t1 values (1),(2),(3),(4),(5); +select sql_calc_found_rows a from t1 where a in (1,2,3) order by a desc limit 0,2; +a +3 +2 +select FOUND_ROWS(); +FOUND_ROWS() +3 +select sql_calc_found_rows a from t1 where a in (1,2,3) order by a+2 desc limit 0,2; +a +3 +2 +select FOUND_ROWS(); +FOUND_ROWS() +3 +drop table t1; diff --git a/mysql-test/t/limit.test b/mysql-test/t/limit.test index 112761abd87..d4f6ce186cf 100644 --- a/mysql-test/t/limit.test +++ b/mysql-test/t/limit.test @@ -28,3 +28,5 @@ delete from t1 limit 0; update t1 set i=3 limit 0; select * from t1; drop table t1; + +select 0 limit 0; diff --git a/mysql-test/t/rpl000001.test b/mysql-test/t/rpl000001.test index 597b1c69b1e..a5496d505f0 100644 --- a/mysql-test/t/rpl000001.test +++ b/mysql-test/t/rpl000001.test @@ -5,6 +5,7 @@ use test; drop table if exists t1,t3; create table t1 (word char(20) not null); load data infile '../../std_data/words.dat' into table t1; +--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR eval load data local infile '$MYSQL_TEST_DIR/std_data/words.dat' into table t1; select * from t1; set password for root@"localhost" = password('foo'); diff --git a/mysql-test/t/select_found.test b/mysql-test/t/select_found.test index 52c8039b2f5..9b14ab1fcf0 100644 --- a/mysql-test/t/select_found.test +++ b/mysql-test/t/select_found.test @@ -18,3 +18,15 @@ select found_rows(); select SQL_CALC_FOUND_ROWS * from t1 left join t1 as t2 on (t1.b=t2.a) limit 2,1; select found_rows(); drop table t1; + +# +# Test SQL_CALC_FOUND_ROWS optimization when used with one table and filesort +# + +create table t1 (a int not null primary key); +insert into t1 values (1),(2),(3),(4),(5); +select sql_calc_found_rows a from t1 where a in (1,2,3) order by a desc limit 0,2; +select FOUND_ROWS(); +select sql_calc_found_rows a from t1 where a in (1,2,3) order by a+2 desc limit 0,2; +select FOUND_ROWS(); +drop table t1; diff --git a/sql/handler.cc b/sql/handler.cc index 1e879c55b5e..507b77c977b 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -45,6 +45,7 @@ static int NEAR_F delete_file(const char *name,const char *ext,int extflag); ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, ha_read_key_count, ha_read_next_count, ha_read_prev_count, ha_read_first_count, ha_read_last_count, + ha_commit_count, ha_rollback_count, ha_read_rnd_count, ha_read_rnd_next_count; const char *ha_table_type[] = { @@ -267,6 +268,7 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) #ifdef USING_TRANSACTIONS if (opt_using_transactions) { + bool operation_done=0; /* Update the binary log if we have cached some queries */ if (trans == &thd->transaction.all && mysql_bin_log.is_open() && my_b_tell(&thd->transaction.trans_log)) @@ -297,12 +299,17 @@ int ha_commit_trans(THD *thd, THD_TRANS* trans) } trans->innodb_active_trans=0; if (trans == &thd->transaction.all) + { query_cache.invalidate(Query_cache_table::INNODB); + operation_done=1; + } } #endif if (error && trans == &thd->transaction.all && mysql_bin_log.is_open()) sql_print_error("Error: Got error during commit; Binlog is not up to date!"); thd->tx_isolation=thd->session_tx_isolation; + if (operation_done) + statistic_increment(ha_commit_count,&LOCK_status); } #endif // using transactions DBUG_RETURN(error); @@ -316,6 +323,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) #ifdef USING_TRANSACTIONS if (opt_using_transactions) { + bool operation_done=0; #ifdef HAVE_BERKELEY_DB if (trans->bdb_tid) { @@ -325,6 +333,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) error=1; } trans->bdb_tid=0; + operation_done=1; } #endif #ifdef HAVE_INNOBASE_DB @@ -336,6 +345,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) error=1; } trans->innodb_active_trans=0; + operation_done=1; } #endif if (trans == &thd->transaction.all) @@ -343,6 +353,8 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) WRITE_CACHE, (my_off_t) 0, 0, 1); thd->transaction.trans_log.end_of_file= max_binlog_cache_size; thd->tx_isolation=thd->session_tx_isolation; + if (operation_done) + statistic_increment(ha_rollback_count,&LOCK_status); } #endif /* USING_TRANSACTIONS */ DBUG_RETURN(error); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 81604a7ecfd..03a50040d70 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -586,7 +586,8 @@ extern char f_fyllchar; extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, ha_read_key_count, ha_read_next_count, ha_read_prev_count, ha_read_first_count, ha_read_last_count, - ha_read_rnd_count, ha_read_rnd_next_count; + ha_read_rnd_count, ha_read_rnd_next_count, + ha_commit_count, ha_rollback_count; extern MY_BITMAP temp_pool; extern uchar *days_in_month; extern DATE_FORMAT dayord; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 52a1206eab9..7250288c924 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3211,6 +3211,7 @@ struct show_var_st status_vars[]= { {"Delayed_writes", (char*) &delayed_insert_writes, SHOW_LONG}, {"Delayed_errors", (char*) &delayed_insert_errors, SHOW_LONG}, {"Flush_commands", (char*) &refresh_version, SHOW_LONG_CONST}, + {"Handler_commit", (char*) &ha_commit_count, SHOW_LONG}, {"Handler_delete", (char*) &ha_delete_count, SHOW_LONG}, {"Handler_read_first", (char*) &ha_read_first_count, SHOW_LONG}, {"Handler_read_key", (char*) &ha_read_key_count, SHOW_LONG}, @@ -3218,6 +3219,7 @@ struct show_var_st status_vars[]= { {"Handler_read_prev", (char*) &ha_read_prev_count, SHOW_LONG}, {"Handler_read_rnd", (char*) &ha_read_rnd_count, SHOW_LONG}, {"Handler_read_rnd_next", (char*) &ha_read_rnd_next_count, SHOW_LONG}, + {"Handler_rollback", (char*) &ha_rollback_count, SHOW_LONG}, {"Handler_update", (char*) &ha_update_count, SHOW_LONG}, {"Handler_write", (char*) &ha_write_count, SHOW_LONG}, {"Key_blocks_used", (char*) &_my_blocks_used, SHOW_LONG_CONST}, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 0911ea57515..e2e5e4bf55a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2929,17 +2929,17 @@ return_zero_rows(select_result *result,TABLE_LIST *tables,List<Item> &fields, if (having && having->val_int() == 0) send_row=0; } - if (!tables || !(result->send_fields(fields,1))) + if (!(result->send_fields(fields,1))) { if (send_row) result->send_data(fields); - if (tables) // Not from do_select() + if (tables) // Not from do_select() { /* Close open cursors */ for (TABLE_LIST *table=tables; table ; table=table->next) table->table->file->index_end(); - result->send_eof(); // Should be safe } + result->send_eof(); // Should be safe } DBUG_RETURN(0); } @@ -4877,8 +4877,10 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), { JOIN_TAB *jt=join->join_tab; if ((join->tables == 1) && !join->tmp_table && !join->sort_and_group - && !join->send_group_parts && !join->having && !jt->select_cond) + && !join->send_group_parts && !join->having && !jt->select_cond && + !(jt->table->file->option_flag() & HA_NOT_EXACT_COUNT)) { + /* Join over all rows in table; Return number of found rows */ join->select_options ^= OPTION_FOUND_ROWS; join->send_records = jt->records; } @@ -5603,6 +5605,7 @@ create_sort_index(JOIN_TAB *tab,ORDER *order,ha_rows select_limit) table->file->info(HA_STATUS_VARIABLE); // Get record count table->found_records=filesort(table,sortorder,length, select, 0L, select_limit, &examined_rows); + tab->records=table->found_records; // For SQL_CALC_ROWS delete select; // filesort did select tab->select=0; tab->select_cond=0; |