mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug#27573: MIN() on an indexed column which is always NULL sets _other_ results
to NULL For queries of the form SELECT MIN(key_part_k) FROM t1 WHERE key_part_1 = const and ... and key_part_k-1 = const, the opt_sum_query optimization tries to use an index to substitute MIN/MAX functions with their values according to the following rules: 1) Insert the minimum non-null values where the WHERE clause still matches, or 3) A row of nulls However, the correct semantics requires that there is a third case 2) such that a NULL value is substituted if there are only NULL values for key_part_k. The patch modifies opt_sum_query() to handle this missing case. mysql-test/r/func_group.result: Bug #27573: Correct result mysql-test/t/func_group.test: Bug #27573: test case sql/opt_sum.cc: Bug #27573: Added code that will try to read the first non-null value for a given complete-field prefix, second choice is to read the null, and lastly set the error code if no row is found.
This commit is contained in:
35
mysql-test/r/bdb_notembedded.result
Normal file
35
mysql-test/r/bdb_notembedded.result
Normal file
@ -0,0 +1,35 @@
|
||||
set autocommit=1;
|
||||
reset master;
|
||||
create table bug16206 (a int);
|
||||
insert into bug16206 values(1);
|
||||
start transaction;
|
||||
insert into bug16206 values(2);
|
||||
commit;
|
||||
show binlog events;
|
||||
Log_name Pos Event_type Server_id End_log_pos Info
|
||||
f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4
|
||||
f n Query 1 n use `test`; create table bug16206 (a int)
|
||||
f n Query 1 n use `test`; insert into bug16206 values(1)
|
||||
f n Query 1 n use `test`; insert into bug16206 values(2)
|
||||
drop table bug16206;
|
||||
reset master;
|
||||
create table bug16206 (a int) engine= bdb;
|
||||
insert into bug16206 values(0);
|
||||
insert into bug16206 values(1);
|
||||
start transaction;
|
||||
insert into bug16206 values(2);
|
||||
commit;
|
||||
insert into bug16206 values(3);
|
||||
show binlog events;
|
||||
Log_name Pos Event_type Server_id End_log_pos Info
|
||||
f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4
|
||||
f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb
|
||||
f n Query 1 n use `test`; insert into bug16206 values(0)
|
||||
f n Query 1 n use `test`; insert into bug16206 values(1)
|
||||
f n Query 1 n use `test`; BEGIN
|
||||
f n Query 1 n use `test`; insert into bug16206 values(2)
|
||||
f n Query 1 n use `test`; COMMIT
|
||||
f n Query 1 n use `test`; insert into bug16206 values(3)
|
||||
drop table bug16206;
|
||||
set autocommit=0;
|
||||
End of 5.0 tests
|
@ -1321,4 +1321,51 @@ SELECT a,AVG(DISTINCT b) AS average FROM t1 GROUP BY a HAVING average > 50;
|
||||
a average
|
||||
1 32768.5000
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 ( a INT, b INT, KEY(a) );
|
||||
INSERT INTO t1 VALUES (NULL, 1), (NULL, 2);
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
|
||||
SELECT MIN(a), MIN(b) FROM t1;
|
||||
MIN(a) MIN(b)
|
||||
NULL 1
|
||||
CREATE TABLE t2( a INT, b INT, c INT, KEY(a, b) );
|
||||
INSERT INTO t2 ( a, b, c ) VALUES ( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 );
|
||||
EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ref a a 5 const 2 Using where
|
||||
SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
|
||||
MIN(b) MIN(c)
|
||||
3 2
|
||||
CREATE TABLE t3 (a INT, b INT, c int, KEY(a, b));
|
||||
INSERT INTO t3 VALUES (1, NULL, 1), (2, NULL, 2), (2, NULL, 2), (3, NULL, 3);
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t3 where a = 2;
|
||||
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(a), MIN(b) FROM t3 where a = 2;
|
||||
MIN(a) MIN(b)
|
||||
2 NULL
|
||||
CREATE TABLE t4 (a INT, b INT, c int, KEY(a, b));
|
||||
INSERT INTO t4 VALUES (1, 1, 1), (2, NULL, 2), (2, NULL, 2), (3, 1, 3);
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t4 where a = 2;
|
||||
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(a), MIN(b) FROM t4 where a = 2;
|
||||
MIN(a) MIN(b)
|
||||
2 NULL
|
||||
SELECT MIN(b), min(c) FROM t4 where a = 2;
|
||||
MIN(b) min(c)
|
||||
NULL 2
|
||||
CREATE TABLE t5( a INT, b INT, KEY( a, b) );
|
||||
INSERT INTO t5 VALUES( 1, 1 ), ( 1, 2 );
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
|
||||
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(a), MIN(b) FROM t5 WHERE a = 1;
|
||||
MIN(a) MIN(b)
|
||||
1 1
|
||||
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1 and b > 1;
|
||||
MIN(a) MIN(b)
|
||||
1 2
|
||||
DROP TABLE t1, t2, t3, t4, t5;
|
||||
End of 5.0 tests
|
||||
|
38
mysql-test/t/bdb_notembedded.test
Normal file
38
mysql-test/t/bdb_notembedded.test
Normal file
@ -0,0 +1,38 @@
|
||||
-- source include/not_embedded.inc
|
||||
-- source include/have_bdb.inc
|
||||
|
||||
#
|
||||
# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode
|
||||
#
|
||||
set autocommit=1;
|
||||
|
||||
let $VERSION=`select version()`;
|
||||
|
||||
reset master;
|
||||
create table bug16206 (a int);
|
||||
insert into bug16206 values(1);
|
||||
start transaction;
|
||||
insert into bug16206 values(2);
|
||||
commit;
|
||||
--replace_result $VERSION VERSION
|
||||
--replace_column 1 f 2 n 5 n
|
||||
show binlog events;
|
||||
drop table bug16206;
|
||||
|
||||
reset master;
|
||||
create table bug16206 (a int) engine= bdb;
|
||||
insert into bug16206 values(0);
|
||||
insert into bug16206 values(1);
|
||||
start transaction;
|
||||
insert into bug16206 values(2);
|
||||
commit;
|
||||
insert into bug16206 values(3);
|
||||
--replace_result $VERSION VERSION
|
||||
--replace_column 1 f 2 n 5 n
|
||||
show binlog events;
|
||||
drop table bug16206;
|
||||
|
||||
set autocommit=0;
|
||||
|
||||
|
||||
--echo End of 5.0 tests
|
@ -817,5 +817,38 @@ SELECT a,AVG(DISTINCT b) AS average FROM t1 GROUP BY a HAVING average > 50;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Bug #27573: MIN() on an indexed column which is always NULL sets _other_
|
||||
# results to NULL
|
||||
#
|
||||
CREATE TABLE t1 ( a INT, b INT, KEY(a) );
|
||||
INSERT INTO t1 VALUES (NULL, 1), (NULL, 2);
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t1;
|
||||
SELECT MIN(a), MIN(b) FROM t1;
|
||||
|
||||
CREATE TABLE t2( a INT, b INT, c INT, KEY(a, b) );
|
||||
INSERT INTO t2 ( a, b, c ) VALUES ( 1, NULL, 2 ), ( 1, 3, 4 ), ( 1, 4, 4 );
|
||||
EXPLAIN SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
|
||||
SELECT MIN(b), MIN(c) FROM t2 WHERE a = 1;
|
||||
|
||||
CREATE TABLE t3 (a INT, b INT, c int, KEY(a, b));
|
||||
INSERT INTO t3 VALUES (1, NULL, 1), (2, NULL, 2), (2, NULL, 2), (3, NULL, 3);
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t3 where a = 2;
|
||||
SELECT MIN(a), MIN(b) FROM t3 where a = 2;
|
||||
|
||||
CREATE TABLE t4 (a INT, b INT, c int, KEY(a, b));
|
||||
INSERT INTO t4 VALUES (1, 1, 1), (2, NULL, 2), (2, NULL, 2), (3, 1, 3);
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t4 where a = 2;
|
||||
SELECT MIN(a), MIN(b) FROM t4 where a = 2;
|
||||
SELECT MIN(b), min(c) FROM t4 where a = 2;
|
||||
|
||||
CREATE TABLE t5( a INT, b INT, KEY( a, b) );
|
||||
INSERT INTO t5 VALUES( 1, 1 ), ( 1, 2 );
|
||||
EXPLAIN SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
|
||||
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1;
|
||||
SELECT MIN(a), MIN(b) FROM t5 WHERE a = 1 and b > 1;
|
||||
|
||||
DROP TABLE t1, t2, t3, t4, t5;
|
||||
|
||||
###
|
||||
--echo End of 5.0 tests
|
||||
|
Reference in New Issue
Block a user