3
drop table if exists t1_30237_bool;
6
create table t1_30237_bool(A boolean, B boolean, C boolean);
8
insert into t1_30237_bool values
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;
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;
45
select count(*) from t1_30237_bool
46
where ((A OR B) OR C) != (A OR (B OR C));
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;
52
select count(*) from t1_30237_bool
53
where ((A XOR B) XOR C) != (A XOR (B XOR C));
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;
59
select count(*) from t1_30237_bool
60
where ((A AND B) AND C) != (A AND (B AND C));
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);
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);
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);
92
drop table t1_30237_bool;
94
--echo Testing that NOT has precedence over OR
95
select (NOT FALSE) OR TRUE, NOT (FALSE OR TRUE), NOT FALSE OR TRUE;
97
--echo Testing that NOT has precedence over XOR
98
select (NOT FALSE) XOR FALSE, NOT (FALSE XOR FALSE), NOT FALSE XOR FALSE;
100
--echo Testing that NOT has precedence over AND
101
select (NOT FALSE) AND FALSE, NOT (FALSE AND FALSE), NOT FALSE AND FALSE;
103
--echo Testing that NOT is associative
104
select NOT NOT TRUE, NOT NOT NOT FALSE;
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;
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;
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;
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);
146
-- echo Testing that | is associative
147
select 0xF0 | 0x0F | 0x55, (0xF0 | 0x0F) | 0x55, 0xF0 | (0x0F | 0x55);
149
-- echo Testing that & is associative
150
select 0xF5 & 0x5F & 0x55, (0xF5 & 0x5F) & 0x55, 0xF5 & (0x5F & 0x55);
152
-- echo Testing that << is left associative
153
select 4 << 3 << 2, (4 << 3) << 2, 4 << (3 << 2);
155
-- echo Testing that >> is left associative
156
select 256 >> 3 >> 2, (256 >> 3) >> 2, 256 >> (3 >> 2);
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);
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);
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);
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);
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);
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);
182
--echo Testing that binary + is associative
183
select 1 + 2 + 3, (1 + 2) + 3, 1 + (2 + 3);
185
--echo Testing that binary - is left associative
186
select 1 - 2 - 3, (1 - 2) - 3, 1 - (2 - 3);
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);
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);
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);
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);
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);
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);
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);
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);
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);
225
--echo Testing that * is associative
226
select 2 * 3 * 4, (2 * 3) * 4, 2 * (3 * 4);
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);
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);
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);
243
--echo Testing that * has precedence over >>
244
# >> is a multiplication by a (negative) power of 2,
246
select 3 * 4 >> 2, (3 * 4) >> 2, 3 * (4 >> 2);
247
select 4 >> 2 * 3, (4 >> 2) * 3, 4 >> (2 * 3);
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);
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);
257
--echo Testing that / is left associative
258
select 15 / 5 / 3, (15 / 5) / 3, 15 / (5 / 3);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);