MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rowid_order.inc
1 # include/rowid_order.inc
2 #
3 # Test for rowid ordering (and comparison) functions.
4 # do index_merge select for tables with PK of various types.
5 #
6 # The variable
7 # $engine_type -- storage engine to be tested
8 # has to be set before sourcing this script.
9 #
10 # Note: The comments/expections refer to InnoDB.
11 # They might be not valid for other storage engines.
12 #
13 # Last update:
14 # 2006-08-02 ML test refactored
15 # old name was t/rowid_order.test
16 # main code went into include/rowid_order.inc
17 #
18 
19 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
20 
21 --disable_warnings
22 drop table if exists t1, t2, t3,t4;
23 --enable_warnings
24 
25 # Signed number as rowid
26 create table t1 (
27  pk1 int not NULL,
28  key1 int(11),
29  key2 int(11),
30  PRIMARY KEY (pk1),
31  KEY key1 (key1),
32  KEY key2 (key2)
33 );
34 insert into t1 values (-5, 1, 1),
35  (-100, 1, 1),
36  (3, 1, 1),
37  (0, 1, 1),
38  (10, 1, 1);
39 -- disable_query_log
40 -- disable_result_log
41 analyze table t1;
42 -- enable_result_log
43 -- enable_query_log
44 explain select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
45 select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
46 drop table t1;
47 
48 # Unsigned numbers as rowids
49 create table t1 (
50  pk1 int unsigned not NULL,
51  key1 int(11),
52  key2 int(11),
53  PRIMARY KEY (pk1),
54  KEY key1 (key1),
55  KEY key2 (key2)
56 );
57 insert into t1 values (0, 1, 1),
58  (0xFFFFFFFF, 1, 1),
59  (0xFFFFFFFE, 1, 1),
60  (1, 1, 1),
61  (2, 1, 1);
62 select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
63 drop table t1;
64 
65 # Case-insensitive char(N)
66 create table t1 (
67  pk1 char(4) not NULL,
68  key1 int(11),
69  key2 int(11),
70  PRIMARY KEY (pk1),
71  KEY key1 (key1),
72  KEY key2 (key2)
73 ) collate latin2_general_ci;
74 insert into t1 values ('a1', 1, 1),
75  ('b2', 1, 1),
76  ('A3', 1, 1),
77  ('B4', 1, 1);
78 select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
79 drop table t1;
80 
81 # Multi-part PK
82 create table t1 (
83  pk1 int not NULL,
84  pk2 char(4) not NULL collate latin1_german1_ci,
85  pk3 char(4) not NULL collate latin1_bin,
86  key1 int(11),
87  key2 int(11),
88  PRIMARY KEY (pk1,pk2,pk3),
89  KEY key1 (key1),
90  KEY key2 (key2)
91 );
92 insert into t1 values
93  (1, 'u', 'u', 1, 1),
94  (1, 'u', char(0xEC), 1, 1),
95  (1, 'u', 'x', 1, 1);
96 insert ignore into t1 select pk1, char(0xEC), pk3, key1, key2 from t1;
97 insert ignore into t1 select pk1, 'x', pk3, key1, key2 from t1 where pk2='u';
98 insert ignore into t1 select 2, pk2, pk3, key1, key2 from t1;
99 select * from t1;
100 select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
101 
102 # Hidden PK
103 alter table t1 drop primary key;
104 select * from t1;
105 select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
106 drop table t1;
107 
108 # Variable-length PK
109 # this is also test for Bug#2688
110 create table t1 (
111  pk1 varchar(8) NOT NULL default '',
112  pk2 varchar(4) NOT NULL default '',
113  key1 int(11),
114  key2 int(11),
115  primary key(pk1, pk2),
116  KEY key1 (key1),
117  KEY key2 (key2)
118 );
119 insert into t1 values ('','empt',2,2),
120  ('a','a--a',2,2),
121  ('bb','b--b',2,2),
122  ('ccc','c--c',2,2),
123  ('dddd','d--d',2,2);
124 select * from t1 force index(key1, key2) where key1 < 3 or key2 < 3;
125 
126 drop table t1;