mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
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'
This commit is contained in:
parent
040b5c2997
commit
d36ac6b669
14 changed files with 128 additions and 48 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -48,3 +48,5 @@ i
|
|||
2
|
||||
1
|
||||
drop table t1;
|
||||
select 0 limit 0;
|
||||
0
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue