mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 13:02:28 +01:00
25f82f8a26
ORDER BY COUNT(*) LIMIT. PROBLEM: With respect to problem in the bug description, we exhibit different behaviors for the two tables presented, because innodb statistics (rec_per_key in this case) are updated for the first table and not so for the second one. As a result the query plan gets changed in test_if_skip_sort_order to use 'index' scan. Hence the difference in the explain output. (NOTE: We can reproduce the problem with first table by reducing the number of tuples and changing the table structure) The varied output w.r.t the query on the second table is because of the result in the query plan change. When a query plan is changed to use 'index' scan, after the call to test_if_skip_sort_order, we set keyread to TRUE immedietly. If for some reason we drop this index scan for a filesort later on, we fetch only the keys not the entire tuple. As a result we would see junk values in the result set. Following is the code flow: Call test_if_skip_sort_order -Choose an index to give sorted output -If this is a covering index, set_keyread to TRUE -Set the scan to INDEX scan Call test_if_skip_sort_order second time -Index is not chosen (note that we do not pass the actual limit value second time. Hence we do not choose index scan second time which in itself is a bug fixed in 5.6 with WL#5558) -goto filesort Call filesort -Create quick range on a different index -Since keyread is set to TRUE, we fetch only the columns of the index -results in the required columns are not fetched FIX: Remove the call to set_keyread(TRUE) from test_if_skip_sort_order. The access function which is 'join_read_first' or 'join_read_last' calls set_keyread anyways. mysql-test/r/func_group_innodb.result: Added test result for Bug#12713907 mysql-test/t/func_group_innodb.test: Added test case for Bug#12713907 sql/sql_select.cc: Remove the call to set_keyread as we do it from access functions 'join_read_first' and 'join_read_last'
194 lines
5.1 KiB
Text
194 lines
5.1 KiB
Text
create table t1 (USR_ID integer not null, MAX_REQ integer not null, constraint PK_SEA_USER primary key (USR_ID)) engine=InnoDB;
|
|
insert into t1 values (1, 3);
|
|
select count(*) + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ from t1 group by MAX_REQ;
|
|
count(*) + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ + MAX_REQ - MAX_REQ
|
|
1
|
|
select Case When Count(*) < MAX_REQ Then 1 Else 0 End from t1 where t1.USR_ID = 1 group by MAX_REQ;
|
|
Case When Count(*) < MAX_REQ Then 1 Else 0 End
|
|
1
|
|
drop table t1;
|
|
create table t1m (a int) engine=myisam;
|
|
create table t1i (a int) engine=innodb;
|
|
create table t2m (a int) engine=myisam;
|
|
create table t2i (a int) engine=innodb;
|
|
insert into t2m values (5);
|
|
insert into t2i values (5);
|
|
select min(a) from t1m;
|
|
min(a)
|
|
NULL
|
|
select min(7) from t1m;
|
|
min(7)
|
|
NULL
|
|
select min(7) from DUAL;
|
|
min(7)
|
|
7
|
|
explain select min(7) from t2m join t1m;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
|
|
select min(7) from t2m join t1m;
|
|
min(7)
|
|
NULL
|
|
select max(a) from t1m;
|
|
max(a)
|
|
NULL
|
|
select max(7) from t1m;
|
|
max(7)
|
|
NULL
|
|
select max(7) from DUAL;
|
|
max(7)
|
|
7
|
|
explain select max(7) from t2m join t1m;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
|
|
select max(7) from t2m join t1m;
|
|
max(7)
|
|
NULL
|
|
select 1, min(a) from t1m where a=99;
|
|
1 min(a)
|
|
1 NULL
|
|
select 1, min(a) from t1m where 1=99;
|
|
1 min(a)
|
|
1 NULL
|
|
select 1, min(1) from t1m where a=99;
|
|
1 min(1)
|
|
1 NULL
|
|
select 1, min(1) from t1m where 1=99;
|
|
1 min(1)
|
|
1 NULL
|
|
select 1, max(a) from t1m where a=99;
|
|
1 max(a)
|
|
1 NULL
|
|
select 1, max(a) from t1m where 1=99;
|
|
1 max(a)
|
|
1 NULL
|
|
select 1, max(1) from t1m where a=99;
|
|
1 max(1)
|
|
1 NULL
|
|
select 1, max(1) from t1m where 1=99;
|
|
1 max(1)
|
|
1 NULL
|
|
select min(a) from t1i;
|
|
min(a)
|
|
NULL
|
|
select min(7) from t1i;
|
|
min(7)
|
|
NULL
|
|
select min(7) from DUAL;
|
|
min(7)
|
|
7
|
|
explain select min(7) from t2i join t1i;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t2i ALL NULL NULL NULL NULL 1
|
|
1 SIMPLE t1i ALL NULL NULL NULL NULL 1 Using join buffer
|
|
select min(7) from t2i join t1i;
|
|
min(7)
|
|
NULL
|
|
select max(a) from t1i;
|
|
max(a)
|
|
NULL
|
|
select max(7) from t1i;
|
|
max(7)
|
|
NULL
|
|
select max(7) from DUAL;
|
|
max(7)
|
|
7
|
|
explain select max(7) from t2i join t1i;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t2i ALL NULL NULL NULL NULL 1
|
|
1 SIMPLE t1i ALL NULL NULL NULL NULL 1 Using join buffer
|
|
select max(7) from t2i join t1i;
|
|
max(7)
|
|
NULL
|
|
select 1, min(a) from t1i where a=99;
|
|
1 min(a)
|
|
1 NULL
|
|
select 1, min(a) from t1i where 1=99;
|
|
1 min(a)
|
|
1 NULL
|
|
select 1, min(1) from t1i where a=99;
|
|
1 min(1)
|
|
1 NULL
|
|
select 1, min(1) from t1i where 1=99;
|
|
1 min(1)
|
|
1 NULL
|
|
select 1, max(a) from t1i where a=99;
|
|
1 max(a)
|
|
1 NULL
|
|
select 1, max(a) from t1i where 1=99;
|
|
1 max(a)
|
|
1 NULL
|
|
select 1, max(1) from t1i where a=99;
|
|
1 max(1)
|
|
1 NULL
|
|
select 1, max(1) from t1i where 1=99;
|
|
1 max(1)
|
|
1 NULL
|
|
explain select count(*), min(7), max(7) from t1m, t1i;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found
|
|
1 SIMPLE t1i ALL NULL NULL NULL NULL 1
|
|
select count(*), min(7), max(7) from t1m, t1i;
|
|
count(*) min(7) max(7)
|
|
0 NULL NULL
|
|
explain select count(*), min(7), max(7) from t1m, t2i;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found
|
|
1 SIMPLE t2i ALL NULL NULL NULL NULL 1
|
|
select count(*), min(7), max(7) from t1m, t2i;
|
|
count(*) min(7) max(7)
|
|
0 NULL NULL
|
|
explain select count(*), min(7), max(7) from t2m, t1i;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t2m system NULL NULL NULL NULL 1
|
|
1 SIMPLE t1i ALL NULL NULL NULL NULL 1
|
|
select count(*), min(7), max(7) from t2m, t1i;
|
|
count(*) min(7) max(7)
|
|
0 NULL NULL
|
|
drop table t1m, t1i, t2m, t2i;
|
|
#
|
|
# Bug #57954: BIT_AND function returns incorrect results when
|
|
# semijoin=on
|
|
CREATE TABLE c (
|
|
pk INT,
|
|
col_varchar_key VARCHAR(1),
|
|
PRIMARY KEY (pk),
|
|
KEY col_varchar_key (col_varchar_key)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO c VALUES (11,NULL);
|
|
INSERT INTO c VALUES (16,'c');
|
|
CREATE TABLE bb (
|
|
pk INT,
|
|
col_varchar_key VARCHAR(1),
|
|
PRIMARY KEY (pk),
|
|
KEY col_varchar_key (col_varchar_key)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO bb VALUES (10,NULL);
|
|
SELECT straight_join BIT_AND(c.pk)
|
|
FROM
|
|
bb, c
|
|
WHERE c.col_varchar_key='ABC'
|
|
ORDER BY c.pk;
|
|
BIT_AND(c.pk)
|
|
18446744073709551615
|
|
DROP TABLE c,bb;
|
|
#
|
|
# Bug #58050: BIT_OR and BIT_XOR return incorrect results when
|
|
# semijoin=on
|
|
#
|
|
CREATE TABLE t1 (pk INT PRIMARY KEY, b INT, c INT) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES(1, 1, 1);
|
|
CREATE TABLE t2 (pk INT PRIMARY KEY, b INT, c INT) ENGINE=InnoDB;
|
|
INSERT INTO t2 VALUES (1, 1, NULL);
|
|
SELECT t1.* FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1;
|
|
pk b c
|
|
SELECT BIT_OR(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1;
|
|
BIT_OR(t1.b)
|
|
0
|
|
SELECT BIT_AND(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1;
|
|
BIT_AND(t1.b)
|
|
18446744073709551615
|
|
SELECT BIT_XOR(t1.b) FROM t1 JOIN t2 ON t1.c=t2.c WHERE t1.pk=1;
|
|
BIT_XOR(t1.b)
|
|
0
|
|
DROP TABLE t1, t2;
|
|
End of 5.5 tests
|