MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
index_merge_ror_cpk.inc
1 # include/index_merge_ror_cpk.inc
2 #
3 # Clustered PK ROR-index_merge tests
4 #
5 # The variable
6 # $engine_type -- storage engine to be tested
7 # has to be set before sourcing this script.
8 #
9 # Note: The comments/expectations refer to InnoDB.
10 # They might be not valid for other storage engines.
11 #
12 # Last update:
13 # 2006-08-02 ML test refactored
14 # old name was t/index_merge_ror_cpk.test
15 # main code went into include/index_merge_ror_cpk.inc
16 #
17 
18 --echo #---------------- Clustered PK ROR-index_merge tests -----------------------------
19 
20 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
21 
22 --disable_warnings
23 drop table if exists t1;
24 --enable_warnings
25 
26 create table t1
27 (
28  pk1 int not null,
29  pk2 int not null,
30 
31  key1 int not null,
32  key2 int not null,
33 
34  pktail1ok int not null,
35  pktail2ok int not null,
36  pktail3bad int not null,
37  pktail4bad int not null,
38  pktail5bad int not null,
39 
40  pk2copy int not null,
41  badkey int not null,
42 
43  filler1 char (200),
44  filler2 char (200),
45  key (key1),
46  key (key2),
47 
48  /* keys with tails from CPK members */
49  key (pktail1ok, pk1),
50  key (pktail2ok, pk1, pk2),
51  key (pktail3bad, pk2, pk1),
52  key (pktail4bad, pk1, pk2copy),
53  key (pktail5bad, pk1, pk2, pk2copy),
54 
55  primary key (pk1, pk2)
56 );
57 
58 --disable_query_log
59 set autocommit=0;
60 let $1=10000;
61 while ($1)
62 {
63  eval insert into t1 values ($1 div 10,$1 mod 100, $1/100,$1/100, $1/100,$1/100,$1/100,$1/100,$1/100, $1 mod 100, $1/1000,'filler-data-$1','filler2');
64  dec $1;
65 }
66 set autocommit=1;
67 --enable_query_log
68 
69 -- disable_query_log
70 -- disable_result_log
71 analyze table t1;
72 -- enable_result_log
73 -- enable_query_log
74 
75 # Verify that range scan on CPK is ROR
76 # (use index_intersection because it is impossible to check that for index union)
77 # Column 9, rows, can change depending on innodb-page-size.
78 --replace_column 9 ROWS
79 explain select * from t1 where pk1 = 1 and pk2 < 80 and key1=0;
80 # CPK scan + 1 ROR range scan is a special case
81 --sorted_result
82 select * from t1 where pk1 = 1 and pk2 < 80 and key1=0;
83 
84 # Verify that CPK fields are considered to be covered by index scans
85 explain select pk1,pk2 from t1 where key1 = 10 and key2=10 and 2*pk1+1 < 2*96+1;
86 select pk1,pk2 from t1 where key1 = 10 and key2=10 and 2*pk1+1 < 2*96+1;
87 
88 # Verify that CPK is always used for index intersection scans
89 # (this is because it is used as a filter, not for retrieval)
90 # The expected number of rows can vary depending on page size
91 --replace_column 9 ROWS
92 explain select * from t1 where badkey=1 and key1=10;
93 # The expected number of rows can vary depending on page size
94 --replace_column 9 ROWS
95 explain select * from t1 where pk1 < 7500 and key1 = 10;
96 
97 # Verify that keys with 'tails' of PK members are ok.
98 explain select * from t1 where pktail1ok=1 and key1=10;
99 explain select * from t1 where pktail2ok=1 and key1=10;
100 
101 # Note: The following is actually a deficiency, it uses sort_union currently.
102 # This comment refers to InnoDB and is probably not valid for other engines.
103 # The expected number of rows can vary depending on page size
104 --replace_column 9 ROWS
105 explain select * from t1 where (pktail2ok=1 and pk1< 50000) or key1=10;
106 
107 # The expected column used for KEY vary depending on page size
108 # The expected number of rows can vary depending on page size and platform
109 --replace_column 6 EITHER_KEY 9 ROWS
110 explain select * from t1 where pktail3bad=1 and key1=10;
111 # The expected column used for KEY vary depending on page size
112 --replace_column 9 ROWS
113 explain select * from t1 where pktail4bad=1 and key1=10;
114 # The expected column used for KEY vary depending on page size
115 --replace_column 9 ROWS
116 explain select * from t1 where pktail5bad=1 and key1=10;
117 
118 # Test for problem with innodb key values prefetch buffer:
119 explain select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10;
120 select pk1,pk2,key1,key2 from t1 where key1 = 10 and key2=10 limit 10;
121 
122 drop table t1;
123 # Testcase for BUG#4984
124 create table t1
125 (
126  RUNID varchar(22),
127  SUBMITNR varchar(5),
128  ORDERNR char(1),
129  PROGRAMM varchar(8),
130  TESTID varchar(4),
131  UCCHECK char(1),
132  ETEXT varchar(80),
133  ETEXT_TYPE char(1),
134  INFO char(1),
135  SEVERITY tinyint(3),
136  TADIRFLAG char(1),
137  PRIMARY KEY (RUNID,SUBMITNR,ORDERNR,PROGRAMM,TESTID,UCCHECK),
138  KEY `TVERM~KEY` (PROGRAMM,TESTID,UCCHECK)
139 ) DEFAULT CHARSET=latin1;
140 
141 update t1 set `ETEXT` = '', `ETEXT_TYPE`='', `INFO`='', `SEVERITY`='', `TADIRFLAG`=''
142 WHERE
143  `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND
144  `TESTID`='' AND `UCCHECK`='';
145 
146 drop table t1;
147 
148 --echo #
149 --echo # Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB
150 --echo #
151 CREATE TABLE t1 (f1 INT, PRIMARY KEY (f1));
152 INSERT INTO t1 VALUES (2);
153 CREATE TABLE t2 (f1 INT, f2 INT, f3 char(1),
154  PRIMARY KEY (f1), KEY (f2), KEY (f3) );
155 INSERT INTO t2 VALUES (1, 1, 'h'), (2, 3, 'h'), (3, 2, ''), (4, 2, '');
156 
157 SELECT t1.f1 FROM t1
158 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
159 
160 -- disable_query_log
161 -- disable_result_log
162 analyze table t1;
163 analyze table t2;
164 -- enable_result_log
165 -- enable_query_log
166 
167 EXPLAIN SELECT t1.f1 FROM t1
168 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
169 
170 DROP TABLE t1,t2;