Commit 4474300a authored by Chad MILLER's avatar Chad MILLER

Merge bugteam trunk and local.

parents 04d83cc8 ed2d0035
......@@ -61,7 +61,7 @@ static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#endif
/* Solaris's term.h does horrid things. */
/* Don't use Solaris's term.h. */
#if (defined(HAVE_TERM_H) && !defined(__SunOS))
#include <term.h>
#endif
......
......@@ -720,3 +720,11 @@ connection con1;
drop table t1;
disconnect con1;
connection default;
#
# Bug#44151 using handler commands on information_schema tables crashes server
#
USE information_schema;
--error ER_WRONG_USAGE
HANDLER COLUMNS OPEN;
USE test;
......@@ -2,7 +2,8 @@ DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (id INTEGER, grp TINYINT, id_rev INTEGER);
SELECT COUNT(*) FROM t1;
COUNT(*)
4181000
4201000
SELECT COUNT(DISTINCT id) FROM t1 GROUP BY grp;
# Begin cleanup
SET session myisam_sort_buffer_size = @orig_myisam_sort_buffer_size;
DROP TABLE t1;
set @@read_buffer_size=default;
select des_encrypt('hello');
des_encrypt('hello')
€Ö2nV“Ø}
#
# Bug #11643: des_encrypt() causes server to die
#
CREATE TABLE t1 (des VARBINARY(200) NOT NULL DEFAULT '') ENGINE=MyISAM;
INSERT INTO t1 VALUES ('1234'), ('12345'), ('123456'), ('1234567');
UPDATE t1 SET des=DES_ENCRYPT('1234');
SELECT LENGTH(des) FROM t1;
LENGTH(des)
9
9
9
9
SELECT DES_DECRYPT(des) FROM t1;
DES_DECRYPT(des)
1234
1234
1234
1234
SELECT
LENGTH(DES_ENCRYPT('1234')),
LENGTH(DES_ENCRYPT('12345')),
LENGTH(DES_ENCRYPT('123456')),
LENGTH(DES_ENCRYPT('1234567'));
LENGTH(DES_ENCRYPT('1234')) LENGTH(DES_ENCRYPT('12345')) LENGTH(DES_ENCRYPT('123456')) LENGTH(DES_ENCRYPT('1234567'))
9 9 9 9
SELECT
DES_DECRYPT(DES_ENCRYPT('1234')),
DES_DECRYPT(DES_ENCRYPT('12345')),
DES_DECRYPT(DES_ENCRYPT('123456')),
DES_DECRYPT(DES_ENCRYPT('1234567'));
DES_DECRYPT(DES_ENCRYPT('1234')) DES_DECRYPT(DES_ENCRYPT('12345')) DES_DECRYPT(DES_ENCRYPT('123456')) DES_DECRYPT(DES_ENCRYPT('1234567'))
1234 12345 123456 1234567
DROP TABLE t1;
End of 5.0 tests
......@@ -739,3 +739,7 @@ handler t1 read a next;
ERROR HY000: Table storage engine for 't1' doesn't have this option
handler t1 close;
drop table t1;
USE information_schema;
HANDLER COLUMNS OPEN;
ERROR HY000: Incorrect usage of HANDLER OPEN and information_schema
USE test;
......@@ -737,3 +737,7 @@ handler t1 read a next;
ERROR HY000: Table storage engine for 't1' doesn't have this option
handler t1 close;
drop table t1;
USE information_schema;
HANDLER COLUMNS OPEN;
ERROR HY000: Incorrect usage of HANDLER OPEN and information_schema
USE test;
......@@ -38,3 +38,10 @@ a
11
7
drop table t1;
create table t1 (a int, b int) engine=myisam;
create table t2 (c int, d int, key (c)) engine=innodb;
insert into t1 values (1,1);
insert into t2 values (1,2);
set session transaction isolation level read committed;
delete from t1 using t1 join t2 on t1.a = t2.c where t2.d in (1);
drop table t1, t2;
......@@ -1736,36 +1736,36 @@ select count(*) from t1 where x = 18446744073709551601;
count(*)
1
drop table t1;
show status like "Innodb_buffer_pool_pages_total";
Variable_name Value
Innodb_buffer_pool_pages_total 512
show status like "Innodb_page_size";
Variable_name Value
Innodb_page_size 16384
show status like "Innodb_rows_deleted";
Variable_name Value
Innodb_rows_deleted 71
show status like "Innodb_rows_inserted";
Variable_name Value
Innodb_rows_inserted 1084
show status like "Innodb_rows_updated";
Variable_name Value
Innodb_rows_updated 885
show status like "Innodb_row_lock_waits";
Variable_name Value
Innodb_row_lock_waits 0
show status like "Innodb_row_lock_current_waits";
Variable_name Value
Innodb_row_lock_current_waits 0
show status like "Innodb_row_lock_time";
Variable_name Value
Innodb_row_lock_time 0
show status like "Innodb_row_lock_time_max";
Variable_name Value
Innodb_row_lock_time_max 0
show status like "Innodb_row_lock_time_avg";
Variable_name Value
Innodb_row_lock_time_avg 0
SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_buffer_pool_pages_total';
variable_value
512
SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_page_size';
variable_value
16384
SELECT variable_value - @innodb_rows_deleted_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_deleted';
variable_value - @innodb_rows_deleted_orig
71
SELECT variable_value - @innodb_rows_inserted_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_inserted';
variable_value - @innodb_rows_inserted_orig
1084
SELECT variable_value - @innodb_rows_updated_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_updated';
variable_value - @innodb_rows_updated_orig
885
SELECT variable_value - @innodb_row_lock_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits';
variable_value - @innodb_row_lock_waits_orig
0
SELECT variable_value - @innodb_row_lock_current_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits';
variable_value - @innodb_row_lock_current_waits_orig
0
SELECT variable_value - @innodb_row_lock_time_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time';
variable_value - @innodb_row_lock_time_orig
0
SELECT variable_value - @innodb_row_lock_time_max_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max';
variable_value - @innodb_row_lock_time_max_orig
0
SELECT variable_value - @innodb_row_lock_time_avg_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg';
variable_value - @innodb_row_lock_time_avg_orig
0
show variables like "innodb_sync_spin_loops";
Variable_name Value
innodb_sync_spin_loops 20
......
......@@ -2115,4 +2115,16 @@ insert into m1 (col1) values (1);
insert into m1 (col1) values (1);
ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
drop table m1, t1;
CREATE TABLE t1 (
col1 INT(10)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE VIEW v1 as SELECT * FROM t1;
CREATE TABLE m1 (
col1 INT(10)
)ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(v1);
#Select should detect that the child table is a view and fail.
SELECT * FROM m1;
ERROR HY000: Unable to open underlying table which is differently defined or of non-MyISAM type or doesn't exist
DROP VIEW v1;
DROP TABLE m1, t1;
End of 5.1 tests
......@@ -10,5 +10,4 @@
#
##############################################################################
rpl_binlog_corruption : BUG#41793 2008-12-30 sven rpl_binlog_corruption disabled in main (needs new mtr)
rpl_cross_version : BUG#42311 2009-03-27 joro rpl_cross_version fails on macosx
......@@ -34,6 +34,7 @@ source include/setup_fake_relay_log.inc;
--echo ==== Test ====
START SLAVE SQL_THREAD;
let $slave_sql_errno= 1594; # ER_SLAVE_RELAY_LOG_READ_FAILURE
source include/wait_for_slave_sql_error.inc;
let $error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Error, 1);
--echo Last_SQL_Error = $error
......
#
# Bug #958 a big table without indices and select with group by doesnt work
# this is a test for error 1032 in count(distinct) + group by, introduced in
# mysql-4.1
#
......@@ -21,27 +21,16 @@ while ($1)
INSERT INTO t1 (id, grp, id_rev) VALUES (@id, @grp, @id_rev);
dec $1;
}
set @@read_buffer_size=2*1024*1024;
CREATE TABLE t2 SELECT * FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
INSERT INTO t1 (id, grp, id_rev) SELECT id, grp, id_rev FROM t2;
INSERT INTO t2 (id, grp, id_rev) SELECT id, grp, id_rev FROM t1;
DROP TABLE t2;
# We increase the size of t1 here.
SET @orig_myisam_sort_buffer_size = @@session.myisam_sort_buffer_size;
SET session myisam_sort_buffer_size=20000000;
INSERT INTO t1
SELECT A.id, A.grp, A.id_rev
FROM
t1 A,
(SELECT * FROM t1 B LIMIT 100) B,
(SELECT * FROM t1 Z LIMIT 42) Z;
--enable_query_log
SELECT COUNT(*) FROM t1;
......@@ -49,12 +38,12 @@ SELECT COUNT(*) FROM t1;
# As t1 contains random numbers, results are different from test to test.
# That's okay, because we test only that select doesn't yield an
# error. Note, that --disable_result_log doesn't suppress error output.
--disable_result_log
SELECT COUNT(DISTINCT id) FROM t1 GROUP BY grp;
--enable_result_log
DROP TABLE t1;
set @@read_buffer_size=default;
--echo # Begin cleanup
SET session myisam_sort_buffer_size = @orig_myisam_sort_buffer_size;
DROP TABLE t1;
# End of 4.1 tests
......@@ -9,3 +9,31 @@
select des_encrypt('hello');
# End of 4.1 tests
--echo #
--echo # Bug #11643: des_encrypt() causes server to die
--echo #
CREATE TABLE t1 (des VARBINARY(200) NOT NULL DEFAULT '') ENGINE=MyISAM;
INSERT INTO t1 VALUES ('1234'), ('12345'), ('123456'), ('1234567');
UPDATE t1 SET des=DES_ENCRYPT('1234');
SELECT LENGTH(des) FROM t1;
SELECT DES_DECRYPT(des) FROM t1;
SELECT
LENGTH(DES_ENCRYPT('1234')),
LENGTH(DES_ENCRYPT('12345')),
LENGTH(DES_ENCRYPT('123456')),
LENGTH(DES_ENCRYPT('1234567'));
SELECT
DES_DECRYPT(DES_ENCRYPT('1234')),
DES_DECRYPT(DES_ENCRYPT('12345')),
DES_DECRYPT(DES_ENCRYPT('123456')),
DES_DECRYPT(DES_ENCRYPT('1234567'));
DROP TABLE t1;
--Echo End of 5.0 tests
......@@ -53,3 +53,16 @@ drop table t1;
connection default;
disconnect a;
disconnect b;
# Bug 39320
create table t1 (a int, b int) engine=myisam;
create table t2 (c int, d int, key (c)) engine=innodb;
insert into t1 values (1,1);
insert into t2 values (1,2);
connect (a,localhost,root,,);
connection a;
set session transaction isolation level read committed;
delete from t1 using t1 join t2 on t1.a = t2.c where t2.d in (1);
connection default;
disconnect a;
drop table t1, t2;
......@@ -6,22 +6,45 @@
# Use innodb_mysql.[test|result] files instead. #
# #
# If nevertheless you need to make some changes here, please, forward #
# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com #
# your commit message #
# To: innodb_dev_ww@oracle.com #
# Cc: dev-innodb@mysql.com #
# (otherwise your changes may be erased). #
# #
#######################################################################
-- source include/have_innodb.inc
#
# Small basic test with ignore
#
# Save the original values of some variables in order to be able to
# estimate how much they have changed during the tests. Previously this
# test assumed that e.g. rows_deleted is 0 here and after deleting 23
# rows it expected that rows_deleted will be 23. Now we do not make
# assumptions about the values of the variables at the beginning, e.g.
# rows_deleted should be 23 + "rows_deleted before the test". This allows
# the test to be run multiple times without restarting the mysqld server.
# See Bug#43309 Test main.innodb can't be run twice
-- disable_query_log
SET @innodb_thread_concurrency_orig = @@innodb_thread_concurrency;
SET @innodb_rows_deleted_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_deleted');
SET @innodb_rows_inserted_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_inserted');
SET @innodb_rows_updated_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_updated');
SET @innodb_row_lock_waits_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits');
SET @innodb_row_lock_current_waits_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits');
SET @innodb_row_lock_time_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time');
SET @innodb_row_lock_time_max_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max');
SET @innodb_row_lock_time_avg_orig = (SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg');
-- enable_query_log
--disable_warnings
drop table if exists t1,t2,t3,t4;
drop database if exists mysqltest;
--enable_warnings
#
# Small basic test with ignore
#
create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
......@@ -1294,18 +1317,18 @@ drop table t1;
# Test for testable InnoDB status variables. This test
# uses previous ones(pages_created, rows_deleted, ...).
show status like "Innodb_buffer_pool_pages_total";
show status like "Innodb_page_size";
show status like "Innodb_rows_deleted";
show status like "Innodb_rows_inserted";
show status like "Innodb_rows_updated";
SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_buffer_pool_pages_total';
SELECT variable_value FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_page_size';
SELECT variable_value - @innodb_rows_deleted_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_deleted';
SELECT variable_value - @innodb_rows_inserted_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_inserted';
SELECT variable_value - @innodb_rows_updated_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_rows_updated';
# Test for row locks InnoDB status variables.
show status like "Innodb_row_lock_waits";
show status like "Innodb_row_lock_current_waits";
show status like "Innodb_row_lock_time";
show status like "Innodb_row_lock_time_max";
show status like "Innodb_row_lock_time_avg";
SELECT variable_value - @innodb_row_lock_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_waits';
SELECT variable_value - @innodb_row_lock_current_waits_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_current_waits';
SELECT variable_value - @innodb_row_lock_time_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time';
SELECT variable_value - @innodb_row_lock_time_max_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_max';
SELECT variable_value - @innodb_row_lock_time_avg_orig FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_row_lock_time_avg';
# Test for innodb_sync_spin_loops variable
show variables like "innodb_sync_spin_loops";
......@@ -2524,6 +2547,8 @@ DROP TABLE bug35537;
DISCONNECT c1;
CONNECTION default;
SET GLOBAL innodb_thread_concurrency = @innodb_thread_concurrency_orig;
#######################################################################
# #
# Please, DO NOT TOUCH this file as well as the innodb.result file. #
......@@ -2532,7 +2557,9 @@ CONNECTION default;
# Use innodb_mysql.[test|result] files instead. #
# #
# If nevertheless you need to make some changes here, please, forward #
# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com #
# your commit message #
# To: innodb_dev_ww@oracle.com #
# Cc: dev-innodb@mysql.com #
# (otherwise your changes may be erased). #
# #
#######################################################################
......@@ -1514,4 +1514,25 @@ insert into m1 (col1) values (1);
insert into m1 (col1) values (1);
drop table m1, t1;
#
#Bug #44040 MySQL allows creating a MERGE table upon VIEWs but crashes
#when using it
#
CREATE TABLE t1 (
col1 INT(10)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE VIEW v1 as SELECT * FROM t1;
CREATE TABLE m1 (
col1 INT(10)
)ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(v1);
--echo #Select should detect that the child table is a view and fail.
--error ER_WRONG_MRG_TABLE
SELECT * FROM m1;
DROP VIEW v1;
DROP TABLE m1, t1;
--echo End of 5.1 tests
......@@ -504,17 +504,21 @@ String *Item_func_des_encrypt::val_str(String *str)
string marking change of string length.
*/
tail= (8-(res_length) % 8); // 1..8 marking extra length
tail= 8 - (res_length % 8); // 1..8 marking extra length
res_length+=tail;
tmp_arg.realloc(res_length);
tmp_arg.length(0);
tmp_arg.append(res->ptr(), res->length());
code= ER_OUT_OF_RESOURCES;
if (tail && res->append(append_str, tail) || tmp_value.alloc(res_length+1))
if (tmp_arg.append(append_str, tail) || tmp_value.alloc(res_length+1))
goto error;
(*res)[res_length-1]=tail; // save extra length
tmp_arg[res_length-1]=tail; // save extra length
tmp_value.realloc(res_length+1);
tmp_value.length(res_length+1);
tmp_value[0]=(char) (128 | key_number);
// Real encryption
bzero((char*) &ivec,sizeof(ivec));
DES_ede3_cbc_encrypt((const uchar*) (res->ptr()),
DES_ede3_cbc_encrypt((const uchar*) (tmp_arg.ptr()),
(uchar*) (tmp_value.ptr()+1),
res_length,
&keyschedule.ks1,
......
......@@ -293,13 +293,17 @@ class Item_func_old_password :public Item_str_func
class Item_func_des_encrypt :public Item_str_func
{
String tmp_value;
String tmp_value,tmp_arg;
public:
Item_func_des_encrypt(Item *a) :Item_str_func(a) {}
Item_func_des_encrypt(Item *a, Item *b): Item_str_func(a,b) {}
String *val_str(String *);
void fix_length_and_dec()
{ maybe_null=1; max_length = args[0]->max_length+8; }
{
maybe_null=1;
/* 9 = MAX ((8- (arg_len % 8)) + 1) */
max_length = args[0]->max_length + 9;
}
const char *func_name() const { return "des_encrypt"; }
};
......@@ -310,7 +314,12 @@ class Item_func_des_decrypt :public Item_str_func
Item_func_des_decrypt(Item *a) :Item_str_func(a) {}
Item_func_des_decrypt(Item *a, Item *b): Item_str_func(a,b) {}
String *val_str(String *);
void fix_length_and_dec() { maybe_null=1; max_length = args[0]->max_length; }
void fix_length_and_dec()
{
maybe_null=1;
/* 9 = MAX ((8- (arg_len % 8)) + 1) */
max_length = args[0]->max_length - 9;
}
const char *func_name() const { return "des_decrypt"; }
};
......
......@@ -3843,6 +3843,16 @@ static int open_unireg_entry(THD *thd, TABLE *entry, TABLE_LIST *table_list,
if (share->is_view)
{
/*
If parent_l of the table_list is non null then a merge table
has this view as child table, which is not supported.
*/
if (table_list->parent_l)
{
my_error(ER_WRONG_MRG_TABLE, MYF(0));
goto err;
}
/*
This table is a view. Validate its metadata version: in particular,
that it was a view when the statement was prepared.
......
......@@ -199,6 +199,14 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
tables->db, tables->table_name, tables->alias,
(int) reopen));
if (tables->schema_table)
{
my_error(ER_WRONG_USAGE, MYF(0), "HANDLER OPEN",
INFORMATION_SCHEMA_NAME.str);
DBUG_PRINT("exit",("ERROR"));
DBUG_RETURN(TRUE);
}
if (! hash_inited(&thd->handler_tables_hash))
{
/*
......
......@@ -8260,6 +8260,14 @@ static MYSQL_SYSVAR_BOOL(stats_on_metadata, innobase_stats_on_metadata,
"Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
NULL, NULL, TRUE);
static MYSQL_SYSVAR_BOOL(use_legacy_cardinality_algorithm,
srv_use_legacy_cardinality_algorithm,
PLUGIN_VAR_OPCMDARG,
"Use legacy algorithm for picking random pages during index cardinality "
"estimation. Disable this to use a better algorithm, but note that your "
"query plans may change (enabled by default).",
NULL, NULL, TRUE);
static MYSQL_SYSVAR_BOOL(adaptive_hash_index, innobase_adaptive_hash_index,
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
"Enable InnoDB adaptive hash index (enabled by default). "
......@@ -8395,6 +8403,7 @@ static struct st_mysql_sys_var* innobase_system_variables[]= {
MYSQL_SYSVAR(open_files),
MYSQL_SYSVAR(rollback_on_timeout),
MYSQL_SYSVAR(stats_on_metadata),
MYSQL_SYSVAR(use_legacy_cardinality_algorithm),
MYSQL_SYSVAR(adaptive_hash_index),
MYSQL_SYSVAR(status_file),
MYSQL_SYSVAR(support_xa),
......
......@@ -656,6 +656,21 @@ struct row_prebuilt_struct {
This eliminates lock waits in some
cases; note that this breaks
serializability. */
ulint new_rec_locks; /* normally 0; if
srv_locks_unsafe_for_binlog is
TRUE or session is using READ
COMMITTED isolation level, in a
cursor search, if we set a new
record lock on an index, this is
incremented; this is used in
releasing the locks under the
cursors if we are performing an
UPDATE and we determine after
retrieving the row that it does
not need to be locked; thus,
these can be used to implement a
'mini-rollback' that releases
the latest record locks */
ulint mysql_prefix_len;/* byte offset of the end of
the last requested column */
ulint mysql_row_len; /* length in bytes of a row in the
......
......@@ -235,6 +235,12 @@ extern ulint srv_read_ahead_seq;
/* variable to count the number of random read-aheads were done */
extern ulint srv_read_ahead_rnd;
/* An option to enable the fix for "Bug#43660 SHOW INDEXES/ANALYZE does
NOT update cardinality for indexes of InnoDB table". By default we are
running with the fix disabled because MySQL 5.1 is frozen for such
behavioral changes. */
extern char srv_use_legacy_cardinality_algorithm;
/* In this structure we store status variables to be passed to MySQL */
typedef struct export_var_struct export_struc;
......
......@@ -21,34 +21,6 @@ Created 3/26/1996 Heikki Tuuri
extern ulint trx_n_mysql_transactions;
/*****************************************************************
Resets the new record lock info in a transaction struct. */
UNIV_INLINE
void
trx_reset_new_rec_lock_info(
/*========================*/
trx_t* trx); /* in: transaction struct */
/*****************************************************************
Registers that we have set a new record lock on an index. We only have space
to store 2 indexes! If this is called to store more than 2 indexes after
trx_reset_new_rec_lock_info(), then this function does nothing. */
UNIV_INLINE
void
trx_register_new_rec_lock(
/*======================*/
trx_t* trx, /* in: transaction struct */
dict_index_t* index); /* in: trx sets a new record lock on this
index */
/*****************************************************************
Checks if trx has set a new record lock on an index. */
UNIV_INLINE
ibool
trx_new_rec_locks_contain(
/*======================*/
/* out: TRUE if trx has set a new record lock
on index */
trx_t* trx, /* in: transaction struct */
dict_index_t* index); /* in: index */
/************************************************************************
Releases the search latch if trx has reserved it. */
......@@ -527,20 +499,6 @@ struct trx_struct{
lock_t* auto_inc_lock; /* possible auto-inc lock reserved by
the transaction; note that it is also
in the lock list trx_locks */
dict_index_t* new_rec_locks[2];/* these are normally NULL; if
srv_locks_unsafe_for_binlog is TRUE
or session is using READ COMMITTED
isolation level,
in a cursor search, if we set a new
record lock on an index, this is set
to point to the index; this is
used in releasing the locks under the
cursors if we are performing an UPDATE
and we determine after retrieving
the row that it does not need to be
locked; thus, these can be used to
implement a 'mini-rollback' that
releases the latest record locks */
UT_LIST_NODE_T(trx_t)
trx_list; /* list of transactions */
UT_LIST_NODE_T(trx_t)
......
......@@ -38,61 +38,3 @@ trx_start_if_not_started_low(
trx_start_low(trx, ULINT_UNDEFINED);
}
}
/*****************************************************************
Resets the new record lock info in a transaction struct. */
UNIV_INLINE
void
trx_reset_new_rec_lock_info(
/*========================*/
trx_t* trx) /* in: transaction struct */
{
trx->new_rec_locks[0] = NULL;
trx->new_rec_locks[1] = NULL;
}
/*****************************************************************
Registers that we have set a new record lock on an index. We only have space
to store 2 indexes! If this is called to store more than 2 indexes after
trx_reset_new_rec_lock_info(), then this function does nothing. */
UNIV_INLINE
void
trx_register_new_rec_lock(
/*======================*/
trx_t* trx, /* in: transaction struct */
dict_index_t* index) /* in: trx sets a new record lock on this
index */
{
if (trx->new_rec_locks[0] == NULL) {
trx->new_rec_locks[0] = index;
return;
}
if (trx->new_rec_locks[0] == index) {
return;
}
if (trx->new_rec_locks[1] != NULL) {
return;
}
trx->new_rec_locks[1] = index;
}
/*****************************************************************
Checks if trx has set a new record lock on an index. */
UNIV_INLINE
ibool
trx_new_rec_locks_contain(
/*======================*/
/* out: TRUE if trx has set a new record lock
on index */
trx_t* trx, /* in: transaction struct */
dict_index_t* index) /* in: index */
{
return(trx->new_rec_locks[0] == index
|| trx->new_rec_locks[1] == index);
}
......@@ -1970,12 +1970,6 @@ lock_rec_lock_fast(
if (lock == NULL) {
if (!impl) {
lock_rec_create(mode, rec, index, trx);
if (srv_locks_unsafe_for_binlog
|| trx->isolation_level
== TRX_ISO_READ_COMMITTED) {
trx_register_new_rec_lock(trx, index);
}
}
return(TRUE);
......@@ -1999,11 +1993,6 @@ lock_rec_lock_fast(
if (!lock_rec_get_nth_bit(lock, heap_no)) {
lock_rec_set_nth_bit(lock, heap_no);
if (srv_locks_unsafe_for_binlog
|| trx->isolation_level
== TRX_ISO_READ_COMMITTED) {
trx_register_new_rec_lock(trx, index);
}
}
}
......@@ -2058,22 +2047,12 @@ lock_rec_lock_slow(
enough already granted on the record, we have to wait. */
err = lock_rec_enqueue_waiting(mode, rec, index, thr);
if (srv_locks_unsafe_for_binlog
|| trx->isolation_level == TRX_ISO_READ_COMMITTED) {
trx_register_new_rec_lock(trx, index);
}
} else {
if (!impl) {
/* Set the requested lock on the record */
lock_rec_add_to_queue(LOCK_REC | mode, rec, index,
trx);
if (srv_locks_unsafe_for_binlog
|| trx->isolation_level
== TRX_ISO_READ_COMMITTED) {
trx_register_new_rec_lock(trx, index);
}
}
err = DB_SUCCESS;
......
......@@ -15,6 +15,8 @@ Created 10/4/1994 Heikki Tuuri
#include "mtr0log.h"
#include "log0recv.h"
#include "rem0cmp.h"
#include "srv0srv.h"
#include "ut0ut.h"
static ulint page_rnd = 976722341;
......@@ -23,6 +25,44 @@ static ulint page_rnd = 976722341;
ulint page_cur_short_succ = 0;
# endif /* UNIV_SEARCH_PERF_STAT */
/***********************************************************************
This is a linear congruential generator PRNG. Returns a pseudo random
number between 0 and 2^64-1 inclusive. The formula and the constants
being used are:
X[n+1] = (a * X[n] + c) mod m
where:
X[0] = ut_usectime()
a = 1103515245 (3^5 * 5 * 7 * 129749)
c = 12345 (3 * 5 * 823)
m = 18446744073709551616 (2^64)
*/
#define LCG_a 1103515245
#define LCG_c 12345
static
unsigned long long
page_cur_lcg_prng()
/*===============*/
/* out: number between 0 and 2^64-1 */
{
static unsigned long long lcg_current = 0;
static ibool initialized = FALSE;
ulint time_sec;
ulint time_ms;
if (!initialized) {
ut_usectime(&time_sec, &time_ms);
lcg_current = (unsigned long long) (time_sec * 1000000
+ time_ms);
initialized = TRUE;
}
/* no need to "% 2^64" explicitly because lcg_current is
64 bit and this will be done anyway */
lcg_current = LCG_a * lcg_current + LCG_c;
return(lcg_current);
}
/********************************************************************
Tries a search shortcut based on the last insert. */
UNIV_INLINE
......@@ -493,9 +533,13 @@ page_cur_open_on_rnd_user_rec(
return;
}
if (srv_use_legacy_cardinality_algorithm) {
page_rnd += 87584577;
rnd = page_rnd % page_get_n_recs(page);
} else {
rnd = (ulint) page_cur_lcg_prng() % page_get_n_recs(page);
}
rec = page_get_infimum_rec(page);
......@@ -1437,3 +1481,30 @@ page_cur_delete_rec(
page_dir_balance_slot(page, cur_slot_no);
}
}
#ifdef UNIV_COMPILE_TEST_FUNCS
/***********************************************************************
Print the first n numbers, generated by page_cur_lcg_prng() to make sure
(visually) that it works properly. */
void
test_page_cur_lcg_prng(
/*===================*/
int n) /* in: print first n numbers */
{
int i;
unsigned long long rnd;
for (i = 0; i < n; i++) {
rnd = page_cur_lcg_prng();
printf("%llu\t%%2=%llu %%3=%llu %%5=%llu %%7=%llu %%11=%llu\n",
rnd,
rnd % 2,
rnd % 3,
rnd % 5,
rnd % 7,
rnd % 11);
}
}
#endif /* UNIV_COMPILE_TEST_FUNCS */
......@@ -1476,12 +1476,9 @@ row_unlock_for_mysql(
and clust_pcur, and we do not need to
reposition the cursors. */
{
dict_index_t* index;
btr_pcur_t* pcur = prebuilt->pcur;
btr_pcur_t* clust_pcur = prebuilt->clust_pcur;
trx_t* trx = prebuilt->trx;
rec_t* rec;
mtr_t mtr;
ut_ad(prebuilt && trx);
ut_ad(trx->mysql_thread_id == os_thread_get_curr_id());
......@@ -1501,9 +1498,12 @@ row_unlock_for_mysql(
trx->op_info = "unlock_row";
index = btr_pcur_get_btr_cur(pcur)->index;
if (prebuilt->new_rec_locks >= 1) {
if (index != NULL && trx_new_rec_locks_contain(trx, index)) {
rec_t* rec;
dict_index_t* index;
dulint rec_trx_id;
mtr_t mtr;
mtr_start(&mtr);
......@@ -1514,43 +1514,64 @@ row_unlock_for_mysql(
}
rec = btr_pcur_get_rec(pcur);
index = btr_pcur_get_btr_cur(pcur)->index;
lock_rec_unlock(trx, rec, prebuilt->select_lock_type);
mtr_commit(&mtr);
/* If the search was done through the clustered index, then
we have not used clust_pcur at all, and we must NOT try to
reset locks on clust_pcur. The values in clust_pcur may be
garbage! */
if (index->type & DICT_CLUSTERED) {
if (prebuilt->new_rec_locks >= 2) {
/* Restore the cursor position and find the record
in the clustered index. */
goto func_exit;
}
if (!has_latches_on_recs) {
btr_pcur_restore_position(BTR_SEARCH_LEAF,
clust_pcur, &mtr);
}
rec = btr_pcur_get_rec(clust_pcur);
index = btr_pcur_get_btr_cur(clust_pcur)->index;
}
if (index != NULL && trx_new_rec_locks_contain(trx, index)) {
/* If the record has been modified by this
transaction, do not unlock it. */
ut_a(index->type & DICT_CLUSTERED);
mtr_start(&mtr);
if (index->trx_id_offset) {
rec_trx_id = trx_read_trx_id(rec
+ index->trx_id_offset);
} else {
mem_heap_t* heap = NULL;
ulint offsets_[REC_OFFS_NORMAL_SIZE];
ulint* offsets = offsets_;
/* Restore the cursor position and find the record */
*offsets_ = (sizeof offsets_) / sizeof *offsets_;
offsets = rec_get_offsets(rec, index, offsets,
ULINT_UNDEFINED, &heap);
if (!has_latches_on_recs) {
btr_pcur_restore_position(BTR_SEARCH_LEAF, clust_pcur,
&mtr);
rec_trx_id = row_get_rec_trx_id(rec, index, offsets);
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
}
}
rec = btr_pcur_get_rec(clust_pcur);
if (ut_dulint_cmp(rec_trx_id, trx->id) != 0) {
/* We did not update the record: unlock it */
rec = btr_pcur_get_rec(pcur);
index = btr_pcur_get_btr_cur(pcur)->index;
lock_rec_unlock(trx, rec, prebuilt->select_lock_type);
if (prebuilt->new_rec_locks >= 2) {
rec = btr_pcur_get_rec(clust_pcur);
index = btr_pcur_get_btr_cur(clust_pcur)->index;
lock_rec_unlock(trx, rec,
prebuilt->select_lock_type);
}
}
mtr_commit(&mtr);
}
func_exit:
trx->op_info = "";
return(DB_SUCCESS);
......
......@@ -2901,8 +2901,9 @@ row_sel_get_clust_rec_for_mysql(
func_exit:
*out_rec = clust_rec;
if (prebuilt->select_lock_type == LOCK_X) {
/* We may use the cursor in update: store its position */
if (prebuilt->select_lock_type != LOCK_NONE) {
/* We may use the cursor in update or in unlock_row():
store its position */
btr_pcur_store_position(prebuilt->clust_pcur, mtr);
}
......@@ -3303,13 +3304,7 @@ row_search_for_mysql(
is set or session is using a READ COMMITED isolation level. Then
we are able to remove the record locks set here on an individual
row. */
if ((srv_locks_unsafe_for_binlog
|| trx->isolation_level == TRX_ISO_READ_COMMITTED)
&& prebuilt->select_lock_type != LOCK_NONE) {
trx_reset_new_rec_lock_info(trx);
}
prebuilt->new_rec_locks = 0;
/*-------------------------------------------------------------*/
/* PHASE 1: Try to pop the row from the prefetch cache */
......@@ -3951,6 +3946,12 @@ row_search_for_mysql(
switch (err) {
rec_t* old_vers;
case DB_SUCCESS:
if (srv_locks_unsafe_for_binlog
|| trx->isolation_level == TRX_ISO_READ_COMMITTED) {
/* Note that a record of
prebuilt->index was locked. */
prebuilt->new_rec_locks = 1;
}
break;
case DB_LOCK_WAIT:
if (UNIV_LIKELY(prebuilt->row_read_type
......@@ -3981,7 +3982,7 @@ row_search_for_mysql(
if (UNIV_LIKELY(trx->wait_lock != NULL)) {
lock_cancel_waiting_and_release(
trx->wait_lock);
trx_reset_new_rec_lock_info(trx);
prebuilt->new_rec_locks = 0;
} else {
mutex_exit(&kernel_mutex);
......@@ -3993,6 +3994,9 @@ row_search_for_mysql(
ULINT_UNDEFINED,
&heap);
err = DB_SUCCESS;
/* Note that a record of
prebuilt->index was locked. */
prebuilt->new_rec_locks = 1;
break;
}
mutex_exit(&kernel_mutex);
......@@ -4142,6 +4146,15 @@ row_search_for_mysql(
goto next_rec;
}
if ((srv_locks_unsafe_for_binlog
|| trx->isolation_level == TRX_ISO_READ_COMMITTED)
&& prebuilt->select_lock_type != LOCK_NONE) {
/* Note that both the secondary index record
and the clustered index record were locked. */
ut_ad(prebuilt->new_rec_locks == 1);
prebuilt->new_rec_locks = 2;
}
if (UNIV_UNLIKELY(rec_get_deleted_flag(clust_rec, comp))) {
/* The record is delete marked: we can skip it */
......@@ -4267,13 +4280,7 @@ row_search_for_mysql(
prebuilt->row_read_type = ROW_READ_TRY_SEMI_CONSISTENT;
}
did_semi_consistent_read = FALSE;
if (UNIV_UNLIKELY(srv_locks_unsafe_for_binlog
|| trx->isolation_level == TRX_ISO_READ_COMMITTED)
&& prebuilt->select_lock_type != LOCK_NONE) {
trx_reset_new_rec_lock_info(trx);
}
prebuilt->new_rec_locks = 0;
/*-------------------------------------------------------------*/
/* PHASE 5: Move the cursor to the next index record */
......@@ -4379,7 +4386,7 @@ row_search_for_mysql(
rec_loop we will again try to set a lock, and
new_rec_lock_info in trx will be right at the end. */
trx_reset_new_rec_lock_info(trx);
prebuilt->new_rec_locks = 0;
}
mode = pcur->search_mode;
......
......@@ -256,6 +256,12 @@ ulint srv_read_ahead_seq = 0;
/* variable to count the number of random read-aheads */
ulint srv_read_ahead_rnd = 0;
/* An option to enable the fix for "Bug#43660 SHOW INDEXES/ANALYZE does
NOT update cardinality for indexes of InnoDB table". By default we are
running with the fix disabled because MySQL 5.1 is frozen for such
behavioral changes. */
char srv_use_legacy_cardinality_algorithm = TRUE;
/* structure to pass status variables to MySQL */
export_struc export_vars;
......
......@@ -192,8 +192,6 @@ trx_create(
trx->n_autoinc_rows = 0;
trx_reset_new_rec_lock_info(trx);
return(trx);
}
......
......@@ -1375,7 +1375,7 @@ BackupRestore::logEntry(const LogEntry & tup)
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
// TODO: handle the error
err << "Cannot start transaction" << endl;
exitHandler();
} // if
......@@ -1524,7 +1524,7 @@ BackupRestore::tuple(const TupleS & tup)
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
// TODO: handle the error
ndbout << "Cannot start transaction" << endl;
exitHandler();
} // if
......
......@@ -374,7 +374,7 @@ BackupRestore::tuple(const TupleS & tup)
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
// TODO: handle the error
ndbout << "Cannot start transaction" << endl;
exit(-1);
} // if
......@@ -463,7 +463,7 @@ BackupRestore::logEntry(const LogEntry & tup)
NdbTransaction * trans = m_ndb->startTransaction();
if (trans == NULL)
{
// Deep shit, TODO: handle the error
// TODO: handle the error
ndbout << "Cannot start transaction" << endl;
exit(-1);
} // if
......
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