File: null_key_innodb.inc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (124 lines) | stat: -rw-r--r-- 3,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';

#
# The last select returned wrong results in 3.23.52
#

create table t1 (id int);
insert into t1 values (null), (0);
create table t2 (id int);
insert into t2 values (null);
select * from t1, t2 where t1.id = t2.id;
alter table t1 add key id (id);
select * from t1, t2 where t1.id = t2.id;
drop table t1,t2;

#
# Check bug when doing <=> NULL on an indexed null field
#

create table t1 (
  id  integer,
  id2 integer not null,
  index (id),
  index (id2)
);
insert into t1 values(null,null),(1,1);
select * from t1; 
select * from t1 where id <=> null;
select * from t1 where id <=> null or id > 0;
select * from t1 where id is null or id > 0;
select * from t1 where id2 <=> null or id2 > 0;
select * from t1 where id2 is null or id2 > 0;
delete from t1 where id <=> NULL;
select * from t1; 
drop table t1; 

#
# Test for bug #12144: optimizations for key access with null keys
#                      used for outer joins
#

CREATE TABLE t1 (a int);
CREATE TABLE t2 (a int, b int, INDEX idx(a));
CREATE TABLE t3 (b int, INDEX idx(b));
CREATE TABLE t4 (b int, INDEX idx(b));
INSERT INTO t1 VALUES (1), (2), (3), (4);
INSERT INTO t2 VALUES (1, 1), (3, 1);
INSERT INTO t3 VALUES
  (NULL), (NULL), (NULL), (NULL), (NULL),
  (NULL), (NULL), (NULL), (NULL), (NULL);
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t4 SELECT * FROM t3;
INSERT INTO t3 SELECT * FROM t4;
INSERT INTO t3 VALUES (2), (3);

ANALYZE table t1, t2, t3;

SELECT COUNT(*) FROM t3;

--replace_column 10 #
EXPLAIN SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
                                             LEFT JOIN t3 ON t2.b=t3.b;
FLUSH STATUS ;
--sorted_result
--replace_column 10 #
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LEFT JOIN t2 ON t1.a=t2.a
                                     LEFT JOIN t3 ON t2.b=t3.b;
SELECT FOUND_ROWS();
--skip_if_hypergraph  # Depends on the query plan.
SHOW STATUS LIKE "handler_read%";

DROP TABLE t1,t2,t3,t4;
# End of 4.1 tests

#
# BUG#34945 "ref_or_null queries that are null_rejecting and have a null value crash mysql"
#
CREATE TABLE t1 (
  a int(11) default NULL,
  b int(11) default NULL,
  KEY a (a,b)
);
INSERT INTO t1 VALUES (0,10),(0,11),(0,12);

CREATE TABLE t2 (
  a int(11) default NULL,
  b int(11) default NULL,
  KEY a (a)
);
INSERT INTO t2 VALUES (3,NULL),(3,11),(3,12);

SELECT * FROM t2 inner join t1 WHERE ( t1.a = 0 OR t1.a IS NULL) AND t2.a = 3 AND t2.b = t1.b;

drop table t1, t2;
-- echo End of 5.0 tests

--echo #
--echo # Bug#54608 Query using IN + OR + IS TRUE and IS NULL returns
--echo # NULL when should be empty
--echo #

CREATE TABLE t1 (a INT, KEY (a));
INSERT INTO t1 VALUES (1), (2), (NULL);
explain SELECT a FROM t1 WHERE a IN (42) OR (a IS TRUE AND a IS NULL);
SELECT a FROM t1 WHERE a IN (42) OR (a IS TRUE AND a IS NULL);
--replace_column 10 #
explain SELECT a FROM t1 WHERE a IN (42) OR (a=NULL);
SELECT a FROM t1 WHERE a IN (42) OR (a=NULL);
drop table t1;
SET sql_mode = default;