summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2011-01-10 23:42:47 +0200
committerMichael Widenius <monty@askmonty.org>2011-01-10 23:42:47 +0200
commit2eaa76b84426b19f8574876ad1fa85ae6cfe3196 (patch)
treec6d4ebe6e2b222092ecff7df1dc5cf5bfdcd9179
parent934c57c77e19109943e45c9b94658efc107ded1e (diff)
parent505c663a1e19af4c8ee726b305691414ab5fc999 (diff)
downloadmariadb-git-2eaa76b84426b19f8574876ad1fa85ae6cfe3196.tar.gz
Automatic merge with 5.1
-rw-r--r--mysql-test/Makefile.am1
-rwxr-xr-xmysql-test/mysql-test-run.pl2
-rw-r--r--mysql-test/r/lock_multi.result7
-rw-r--r--mysql-test/suite/handler/aria.result671
-rw-r--r--mysql-test/suite/handler/aria.test82
-rw-r--r--mysql-test/suite/handler/handler.inc (renamed from mysql-test/include/handler.inc)382
-rw-r--r--mysql-test/suite/handler/init.inc33
-rw-r--r--mysql-test/suite/handler/innodb.result (renamed from mysql-test/r/handler_innodb.result)371
-rw-r--r--mysql-test/suite/handler/innodb.test (renamed from mysql-test/t/handler_innodb.test)11
-rw-r--r--mysql-test/suite/handler/interface.result259
-rw-r--r--mysql-test/suite/handler/interface.test307
-rw-r--r--mysql-test/suite/handler/myisam.result (renamed from mysql-test/r/handler_myisam.result)390
-rw-r--r--mysql-test/suite/handler/myisam.test (renamed from mysql-test/t/handler_myisam.test)24
-rw-r--r--mysql-test/t/lock_multi.test16
-rw-r--r--mysys/tree.c4
-rw-r--r--sql/handler.cc5
-rw-r--r--sql/handler.h1
-rw-r--r--sql/sql_handler.cc19
-rw-r--r--storage/maria/ma_extra.c4
-rw-r--r--storage/maria/ma_ft_boolean_search.c4
-rw-r--r--storage/maria/ma_open.c2
-rw-r--r--storage/maria/ma_rkey.c2
-rw-r--r--storage/maria/ma_rnext.c17
-rw-r--r--storage/maria/ma_rsame.c5
-rw-r--r--storage/maria/ma_search.c9
-rw-r--r--storage/maria/ma_unique.c1
26 files changed, 1665 insertions, 964 deletions
diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am
index e565521a8b0..07cf5fc8e7b 100644
--- a/mysql-test/Makefile.am
+++ b/mysql-test/Makefile.am
@@ -109,6 +109,7 @@ TEST_DIRS = t r include std_data std_data/parts collections \
suite/innodb suite/innodb/t suite/innodb/r suite/innodb/include \
suite/innodb_plugin suite/innodb_plugin/t suite/innodb_plugin/r \
suite/innodb_plugin/include \
+ suite/handler \
suite/engines suite/engines/funcs suite/engines/iuds suite/engines/rr_trx \
suite/engines/funcs/r suite/engines/funcs/t suite/engines/iuds/r \
suite/engines/iuds/t suite/engines/rr_trx/include suite/engines/rr_trx/r \
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 745fed0ceb8..962f0553b01 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -142,7 +142,7 @@ my $path_config_file; # The generated config file, var/my.cnf
# executables will be used by the test suite.
our $opt_vs_config = $ENV{'MTR_VS_CONFIG'};
-my $DEFAULT_SUITES= "main,binlog,federated,rpl,maria,parts,innodb,innodb_plugin,percona,ndb,vcol,oqgraph,sphinx";
+my $DEFAULT_SUITES= "main,binlog,federated,rpl,maria,handler,parts,innodb,innodb_plugin,percona,ndb,vcol,oqgraph,sphinx";
my $opt_suites;
our $opt_verbose= 0; # Verbose output, enable with --verbose
diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result
index d8768e802ea..3fc4de3da06 100644
--- a/mysql-test/r/lock_multi.result
+++ b/mysql-test/r/lock_multi.result
@@ -162,13 +162,6 @@ ERROR 70100: Query execution was interrupted
unlock tables;
drop table t1;
drop table if exists t1;
-create table t1 (a int) ENGINE=MEMORY;
---> client 2
-handler t1 open;
-ERROR HY000: Table storage engine for 't1' doesn't have this option
---> client 1
-drop table t1;
-drop table if exists t1;
create table t1 (i int);
connection: default
lock tables t1 write;
diff --git a/mysql-test/suite/handler/aria.result b/mysql-test/suite/handler/aria.result
new file mode 100644
index 00000000000..a912a2559e3
--- /dev/null
+++ b/mysql-test/suite/handler/aria.result
@@ -0,0 +1,671 @@
+SET SESSION STORAGE_ENGINE = Aria;
+drop table if exists t1,t3,t4,t5;
+create table t1 (a int, b char(10), key a (a), key b (a,b));
+insert into t1 values
+(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
+(14,"aaa"),(16,"ccc"),(16,"xxx"),
+(20,"ggg"),(21,"hhh"),(22,"iii");
+handler t1 open as t2;
+handler t2 read a first;
+a b
+14 aaa
+handler t2 read a next;
+a b
+16 ccc
+handler t2 read a next;
+a b
+16 xxx
+handler t2 read a prev;
+a b
+16 ccc
+handler t2 read a last;
+a b
+22 iii
+handler t2 read a prev;
+a b
+21 hhh
+handler t2 read a prev;
+a b
+20 ggg
+handler t2 read a first;
+a b
+14 aaa
+handler t2 read a prev;
+a b
+handler t2 read a last;
+a b
+22 iii
+handler t2 read a prev;
+a b
+21 hhh
+handler t2 read a next;
+a b
+22 iii
+handler t2 read a next;
+a b
+handler t2 read a=(15);
+a b
+handler t2 read a=(16);
+a b
+16 ccc
+handler t2 read a=(19,"fff");
+ERROR 42000: Too many key parts specified; max 1 parts allowed
+handler t2 read b=(19,"fff");
+a b
+19 fff
+handler t2 read b=(19,"yyy");
+a b
+19 yyy
+handler t2 read b=(19);
+a b
+19 fff
+handler t1 read a last;
+ERROR 42S02: Unknown table 't1' in HANDLER
+handler t2 read a=(11);
+a b
+handler t2 read a>=(11);
+a b
+14 aaa
+handler t2 read a=(18);
+a b
+18 eee
+handler t2 read a>=(18);
+a b
+18 eee
+handler t2 read a>(18);
+a b
+19 fff
+handler t2 read a<=(18);
+a b
+18 eee
+handler t2 read a<(18);
+a b
+17 ddd
+handler t2 read a=(15);
+a b
+handler t2 read a>=(15);
+a b
+16 ccc
+handler t2 read a>(15);
+a b
+16 ccc
+handler t2 read a<=(15);
+a b
+14 aaa
+handler t2 read a<(15);
+a b
+14 aaa
+handler t2 read a=(54);
+a b
+handler t2 read a>=(54);
+a b
+handler t2 read a>(54);
+a b
+handler t2 read a<=(54);
+a b
+22 iii
+handler t2 read a<(54);
+a b
+22 iii
+handler t2 read a=(1);
+a b
+handler t2 read a>=(1);
+a b
+14 aaa
+handler t2 read a>(1);
+a b
+14 aaa
+handler t2 read a<=(1);
+a b
+handler t2 read a<(1);
+a b
+handler t2 read a first limit 5;
+a b
+14 aaa
+16 ccc
+16 xxx
+17 ddd
+18 eee
+handler t2 read a next limit 3;
+a b
+19 fff
+19 yyy
+20 ggg
+handler t2 read a prev limit 10;
+a b
+19 yyy
+19 fff
+18 eee
+17 ddd
+16 xxx
+16 ccc
+14 aaa
+handler t2 read a>=(16) limit 4;
+a b
+16 ccc
+16 xxx
+17 ddd
+18 eee
+handler t2 read a>=(16) limit 2,2;
+a b
+17 ddd
+18 eee
+handler t2 read a last limit 3;
+a b
+22 iii
+21 hhh
+20 ggg
+handler t2 read a=(19);
+a b
+19 fff
+handler t2 read a=(19) where b="yyy";
+a b
+19 yyy
+handler t2 read first;
+a b
+17 ddd
+handler t2 read next;
+a b
+18 eee
+handler t2 read next;
+a b
+19 fff
+handler t2 close;
+handler t1 open;
+handler t1 read a next;
+a b
+14 aaa
+handler t1 read a next;
+a b
+16 ccc
+handler t1 close;
+handler t1 open;
+handler t1 read a prev;
+a b
+22 iii
+handler t1 read a prev;
+a b
+21 hhh
+handler t1 close;
+handler t1 open as t2;
+handler t2 read first;
+a b
+17 ddd
+alter table t1 engine = Aria;
+handler t2 read first;
+ERROR 42S02: Unknown table 't2' in HANDLER
+handler t1 open as t2;
+drop table t1;
+create table t1 (a int not null);
+insert into t1 values (17);
+handler t2 read first;
+ERROR 42S02: Unknown table 't2' in HANDLER
+handler t1 open as t2;
+alter table t1 engine=CSV;
+handler t2 read first;
+ERROR 42S02: Unknown table 't2' in HANDLER
+drop table t1;
+create table t1 (a int);
+insert into t1 values (1),(2),(3),(4),(5),(6);
+delete from t1 limit 2;
+handler t1 open;
+handler t1 read first;
+a
+3
+handler t1 read first limit 1,1;
+a
+4
+handler t1 read first limit 2,2;
+a
+5
+6
+delete from t1 limit 3;
+handler t1 read first;
+a
+6
+drop table t1;
+create table t1(a int, index (a));
+insert into t1 values (1), (2), (3);
+handler t1 open;
+handler t1 read a=(W);
+ERROR 42S22: Unknown column 'W' in 'field list'
+handler t1 read a=(a);
+ERROR HY000: Incorrect arguments to HANDLER ... READ
+drop table t1;
+create table t1 (a char(5));
+insert into t1 values ("Ok");
+handler t1 open as t;
+handler t read first;
+a
+Ok
+use mysql;
+handler t read first;
+a
+Ok
+handler t close;
+handler test.t1 open as t;
+handler t read first;
+a
+Ok
+handler t close;
+use test;
+drop table t1;
+create table t1 ( a int, b int, INDEX a (a) );
+insert into t1 values (1,2), (2,1);
+handler t1 open;
+handler t1 read a=(1) where b=2;
+a b
+1 2
+handler t1 read a=(1) where b=3;
+a b
+handler t1 read a=(1) where b=1;
+a b
+handler t1 close;
+drop table t1;
+create table t1 (c1 char(20));
+insert into t1 values ("t1");
+handler t1 open as h1;
+handler h1 read first limit 9;
+c1
+t1
+create table t2 (c1 char(20));
+insert into t2 values ("t2");
+handler t2 open as h2;
+handler h2 read first limit 9;
+c1
+t2
+create table t3 (c1 char(20));
+insert into t3 values ("t3");
+handler t3 open as h3;
+handler h3 read first limit 9;
+c1
+t3
+create table t4 (c1 char(20));
+insert into t4 values ("t4");
+handler t4 open as h4;
+handler h4 read first limit 9;
+c1
+t4
+create table t5 (c1 char(20));
+insert into t5 values ("t5");
+handler t5 open as h5;
+handler h5 read first limit 9;
+c1
+t5
+alter table t1 engine=MyISAM;
+handler h1 read first limit 9;
+ERROR 42S02: Unknown table 'h1' in HANDLER
+handler h2 read first limit 9;
+c1
+t2
+handler h3 read first limit 9;
+c1
+t3
+handler h4 read first limit 9;
+c1
+t4
+handler h5 read first limit 9;
+c1
+t5
+alter table t5 engine=MyISAM;
+handler h1 read first limit 9;
+ERROR 42S02: Unknown table 'h1' in HANDLER
+handler h2 read first limit 9;
+c1
+t2
+handler h3 read first limit 9;
+c1
+t3
+handler h4 read first limit 9;
+c1
+t4
+handler h5 read first limit 9;
+ERROR 42S02: Unknown table 'h5' in HANDLER
+alter table t3 engine=MyISAM;
+handler h1 read first limit 9;
+ERROR 42S02: Unknown table 'h1' in HANDLER
+handler h2 read first limit 9;
+c1
+t2
+handler h3 read first limit 9;
+ERROR 42S02: Unknown table 'h3' in HANDLER
+handler h4 read first limit 9;
+c1
+t4
+handler h5 read first limit 9;
+ERROR 42S02: Unknown table 'h5' in HANDLER
+handler h2 close;
+handler h4 close;
+handler t1 open as h1_1;
+handler t1 open as h1_2;
+handler t1 open as h1_3;
+handler h1_1 read first limit 9;
+c1
+t1
+handler h1_2 read first limit 9;
+c1
+t1
+handler h1_3 read first limit 9;
+c1
+t1
+alter table t1 engine=Aria;
+handler h1_1 read first limit 9;
+ERROR 42S02: Unknown table 'h1_1' in HANDLER
+handler h1_2 read first limit 9;
+ERROR 42S02: Unknown table 'h1_2' in HANDLER
+handler h1_3 read first limit 9;
+ERROR 42S02: Unknown table 'h1_3' in HANDLER
+drop table t1;
+drop table t2;
+drop table t3;
+drop table t4;
+drop table t5;
+create table t1 (c1 int);
+insert into t1 values (1);
+handler t1 open;
+handler t1 read first;
+c1
+1
+send the below to another connection, do not wait for the result
+optimize table t1;
+proceed with the normal connection
+handler t1 read next;
+c1
+1
+handler t1 close;
+read the result from the other connection
+Table Op Msg_type Msg_text
+test.t1 optimize status OK
+proceed with the normal connection
+drop table t1;
+CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY (no1,no2));
+INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2);
+HANDLER t1 OPEN;
+HANDLER t1 READ `primary` = (1, 1000);
+no1 no2
+HANDLER t1 READ `primary` PREV;
+no1 no2
+1 275
+HANDLER t1 READ `primary` = (1, 1000);
+no1 no2
+HANDLER t1 READ `primary` NEXT;
+no1 no2
+2 6
+DROP TABLE t1;
+create table t1 (c1 int);
+insert into t1 values (14397);
+flush tables with read lock;
+drop table t1;
+ERROR HY000: Can't execute the query because you have a conflicting read lock
+send the below to another connection, do not wait for the result
+drop table t1;
+proceed with the normal connection
+select * from t1;
+c1
+14397
+unlock tables;
+read the result from the other connection
+proceed with the normal connection
+select * from t1;
+ERROR 42S02: Table 'test.t1' doesn't exist
+drop table if exists t1;
+Warnings:
+Note 1051 Unknown table 't1'
+create table t1 (a int not null) ENGINE=CSV;
+--> client 2
+handler t1 open;
+ERROR HY000: Table storage engine for 't1' doesn't have this option
+--> client 1
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias read a next;
+ERROR 42000: Key 'a' doesn't exist in table 't1_alias'
+handler t1_alias READ a next where inexistent > 0;
+ERROR 42S22: Unknown column 'inexistent' in 'field list'
+handler t1_alias read a next;
+ERROR 42000: Key 'a' doesn't exist in table 't1_alias'
+handler t1_alias READ a next where inexistent > 0;
+ERROR 42S22: Unknown column 'inexistent' in 'field list'
+handler t1_alias close;
+drop table t1;
+create temporary table t1 (a int, b char(1), key a (a), key b(a,b));
+insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
+(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"),(9,'k');
+select a,b from t1;
+a b
+0 a
+1 b
+2 c
+3 d
+4 e
+5 f
+6 g
+7 h
+8 i
+9 j
+9 k
+handler t1 open as a1;
+handler a1 read a=(1);
+a b
+1 b
+handler a1 read a next;
+a b
+2 c
+handler a1 read a next;
+a b
+3 d
+select a,b from t1;
+ERROR HY000: Can't reopen table: 'a1'
+handler a1 read a prev;
+a b
+2 c
+handler a1 read a prev;
+a b
+1 b
+handler a1 read a=(6) where b="g";
+a b
+6 g
+handler a1 close;
+select a,b from t1;
+a b
+0 a
+1 b
+2 c
+3 d
+4 e
+5 f
+6 g
+7 h
+8 i
+9 j
+9 k
+handler t1 open as a2;
+handler a2 read a=(9);
+a b
+9 j
+handler a2 read a next;
+a b
+9 k
+handler a2 read a prev limit 2;
+a b
+9 j
+8 i
+handler a2 read a last;
+a b
+9 k
+handler a2 read a prev;
+a b
+9 j
+handler a2 close;
+drop table t1;
+create table t1 (a int);
+create temporary table t2 (a int, key (a));
+handler t1 open as a1;
+handler t2 open as a2;
+handler a2 read a first;
+a
+drop table t1, t2;
+handler a2 read a next;
+ERROR 42S02: Unknown table 'a2' in HANDLER
+handler a1 close;
+ERROR 42S02: Unknown table 'a1' in HANDLER
+create table t1 (a int, key (a));
+create table t2 like t1;
+handler t1 open as a1;
+handler t2 open as a2;
+handler a1 read a first;
+a
+handler a2 read a first;
+a
+alter table t1 add b int;
+handler a1 close;
+ERROR 42S02: Unknown table 'a1' in HANDLER
+handler a2 close;
+drop table t1, t2;
+create table t1 (a int, key (a));
+handler t1 open as a1;
+handler a1 read a first;
+a
+rename table t1 to t2;
+handler a1 read a first;
+ERROR 42S02: Unknown table 'a1' in HANDLER
+drop table t2;
+create table t1 (a int, key (a));
+create table t2 like t1;
+handler t1 open as a1;
+handler t2 open as a2;
+handler a1 read a first;
+a
+handler a2 read a first;
+a
+optimize table t1;
+Table Op Msg_type Msg_text
+test.t1 optimize status Table is already up to date
+handler a1 close;
+ERROR 42S02: Unknown table 'a1' in HANDLER
+handler a2 close;
+drop table t1, t2;
+#
+# BUG#51877 - HANDLER interface causes invalid memory read
+#
+CREATE TABLE t1(a INT, KEY (a));
+HANDLER t1 OPEN;
+HANDLER t1 READ a FIRST;
+a
+INSERT INTO t1 VALUES(1);
+HANDLER t1 READ a NEXT;
+a
+1
+HANDLER t1 CLOSE;
+DROP TABLE t1;
+#
+# BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
+#
+CREATE TABLE t1 AS SELECT 1 AS f1;
+HANDLER t1 OPEN;
+TRUNCATE t1;
+HANDLER t1 READ FIRST;
+ERROR 42S02: Unknown table 't1' in HANDLER
+DROP TABLE t1;
+CREATE TEMPORARY TABLE t1 AS SELECT 1 AS f1;
+HANDLER t1 OPEN;
+TRUNCATE t1;
+HANDLER t1 READ FIRST;
+ERROR 42S02: Unknown table 't1' in HANDLER
+DROP TABLE t1;
+#
+# Bug #54007: assert in ha_myisam::index_next , HANDLER
+#
+CREATE TABLE t1(a INT, b INT, PRIMARY KEY(a), KEY b(b), KEY ab(a, b));
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+a b
+HANDLER t1 READ `PRIMARY` NEXT;
+a b
+HANDLER t1 READ ab NEXT;
+a b
+HANDLER t1 READ b NEXT;
+a b
+HANDLER t1 READ NEXT;
+a b
+HANDLER t1 CLOSE;
+INSERT INTO t1 VALUES (2, 20), (1, 10), (4, 40), (3, 30);
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+a b
+2 20
+HANDLER t1 READ NEXT;
+a b
+1 10
+HANDLER t1 READ `PRIMARY` NEXT;
+a b
+1 10
+HANDLER t1 READ `PRIMARY` NEXT;
+a b
+2 20
+HANDLER t1 READ ab NEXT;
+a b
+1 10
+HANDLER t1 READ ab NEXT;
+a b
+2 20
+HANDLER t1 READ b NEXT;
+a b
+1 10
+HANDLER t1 READ b NEXT;
+a b
+2 20
+HANDLER t1 READ b NEXT;
+a b
+3 30
+HANDLER t1 READ b NEXT;
+a b
+4 40
+HANDLER t1 READ b NEXT;
+a b
+HANDLER t1 READ NEXT;
+a b
+2 20
+HANDLER t1 READ NEXT;
+a b
+1 10
+HANDLER t1 READ NEXT;
+a b
+4 40
+HANDLER t1 CLOSE;
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+a b
+2 20
+HANDLER t1 READ `PRIMARY` PREV;
+a b
+4 40
+HANDLER t1 READ `PRIMARY` PREV;
+a b
+3 30
+HANDLER t1 READ b PREV;
+a b
+4 40
+HANDLER t1 READ b PREV;
+a b
+3 30
+HANDLER t1 CLOSE;
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+a b
+2 20
+HANDLER t1 READ `PRIMARY` PREV LIMIT 3;
+a b
+4 40
+3 30
+2 20
+HANDLER t1 READ b NEXT LIMIT 5;
+a b
+1 10
+2 20
+3 30
+4 40
+HANDLER t1 CLOSE;
+DROP TABLE t1;
+End of 5.1 tests
diff --git a/mysql-test/suite/handler/aria.test b/mysql-test/suite/handler/aria.test
new file mode 100644
index 00000000000..1913d2b791c
--- /dev/null
+++ b/mysql-test/suite/handler/aria.test
@@ -0,0 +1,82 @@
+# t/handler_innodb.test
+#
+# test of HANDLER ...
+#
+# Last update:
+# 2006-07-31 ML test refactored (MySQL 5.1)
+# code of t/handler.test and t/innodb_handler.test united
+# main testing code put into handler.inc
+# rename t/innodb_handler.test to t/handler_innodb.test
+#
+
+--source include/have_maria.inc
+let $engine_type= Aria;
+
+--source init.inc
+--source handler.inc
+
+--echo #
+--echo # BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
+--echo #
+CREATE TABLE t1 AS SELECT 1 AS f1;
+HANDLER t1 OPEN;
+TRUNCATE t1;
+--error ER_UNKNOWN_TABLE
+HANDLER t1 READ FIRST;
+DROP TABLE t1;
+
+CREATE TEMPORARY TABLE t1 AS SELECT 1 AS f1;
+HANDLER t1 OPEN;
+TRUNCATE t1;
+--error ER_UNKNOWN_TABLE
+HANDLER t1 READ FIRST;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #54007: assert in ha_myisam::index_next , HANDLER
+--echo #
+CREATE TABLE t1(a INT, b INT, PRIMARY KEY(a), KEY b(b), KEY ab(a, b));
+
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+HANDLER t1 READ `PRIMARY` NEXT;
+HANDLER t1 READ ab NEXT;
+HANDLER t1 READ b NEXT;
+HANDLER t1 READ NEXT;
+HANDLER t1 CLOSE;
+
+INSERT INTO t1 VALUES (2, 20), (1, 10), (4, 40), (3, 30);
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+HANDLER t1 READ NEXT;
+HANDLER t1 READ `PRIMARY` NEXT;
+HANDLER t1 READ `PRIMARY` NEXT;
+HANDLER t1 READ ab NEXT;
+HANDLER t1 READ ab NEXT;
+HANDLER t1 READ b NEXT;
+HANDLER t1 READ b NEXT;
+HANDLER t1 READ b NEXT;
+HANDLER t1 READ b NEXT;
+HANDLER t1 READ b NEXT;
+HANDLER t1 READ NEXT;
+HANDLER t1 READ NEXT;
+HANDLER t1 READ NEXT;
+HANDLER t1 CLOSE;
+
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+HANDLER t1 READ `PRIMARY` PREV;
+HANDLER t1 READ `PRIMARY` PREV;
+HANDLER t1 READ b PREV;
+HANDLER t1 READ b PREV;
+HANDLER t1 CLOSE;
+
+HANDLER t1 OPEN;
+HANDLER t1 READ FIRST;
+HANDLER t1 READ `PRIMARY` PREV LIMIT 3;
+HANDLER t1 READ b NEXT LIMIT 5;
+HANDLER t1 CLOSE;
+
+DROP TABLE t1;
+
+--echo End of 5.1 tests
diff --git a/mysql-test/include/handler.inc b/mysql-test/suite/handler/handler.inc
index 6e7f53ba9b2..48ed2ce0b8a 100644
--- a/mysql-test/include/handler.inc
+++ b/mysql-test/suite/handler/handler.inc
@@ -1,5 +1,7 @@
-# include/handler.inc
+# handler.inc
#
+# See init.inc for setup of variables for this script
+#
# The variables
# $engine_type -- storage engine to be tested
# $other_engine_type -- storage engine <> $engine_type
@@ -8,31 +10,19 @@
# 2. $other_handler_engine_type must point to an all
# time available storage engine
# 2006-08 MySQL 5.1 MyISAM and MEMORY only
-# have to be set before sourcing this script.
--- source include/not_embedded.inc
#
# test of HANDLER ...
#
# Last update:
# 2006-07-31 ML test refactored (MySQL 5.1)
# code of t/handler.test and t/innodb_handler.test united
-# main testing code put into include/handler.inc
+# main testing code put into handler.inc
#
-eval SET SESSION STORAGE_ENGINE = $engine_type;
-
---disable_warnings
-drop table if exists t1,t3,t4,t5;
---enable_warnings
-
-create table t1 (a int, b char(10), key a(a), key b(a,b));
-insert into t1 values
-(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
-(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"),
-(20,"ggg"),(21,"hhh"),(22,"iii");
+#
+# Start testing the table created in init.inc
+#
handler t1 open as t2;
--- error 1064
-handler t2 read a=(SELECT 1);
handler t2 read a first;
handler t2 read a next;
handler t2 read a next;
@@ -65,12 +55,34 @@ handler t1 read a last;
handler t2 read a=(11);
handler t2 read a>=(11);
+# Search on something we ca nfind
handler t2 read a=(18);
handler t2 read a>=(18);
handler t2 read a>(18);
handler t2 read a<=(18);
handler t2 read a<(18);
+# Search on something we can't find
+handler t2 read a=(15);
+handler t2 read a>=(15);
+handler t2 read a>(15);
+handler t2 read a<=(15);
+handler t2 read a<(15);
+
+# Search from upper end
+handler t2 read a=(54);
+handler t2 read a>=(54);
+handler t2 read a>(54);
+handler t2 read a<=(54);
+handler t2 read a<(54);
+
+# Search from lower end
+handler t2 read a=(1);
+handler t2 read a>=(1);
+handler t2 read a>(1);
+handler t2 read a<=(1);
+handler t2 read a<(1);
+
handler t2 read a first limit 5;
handler t2 read a next limit 3;
handler t2 read a prev limit 10;
@@ -85,8 +97,6 @@ handler t2 read a=(19) where b="yyy";
handler t2 read first;
handler t2 read next;
handler t2 read next;
---error 1064
-handler t2 read last;
handler t2 close;
handler t1 open;
@@ -110,7 +120,7 @@ handler t2 read first;
#
handler t1 open as t2;
drop table t1;
-create table t1 (a int);
+create table t1 (a int not null);
insert into t1 values (17);
--error 1109
handler t2 read first;
@@ -137,7 +147,7 @@ drop table t1;
#
# Test for #751
#
-create table t1(a int, index(a));
+eval create table t1(a int, index $key_type (a));
insert into t1 values (1), (2), (3);
handler t1 open;
--error 1054
@@ -164,7 +174,7 @@ drop table t1;
#
# BUG#3649
#
-create table t1 ( a int, b int, INDEX a (a) );
+eval create table t1 ( a int, b int, INDEX a $key_type (a) );
insert into t1 values (1,2), (2,1);
handler t1 open;
handler t1 read a=(1) where b=2;
@@ -174,143 +184,6 @@ handler t1 close;
drop table t1;
#
-# Check if two database names beginning the same are seen as different.
-#
-# This database begins like the usual 'test' database.
-#
---disable_warnings
-drop database if exists test_test;
---enable_warnings
-create database test_test;
-use test_test;
-create table t1(table_id char(20) primary key);
-insert into t1 values ('test_test.t1');
-insert into t1 values ('');
-handler t1 open;
-handler t1 read first limit 9;
-create table t2(table_id char(20) primary key);
-insert into t2 values ('test_test.t2');
-insert into t2 values ('');
-handler t2 open;
-handler t2 read first limit 9;
-#
-# This is the usual 'test' database.
-#
-use test;
---disable_warnings
-drop table if exists t1;
---enable_warnings
-create table t1(table_id char(20) primary key);
-insert into t1 values ('test.t1');
-insert into t1 values ('');
---error 1066
-handler t1 open;
-#
-# Check accesibility of all the tables.
-#
-use test;
---error 1064
-handler test.t1 read first limit 9;
---error 1064
-handler test_test.t1 read first limit 9;
-handler t1 read first limit 9;
---error 1064
-handler test_test.t2 read first limit 9;
-handler t2 read first limit 9;
-
-#
-# Cleanup.
-#
-
---error 1064
-handler test_test.t1 close;
-handler t1 close;
-drop table test_test.t1;
---error 1064
-handler test_test.t2 close;
-handler t2 close;
-drop table test_test.t2;
-drop database test_test;
-
-#
-use test;
---error 1064
-handler test.t1 close;
---error 1109
-handler t1 close;
-drop table test.t1;
-
-#
-# BUG#4335
-#
---disable_warnings
-drop database if exists test_test;
-drop table if exists t1;
-drop table if exists t2;
-drop table if exists t3;
---enable_warnings
-create database test_test;
-use test_test;
-create table t1 (c1 char(20));
-insert into t1 values ('test_test.t1');
-create table t3 (c1 char(20));
-insert into t3 values ('test_test.t3');
-handler t1 open;
-handler t1 read first limit 9;
-handler t1 open h1;
-handler h1 read first limit 9;
-use test;
-create table t1 (c1 char(20));
-create table t2 (c1 char(20));
-create table t3 (c1 char(20));
-insert into t1 values ('t1');
-insert into t2 values ('t2');
-insert into t3 values ('t3');
---error 1066
-handler t1 open;
---error 1066
-handler t2 open t1;
---error 1066
-handler t3 open t1;
-handler t1 read first limit 9;
---error 1064
-handler test.t1 close;
---error 1066
-handler test.t1 open h1;
---error 1066
-handler test_test.t1 open h1;
-handler test_test.t3 open h3;
-handler test.t1 open h2;
-handler t1 read first limit 9;
-handler h1 read first limit 9;
-handler h2 read first limit 9;
-handler h3 read first limit 9;
-handler h2 read first limit 9;
---error 1064
-handler test.h1 close;
-handler t1 close;
-handler h1 close;
-handler h2 close;
---error 1109
-handler t1 read first limit 9;
---error 1109
-handler h1 read first limit 9;
---error 1109
-handler h2 read first limit 9;
-handler h3 read first limit 9;
-handler h3 read first limit 9;
-use test_test;
-handler h3 read first limit 9;
---error 1064
-handler test.h3 read first limit 9;
-handler h3 close;
-use test;
-drop table t3;
-drop table t2;
-drop table t1;
-drop database test_test;
-
-#
# Test if fix for BUG#4286 correctly closes handler tables.
#
create table t1 (c1 char(20));
@@ -410,11 +283,13 @@ reap;
connection default;
drop table t1;
-CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY (no1,no2));
+eval CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY $key_type (no1,no2));
INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2);
HANDLER t1 OPEN;
HANDLER t1 READ `primary` = (1, 1000);
HANDLER t1 READ `primary` PREV;
+HANDLER t1 READ `primary` = (1, 1000);
+HANDLER t1 READ `primary` NEXT;
DROP TABLE t1;
# End of 4.1 tests
@@ -468,10 +343,7 @@ drop table if exists t1;
#
# Bug#25856 - HANDLER table OPEN in one connection lock DROP TABLE in another one
#
---disable_warnings
-drop table if exists t1;
---enable_warnings
-eval create table t1 (a int) ENGINE=$other_engine_type;
+eval create table t1 (a int not null) ENGINE=$other_engine_type;
--echo --> client 2
connection con2;
--error 1031
@@ -484,9 +356,6 @@ disconnect con2;
#
# Bug#30632 HANDLER read failure causes hang
#
---disable_warnings
-drop table if exists t1;
---enable_warnings
create table t1 (a int);
handler t1 open as t1_alias;
--error 1176
@@ -501,89 +370,18 @@ handler t1_alias close;
drop table t1;
#
-# Bug#21587 FLUSH TABLES causes server crash when used with HANDLER statements
-#
-
---disable_warnings
-drop table if exists t1,t2;
---enable_warnings
-create table t1 (c1 int);
-create table t2 (c1 int);
-insert into t1 values (1);
-insert into t2 values (2);
---echo connection: default
-handler t1 open;
-handler t1 read first;
-connect (flush,localhost,root,,);
-connection flush;
---echo connection: flush
---send flush tables;
-connection default;
---echo connection: default
-let $wait_condition=
- select count(*) = 1 from information_schema.processlist
- where state = "Flushing tables";
---source include/wait_condition.inc
-handler t2 open;
-handler t2 read first;
-handler t1 read next;
-handler t1 close;
-handler t2 close;
-connection flush;
-reap;
-connection default;
-drop table t1,t2;
-disconnect flush;
-
-#
-# Bug#31409 RENAME TABLE causes server crash or deadlock when used with HANDLER statements
-#
-
---disable_warnings
-drop table if exists t1,t2;
---enable_warnings
-create table t1 (c1 int);
---echo connection: default
-handler t1 open;
-handler t1 read first;
-connect (flush,localhost,root,,);
-connection flush;
---echo connection: flush
---send rename table t1 to t2;
-connection default;
---echo connection: default
-let $wait_condition=
- select count(*) = 1 from information_schema.processlist
- where state = "Waiting for table" and info = "rename table t1 to t2";
---source include/wait_condition.inc
-handler t2 open;
-handler t2 read first;
---error ER_NO_SUCH_TABLE
-handler t1 read next;
-handler t1 close;
-handler t2 close;
-connection flush;
-reap;
-connection default;
-drop table t2;
-disconnect flush;
-
-#
# Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
#
# Test HANDLER statements in conjunction with temporary tables. While the temporary table
# is open by a HANDLER, no other statement can access it.
#
---disable_warnings
-drop table if exists t1;
---enable_warnings
-create temporary table t1 (a int, b char(1), key a(a), key b(a,b));
+eval create temporary table t1 (a int, b char(1), key a $key_type (a), key b(a,b));
insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
- (5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+ (5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"),(9,'k');
select a,b from t1;
handler t1 open as a1;
-handler a1 read a first;
+handler a1 read a=(1);
handler a1 read a next;
handler a1 read a next;
--error ER_CANT_REOPEN_TABLE
@@ -594,41 +392,19 @@ handler a1 read a=(6) where b="g";
handler a1 close;
select a,b from t1;
handler t1 open as a2;
-handler a2 read a first;
+handler a2 read a=(9);
+handler a2 read a next;
+handler a2 read a prev limit 2;
+--error 0,1031
handler a2 read a last;
handler a2 read a prev;
handler a2 close;
drop table t1;
-#
-# Bug#31397 Inconsistent drop table behavior of handler tables.
-#
-
---disable_warnings
-drop table if exists t1,t2;
---enable_warnings
-create table t1 (a int);
-handler t1 open as t1_alias;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-flush tables;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-handler t1_alias close;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-handler t1_alias read first;
-drop table t1;
---error ER_UNKNOWN_TABLE
-handler t1_alias read next;
-
# Test that temporary tables associated with handlers are properly dropped.
create table t1 (a int);
-create temporary table t2 (a int, key(a));
+eval create temporary table t2 (a int, key $key_type (a));
handler t1 open as a1;
handler t2 open as a2;
handler a2 read a first;
@@ -640,7 +416,7 @@ handler a1 close;
# Alter table drop handlers
-create table t1 (a int, key(a));
+eval create table t1 (a int, key $key_type (a));
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
@@ -654,7 +430,7 @@ drop table t1, t2;
# Rename table drop handlers
-create table t1 (a int, key(a));
+eval create table t1 (a int, key $key_type (a));
handler t1 open as a1;
handler a1 read a first;
rename table t1 to t2;
@@ -664,7 +440,7 @@ drop table t2;
# Optimize table drop handlers
-create table t1 (a int, key(a));
+eval create table t1 (a int, key $key_type (a));
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
@@ -676,56 +452,14 @@ handler a1 close;
handler a2 close;
drop table t1, t2;
-# Flush tables causes handlers reopen
-
-create table t1 (a int, b char(1), key a(a), key b(a,b));
-insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
- (5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
-handler t1 open;
-handler t1 read a first;
-handler t1 read a next;
-flush tables;
-handler t1 read a next;
-handler t1 read a next;
-flush tables with read lock;
-handler t1 read a next;
-unlock tables;
-drop table t1;
---error ER_UNKNOWN_TABLE
-handler t1 read a next;
-
-#
-# Bug#41110: crash with handler command when used concurrently with alter table
-# Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table
-#
-
---disable_warnings
-drop table if exists t1;
---enable_warnings
-create table t1 (a int);
-insert into t1 values (1);
-handler t1 open;
-connect(con1,localhost,root,,);
-send alter table t1 engine=memory;
-connection default;
-let $wait_condition=
- select count(*) = 1 from information_schema.processlist
- where state = "rename result table" and info = "alter table t1 engine=memory";
---source include/wait_condition.inc
---error ER_ILLEGAL_HA
-handler t1 read a next;
-handler t1 close;
-connection con1;
---reap
-drop table t1;
-disconnect con1;
---source include/wait_until_disconnected.inc
-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;
+--echo #
+--echo # BUG#51877 - HANDLER interface causes invalid memory read
+--echo #
+eval CREATE TABLE t1(a INT, KEY $key_type (a));
+HANDLER t1 OPEN;
+HANDLER t1 READ a FIRST;
+INSERT INTO t1 VALUES(1);
+--error 0,ER_CHECKREAD
+HANDLER t1 READ a NEXT;
+HANDLER t1 CLOSE;
+DROP TABLE t1;
diff --git a/mysql-test/suite/handler/init.inc b/mysql-test/suite/handler/init.inc
new file mode 100644
index 00000000000..32c6010f95b
--- /dev/null
+++ b/mysql-test/suite/handler/init.inc
@@ -0,0 +1,33 @@
+# Setup things for handler.inc
+#
+# Input variables
+# $engine_type -- storage engine to be tested
+# $key_type -- set if you want a non standard key type
+#
+# This scripts sets up default values for:
+# $other_engine_type -- storage engine <> $engine_type
+# $other_handler_engine_type -- storage engine <> $engine_type, if possible
+# 1. $other_handler_engine_type must support handler
+# 2. $other_handler_engine_type must point to an all
+# time available storage engine
+# have to be set before sourcing this script.
+#
+# Handler tests don't work with embedded server
+#
+-- source include/not_embedded.inc
+
+eval SET SESSION STORAGE_ENGINE = $engine_type;
+let $other_engine_type= CSV;
+let $other_handler_engine_type= MyISAM;
+
+--disable_warnings
+drop table if exists t1,t3,t4,t5;
+--enable_warnings
+
+# Create default test table
+
+eval create table t1 (a int, b char(10), key a $key_type (a), key b $key_type (a,b));
+insert into t1 values
+(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
+(14,"aaa"),(16,"ccc"),(16,"xxx"),
+(20,"ggg"),(21,"hhh"),(22,"iii");
diff --git a/mysql-test/r/handler_innodb.result b/mysql-test/suite/handler/innodb.result
index 957fc30acef..83ce270612d 100644
--- a/mysql-test/r/handler_innodb.result
+++ b/mysql-test/suite/handler/innodb.result
@@ -1,25 +1,23 @@
SET SESSION STORAGE_ENGINE = InnoDB;
drop table if exists t1,t3,t4,t5;
-create table t1 (a int, b char(10), key a(a), key b(a,b));
+create table t1 (a int, b char(10), key a (a), key b (a,b));
insert into t1 values
(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
-(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"),
+(14,"aaa"),(16,"ccc"),(16,"xxx"),
(20,"ggg"),(21,"hhh"),(22,"iii");
handler t1 open as t2;
-handler t2 read a=(SELECT 1);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1)' at line 1
handler t2 read a first;
a b
14 aaa
handler t2 read a next;
a b
-15 bbb
+16 ccc
handler t2 read a next;
a b
-16 ccc
+16 xxx
handler t2 read a prev;
a b
-15 bbb
+16 ccc
handler t2 read a last;
a b
22 iii
@@ -47,7 +45,6 @@ handler t2 read a next;
a b
handler t2 read a=(15);
a b
-15 bbb
handler t2 read a=(16);
a b
16 ccc
@@ -84,26 +81,64 @@ a b
handler t2 read a<(18);
a b
17 ddd
+handler t2 read a=(15);
+a b
+handler t2 read a>=(15);
+a b
+16 ccc
+handler t2 read a>(15);
+a b
+16 ccc
+handler t2 read a<=(15);
+a b
+14 aaa
+handler t2 read a<(15);
+a b
+14 aaa
+handler t2 read a=(54);
+a b
+handler t2 read a>=(54);
+a b
+handler t2 read a>(54);
+a b
+handler t2 read a<=(54);
+a b
+22 iii
+handler t2 read a<(54);
+a b
+22 iii
+handler t2 read a=(1);
+a b
+handler t2 read a>=(1);
+a b
+14 aaa
+handler t2 read a>(1);
+a b
+14 aaa
+handler t2 read a<=(1);
+a b
+handler t2 read a<(1);
+a b
handler t2 read a first limit 5;
a b
14 aaa
-15 bbb
16 ccc
16 xxx
17 ddd
+18 eee
handler t2 read a next limit 3;
a b
-18 eee
19 fff
19 yyy
+20 ggg
handler t2 read a prev limit 10;
a b
+19 yyy
19 fff
18 eee
17 ddd
16 xxx
16 ccc
-15 bbb
14 aaa
handler t2 read a>=(16) limit 4;
a b
@@ -135,8 +170,6 @@ a b
handler t2 read next;
a b
19 fff
-handler t2 read last;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
handler t2 close;
handler t1 open;
handler t1 read a next;
@@ -144,7 +177,7 @@ a b
14 aaa
handler t1 read a next;
a b
-15 bbb
+16 ccc
handler t1 close;
handler t1 open;
handler t1 read a prev;
@@ -163,12 +196,12 @@ handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
handler t1 open as t2;
drop table t1;
-create table t1 (a int);
+create table t1 (a int not null);
insert into t1 values (17);
handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
handler t1 open as t2;
-alter table t1 engine=MEMORY;
+alter table t1 engine=CSV;
handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
drop table t1;
@@ -191,7 +224,7 @@ handler t1 read first;
a
6
drop table t1;
-create table t1(a int, index(a));
+create table t1(a int, index (a));
insert into t1 values (1), (2), (3);
handler t1 open;
handler t1 read a=(W);
@@ -217,7 +250,7 @@ Ok
handler t close;
use test;
drop table t1;
-create table t1 ( a int, b int, INDEX a (a) );
+create table t1 ( a int, b int, INDEX a (a) );
insert into t1 values (1,2), (2,1);
handler t1 open;
handler t1 read a=(1) where b=2;
@@ -229,148 +262,6 @@ handler t1 read a=(1) where b=1;
a b
handler t1 close;
drop table t1;
-drop database if exists test_test;
-create database test_test;
-use test_test;
-create table t1(table_id char(20) primary key);
-insert into t1 values ('test_test.t1');
-insert into t1 values ('');
-handler t1 open;
-handler t1 read first limit 9;
-table_id
-
-test_test.t1
-create table t2(table_id char(20) primary key);
-insert into t2 values ('test_test.t2');
-insert into t2 values ('');
-handler t2 open;
-handler t2 read first limit 9;
-table_id
-
-test_test.t2
-use test;
-drop table if exists t1;
-create table t1(table_id char(20) primary key);
-insert into t1 values ('test.t1');
-insert into t1 values ('');
-handler t1 open;
-ERROR 42000: Not unique table/alias: 't1'
-use test;
-handler test.t1 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler test_test.t1 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler t1 read first limit 9;
-table_id
-
-test_test.t1
-handler test_test.t2 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler t2 read first limit 9;
-table_id
-
-test_test.t2
-handler test_test.t1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t1 close;
-drop table test_test.t1;
-handler test_test.t2 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t2 close;
-drop table test_test.t2;
-drop database test_test;
-use test;
-handler test.t1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t1 close;
-ERROR 42S02: Unknown table 't1' in HANDLER
-drop table test.t1;
-drop database if exists test_test;
-drop table if exists t1;
-drop table if exists t2;
-drop table if exists t3;
-create database test_test;
-use test_test;
-create table t1 (c1 char(20));
-insert into t1 values ('test_test.t1');
-create table t3 (c1 char(20));
-insert into t3 values ('test_test.t3');
-handler t1 open;
-handler t1 read first limit 9;
-c1
-test_test.t1
-handler t1 open h1;
-handler h1 read first limit 9;
-c1
-test_test.t1
-use test;
-create table t1 (c1 char(20));
-create table t2 (c1 char(20));
-create table t3 (c1 char(20));
-insert into t1 values ('t1');
-insert into t2 values ('t2');
-insert into t3 values ('t3');
-handler t1 open;
-ERROR 42000: Not unique table/alias: 't1'
-handler t2 open t1;
-ERROR 42000: Not unique table/alias: 't1'
-handler t3 open t1;
-ERROR 42000: Not unique table/alias: 't1'
-handler t1 read first limit 9;
-c1
-test_test.t1
-handler test.t1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler test.t1 open h1;
-ERROR 42000: Not unique table/alias: 'h1'
-handler test_test.t1 open h1;
-ERROR 42000: Not unique table/alias: 'h1'
-handler test_test.t3 open h3;
-handler test.t1 open h2;
-handler t1 read first limit 9;
-c1
-test_test.t1
-handler h1 read first limit 9;
-c1
-test_test.t1
-handler h2 read first limit 9;
-c1
-t1
-handler h3 read first limit 9;
-c1
-test_test.t3
-handler h2 read first limit 9;
-c1
-t1
-handler test.h1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t1 close;
-handler h1 close;
-handler h2 close;
-handler t1 read first limit 9;
-ERROR 42S02: Unknown table 't1' in HANDLER
-handler h1 read first limit 9;
-ERROR 42S02: Unknown table 'h1' in HANDLER
-handler h2 read first limit 9;
-ERROR 42S02: Unknown table 'h2' in HANDLER
-handler h3 read first limit 9;
-c1
-test_test.t3
-handler h3 read first limit 9;
-c1
-test_test.t3
-use test_test;
-handler h3 read first limit 9;
-c1
-test_test.t3
-handler test.h3 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler h3 close;
-use test;
-drop table t3;
-drop table t2;
-drop table t1;
-drop database test_test;
create table t1 (c1 char(20));
insert into t1 values ("t1");
handler t1 open as h1;
@@ -496,6 +387,11 @@ no1 no2
HANDLER t1 READ `primary` PREV;
no1 no2
1 275
+HANDLER t1 READ `primary` = (1, 1000);
+no1 no2
+HANDLER t1 READ `primary` NEXT;
+no1 no2
+2 8
DROP TABLE t1;
create table t1 (c1 int);
insert into t1 values (14397);
@@ -516,14 +412,12 @@ ERROR 42S02: Table 'test.t1' doesn't exist
drop table if exists t1;
Warnings:
Note 1051 Unknown table 't1'
-drop table if exists t1;
-create table t1 (a int) ENGINE=MEMORY;
+create table t1 (a int not null) ENGINE=CSV;
--> client 2
handler t1 open;
ERROR HY000: Table storage engine for 't1' doesn't have this option
--> client 1
drop table t1;
-drop table if exists t1;
create table t1 (a int);
handler t1 open as t1_alias;
handler t1_alias read a next;
@@ -536,50 +430,9 @@ handler t1_alias READ a next where inexistent > 0;
ERROR 42S22: Unknown column 'inexistent' in 'field list'
handler t1_alias close;
drop table t1;
-drop table if exists t1,t2;
-create table t1 (c1 int);
-create table t2 (c1 int);
-insert into t1 values (1);
-insert into t2 values (2);
-connection: default
-handler t1 open;
-handler t1 read first;
-c1
-1
-connection: flush
-flush tables;;
-connection: default
-handler t2 open;
-handler t2 read first;
-c1
-2
-handler t1 read next;
-c1
-1
-handler t1 close;
-handler t2 close;
-drop table t1,t2;
-drop table if exists t1,t2;
-create table t1 (c1 int);
-connection: default
-handler t1 open;
-handler t1 read first;
-c1
-connection: flush
-rename table t1 to t2;;
-connection: default
-handler t2 open;
-handler t2 read first;
-c1
-handler t1 read next;
-ERROR 42S02: Table 'test.t1' doesn't exist
-handler t1 close;
-handler t2 close;
-drop table t2;
-drop table if exists t1;
-create temporary table t1 (a int, b char(1), key a(a), key b(a,b));
+create temporary table t1 (a int, b char(1), key a (a), key b(a,b));
insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
-(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"),(9,'k');
select a,b from t1;
a b
0 a
@@ -592,24 +445,25 @@ a b
7 h
8 i
9 j
+9 k
handler t1 open as a1;
-handler a1 read a first;
-a b
-0 a
-handler a1 read a next;
+handler a1 read a=(1);
a b
1 b
handler a1 read a next;
a b
2 c
+handler a1 read a next;
+a b
+3 d
select a,b from t1;
ERROR HY000: Can't reopen table: 'a1'
handler a1 read a prev;
a b
-1 b
+2 c
handler a1 read a prev;
a b
-0 a
+1 b
handler a1 read a=(6) where b="g";
a b
6 g
@@ -626,39 +480,28 @@ a b
7 h
8 i
9 j
+9 k
handler t1 open as a2;
-handler a2 read a first;
+handler a2 read a=(9);
a b
-0 a
-handler a2 read a last;
+9 j
+handler a2 read a next;
+a b
+9 k
+handler a2 read a prev limit 2;
a b
9 j
+8 i
+handler a2 read a last;
+a b
+9 k
handler a2 read a prev;
a b
-8 i
+9 j
handler a2 close;
drop table t1;
-drop table if exists t1,t2;
create table t1 (a int);
-handler t1 open as t1_alias;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-flush tables;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-handler t1_alias close;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-handler t1_alias read first;
-a
-drop table t1;
-handler t1_alias read next;
-ERROR 42S02: Unknown table 't1_alias' in HANDLER
-create table t1 (a int);
-create temporary table t2 (a int, key(a));
+create temporary table t2 (a int, key (a));
handler t1 open as a1;
handler t2 open as a2;
handler a2 read a first;
@@ -668,7 +511,7 @@ handler a2 read a next;
ERROR 42S02: Unknown table 'a2' in HANDLER
handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
-create table t1 (a int, key(a));
+create table t1 (a int, key (a));
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
@@ -681,7 +524,7 @@ handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
handler a2 close;
drop table t1, t2;
-create table t1 (a int, key(a));
+create table t1 (a int, key (a));
handler t1 open as a1;
handler a1 read a first;
a
@@ -689,7 +532,7 @@ rename table t1 to t2;
handler a1 read a first;
ERROR 42S02: Unknown table 'a1' in HANDLER
drop table t2;
-create table t1 (a int, key(a));
+create table t1 (a int, key (a));
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
@@ -705,41 +548,15 @@ handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
handler a2 close;
drop table t1, t2;
-create table t1 (a int, b char(1), key a(a), key b(a,b));
-insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
-(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
-handler t1 open;
-handler t1 read a first;
-a b
-0 a
-handler t1 read a next;
-a b
-1 b
-flush tables;
-handler t1 read a next;
-a b
-0 a
-handler t1 read a next;
-a b
-1 b
-flush tables with read lock;
-handler t1 read a next;
-a b
-0 a
-unlock tables;
-drop table t1;
-handler t1 read a next;
-ERROR 42S02: Unknown table 't1' in HANDLER
-drop table if exists t1;
-create table t1 (a int);
-insert into t1 values (1);
-handler t1 open;
-alter table t1 engine=memory;
-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;
+#
+# BUG#51877 - HANDLER interface causes invalid memory read
+#
+CREATE TABLE t1(a INT, KEY (a));
+HANDLER t1 OPEN;
+HANDLER t1 READ a FIRST;
+a
+INSERT INTO t1 VALUES(1);
+HANDLER t1 READ a NEXT;
+a
+HANDLER t1 CLOSE;
+DROP TABLE t1;
diff --git a/mysql-test/t/handler_innodb.test b/mysql-test/suite/handler/innodb.test
index 02982716f78..f4e4bf7cc3f 100644
--- a/mysql-test/t/handler_innodb.test
+++ b/mysql-test/suite/handler/innodb.test
@@ -5,16 +5,13 @@
# Last update:
# 2006-07-31 ML test refactored (MySQL 5.1)
# code of t/handler.test and t/innodb_handler.test united
-# main testing code put into include/handler.inc
+# main testing code put into handler.inc
# rename t/innodb_handler.test to t/handler_innodb.test
#
-# should work in embedded server after mysqltest is fixed
---source include/not_embedded.inc
-
--source include/have_innodb.inc
+
let $engine_type= InnoDB;
-let $other_engine_type= MEMORY;
-let $other_handler_engine_type= MyISAM;
---source include/handler.inc
+--source init.inc
+--source handler.inc
diff --git a/mysql-test/suite/handler/interface.result b/mysql-test/suite/handler/interface.result
new file mode 100644
index 00000000000..0b5a4447739
--- /dev/null
+++ b/mysql-test/suite/handler/interface.result
@@ -0,0 +1,259 @@
+drop table if exists t1,t3,t4,t5;
+drop database if exists test_test;
+SET SESSION STORAGE_ENGINE = MyISAM;
+drop table if exists t1,t3,t4,t5;
+create table t1 (a int, b char(10), key a (a), key b (a,b));
+insert into t1 values
+(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
+(14,"aaa"),(16,"ccc"),(16,"xxx"),
+(20,"ggg"),(21,"hhh"),(22,"iii");
+handler t1 open;
+handler t1 read a=(SELECT 1);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1)' at line 1
+handler t1 read a=(1) FIRST;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FIRST' at line 1
+handler t1 read a=(1) NEXT;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NEXT' at line 1
+handler t1 read last;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
+handler t1 close;
+drop table t1;
+CREATE TABLE t1(a INT, PRIMARY KEY(a));
+insert into t1 values(1),(2);
+handler t1 open;
+handler t1 read primary=(1);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'primary=(1)' at line 1
+handler t1 read `primary`=(1);
+a
+1
+handler t1 close;
+drop table t1;
+create database test_test;
+use test_test;
+create table t1(table_id char(20), primary key (table_id));
+insert into t1 values ('test_test.t1');
+insert into t1 values ('');
+handler t1 open;
+handler t1 read first limit 9;
+table_id
+test_test.t1
+
+create table t2(table_id char(20), primary key (table_id));
+insert into t2 values ('test_test.t2');
+insert into t2 values ('');
+handler t2 open;
+handler t2 read first limit 9;
+table_id
+test_test.t2
+
+use test;
+create table t1(table_id char(20), primary key (table_id));
+insert into t1 values ('test.t1');
+insert into t1 values ('');
+handler t1 open;
+ERROR 42000: Not unique table/alias: 't1'
+use test;
+handler test.t1 read first limit 9;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
+handler test_test.t1 read first limit 9;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
+handler t1 read first limit 9;
+table_id
+test_test.t1
+
+handler test_test.t2 read first limit 9;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
+handler t2 read first limit 9;
+table_id
+test_test.t2
+
+handler test_test.t1 close;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
+handler t1 close;
+drop table test_test.t1;
+handler test_test.t2 close;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
+handler t2 close;
+drop table test_test.t2;
+drop database test_test;
+use test;
+handler test.t1 close;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
+handler t1 close;
+ERROR 42S02: Unknown table 't1' in HANDLER
+drop table test.t1;
+create database test_test;
+use test_test;
+create table t1 (c1 char(20));
+insert into t1 values ('test_test.t1');
+create table t3 (c1 char(20));
+insert into t3 values ('test_test.t3');
+handler t1 open;
+handler t1 read first limit 9;
+c1
+test_test.t1
+handler t1 open h1;
+handler h1 read first limit 9;
+c1
+test_test.t1
+use test;
+create table t1 (c1 char(20));
+create table t2 (c1 char(20));
+create table t3 (c1 char(20));
+insert into t1 values ('t1');
+insert into t2 values ('t2');
+insert into t3 values ('t3');
+handler t1 open;
+ERROR 42000: Not unique table/alias: 't1'
+handler t2 open t1;
+ERROR 42000: Not unique table/alias: 't1'
+handler t3 open t1;
+ERROR 42000: Not unique table/alias: 't1'
+handler t1 read first limit 9;
+c1
+test_test.t1
+handler test.t1 close;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
+handler test.t1 open h1;
+ERROR 42000: Not unique table/alias: 'h1'
+handler test_test.t1 open h1;
+ERROR 42000: Not unique table/alias: 'h1'
+handler test_test.t3 open h3;
+handler test.t1 open h2;
+handler t1 read first limit 9;
+c1
+test_test.t1
+handler h1 read first limit 9;
+c1
+test_test.t1
+handler h2 read first limit 9;
+c1
+t1
+handler h3 read first limit 9;
+c1
+test_test.t3
+handler h2 read first limit 9;
+c1
+t1
+handler test.h1 close;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
+handler t1 close;
+handler h1 close;
+handler h2 close;
+handler t1 read first limit 9;
+ERROR 42S02: Unknown table 't1' in HANDLER
+handler h1 read first limit 9;
+ERROR 42S02: Unknown table 'h1' in HANDLER
+handler h2 read first limit 9;
+ERROR 42S02: Unknown table 'h2' in HANDLER
+handler h3 read first limit 9;
+c1
+test_test.t3
+handler h3 read first limit 9;
+c1
+test_test.t3
+use test_test;
+handler h3 read first limit 9;
+c1
+test_test.t3
+handler test.h3 read first limit 9;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
+handler h3 close;
+use test;
+drop table t3;
+drop table t2;
+drop table t1;
+drop database test_test;
+create table t1 (c1 int);
+create table t2 (c1 int);
+insert into t1 values (1);
+insert into t2 values (2);
+connection: default
+handler t1 open;
+handler t1 read first;
+c1
+1
+connection: flush
+flush tables;;
+connection: default
+handler t2 open;
+handler t2 read first;
+c1
+2
+handler t1 read next;
+c1
+1
+handler t1 close;
+handler t2 close;
+drop table t1,t2;
+create table t1 (a int);
+handler t1 open as t1_alias;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+flush tables;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias close;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias read first;
+a
+drop table t1;
+handler t1_alias read next;
+ERROR 42S02: Unknown table 't1_alias' in HANDLER
+create table t1 (c1 int);
+connection: default
+handler t1 open;
+handler t1 read first;
+c1
+connection: flush
+rename table t1 to t2;;
+connection: default
+handler t2 open;
+handler t2 read first;
+c1
+handler t1 read next;
+ERROR 42S02: Table 'test.t1' doesn't exist
+handler t1 close;
+handler t2 close;
+drop table t2;
+create table t1 (a int, b char(1), key a (a), key b (a,b));
+insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
+(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+handler t1 open;
+handler t1 read a first;
+a b
+0 a
+handler t1 read a next;
+a b
+1 b
+flush tables;
+handler t1 read a next;
+a b
+0 a
+handler t1 read a next;
+a b
+1 b
+flush tables with read lock;
+handler t1 read a next;
+a b
+0 a
+unlock tables;
+drop table t1;
+handler t1 read a next;
+ERROR 42S02: Unknown table 't1' in HANDLER
+drop table if exists t1;
+create table t1 (a int not null);
+insert into t1 values (1);
+handler t1 open;
+alter table t1 engine=csv;
+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
diff --git a/mysql-test/suite/handler/interface.test b/mysql-test/suite/handler/interface.test
new file mode 100644
index 00000000000..809f0228f98
--- /dev/null
+++ b/mysql-test/suite/handler/interface.test
@@ -0,0 +1,307 @@
+#
+# Tests of handler interface that are system independent
+#
+# Handler tests don't work yet with embedded server
+#
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1,t3,t4,t5;
+drop database if exists test_test;
+--enable_warnings
+
+# Run tests with myisam (any engine should be ok)
+
+let $engine_type= MyISAM;
+
+--source init.inc
+
+#
+# Do some syntax checking
+#
+
+handler t1 open;
+--error ER_PARSE_ERROR
+handler t1 read a=(SELECT 1);
+--error ER_PARSE_ERROR
+handler t1 read a=(1) FIRST;
+--error ER_PARSE_ERROR
+handler t1 read a=(1) NEXT;
+--error ER_PARSE_ERROR
+handler t1 read last;
+handler t1 close;
+drop table t1;
+
+CREATE TABLE t1(a INT, PRIMARY KEY(a));
+insert into t1 values(1),(2);
+handler t1 open;
+--error ER_PARSE_ERROR
+handler t1 read primary=(1);
+handler t1 read `primary`=(1);
+handler t1 close;
+drop table t1;
+
+#
+# Check if two database names beginning the same are seen as different.
+#
+# This database begins like the usual 'test' database.
+#
+create database test_test;
+use test_test;
+eval create table t1(table_id char(20), primary key $key_type (table_id));
+insert into t1 values ('test_test.t1');
+insert into t1 values ('');
+handler t1 open;
+handler t1 read first limit 9;
+eval create table t2(table_id char(20), primary key $key_type (table_id));
+insert into t2 values ('test_test.t2');
+insert into t2 values ('');
+handler t2 open;
+handler t2 read first limit 9;
+#
+# This is the usual 'test' database.
+#
+use test;
+eval create table t1(table_id char(20), primary key $key_type (table_id));
+insert into t1 values ('test.t1');
+insert into t1 values ('');
+--error 1066
+handler t1 open;
+#
+# Check accessibility of all the tables.
+#
+use test;
+--error 1064
+handler test.t1 read first limit 9;
+--error 1064
+handler test_test.t1 read first limit 9;
+handler t1 read first limit 9;
+--error 1064
+handler test_test.t2 read first limit 9;
+handler t2 read first limit 9;
+
+#
+# Cleanup.
+#
+
+--error 1064
+handler test_test.t1 close;
+handler t1 close;
+drop table test_test.t1;
+--error 1064
+handler test_test.t2 close;
+handler t2 close;
+drop table test_test.t2;
+drop database test_test;
+
+#
+use test;
+--error 1064
+handler test.t1 close;
+--error 1109
+handler t1 close;
+drop table test.t1;
+
+#
+# BUG#4335 one name can be handler open'ed many times
+#
+
+create database test_test;
+use test_test;
+create table t1 (c1 char(20));
+insert into t1 values ('test_test.t1');
+create table t3 (c1 char(20));
+insert into t3 values ('test_test.t3');
+handler t1 open;
+handler t1 read first limit 9;
+handler t1 open h1;
+handler h1 read first limit 9;
+use test;
+create table t1 (c1 char(20));
+create table t2 (c1 char(20));
+create table t3 (c1 char(20));
+insert into t1 values ('t1');
+insert into t2 values ('t2');
+insert into t3 values ('t3');
+--error 1066
+handler t1 open;
+--error 1066
+handler t2 open t1;
+--error 1066
+handler t3 open t1;
+handler t1 read first limit 9;
+--error 1064
+handler test.t1 close;
+--error 1066
+handler test.t1 open h1;
+--error 1066
+handler test_test.t1 open h1;
+handler test_test.t3 open h3;
+handler test.t1 open h2;
+handler t1 read first limit 9;
+handler h1 read first limit 9;
+handler h2 read first limit 9;
+handler h3 read first limit 9;
+handler h2 read first limit 9;
+--error 1064
+handler test.h1 close;
+handler t1 close;
+handler h1 close;
+handler h2 close;
+--error 1109
+handler t1 read first limit 9;
+--error 1109
+handler h1 read first limit 9;
+--error 1109
+handler h2 read first limit 9;
+handler h3 read first limit 9;
+handler h3 read first limit 9;
+use test_test;
+handler h3 read first limit 9;
+--error 1064
+handler test.h3 read first limit 9;
+handler h3 close;
+use test;
+drop table t3;
+drop table t2;
+drop table t1;
+drop database test_test;
+
+#
+# Bug#21587 FLUSH TABLES causes server crash when used with HANDLER statements
+#
+
+create table t1 (c1 int);
+create table t2 (c1 int);
+insert into t1 values (1);
+insert into t2 values (2);
+--echo connection: default
+handler t1 open;
+handler t1 read first;
+connect (flush,localhost,root,,);
+connection flush;
+--echo connection: flush
+--send flush tables;
+connection default;
+--echo connection: default
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Flushing tables";
+--source include/wait_condition.inc
+handler t2 open;
+handler t2 read first;
+handler t1 read next;
+handler t1 close;
+handler t2 close;
+connection flush;
+reap;
+connection default;
+drop table t1,t2;
+disconnect flush;
+
+#
+# Bug#31397 Inconsistent drop table behavior of handler tables.
+#
+
+create table t1 (a int);
+handler t1 open as t1_alias;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+flush tables;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias close;
+drop table t1;
+create table t1 (a int);
+handler t1 open as t1_alias;
+handler t1_alias read first;
+drop table t1;
+--error ER_UNKNOWN_TABLE
+handler t1_alias read next;
+
+#
+# Bug#31409 RENAME TABLE causes server crash or deadlock when used with
+# HANDLER statements
+#
+
+create table t1 (c1 int);
+--echo connection: default
+handler t1 open;
+handler t1 read first;
+connect (flush,localhost,root,,);
+connection flush;
+--echo connection: flush
+--send rename table t1 to t2;
+connection default;
+--echo connection: default
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "Waiting for table" and info = "rename table t1 to t2";
+--source include/wait_condition.inc
+handler t2 open;
+handler t2 read first;
+--error ER_NO_SUCH_TABLE
+handler t1 read next;
+handler t1 close;
+handler t2 close;
+connection flush;
+reap;
+connection default;
+drop table t2;
+disconnect flush;
+
+# Flush tables causes handlers reopen
+
+eval create table t1 (a int, b char(1), key a $key_type (a), key b $key_type (a,b));
+insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
+ (5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+handler t1 open;
+handler t1 read a first;
+handler t1 read a next;
+flush tables;
+handler t1 read a next;
+handler t1 read a next;
+flush tables with read lock;
+handler t1 read a next;
+unlock tables;
+drop table t1;
+--error ER_UNKNOWN_TABLE
+handler t1 read a next;
+
+#
+# Bug#41110: crash with handler command when used concurrently with alter table
+# Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table
+#
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+create table t1 (a int not null);
+insert into t1 values (1);
+handler t1 open;
+connect(con1,localhost,root,,);
+send alter table t1 engine=csv;
+connection default;
+let $wait_condition=
+ select count(*) = 1 from information_schema.processlist
+ where state = "rename result table" and info = "alter table t1 engine=csv";
+--source include/wait_condition.inc
+--error ER_ILLEGAL_HA
+handler t1 read a next;
+handler t1 close;
+connection con1;
+--reap
+drop table t1;
+disconnect con1;
+--source include/wait_until_disconnected.inc
+connection default;
+
+#
+# Bug#44151 using handler commands on information_schema tables crashes server
+#
+
+USE information_schema;
+--error ER_WRONG_USAGE
+HANDLER COLUMNS OPEN;
diff --git a/mysql-test/r/handler_myisam.result b/mysql-test/suite/handler/myisam.result
index b20b8dbb138..bd356d6e81d 100644
--- a/mysql-test/r/handler_myisam.result
+++ b/mysql-test/suite/handler/myisam.result
@@ -1,25 +1,23 @@
SET SESSION STORAGE_ENGINE = MyISAM;
drop table if exists t1,t3,t4,t5;
-create table t1 (a int, b char(10), key a(a), key b(a,b));
+create table t1 (a int, b char(10), key a (a), key b (a,b));
insert into t1 values
(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
-(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"),
+(14,"aaa"),(16,"ccc"),(16,"xxx"),
(20,"ggg"),(21,"hhh"),(22,"iii");
handler t1 open as t2;
-handler t2 read a=(SELECT 1);
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1)' at line 1
handler t2 read a first;
a b
14 aaa
handler t2 read a next;
a b
-15 bbb
+16 ccc
handler t2 read a next;
a b
-16 ccc
+16 xxx
handler t2 read a prev;
a b
-15 bbb
+16 ccc
handler t2 read a last;
a b
22 iii
@@ -47,7 +45,6 @@ handler t2 read a next;
a b
handler t2 read a=(15);
a b
-15 bbb
handler t2 read a=(16);
a b
16 ccc
@@ -84,26 +81,64 @@ a b
handler t2 read a<(18);
a b
17 ddd
+handler t2 read a=(15);
+a b
+handler t2 read a>=(15);
+a b
+16 ccc
+handler t2 read a>(15);
+a b
+16 ccc
+handler t2 read a<=(15);
+a b
+14 aaa
+handler t2 read a<(15);
+a b
+14 aaa
+handler t2 read a=(54);
+a b
+handler t2 read a>=(54);
+a b
+handler t2 read a>(54);
+a b
+handler t2 read a<=(54);
+a b
+22 iii
+handler t2 read a<(54);
+a b
+22 iii
+handler t2 read a=(1);
+a b
+handler t2 read a>=(1);
+a b
+14 aaa
+handler t2 read a>(1);
+a b
+14 aaa
+handler t2 read a<=(1);
+a b
+handler t2 read a<(1);
+a b
handler t2 read a first limit 5;
a b
14 aaa
-15 bbb
16 ccc
16 xxx
17 ddd
+18 eee
handler t2 read a next limit 3;
a b
-18 eee
19 fff
19 yyy
+20 ggg
handler t2 read a prev limit 10;
a b
+19 yyy
19 fff
18 eee
17 ddd
16 xxx
16 ccc
-15 bbb
14 aaa
handler t2 read a>=(16) limit 4;
a b
@@ -135,8 +170,6 @@ a b
handler t2 read next;
a b
19 fff
-handler t2 read last;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
handler t2 close;
handler t1 open;
handler t1 read a next;
@@ -144,7 +177,7 @@ a b
14 aaa
handler t1 read a next;
a b
-15 bbb
+16 ccc
handler t1 close;
handler t1 open;
handler t1 read a prev;
@@ -163,12 +196,12 @@ handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
handler t1 open as t2;
drop table t1;
-create table t1 (a int);
+create table t1 (a int not null);
insert into t1 values (17);
handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
handler t1 open as t2;
-alter table t1 engine=MEMORY;
+alter table t1 engine=CSV;
handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
drop table t1;
@@ -191,7 +224,7 @@ handler t1 read first;
a
6
drop table t1;
-create table t1(a int, index(a));
+create table t1(a int, index (a));
insert into t1 values (1), (2), (3);
handler t1 open;
handler t1 read a=(W);
@@ -217,7 +250,7 @@ Ok
handler t close;
use test;
drop table t1;
-create table t1 ( a int, b int, INDEX a (a) );
+create table t1 ( a int, b int, INDEX a (a) );
insert into t1 values (1,2), (2,1);
handler t1 open;
handler t1 read a=(1) where b=2;
@@ -229,148 +262,6 @@ handler t1 read a=(1) where b=1;
a b
handler t1 close;
drop table t1;
-drop database if exists test_test;
-create database test_test;
-use test_test;
-create table t1(table_id char(20) primary key);
-insert into t1 values ('test_test.t1');
-insert into t1 values ('');
-handler t1 open;
-handler t1 read first limit 9;
-table_id
-test_test.t1
-
-create table t2(table_id char(20) primary key);
-insert into t2 values ('test_test.t2');
-insert into t2 values ('');
-handler t2 open;
-handler t2 read first limit 9;
-table_id
-test_test.t2
-
-use test;
-drop table if exists t1;
-create table t1(table_id char(20) primary key);
-insert into t1 values ('test.t1');
-insert into t1 values ('');
-handler t1 open;
-ERROR 42000: Not unique table/alias: 't1'
-use test;
-handler test.t1 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler test_test.t1 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler t1 read first limit 9;
-table_id
-test_test.t1
-
-handler test_test.t2 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler t2 read first limit 9;
-table_id
-test_test.t2
-
-handler test_test.t1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t1 close;
-drop table test_test.t1;
-handler test_test.t2 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t2 close;
-drop table test_test.t2;
-drop database test_test;
-use test;
-handler test.t1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t1 close;
-ERROR 42S02: Unknown table 't1' in HANDLER
-drop table test.t1;
-drop database if exists test_test;
-drop table if exists t1;
-drop table if exists t2;
-drop table if exists t3;
-create database test_test;
-use test_test;
-create table t1 (c1 char(20));
-insert into t1 values ('test_test.t1');
-create table t3 (c1 char(20));
-insert into t3 values ('test_test.t3');
-handler t1 open;
-handler t1 read first limit 9;
-c1
-test_test.t1
-handler t1 open h1;
-handler h1 read first limit 9;
-c1
-test_test.t1
-use test;
-create table t1 (c1 char(20));
-create table t2 (c1 char(20));
-create table t3 (c1 char(20));
-insert into t1 values ('t1');
-insert into t2 values ('t2');
-insert into t3 values ('t3');
-handler t1 open;
-ERROR 42000: Not unique table/alias: 't1'
-handler t2 open t1;
-ERROR 42000: Not unique table/alias: 't1'
-handler t3 open t1;
-ERROR 42000: Not unique table/alias: 't1'
-handler t1 read first limit 9;
-c1
-test_test.t1
-handler test.t1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler test.t1 open h1;
-ERROR 42000: Not unique table/alias: 'h1'
-handler test_test.t1 open h1;
-ERROR 42000: Not unique table/alias: 'h1'
-handler test_test.t3 open h3;
-handler test.t1 open h2;
-handler t1 read first limit 9;
-c1
-test_test.t1
-handler h1 read first limit 9;
-c1
-test_test.t1
-handler h2 read first limit 9;
-c1
-t1
-handler h3 read first limit 9;
-c1
-test_test.t3
-handler h2 read first limit 9;
-c1
-t1
-handler test.h1 close;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1
-handler t1 close;
-handler h1 close;
-handler h2 close;
-handler t1 read first limit 9;
-ERROR 42S02: Unknown table 't1' in HANDLER
-handler h1 read first limit 9;
-ERROR 42S02: Unknown table 'h1' in HANDLER
-handler h2 read first limit 9;
-ERROR 42S02: Unknown table 'h2' in HANDLER
-handler h3 read first limit 9;
-c1
-test_test.t3
-handler h3 read first limit 9;
-c1
-test_test.t3
-use test_test;
-handler h3 read first limit 9;
-c1
-test_test.t3
-handler test.h3 read first limit 9;
-ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1
-handler h3 close;
-use test;
-drop table t3;
-drop table t2;
-drop table t1;
-drop database test_test;
create table t1 (c1 char(20));
insert into t1 values ("t1");
handler t1 open as h1;
@@ -495,6 +386,11 @@ no1 no2
HANDLER t1 READ `primary` PREV;
no1 no2
1 275
+HANDLER t1 READ `primary` = (1, 1000);
+no1 no2
+HANDLER t1 READ `primary` NEXT;
+no1 no2
+2 6
DROP TABLE t1;
create table t1 (c1 int);
insert into t1 values (14397);
@@ -515,14 +411,12 @@ ERROR 42S02: Table 'test.t1' doesn't exist
drop table if exists t1;
Warnings:
Note 1051 Unknown table 't1'
-drop table if exists t1;
-create table t1 (a int) ENGINE=MEMORY;
+create table t1 (a int not null) ENGINE=CSV;
--> client 2
handler t1 open;
ERROR HY000: Table storage engine for 't1' doesn't have this option
--> client 1
drop table t1;
-drop table if exists t1;
create table t1 (a int);
handler t1 open as t1_alias;
handler t1_alias read a next;
@@ -535,50 +429,9 @@ handler t1_alias READ a next where inexistent > 0;
ERROR 42S22: Unknown column 'inexistent' in 'field list'
handler t1_alias close;
drop table t1;
-drop table if exists t1,t2;
-create table t1 (c1 int);
-create table t2 (c1 int);
-insert into t1 values (1);
-insert into t2 values (2);
-connection: default
-handler t1 open;
-handler t1 read first;
-c1
-1
-connection: flush
-flush tables;;
-connection: default
-handler t2 open;
-handler t2 read first;
-c1
-2
-handler t1 read next;
-c1
-1
-handler t1 close;
-handler t2 close;
-drop table t1,t2;
-drop table if exists t1,t2;
-create table t1 (c1 int);
-connection: default
-handler t1 open;
-handler t1 read first;
-c1
-connection: flush
-rename table t1 to t2;;
-connection: default
-handler t2 open;
-handler t2 read first;
-c1
-handler t1 read next;
-ERROR 42S02: Table 'test.t1' doesn't exist
-handler t1 close;
-handler t2 close;
-drop table t2;
-drop table if exists t1;
-create temporary table t1 (a int, b char(1), key a(a), key b(a,b));
+create temporary table t1 (a int, b char(1), key a (a), key b(a,b));
insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
-(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
+(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"),(9,'k');
select a,b from t1;
a b
0 a
@@ -591,24 +444,25 @@ a b
7 h
8 i
9 j
+9 k
handler t1 open as a1;
-handler a1 read a first;
-a b
-0 a
-handler a1 read a next;
+handler a1 read a=(1);
a b
1 b
handler a1 read a next;
a b
2 c
+handler a1 read a next;
+a b
+3 d
select a,b from t1;
ERROR HY000: Can't reopen table: 'a1'
handler a1 read a prev;
a b
-1 b
+2 c
handler a1 read a prev;
a b
-0 a
+1 b
handler a1 read a=(6) where b="g";
a b
6 g
@@ -625,39 +479,28 @@ a b
7 h
8 i
9 j
+9 k
handler t1 open as a2;
-handler a2 read a first;
+handler a2 read a=(9);
a b
-0 a
-handler a2 read a last;
+9 j
+handler a2 read a next;
+a b
+9 k
+handler a2 read a prev limit 2;
a b
9 j
+8 i
+handler a2 read a last;
+a b
+9 k
handler a2 read a prev;
a b
-8 i
+9 j
handler a2 close;
drop table t1;
-drop table if exists t1,t2;
-create table t1 (a int);
-handler t1 open as t1_alias;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-flush tables;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-handler t1_alias close;
-drop table t1;
-create table t1 (a int);
-handler t1 open as t1_alias;
-handler t1_alias read first;
-a
-drop table t1;
-handler t1_alias read next;
-ERROR 42S02: Unknown table 't1_alias' in HANDLER
create table t1 (a int);
-create temporary table t2 (a int, key(a));
+create temporary table t2 (a int, key (a));
handler t1 open as a1;
handler t2 open as a2;
handler a2 read a first;
@@ -667,7 +510,7 @@ handler a2 read a next;
ERROR 42S02: Unknown table 'a2' in HANDLER
handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
-create table t1 (a int, key(a));
+create table t1 (a int, key (a));
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
@@ -680,7 +523,7 @@ handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
handler a2 close;
drop table t1, t2;
-create table t1 (a int, key(a));
+create table t1 (a int, key (a));
handler t1 open as a1;
handler a1 read a first;
a
@@ -688,7 +531,7 @@ rename table t1 to t2;
handler a1 read a first;
ERROR 42S02: Unknown table 'a1' in HANDLER
drop table t2;
-create table t1 (a int, key(a));
+create table t1 (a int, key (a));
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
@@ -703,44 +546,19 @@ handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
handler a2 close;
drop table t1, t2;
-create table t1 (a int, b char(1), key a(a), key b(a,b));
-insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
-(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j");
-handler t1 open;
-handler t1 read a first;
-a b
-0 a
-handler t1 read a next;
-a b
-1 b
-flush tables;
-handler t1 read a next;
-a b
-0 a
-handler t1 read a next;
-a b
-1 b
-flush tables with read lock;
-handler t1 read a next;
-a b
-0 a
-unlock tables;
-drop table t1;
-handler t1 read a next;
-ERROR 42S02: Unknown table 't1' in HANDLER
-drop table if exists t1;
-create table t1 (a int);
-insert into t1 values (1);
-handler t1 open;
-alter table t1 engine=memory;
-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;
+#
+# BUG#51877 - HANDLER interface causes invalid memory read
+#
+CREATE TABLE t1(a INT, KEY (a));
+HANDLER t1 OPEN;
+HANDLER t1 READ a FIRST;
+a
+INSERT INTO t1 VALUES(1);
+HANDLER t1 READ a NEXT;
+a
+1
+HANDLER t1 CLOSE;
+DROP TABLE t1;
#
# BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
#
@@ -757,19 +575,6 @@ HANDLER t1 READ FIRST;
ERROR 42S02: Unknown table 't1' in HANDLER
DROP TABLE t1;
#
-# BUG#51877 - HANDLER interface causes invalid memory read
-#
-CREATE TABLE t1(a INT, KEY(a));
-HANDLER t1 OPEN;
-HANDLER t1 READ a FIRST;
-a
-INSERT INTO t1 VALUES(1);
-HANDLER t1 READ a NEXT;
-a
-1
-HANDLER t1 CLOSE;
-DROP TABLE t1;
-#
# Bug #54007: assert in ha_myisam::index_next , HANDLER
#
CREATE TABLE t1(a INT, b INT, PRIMARY KEY(a), KEY b(b), KEY ab(a, b));
@@ -821,12 +626,13 @@ HANDLER t1 READ b NEXT;
a b
HANDLER t1 READ NEXT;
a b
-4 40
+2 20
HANDLER t1 READ NEXT;
a b
-3 30
+1 10
HANDLER t1 READ NEXT;
a b
+4 40
HANDLER t1 CLOSE;
HANDLER t1 OPEN;
HANDLER t1 READ FIRST;
diff --git a/mysql-test/t/handler_myisam.test b/mysql-test/suite/handler/myisam.test
index e78072ef8a0..c6acf1e822c 100644
--- a/mysql-test/t/handler_myisam.test
+++ b/mysql-test/suite/handler/myisam.test
@@ -5,20 +5,14 @@
# Last update:
# 2006-07-31 ML test refactored (MySQL 5.1)
# code of t/handler.test and t/innodb_handler.test united
-# main testing code put into include/handler.inc
+# main testing code put into handler.inc
# rename t/handler.test to t/handler_myisam.test
#
-# should work in embedded server after mysqltest is fixed
---source include/not_embedded.inc
-
let $engine_type= MyISAM;
-let $other_engine_type= MEMORY;
-# There is unfortunately no other all time available storage engine
-# which supports the handler interface
-let $other_handler_engine_type= MyISAM;
---source include/handler.inc
+--source init.inc
+--source handler.inc
--echo #
--echo # BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
@@ -38,18 +32,6 @@ HANDLER t1 READ FIRST;
DROP TABLE t1;
--echo #
---echo # BUG#51877 - HANDLER interface causes invalid memory read
---echo #
-CREATE TABLE t1(a INT, KEY(a));
-HANDLER t1 OPEN;
-HANDLER t1 READ a FIRST;
-INSERT INTO t1 VALUES(1);
-HANDLER t1 READ a NEXT;
-HANDLER t1 CLOSE;
-DROP TABLE t1;
-
-
---echo #
--echo # Bug #54007: assert in ha_myisam::index_next , HANDLER
--echo #
CREATE TABLE t1(a INT, b INT, PRIMARY KEY(a), KEY b(b), KEY ab(a, b));
diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test
index 4df1a0f3478..742a83f7bad 100644
--- a/mysql-test/t/lock_multi.test
+++ b/mysql-test/t/lock_multi.test
@@ -484,22 +484,6 @@ unlock tables;
connection default;
drop table t1;
-#
-# Bug#25856 HANDLER table OPEN in one connection lock DROP TABLE in another one
-#
---disable_warnings
-drop table if exists t1;
---enable_warnings
-create table t1 (a int) ENGINE=MEMORY;
---echo --> client 2
-connection locker;
---error ER_ILLEGAL_HA
-handler t1 open;
---echo --> client 1
-connection default;
-drop table t1;
-
-
# Disconnect sessions used in many subtests above
disconnect locker;
disconnect reader;
diff --git a/mysys/tree.c b/mysys/tree.c
index e4854581204..68eaecbb27b 100644
--- a/mysys/tree.c
+++ b/mysys/tree.c
@@ -375,6 +375,7 @@ void *tree_search_key(TREE *tree, const void *key,
case HA_READ_KEY_EXACT:
case HA_READ_KEY_OR_NEXT:
case HA_READ_BEFORE_KEY:
+ case HA_READ_KEY_OR_PREV:
last_equal_element= parents;
cmp= 1;
break;
@@ -418,6 +419,9 @@ void *tree_search_key(TREE *tree, const void *key,
case HA_READ_BEFORE_KEY:
*last_pos= last_right_step_parent;
break;
+ case HA_READ_KEY_OR_PREV:
+ *last_pos= last_equal_element ? last_equal_element : last_right_step_parent;
+ break;
default:
return NULL;
}
diff --git a/sql/handler.cc b/sql/handler.cc
index e851d9248c2..e1808e8d460 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2736,7 +2736,10 @@ void handler::print_error(int error, myf errflag)
textno=ER_DUP_UNIQUE;
break;
case HA_ERR_RECORD_CHANGED:
- SET_FATAL_ERROR;
+ /*
+ This is not fatal error when using HANDLER interface
+ SET_FATAL_ERROR;
+ */
textno=ER_CHECKREAD;
break;
case HA_ERR_CRASHED:
diff --git a/sql/handler.h b/sql/handler.h
index 7e39ead5029..b7bc188b2ad 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1753,6 +1753,7 @@ public:
{ return(NULL);} /* gets tablespace name from handler */
/** used in ALTER TABLE; 1 if changing storage engine is allowed */
virtual bool can_switch_engines() { return 1; }
+ virtual int can_continue_handler_scan() { return 0; }
/** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */
virtual int get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
{ return 0; }
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 69be8c8e9b4..85b7e46a313 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -548,6 +548,12 @@ retry:
mode= RLAST;
}
}
+ else if (table->file->inited != handler::RND)
+ {
+ /* Convert RNEXT to RFIRST if we haven't started row scan */
+ if (mode == RNEXT)
+ mode= RFIRST;
+ }
if (insert_fields(thd, &thd->lex->select_lex.context,
tables->db, tables->alias, &it, 0))
@@ -569,6 +575,8 @@ retry:
case RNEXT:
if (table->file->inited != handler::NONE)
{
+ if ((error= table->file->can_continue_handler_scan()))
+ break;
if (keyname)
{
/* Check if we read from the same index. */
@@ -603,7 +611,9 @@ retry:
DBUG_ASSERT((uint) keyno == table->file->get_index());
if (table->file->inited != handler::NONE)
{
- error=table->file->ha_index_prev(table->record[0]);
+ if ((error= table->file->can_continue_handler_scan()))
+ break;
+ error= table->file->ha_index_prev(table->record[0]);
break;
}
/* else fall through */
@@ -673,8 +683,11 @@ retry:
continue;
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
{
- sql_print_error("mysql_ha_read: Got error %d when reading table '%s'",
- error, tables->table_name);
+ /* Don't give error in the log file for some expected problems */
+ if (error != HA_ERR_RECORD_CHANGED && error != HA_ERR_WRONG_COMMAND)
+ sql_print_error("mysql_ha_read: Got error %d when reading "
+ "table '%s'",
+ error, tables->table_name);
table->file->print_error(error,MYF(0));
goto err;
}
diff --git a/storage/maria/ma_extra.c b/storage/maria/ma_extra.c
index 81f3789523f..e436a51248a 100644
--- a/storage/maria/ma_extra.c
+++ b/storage/maria/ma_extra.c
@@ -50,7 +50,7 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function,
switch (function) {
case HA_EXTRA_RESET_STATE: /* Reset state (don't free buffers) */
- info->lastinx= 0; /* Use first index as def */
+ info->lastinx= ~0; /* Detect index changes */
info->last_search_keypage= info->cur_row.lastpos= HA_OFFSET_ERROR;
info->page_changed= 1;
/* Next/prev gives first/last */
@@ -545,7 +545,7 @@ int maria_reset(MARIA_HA *info)
#endif
info->opt_flag&= ~(KEY_READ_USED | REMEMBER_OLD_POS);
info->quick_mode= 0;
- info->lastinx= 0; /* Use first index as def */
+ info->lastinx= ~0; /* detect index changes */
info->last_search_keypage= info->cur_row.lastpos= HA_OFFSET_ERROR;
info->page_changed= 1;
info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND |
diff --git a/storage/maria/ma_ft_boolean_search.c b/storage/maria/ma_ft_boolean_search.c
index d302892ce05..40b0623adb1 100644
--- a/storage/maria/ma_ft_boolean_search.c
+++ b/storage/maria/ma_ft_boolean_search.c
@@ -356,7 +356,7 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search)
{
ftbw->key_root=info->s->state.key_root[ftb->keynr];
ftbw->keyinfo=info->s->keyinfo+ftb->keynr;
- key.keyinfo= ftbw->keyinfo;
+ info->last_key.keyinfo= key.keyinfo= ftbw->keyinfo;
key.data= ftbw->word;
key.data_length= ftbw->len;
key.ref_length= 0;
@@ -380,7 +380,7 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search)
max_docid);
}
- key.keyinfo= ftbw->keyinfo;
+ info->last_key.keyinfo= key.keyinfo= ftbw->keyinfo;
key.data= lastkey_buf;
key.data_length= USE_WHOLE_KEY;
key.ref_length= 0;
diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c
index 63e1801a39a..0890ff7e000 100644
--- a/storage/maria/ma_open.c
+++ b/storage/maria/ma_open.c
@@ -130,6 +130,8 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share, const char *name,
info.s=share;
info.cur_row.lastpos= HA_OFFSET_ERROR;
+ /* Impossible first index to force initialization in _ma_check_index() */
+ info.lastinx= ~0;
info.update= (short) (HA_STATE_NEXT_FOUND+HA_STATE_PREV_FOUND);
info.opt_flag=READ_CHECK_USED;
info.this_unique= (ulong) info.dfile.file; /* Uniq number in process */
diff --git a/storage/maria/ma_rkey.c b/storage/maria/ma_rkey.c
index daf1fd5a60c..85b3b463f49 100644
--- a/storage/maria/ma_rkey.c
+++ b/storage/maria/ma_rkey.c
@@ -43,7 +43,7 @@ int maria_rkey(MARIA_HA *info, uchar *buf, int inx, const uchar *key_data,
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
info->last_key_func= search_flag;
- keyinfo= share->keyinfo + inx;
+ keyinfo= info->last_key.keyinfo;
key_buff= info->lastkey_buff+info->s->base.max_key_length;
diff --git a/storage/maria/ma_rnext.c b/storage/maria/ma_rnext.c
index be960eccfe0..c49bbb19e83 100644
--- a/storage/maria/ma_rnext.c
+++ b/storage/maria/ma_rnext.c
@@ -30,6 +30,7 @@ int maria_rnext(MARIA_HA *info, uchar *buf, int inx)
uint flag;
MARIA_SHARE *share= info->s;
MARIA_KEYDEF *keyinfo;
+ uint update_mask= HA_STATE_NEXT_FOUND;
DBUG_ENTER("maria_rnext");
if ((inx = _ma_check_index(info,inx)) < 0)
@@ -61,6 +62,20 @@ int maria_rnext(MARIA_HA *info, uchar *buf, int inx)
error= _ma_search_first(info, keyinfo, share->state.key_root[inx]);
break;
}
+ /*
+ "search first" failed. This means we have no pivot for
+ "search next", or in other words MI_INFO::lastkey is
+ likely uninitialized.
+
+ Normally SQL layer would never request "search next" if
+ "search first" failed. But HANDLER may do anything.
+
+ As mi_rnext() without preceeding mi_rkey()/mi_rfirst()
+ equals to mi_rfirst(), we must restore original state
+ as if failing mi_rfirst() was not called.
+ */
+ if (error)
+ update_mask|= HA_STATE_PREV_FOUND;
}
else
{
@@ -104,7 +119,7 @@ int maria_rnext(MARIA_HA *info, uchar *buf, int inx)
/* Don't clear if database-changed */
info->update&= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED);
- info->update|= HA_STATE_NEXT_FOUND;
+ info->update|= update_mask;
if (error)
{
diff --git a/storage/maria/ma_rsame.c b/storage/maria/ma_rsame.c
index 4bdbfd526ba..4bd218a01df 100644
--- a/storage/maria/ma_rsame.c
+++ b/storage/maria/ma_rsame.c
@@ -36,7 +36,7 @@ int maria_rsame(MARIA_HA *info, uchar *record, int inx)
{
DBUG_ENTER("maria_rsame");
- if (inx != -1 && ! maria_is_key_active(info->s->state.key_map, inx))
+ if (inx >= 0 && !_ma_check_index(info, inx))
{
DBUG_PRINT("error", ("wrong index usage"));
DBUG_RETURN(my_errno=HA_ERR_WRONG_INDEX);
@@ -55,8 +55,7 @@ int maria_rsame(MARIA_HA *info, uchar *record, int inx)
if (inx >= 0)
{
- MARIA_KEYDEF *keyinfo= info->s->keyinfo + inx;
- info->lastinx= inx;
+ MARIA_KEYDEF *keyinfo= info->last_key.keyinfo;
(*keyinfo->make_key)(info, &info->last_key, (uint) inx,
info->lastkey_buff, record,
info->cur_row.lastpos,
diff --git a/storage/maria/ma_search.c b/storage/maria/ma_search.c
index 9f1e8e2554b..61ac1c6c23b 100644
--- a/storage/maria/ma_search.c
+++ b/storage/maria/ma_search.c
@@ -38,6 +38,8 @@ int _ma_check_index(MARIA_HA *info, int inx)
if (info->lastinx != inx) /* Index changed */
{
info->lastinx = inx;
+ info->last_key.keyinfo= info->s->keyinfo + inx;
+ info->last_key.flag= 0;
info->page_changed=1;
info->update= ((info->update & (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED)) |
HA_STATE_NEXT_FOUND | HA_STATE_PREV_FOUND);
@@ -180,7 +182,6 @@ static int _ma_search_no_save(register MARIA_HA *info, MARIA_KEY *key,
}
}
- info->last_key.keyinfo= keyinfo;
if ((nextflag & (SEARCH_SMALLER | SEARCH_LAST)) && flag != 0)
{
uint not_used[2];
@@ -1696,7 +1697,7 @@ int _ma_search_next(register MARIA_HA *info, MARIA_KEY *key,
}
tmp_key.data= lastkey;
- info->last_key.keyinfo= tmp_key.keyinfo= keyinfo;
+ tmp_key.keyinfo= keyinfo;
if (nextflag & SEARCH_BIGGER) /* Next key */
{
@@ -1778,8 +1779,6 @@ int _ma_search_first(MARIA_HA *info, MARIA_KEYDEF *keyinfo,
first_pos= page.buff + share->keypage_header + page.node;
} while ((pos= _ma_kpos(page.node, first_pos)) != HA_OFFSET_ERROR);
- info->last_key.keyinfo= keyinfo;
-
if (!(*keyinfo->get_key)(&info->last_key, page.flag, page.node, &first_pos))
DBUG_RETURN(-1); /* Crashed */
@@ -1830,8 +1829,6 @@ int _ma_search_last(MARIA_HA *info, MARIA_KEYDEF *keyinfo,
end_of_page= page.buff + page.size;
} while ((pos= _ma_kpos(page.node, end_of_page)) != HA_OFFSET_ERROR);
- info->last_key.keyinfo= keyinfo;
-
if (!_ma_get_last_key(&info->last_key, &page, end_of_page))
DBUG_RETURN(-1);
info->cur_row.lastpos= _ma_row_pos_from_key(&info->last_key);
diff --git a/storage/maria/ma_unique.c b/storage/maria/ma_unique.c
index a90578c2162..6090c624f36 100644
--- a/storage/maria/ma_unique.c
+++ b/storage/maria/ma_unique.c
@@ -43,6 +43,7 @@ my_bool _ma_check_unique(MARIA_HA *info, MARIA_UNIQUEDEF *def, uchar *record,
/* The above changed info->lastkey_buff2. Inform maria_rnext_same(). */
info->update&= ~HA_STATE_RNEXT_SAME;
+ info->last_key.keyinfo= keyinfo;
DBUG_ASSERT(key.data_length == MARIA_UNIQUE_HASH_LENGTH);
if (_ma_search(info, &key, SEARCH_FIND, info->s->state.key_root[def->key]))