set @is_enable_default = @@global.ndb_index_stat_enable;
set @is_enable = 1;
set @is_enable = NULL;
# is_enable_on=1 is_enable_off=0
# ndb_index_stat_enable - before
show global variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	OFF
show local variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	OFF
set @@global.ndb_index_stat_enable = 1;
set @@local.ndb_index_stat_enable = 1;
# ndb_index_stat_enable - after
show global variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	ON
show local variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	ON
drop table if exists t1, t2, t3, t4;
CREATE TABLE t10(
K INT NOT NULL AUTO_INCREMENT,
I INT, J INT,
PRIMARY KEY(K),
KEY(I,J),
UNIQUE KEY(J,K)
) ENGINE=ndbcluster
partition by key (K) partitions 1;
INSERT INTO t10(I,J) VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);
CREATE TABLE t100 LIKE t10;
INSERT INTO t100(I,J)
SELECT X.J, X.J+(10*Y.J) FROM t10 AS X,t10 AS Y;
CREATE TABLE t10000 LIKE t10;
INSERT INTO t10000(I,J)
SELECT X.J, X.J+(100*Y.J) FROM t100 AS X,t100 AS Y
WHERE X.J<50;
INSERT INTO t10000(I,J)
SELECT X.J, X.J+(100*Y.J) FROM t100 AS X,t100 AS Y
WHERE X.J>=50;
ANALYZE TABLE t10,t100,t10000;
Table	Op	Msg_type	Msg_text
test.t10	analyze	status	OK
test.t100	analyze	status	OK
test.t10000	analyze	status	OK
SELECT COUNT(*) FROM t10;
COUNT(*)
10
SELECT COUNT(*) FROM t100;
COUNT(*)
100
SELECT COUNT(*) FROM t10000;
COUNT(*)
10000
EXPLAIN
SELECT * FROM t10000 WHERE k = 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	const	PRIMARY	PRIMARY	4	const	1	
EXPLAIN
SELECT * FROM t10000 WHERE k >= 42 and k < 10000;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	9958	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE k BETWEEN 42 AND 10000;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	9959	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE k < 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	41	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE k > 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	9958	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 AS X JOIN t10000 AS Y
ON Y.I=X.I AND Y.J = X.I;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	X	ALL	I	NULL	NULL	NULL	10000	Parent of 2 pushed join@1; Using where with pushed condition
1	SIMPLE	Y	ref	J,I	J	5	test.X.I	1	Child of 'X' in pushed join@1; Using where
EXPLAIN
SELECT * FROM t100 WHERE k < 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t100	range	PRIMARY	PRIMARY	4	NULL	41	Using where with pushed condition
EXPLAIN
SELECT * FROM t100 WHERE k > 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t100	range	PRIMARY	PRIMARY	4	NULL	58	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE k < 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	41	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE k > 42;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	9958	Using where with pushed condition
EXPLAIN
SELECT * FROM t100 WHERE k BETWEEN 42 AND 10000;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t100	range	PRIMARY	PRIMARY	4	NULL	59	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE k BETWEEN 42 AND 10000;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY	PRIMARY	4	NULL	9959	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I = 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	I	I	5	const	100	
EXPLAIN
SELECT * FROM t10000 WHERE J = 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	J	J	5	const	2	
EXPLAIN
SELECT * FROM t10000 WHERE I = 0 AND J = 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	J,I	J	5	const	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I = 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	I	I	5	const	100	
EXPLAIN
SELECT * FROM t10000 WHERE I = 0 AND J > 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	I	10	NULL	99	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I = 0 AND J < 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	J	5	NULL	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I = 0 AND J BETWEEN 1 AND 10;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	I	10	NULL	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I = 0 AND J = 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	J,I	J	5	const	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J = 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	J	J	5	const	2	
EXPLAIN
SELECT * FROM t10000 WHERE J = 0 AND K > 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY,J	J	9	NULL	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J = 0 AND K < 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	PRIMARY,J	J	5	const	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J = 0 AND K BETWEEN 1 AND 10;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	PRIMARY,J	J	9	NULL	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J = 0 AND K = 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	const	PRIMARY,J	PRIMARY	4	const	1	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I = 0 AND J <> 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	I	10	NULL	101	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I <> 0 AND J = 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	J,I	J	5	const	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE I <> 0 AND J <> 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	I	5	NULL	9902	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J <> 1 AND I = 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	I	10	NULL	101	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J = 1 AND I <> 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	ref	J,I	J	5	const	2	Using where with pushed condition
EXPLAIN
SELECT * FROM t10000 WHERE J <> 1 AND I <> 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t10000	range	J,I	I	5	NULL	9902	Using where with pushed condition
DROP TABLE t10,t100,t10000;
End of 5.1 tests
set @is_enable = @is_enable_default;
set @is_enable = NULL;
# is_enable_on=0 is_enable_off=1
# ndb_index_stat_enable - before
show global variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	ON
show local variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	ON
set @@local.ndb_index_stat_enable = 0;
set @@global.ndb_index_stat_enable = 0;
drop table mysql.ndb_index_stat_sample;
drop table mysql.ndb_index_stat_head;
# ndb_index_stat_enable - after
show global variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	OFF
show local variables like 'ndb_index_stat_enable';
Variable_name	Value
ndb_index_stat_enable	OFF
