~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/t/parser_precedence.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
--disable_warnings
 
3
drop table if exists t1_30237_bool;
 
4
--enable_warnings
 
5
 
 
6
create table t1_30237_bool(A boolean, B boolean, C boolean);
 
7
 
 
8
insert into t1_30237_bool values
 
9
(FALSE, FALSE, FALSE),
 
10
(FALSE, FALSE, NULL),
 
11
(FALSE, FALSE, TRUE),
 
12
(FALSE, NULL, FALSE),
 
13
(FALSE, NULL, NULL),
 
14
(FALSE, NULL, TRUE),
 
15
(FALSE, TRUE, FALSE),
 
16
(FALSE, TRUE, NULL),
 
17
(FALSE, TRUE, TRUE),
 
18
(NULL, FALSE, FALSE),
 
19
(NULL, FALSE, NULL),
 
20
(NULL, FALSE, TRUE),
 
21
(NULL, NULL, FALSE),
 
22
(NULL, NULL, NULL),
 
23
(NULL, NULL, TRUE),
 
24
(NULL, TRUE, FALSE),
 
25
(NULL, TRUE, NULL),
 
26
(NULL, TRUE, TRUE),
 
27
(TRUE, FALSE, FALSE),
 
28
(TRUE, FALSE, NULL),
 
29
(TRUE, FALSE, TRUE),
 
30
(TRUE, NULL, FALSE),
 
31
(TRUE, NULL, NULL),
 
32
(TRUE, NULL, TRUE),
 
33
(TRUE, TRUE, FALSE),
 
34
(TRUE, TRUE, NULL),
 
35
(TRUE, TRUE, TRUE) ;
 
36
 
 
37
--echo Testing OR, XOR, AND
 
38
select A, B, A OR B, A XOR B, A AND B
 
39
  from t1_30237_bool where C is null order by A, B;
 
40
 
 
41
--echo Testing that OR is associative 
 
42
select A, B, C, (A OR B) OR C, A OR (B OR C), A OR B OR C
 
43
 from t1_30237_bool order by A, B, C;
 
44
 
 
45
select count(*) from t1_30237_bool
 
46
  where ((A OR B) OR C) != (A OR (B OR C));
 
47
 
 
48
--echo Testing that XOR is associative 
 
49
select A, B, C, (A XOR B) XOR C, A XOR (B XOR C), A XOR B XOR C
 
50
  from t1_30237_bool order by A, B, C;
 
51
 
 
52
select count(*) from t1_30237_bool
 
53
  where ((A XOR B) XOR C) != (A XOR (B XOR C));
 
54
 
 
55
--echo Testing that AND is associative 
 
56
select A, B, C, (A AND B) AND C, A AND (B AND C), A AND B AND C
 
57
  from t1_30237_bool order by A, B, C;
 
58
 
 
59
select count(*) from t1_30237_bool
 
60
  where ((A AND B) AND C) != (A AND (B AND C));
 
61
 
 
62
--echo Testing that AND has precedence over OR
 
63
select A, B, C, (A OR B) AND C, A OR (B AND C), A OR B AND C
 
64
  from t1_30237_bool order by A, B, C;
 
65
select count(*) from t1_30237_bool
 
66
  where (A OR (B AND C)) != (A OR B AND C);
 
67
select A, B, C, (A AND B) OR C, A AND (B OR C), A AND B OR C
 
68
  from t1_30237_bool order by A, B, C;
 
69
select count(*) from t1_30237_bool
 
70
  where ((A AND B) OR C) != (A AND B OR C);
 
71
 
 
72
--echo Testing that AND has precedence over XOR
 
73
select A, B, C, (A XOR B) AND C, A XOR (B AND C), A XOR B AND C
 
74
  from t1_30237_bool order by A, B, C;
 
75
select count(*) from t1_30237_bool
 
76
  where (A XOR (B AND C)) != (A XOR B AND C);
 
77
select A, B, C, (A AND B) XOR C, A AND (B XOR C), A AND B XOR C
 
