1 # include/index_merge_ror_cpk.inc
3 # Clustered PK ROR-index_merge tests
6 # $engine_type -- storage engine to be tested
7 # has to be set before sourcing this script.
9 # Note: The comments/expectations refer to InnoDB.
10 # They might be not valid for other storage engines.
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
18 --echo #---------------- Clustered PK ROR-index_merge tests -----------------------------
20 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
23 drop
table if exists t1;
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,
50 key (pktail2ok, pk1, pk2),
51 key (pktail3bad, pk2, pk1),
52 key (pktail4bad, pk1, pk2copy),
53 key (pktail5bad, pk1, pk2, pk2copy),
55 primary key (pk1, pk2)
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');
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
82 select * from t1 where pk1 = 1 and pk2 < 80 and key1=0;
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;
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;
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;
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;
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;
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;
123 # Testcase for BUG#4984
137 PRIMARY
KEY (RUNID,SUBMITNR,ORDERNR,PROGRAMM,TESTID,UCCHECK),
138 KEY `TVERM~
KEY` (PROGRAMM,TESTID,UCCHECK)
139 ) DEFAULT CHARSET=latin1;
141 update t1 set `ETEXT` = '', `ETEXT_TYPE`='', `INFO`='', `SEVERITY`='', `TADIRFLAG`=''
143 `RUNID`= '' AND `SUBMITNR`= '' AND `ORDERNR`='' AND `PROGRAMM`='' AND
144 `TESTID`='' AND `UCCHECK`='';
149 --echo # Bug#50402 Optimizer producing wrong results when
using Index Merge on InnoDB
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),
155 INSERT INTO t2 VALUES (1, 1,
'h'), (2, 3,
'h'), (3, 2,
''), (4, 2,
'');
158 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 =
'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2;
161 -- disable_result_log
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;