78
  from t1_30237_bool order by A, B, C;
 
79
select count(*) from t1_30237_bool
 
80
  where ((A AND B) XOR C) != (A AND B XOR C);
 
81
 
 
82
--echo Testing that XOR has precedence over OR
 
83
select A, B, C, (A XOR B) OR C, A XOR (B OR C), A XOR B OR C
 
84
  from t1_30237_bool order by A, B, C;
 
85
select count(*) from t1_30237_bool
 
86
  where ((A XOR B) OR C) != (A XOR B OR C);
 
87
select A, B, C, (A OR B) XOR C, A OR (B XOR C), A OR B XOR C
 
88
  from t1_30237_bool order by A, B, C;
 
89
select count(*) from t1_30237_bool
 
90
  where (A OR (B XOR C)) != (A OR B XOR C);
 
91
 
 
92
drop table t1_30237_bool;
 
93
 
 
94
--echo Testing that NOT has precedence over OR
 
95
select (NOT FALSE) OR TRUE, NOT (FALSE OR TRUE), NOT FALSE OR TRUE;
 
96
 
 
97
--echo Testing that NOT has precedence over XOR
 
98
select (NOT FALSE) XOR FALSE, NOT (FALSE XOR FALSE), NOT FALSE XOR FALSE;
 
99
 
 
100
--echo Testing that NOT has precedence over AND
 
101
select (NOT FALSE) AND FALSE, NOT (FALSE AND FALSE), NOT FALSE AND FALSE;
 
102
 
 
103
--echo Testing that NOT is associative
 
104
select NOT NOT TRUE, NOT NOT NOT FALSE;
 
105
 
 
106
--echo Testing that IS has precedence over NOT
 
107
select (NOT NULL) IS TRUE, NOT (NULL IS TRUE), NOT NULL IS TRUE;
 
108
select (NOT NULL) IS NOT TRUE, NOT (NULL IS NOT TRUE), NOT NULL IS NOT TRUE;
 
109
select (NOT NULL) IS FALSE, NOT (NULL IS FALSE), NOT NULL IS FALSE;
 
110
select (NOT NULL) IS NOT FALSE, NOT (NULL IS NOT FALSE), NOT NULL IS NOT FALSE;
 
111
select (NOT TRUE) IS UNKNOWN, NOT (TRUE IS UNKNOWN), NOT TRUE IS UNKNOWN;
 
112
select (NOT TRUE) IS NOT UNKNOWN, NOT (TRUE IS NOT UNKNOWN), NOT TRUE IS NOT UNKNOWN;
 
113
select (NOT TRUE) IS NULL, NOT (TRUE IS NULL), NOT TRUE IS NULL;
 
114
select (NOT TRUE) IS NOT NULL, NOT (TRUE IS NOT NULL), NOT TRUE IS NOT NULL;
 
115
 
 
116
--echo Testing that IS [NOT] TRUE/FALSE/UNKNOWN predicates are not associative
 
117
# Documenting existing behavior in 5.0.48
 
118
-- error ER_PARSE_ERROR
 
119
select TRUE IS TRUE IS TRUE IS TRUE;
 
120
-- error ER_PARSE_ERROR
 
121
select FALSE IS NOT TRUE IS NOT TRUE IS NOT TRUE;
 
122
-- error ER_PARSE_ERROR
 
123
select NULL IS FALSE IS FALSE IS FALSE;
 
124
-- error ER_PARSE_ERROR
 
125
select TRUE IS NOT FALSE IS NOT FALSE IS NOT FALSE;
 
126
-- error ER_PARSE_ERROR
 
127
select FALSE IS UNKNOWN IS UNKNOWN IS UNKNOWN;
 
128
-- error ER_PARSE_ERROR
 
129
select TRUE IS NOT UNKNOWN IS NOT UNKNOWN IS NOT UNKNOWN;
 
130
 
 
131
--echo Testing that IS [NOT] NULL predicates are associative
 
132
# Documenting existing behavior in 5.0.48
 
133
select FALSE IS NULL IS NULL IS NULL;
 
134
select TRUE IS NOT NULL IS NOT NULL IS NOT NULL;
 
135
 
 
136
--echo Testing that comparison operators are left associative
 
137
select 1 <=> 2 <=> 2, (1 <=> 2) <=> 2, 1 <=> (2 <=> 2);
 
138
select 1 = 2 = 2, (1 = 2) = 2, 1 = (2 = 2);
 
139
select 1 != 2 != 3, (1 != 2) != 3, 1 != (2 != 3);
 
140
select 1 <> 2 <> 3, (1 <> 2) <> 3, 1 <> (2 <> 3);
 
141
select 1 < 2 < 3, (1 < 2) < 3, 1 < (2 < 3);
 
142
select 3 <= 2 <= 1, (3 <= 2) <= 1, 3 <= (2 <= 1);
 
143
select 1 > 2 > 3, (1 > 2) > 3, 1 > (2 > 3);
 
144
select 1 >= 2 >= 3, (1 >= 2) >= 3, 1 >= (2 >= 3);
 
145
 
 
146
-- echo Testing that | is associative
 
147
select 0xF0 | 0x0F | 0x55, (0xF0 | 0x0F) | 0x55, 0xF0 | (0x0F | 0x55);
 
148
 
 
149
-- echo Testing that & is associative
 
150
select 0xF5 & 0x5F & 0x55, (0xF5 & 0x5F) & 0x55, 0xF5 & (0x5F & 0x55);
 
151
 
 
152
-- echo Testing that << is left associative
 
153
select 4 << 3 << 2, (4 << 3) << 2, 4 << (3 << 2);
 
154
 
 
155
-- echo Testing that >> is left associative
 
156
select 256 >> 3 >> 2, (256 >> 3) >> 2, 256 >> (3 >> 2);
 
157
 
 
158
--echo Testing that & has precedence over |
 
159
select 0xF0 & 0x0F | 0x55, (0xF0 & 0x0F) | 0x55, 0xF0 & (0x0F | 0x55);
 
160
select 0x55 | 0xF0 & 0x0F, (0x55 | 0xF0) & 0x0F, 0x55 | (0xF0 & 0x0F);
 
161
 
 
162
--echo Testing that << has precedence over |
 
163
select 0x0F << 4 | 0x0F, (0x0F << 4) | 0x0F, 0x0F << (4 | 0x0F);
 
164
select 0x0F | 0x0F << 4, (0x0F | 0x0F) << 4, 0x0F | (0x0F << 4);
 
165
 
 
166
--echo Testing that >> has precedence over |
 
167
select 0xF0 >> 4 | 0xFF, (0xF0 >> 4) | 0xFF, 0xF0 >> (4 | 0xFF);
 
168
select 0xFF | 0xF0 >> 4, (0xFF | 0xF0) >> 4, 0xFF | (0xF0 >> 4);
 
169
 
 
170
--echo Testing that << has precedence over &
 
171
select 0x0F << 4 & 0xF0, (0x0F << 4) & 0xF0, 0x0F << (4 & 0xF0);
 
172
select 0xF0 & 0x0F << 4, (0xF0 & 0x0F) << 4, 0xF0 & (0x0F << 4);
 
173
 
 
174
--echo Testing that >> has precedence over &
 
175
select 0xF0 >> 4 & 0x55, (0xF0 >> 4) & 0x55, 0xF0 >> (4 & 0x55);
 
176
select 0x0F & 0xF0 >> 4, (0x0F & 0xF0) >> 4, 0x0F & (0xF0 >> 4);
 
177
 
 
178
--echo Testing that >> and << have the same precedence
 
179
select 0xFF >> 4 << 2, (0xFF >> 4) << 2, 0xFF >> (4 << 2);
 
180
select 0x0F << 4 >> 2, (0x0F << 4) >> 2, 0x0F << (4 >> 2);
 
181
 
 
182
--echo Testing that binary + is associative
 
183
select 1 + 2 + 3, (1 + 2) + 3, 1 + (2 + 3);
 
184
 
 
185
--echo Testing that binary - is left associative
 
186
select 1 - 2 - 3, (1 - 2) - 3, 1 - (2 - 3);
 
187
 
 
188
--echo Testing that binary + and binary - have the same precedence
 
189
# evaluated left to right
 
190
select 1 + 2 - 3, (1 + 2) - 3, 1 + (2 - 3);
 
191
select 1 - 2 + 3, (1 - 2) + 3, 1 - (2 + 3);
 
192
 
 
193
--echo Testing that binary + has precedence over |
 
194
select 0xF0 + 0x0F | 0x55, (0xF0 + 0x0F) | 0x55, 0xF0 + (0x0F | 0x55);
 
195
select 0x55 | 0xF0 + 0x0F, (0x55 | 0xF0) + 0x0F, 0x55 | (0xF0 + 0x0F);
 
196
 
 
197
--echo Testing that binary + has precedence over &
 
198
select 0xF0 + 0x0F & 0x55, (0xF0 + 0x0F) & 0x55, 0xF0 + (0x0F & 0x55);
 
199
select 0x55 & 0xF0 + 0x0F, (0x55 & 0xF0) + 0x0F, 0x55 & (0xF0 + 0x0F);
 
200
 
 
201
--echo Testing that binary + has precedence over <<
 
202
select 2 + 3 << 4, (2 + 3) << 4, 2 + (3 << 4);
 
203
select 3 << 4 + 2, (3 << 4) + 2, 3 << (4 + 2);
 
204
 
 
205
--echo Testing that binary + has precedence over >>
 
206
select 4 + 3 >> 2, (4 + 3) >> 2, 4 + (3 >> 2);
 
207
select 3 >> 2 + 1, (3 >> 2) + 1, 3 >> (2 + 1);
 
208
 
 
209
--echo Testing that binary - has precedence over |
 
210
select 0xFF - 0x0F | 0x55, (0xFF - 0x0F) | 0x55, 0xFF - (0x0F | 0x55);
 
211
select 0x55 | 0xFF - 0xF0, (0x55 | 0xFF) - 0xF0, 0x55 | (0xFF - 0xF0);
 
212
 
 
213
--echo Testing that binary - has precedence over &
 
214
select 0xFF - 0xF0 & 0x55, (0xFF - 0xF0) & 0x55, 0xFF - (0xF0 & 0x55);
 
215
select 0x55 & 0xFF - 0xF0, (0x55 & 0xFF) - 0xF0, 0x55 & (0xFF - 0xF0);
 
216
 
 
217
--echo Testing that binary - has precedence over <<
 
218
select 16 - 3 << 2, (16 - 3) << 2, 16 - (3 << 2);
 
219
select 4 << 3 - 2, (4 << 3) - 2, 4 << (3 - 2);
 
220
 
 
221
--echo Testing that binary - has precedence over >>
 
222
select 16 - 3 >> 2, (16 - 3) >> 2, 16 - (3 >> 2);
 
223
select 16 >> 3 - 2, (16 >> 3) - 2, 16 >> (3 - 2);
 
224
 
 
225
--echo Testing that * is associative
 
226
select 2 * 3 * 4, (2 * 3) * 4, 2 * (3 * 4);
 
227
 
 
228
--echo Testing that * has precedence over |
 
229
select 2 * 0x40 | 0x0F, (2 * 0x40) | 0x0F, 2 * (0x40 | 0x0F);
 
230
select 0x0F | 2 * 0x40, (0x0F | 2) * 0x40, 0x0F | (2 * 0x40);
 
231
 
 
232
--echo Testing that * has precedence over &
 
233
select 2 * 0x40 & 0x55, (2 * 0x40) & 0x55, 2 * (0x40 & 0x55);
 
234
select 0xF0 & 2 * 0x40, (0xF0 & 2) * 0x40, 0xF0 & (2 * 0x40);
 
235
 
 
236
--echo Testing that * has precedence over << 
 
237
# Actually, can't prove it for the first case,
 
238
# since << is a multiplication by a power of 2,
 
239
# and * is associative
 
240
select 5 * 3 << 4, (5 * 3) << 4, 5 * (3 << 4);
 
241
select 2 << 3 * 4, (2 << 3) * 4, 2 << (3 * 4);
 
242
 
 
243
--echo Testing that * has precedence over >>
 
244
# >> is a multiplication by a (negative) power of 2,
 
245
# see above.
 
246
select 3 * 4 >> 2, (3 * 4) >> 2, 3 * (4 >> 2);
 
247
select 4 >> 2 * 3, (4 >> 2) * 3, 4 >> (2 * 3);
 
248
 
 
249
--echo Testing that * has precedence over binary +
 
250
select 2 * 3 + 4, (2 * 3) + 4, 2 * (3 + 4);
 
251
select 2 + 3 * 4, (2 + 3) * 4, 2 + (3 * 4);
 
252
 
 
253
--echo Testing that * has precedence over binary -
 
254
select 4 * 3 - 2, (4 * 3) - 2, 4 * (3 - 2);
 
255
select 4 - 3 * 2, (4 - 3) * 2, 4 - (3 * 2);
 
256
 
 
257
--echo Testing that / is left associative
 
258
select 15 / 5 / 3, (15 / 5) / 3, 15 / (5 / 3);
 
259
 
 
260
--echo Testing that / has precedence over |
 
261
select 105 / 5 | 2, (105 / 5) | 2, 105 / (5 | 2);
 
262
select 105 | 2 / 5, (105 | 2) / 5, 105 | (2 / 5);
 
263
 
 
264
--echo Testing that / has precedence over &
 
265
select 105 / 5 & 0x0F, (105 / 5) & 0x0F, 105 / (5 & 0x0F);
 
266
select 0x0F & 105 / 5, (0x0F & 105) / 5, 0x0F & (105 / 5);
 
267
 
 
268
--echo Testing that / has precedence over << 
 
269
select 0x80 / 4 << 2, (0x80 / 4) << 2, 0x80 / (4 << 2);
 
270
select 0x80 << 4 / 2, (0x80 << 4) / 2, 0x80 << (4 / 2);
 
271
 
 
272
--echo Testing that / has precedence over >>
 
273
select 0x80 / 4 >> 2, (0x80 / 4) >> 2, 0x80 / (4 >> 2);
 
274
select 0x80 >> 4 / 2, (0x80 >> 4) / 2, 0x80 >> (4 / 2);
 
275
 
 
276
--echo Testing that / has precedence over binary +
 
277
select 0x80 / 2 + 2, (0x80 / 2) + 2, 0x80 / (2 + 2);
 
278
select 0x80 + 2 / 2, (0x80 + 2) / 2, 0x80 + (2 / 2);
 
279
 
 
280
--echo Testing that / has precedence over binary -
 
281
select 0x80 / 4 - 2, (0x80 / 4) - 2, 0x80 / (4 - 2);
 
282
select 0x80 - 4 / 2, (0x80 - 4) / 2, 0x80 - (4 / 2);
 
283
 
 
284
# TODO: %, DIV, MOD
 
285
 
 
286
--echo Testing that ^ is associative
 
287
select 0xFF ^ 0xF0 ^ 0x0F, (0xFF ^ 0xF0) ^ 0x0F, 0xFF ^ (0xF0 ^ 0x0F);
 
288
select 0xFF ^ 0xF0 ^ 0x55, (0xFF ^ 0xF0) ^ 0x55, 0xFF ^ (0xF0 ^ 0x55);
 
289
 
 
290
--echo Testing that ^ has precedence over |
 
291
select 0xFF ^ 0xF0 | 0x0F, (0xFF ^ 0xF0) | 0x0F, 0xFF ^ (0xF0 | 0x0F);
 
292
select 0xF0 | 0xFF ^ 0xF0, (0xF0 | 0xFF) ^ 0xF0, 0xF0 | (0xFF ^ 0xF0);
 
293
 
 
294
--echo Testing that ^ has precedence over &
 
295
select 0xFF ^ 0xF0 & 0x0F, (0xFF ^ 0xF0) & 0x0F, 0xFF ^ (0xF0 & 0x0F);
 
296
select 0x0F & 0xFF ^ 0xF0, (0x0F & 0xFF) ^ 0xF0, 0x0F & (0xFF ^ 0xF0);
 
297
 
 
298
--echo Testing that ^ has precedence over <<
 
299
select 0xFF ^ 0xF0 << 2, (0xFF ^ 0xF0) << 2, 0xFF ^ (0xF0 << 2);
 
300
select 0x0F << 2 ^ 0xFF, (0x0F << 2) ^ 0xFF, 0x0F << (2 ^ 0xFF);
 
301
 
 
302
--echo Testing that ^ has precedence over >>
 
303
select 0xFF ^ 0xF0 >> 2, (0xFF ^ 0xF0) >> 2, 0xFF ^ (0xF0 >> 2);
 
304
select 0xFF >> 2 ^ 0xF0, (0xFF >> 2) ^ 0xF0, 0xFF >> (2 ^ 0xF0);
 
305
 
 
306
--echo Testing that ^ has precedence over binary +
 
307
select 0xFF ^ 0xF0 + 0x0F, (0xFF ^ 0xF0) + 0x0F, 0xFF ^ (0xF0 + 0x0F);
 
308
select 0x0F + 0xFF ^ 0xF0, (0x0F + 0xFF) ^ 0xF0, 0x0F + (0xFF ^ 0xF0);
 
309
 
 
310
--echo Testing that ^ has precedence over binary -
 
311
select 0xFF ^ 0xF0 - 1, (0xFF ^ 0xF0) - 1, 0xFF ^ (0xF0 - 1);
 
312
select 0x55 - 0x0F ^ 0x55, (0x55 - 0x0F) ^ 0x55, 0x55 - (0x0F ^ 0x55);
 
313
 
 
314
--echo Testing that ^ has precedence over *
 
315
select 0xFF ^ 0xF0 * 2, (0xFF ^ 0xF0) * 2, 0xFF ^ (0xF0 * 2);
 
316
select 2 * 0xFF ^ 0xF0, (2 * 0xFF) ^ 0xF0, 2 * (0xFF ^ 0xF0);
 
317
 
 
318
--echo Testing that ^ has precedence over /
 
319
select 0xFF ^ 0xF0 / 2, (0xFF ^ 0xF0) / 2, 0xFF ^ (0xF0 / 2);
 
320
select 0xF2 / 2 ^ 0xF0, (0xF2 / 2) ^ 0xF0, 0xF2 / (2 ^ 0xF0);
 
321
 
 
322
--echo Testing that ^ has precedence over %
 
323
select 0xFF ^ 0xF0 % 0x20, (0xFF ^ 0xF0) % 0x20, 0xFF ^ (0xF0 % 0x20);
 
324
select 0xFF % 0x20 ^ 0xF0, (0xFF % 0x20) ^ 0xF0, 0xFF % (0x20 ^ 0xF0);
 
325
 
 
326
--echo Testing that ^ has precedence over DIV
 
327
select 0xFF ^ 0xF0 DIV 2, (0xFF ^ 0xF0) DIV 2, 0xFF ^ (0xF0 DIV 2);
 
328
select 0xF2 DIV 2 ^ 0xF0, (0xF2 DIV 2) ^ 0xF0, 0xF2 DIV (2 ^ 0xF0);
 
329
 
 
330
--echo Testing that ^ has precedence over MOD
 
331
select 0xFF ^ 0xF0 MOD 0x20, (0xFF ^ 0xF0) MOD 0x20, 0xFF ^ (0xF0 MOD 0x20);
 
332
select 0xFF MOD 0x20 ^ 0xF0, (0xFF MOD 0x20) ^ 0xF0, 0xFF MOD (0x20 ^ 0xF0);
 
333