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

« back to all changes in this revision

Viewing changes to mysql-test/r/type_bit.result

  • 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
select 0 + b'1';
 
2
0 + b'1'
 
3
1
 
4
select 0 + b'0';
 
5
0 + b'0'
 
6
0
 
7
select 0 + b'000001';
 
8
0 + b'000001'
 
9
1
 
10
select 0 + b'000011';
 
11
0 + b'000011'
 
12
3
 
13
select 0 + b'000101';
 
14
0 + b'000101'
 
15
5
 
16
select 0 + b'000000';
 
17
0 + b'000000'
 
18
0
 
19
select 0 + b'10000000';
 
20
0 + b'10000000'
 
21
128
 
22
select 0 + b'11111111';
 
23
0 + b'11111111'
 
24
255
 
25
select 0 + b'10000001';
 
26
0 + b'10000001'
 
27
129
 
28
select 0 + b'1000000000000000';
 
29
0 + b'1000000000000000'
 
30
32768
 
31
select 0 + b'1111111111111111';
 
32
0 + b'1111111111111111'
 
33
65535
 
34
select 0 + b'1000000000000001';
 
35
0 + b'1000000000000001'
 
36
32769
 
37
drop table if exists t1,t2;
 
38
create table t1 (a bit(65));
 
39
ERROR 42000: Display width out of range for column 'a' (max = 64)
 
40
create table t1 (a bit(0));
 
41
show create table t1;
 
42
Table   Create Table
 
43
t1      CREATE TABLE `t1` (
 
44
  `a` bit(1) DEFAULT NULL
 
45
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
46
drop table t1;
 
47
create table t1 (a bit(64));
 
48
insert into t1 values 
 
49
(b'1111111111111111111111111111111111111111111111111111111111111111'),
 
50
(b'1000000000000000000000000000000000000000000000000000000000000000'),
 
51
(b'0000000000000000000000000000000000000000000000000000000000000001'),
 
52
(b'1010101010101010101010101010101010101010101010101010101010101010'),
 
53
(b'0101010101010101010101010101010101010101010101010101010101010101');
 
54
select hex(a) from t1;
 
55
hex(a)
 
56
FFFFFFFFFFFFFFFF
 
57
8000000000000000
 
58
1
 
59
AAAAAAAAAAAAAAAA
 
60
5555555555555555
 
61
drop table t1;
 
62
create table t1 (a bit);
 
63
insert into t1 values (b'0'), (b'1'), (b'000'), (b'100'), (b'001');
 
64
Warnings:
 
65
Warning 1264    Out of range value for column 'a' at row 4
 
66
select hex(a) from t1;
 
67
hex(a)
 
68
0
 
69
1
 
70
0
 
71
1
 
72
1
 
73
alter table t1 add unique (a);
 
74
ERROR 23000: Duplicate entry '' for key 'a'
 
75
drop table t1;
 
76
create table t1 (a bit(2));
 
77
insert into t1 values (b'00'), (b'01'), (b'10'), (b'100');
 
78
Warnings:
 
79
Warning 1264    Out of range value for column 'a' at row 4
 
80
select a+0 from t1;
 
81
a+0
 
82
0
 
83
1
 
84
2
 
85
3
 
86
alter table t1 add key (a);
 
87
explain select a+0 from t1;
 
88
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
89
1       SIMPLE  t1      index   NULL    a       2       NULL    4       Using index
 
90
select a+0 from t1;
 
91
a+0
 
92
0
 
93
1
 
94
2
 
95
3
 
96
drop table t1;
 
97
create table t1 (a bit(7), b bit(9), key(a, b));
 
98
insert into t1 values 
 
99
(94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),    
 
100
(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),   
 
101
(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),    
 
102
(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),
 
103
(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),   
 
104
(44, 307), (68, 454), (57, 135);
 
105
explain select a+0 from t1;
 
106
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
107
1       SIMPLE  t1      index   NULL    a       5       NULL    38      Using index
 
108
select a+0 from t1;
 
109
a+0
 
110
0
 
111
4
 
112
5
 
113
9
 
114
23
 
115
24
 
116
28
 
117
29
 
118
30
 
119
31
 
120
34
 
121
44
 
122
49
 
123
56
 
124
57
 
125
59
 
126
60
 
127
61
 
128
68
 
129
68
 
130
75
 
131
77
 
132
78
 
133
79
 
134
87
 
135
88
 
136
94
 
137
94
 
138
104
 
139
106
 
140
108
 
141
111
 
142
116
 
143
118
 
144
119
 
145
122
 
146
123
 
147
127
 
148
explain select b+0 from t1;
 
149
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
150
1       SIMPLE  t1      index   NULL    a       5       NULL    38      Using index
 
151
select b+0 from t1;
 
152
b+0
 
153
177
 
154
245
 
155
178
 
156
363
 
157
36
 
158
398
 
159
499
 
160
399
 
161
83
 
162
438
 
163
202
 
164
307
 
165
345
 
166
379
 
167
135
 
168
188
 
169
343
 
170
152
 
171
206
 
172
454
 
173
42
 
174
133
 
175
123
 
176
349
 
177
351
 
178
411
 
179
46
 
180
468
 
181
280
 
182
446
 
183
67
 
184
368
 
185
390
 
186
380
 
187
368
 
188
118
 
189
411
 
190
403
 
191
explain select a+0, b+0 from t1;
 
192
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
193
1       SIMPLE  t1      index   NULL    a       5       NULL    38      Using index
 
194
select a+0, b+0 from t1;
 
195
a+0     b+0
 
196
0       177
 
197
4       245
 
198
5       178
 
199
9       363
 
200
23      36
 
201
24      398
 
202
28      499
 
203
29      399
 
204
30      83
 
205
31      438
 
206
34      202
 
207
44      307
 
208
49      345
 
209
56      379
 
210
57      135
 
211
59      188
 
212
60      343
 
213
61      152
 
214
68      206
 
215
68      454
 
216
75      42
 
217
77      133
 
218
78      123
 
219
79      349
 
220
87      351
 
221
88      411
 
222
94      46
 
223
94      468
 
224
104     280
 
225
106     446
 
226
108     67
 
227
111     368
 
228
116     390
 
229
118     380
 
230
119     368
 
231
122     118
 
232
123     411
 
233
127     403
 
234
explain select a+0, b+0 from t1 where a > 40 and b > 200 order by 1;
 
235
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
236
1       SIMPLE  t1      range   a       a       2       NULL    27      Using where; Using index; Using filesort
 
237
select a+0, b+0 from t1 where a > 40 and b > 200 order by 1;
 
238
a+0     b+0
 
239
44      307
 
240
49      345
 
241
56      379
 
242
60      343
 
243
68      206
 
244
68      454
 
245
79      349
 
246
87      351
 
247
88      411
 
248
94      468
 
249
104     280
 
250
106     446
 
251
111     368
 
252
116     390
 
253
118     380
 
254
119     368
 
255
123     411
 
256
127     403
 
257
explain select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;
 
258
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
259
1       SIMPLE  t1      range   a       a       2       NULL    8       Using where; Using index; Using filesort
 
260
select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;
 
261
a+0     b+0
 
262
57      135
 
263
61      152
 
264
59      188
 
265
68      206
 
266
44      307
 
267
60      343
 
268
49      345
 
269
56      379
 
270
68      454
 
271
set @@max_length_for_sort_data=0;
 
272
Warnings:
 
273
Warning 1292    Truncated incorrect max_length_for_sort_data value: '0'
 
274
select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;
 
275
a+0     b+0
 
276
57      135
 
277
61      152
 
278
59      188
 
279
68      206
 
280
44      307
 
281
60      343
 
282
49      345
 
283
56      379
 
284
68      454
 
285
select hex(min(a)) from t1;
 
286
hex(min(a))
 
287
0
 
288
select hex(min(b)) from t1;
 
289
hex(min(b))
 
290
24
 
291
select hex(min(a)), hex(max(a)), hex(min(b)), hex(max(b)) from t1;
 
292
hex(min(a))     hex(max(a))     hex(min(b))     hex(max(b))
 
293
0       7F      24      1F3
 
294
drop table t1;
 
295
create table t1 (a int not null, b bit, c bit(9), key(a, b, c));
 
296
insert into t1 values
 
297
(4, NULL, 1), (4, 0, 3), (2, 1, 4), (1, 1, 100), (4, 0, 23), (4, 0, 54),
 
298
(56, 0, 22), (4, 1, 100), (23, 0, 1), (4, 0, 34);
 
299
select a+0, b+0, c+0 from t1;
 
300
a+0     b+0     c+0
 
301
1       1       100
 
302
2       1       4
 
303
4       NULL    1
 
304
4       0       3
 
305
4       0       23
 
306
4       0       34
 
307
4       0       54
 
308
4       1       100
 
309
23      0       1
 
310
56      0       22
 
311
select hex(min(b)) from t1 where a = 4;
 
312
hex(min(b))
 
313
0
 
314
select hex(min(c)) from t1 where a = 4 and b = 0;
 
315
hex(min(c))
 
316
3
 
317
select hex(max(b)) from t1;
 
318
hex(max(b))
 
319
1
 
320
select a+0, b+0, c+0 from t1 where a = 4 and b = 0 limit 2;
 
321
a+0     b+0     c+0
 
322
4       0       3
 
323
4       0       23
 
324
select a+0, b+0, c+0 from t1 where a = 4 and b = 1;
 
325
a+0     b+0     c+0
 
326
4       1       100
 
327
select a+0, b+0, c+0 from t1 where a = 4 and b = 1 and c=100;
 
328
a+0     b+0     c+0
 
329
4       1       100
 
330
select a+0, b+0, c+0 from t1 order by b desc;
 
331
a+0     b+0     c+0
 
332
2       1       4
 
333
1       1       100
 
334
4       1       100
 
335
4       0       3
 
336
4       0       23
 
337
4       0       54
 
338
56      0       22
 
339
23      0       1
 
340
4       0       34
 
341
4       NULL    1
 
342
select a+0, b+0, c+0 from t1 order by c;
 
343
a+0     b+0     c+0
 
344
4       NULL    1
 
345
23      0       1
 
346
4       0       3
 
347
2       1       4
 
348
56      0       22
 
349
4       0       23
 
350
4       0       34
 
351
4       0       54
 
352
1       1       100
 
353
4       1       100
 
354
drop table t1;
 
355
create table t1(a bit(2), b bit(2));
 
356
insert into t1 (a) values (0x01), (0x03), (0x02);
 
357
update t1 set b= concat(a);
 
358
select a+0, b+0 from t1;
 
359
a+0     b+0
 
360
1       1
 
361
3       3
 
362
2       2
 
363
drop table t1;
 
364
create table t1 (a bit(7), key(a));
 
365
insert into t1 values (44), (57);
 
366
select a+0 from t1;
 
367
a+0
 
368
44
 
369
57
 
370
drop table t1;
 
371
create table t1 (a bit(3), b bit(12));
 
372
insert into t1 values (7,(1<<12)-2), (0x01,0x01ff);
 
373
select hex(a),hex(b) from t1;
 
374
hex(a)  hex(b)
 
375
7       FFE
 
376
1       1FF
 
377
select hex(concat(a)),hex(concat(b)) from t1;
 
378
hex(concat(a))  hex(concat(b))
 
379
07      0FFE
 
380
01      01FF
 
381
drop table t1;
 
382
create table t1(a int, b bit not null);
 
383
alter table t1 add primary key (a);
 
384
drop table t1;
 
385
create table t1 (a bit(19), b bit(5));
 
386
insert into t1 values (1000, 10), (3, 8), (200, 6), (2303, 2), (12345, 4), (1, 0);
 
387
select a+0, b+0 from t1;
 
388
a+0     b+0
 
389
1000    10
 
390
3       8
 
391
200     6
 
392
2303    2
 
393
12345   4
 
394
1       0
 
395
alter table t1 engine=heap;
 
396
select a+0, b+0 from t1;
 
397
a+0     b+0
 
398
1000    10
 
399
3       8
 
400
200     6
 
401
2303    2
 
402
12345   4
 
403
1       0
 
404
alter table t1 add key(a, b);
 
405
select a+0, b+0 from t1;
 
406
a+0     b+0
 
407
1000    10
 
408
3       8
 
409
200     6
 
410
2303    2
 
411
12345   4
 
412
1       0
 
413
alter table t1 engine=myisam;
 
414
select a+0, b+0 from t1;
 
415
a+0     b+0
 
416
1       0
 
417
3       8
 
418
200     6
 
419
1000    10
 
420
2303    2
 
421
12345   4
 
422
create table t2 engine=heap select * from t1;
 
423
select a+0, b+0 from t2;
 
424
a+0     b+0
 
425
1       0
 
426
3       8
 
427
200     6
 
428
1000    10
 
429
2303    2
 
430
12345   4
 
431
drop table t1;
 
432
create table t1 select * from t2;
 
433
select a+0, b+0 from t1;
 
434
a+0     b+0
 
435
1       0
 
436
3       8
 
437
200     6
 
438
1000    10
 
439
2303    2
 
440
12345   4
 
441
drop table t1, t2;
 
442
create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), 
 
443
g bit(1) NOT NULL default 1, h char(1) default 'a');
 
444
insert into t1 set a=1;
 
445
select hex(g), h from t1;
 
446
hex(g)  h
 
447
1       a
 
448
drop table t1;
 
449
create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1),
 
450
g bit(1) NOT NULL default 1);
 
451
insert into t1 set a=1;
 
452
select hex(g) from t1;
 
453
hex(g)
 
454
1
 
455
drop table t1;
 
456
create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), 
 
457
h char(1) default 'a') engine=myisam;
 
458
insert into t1 set a=1;
 
459
select h from t1;
 
460
h
 
461
a
 
462
drop table t1;
 
463
create table t1 (a bit(8)) engine=heap;
 
464
insert into t1 values ('1111100000');
 
465
Warnings:
 
466
Warning 1264    Out of range value for column 'a' at row 1
 
467
select a+0 from t1;
 
468
a+0
 
469
255
 
470
drop table t1;
 
471
create table t1 (a bit(7));
 
472
insert into t1 values (120), (0), (111);
 
473
select a+0 from t1 union select a+0 from t1;
 
474
a+0
 
475
120
 
476
0
 
477
111
 
478
select a+0 from t1 union select NULL;
 
479
a+0
 
480
120
 
481
0
 
482
111
 
483
NULL
 
484
select NULL union select a+0 from t1;
 
485
NULL
 
486
NULL
 
487
120
 
488
0
 
489
111
 
490
create table t2 select a from t1 union select a from t1;
 
491
select a+0 from t2;
 
492
a+0
 
493
120
 
494
0
 
495
111
 
496
show create table t2;
 
497
Table   Create Table
 
498
t2      CREATE TABLE `t2` (
 
499
  `a` bit(7) DEFAULT NULL
 
500
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
501
drop table t1, t2;
 
502
create table t1 (id1 int(11), b1 bit(1));
 
503
create table t2 (id2 int(11), b2 bit(1));
 
504
insert into t1 values (1, 1), (2, 0), (3, 1);
 
505
insert into t2 values (2, 1), (3, 0), (4, 0);
 
506
create algorithm=undefined view v1 as 
 
507
select b1+0, b2+0 from t1, t2 where id1 = id2 and b1 = 0
 
508
union
 
509
select b1+0, b2+0 from t1, t2 where id1 = id2 and b2 = 1;
 
510
select * from v1;
 
511
b1+0    b2+0
 
512
0       1
 
513
drop table t1, t2;
 
514
drop view v1;
 
515
create table t1(a bit(4));
 
516
insert into t1(a) values (1), (2), (5), (4), (3);
 
517
insert into t1 select * from t1;
 
518
select a+0 from t1;
 
519
a+0
 
520
1
 
521
2
 
522
5
 
523
4
 
524
3
 
525
1
 
526
2
 
527
5
 
528
4
 
529
3
 
530
drop table t1;
 
531
create table t1 (a1 int(11), b1 bit(2));
 
532
create table t2 (a2 int(11), b2 bit(2));
 
533
insert into t1 values (1, 1), (2, 0), (3, 1), (4, 2);
 
534
insert into t2 values (2, 1), (3, 0), (4, 1), (5, 2);
 
535
select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2;
 
536
a1      a2      b1+0    b2+0
 
537
2       2       0       1
 
538
3       3       1       0
 
539
4       4       2       1
 
540
select a1, a2, b1+0, b2+0 from t1 join t2 on a1 = a2 order by a1;
 
541
a1      a2      b1+0    b2+0
 
542
2       2       0       1
 
543
3       3       1       0
 
544
4       4       2       1
 
545
select a1, a2, b1+0, b2+0 from t1 join t2 on b1 = b2;
 
546
a1      a2      b1+0    b2+0
 
547
1       2       1       1
 
548
3       2       1       1
 
549
2       3       0       0
 
550
1       4       1       1
 
551
3       4       1       1
 
552
4       5       2       2
 
553
select sum(a1), b1+0, b2+0 from t1 join t2 on b1 = b2 group by b1 order by 1;
 
554
sum(a1) b1+0    b2+0
 
555
2       0       0
 
556
4       2       2
 
557
8       1       1
 
558
select 1 from t1 join t2 on b1 = b2 group by b1 order by 1;
 
559
1
 
560
1
 
561
1
 
562
1
 
563
select b1+0,sum(b1), sum(b2) from t1 join t2 on b1 = b2 group by b1 order by 1;
 
564
b1+0    sum(b1) sum(b2)
 
565
0       0       0
 
566
1       4       4
 
567
2       2       2
 
568
drop table t1, t2;
 
569
create table t1 (a bit(7));
 
570
insert into t1 values (0x60);
 
571
select * from t1;
 
572
Catalog Database        Table   Table_alias     Column  Column_alias    Type    Length  Max length      Is_null Flags   Decimals        Charsetnr
 
573
def     test    t1      t1      a       a       16      7       1       Y       32      0       63
 
574
a
 
575
`
 
576
drop table t1;
 
577
create table bug15583(b BIT(8), n INT);
 
578
insert into bug15583 values(128, 128);
 
579
insert into bug15583 values(null, null);
 
580
insert into bug15583 values(0, 0);
 
581
insert into bug15583 values(255, 255);
 
582
select hex(b), bin(b), oct(b), hex(n), bin(n), oct(n) from bug15583;
 
583
hex(b)  bin(b)  oct(b)  hex(n)  bin(n)  oct(n)
 
584
80      10000000        200     80      10000000        200
 
585
NULL    NULL    NULL    NULL    NULL    NULL
 
586
0       0       0       0       0       0
 
587
FF      11111111        377     FF      11111111        377
 
588
select hex(b)=hex(n) as should_be_onetrue, bin(b)=bin(n) as should_be_onetrue, oct(b)=oct(n) as should_be_onetrue from bug15583;
 
589
should_be_onetrue       should_be_onetrue       should_be_onetrue
 
590
1       1       1
 
591
NULL    NULL    NULL
 
592
1       1       1
 
593
1       1       1
 
594
select hex(b + 0), bin(b + 0), oct(b + 0), hex(n), bin(n), oct(n) from bug15583;
 
595
hex(b + 0)      bin(b + 0)      oct(b + 0)      hex(n)  bin(n)  oct(n)
 
596
80      10000000        200     80      10000000        200
 
597
NULL    NULL    NULL    NULL    NULL    NULL
 
598
0       0       0       0       0       0
 
599
FF      11111111        377     FF      11111111        377
 
600
select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583;
 
601
conv(b, 10, 2)  conv(b + 0, 10, 2)
 
602
10000000        10000000
 
603
NULL    NULL
 
604
0       0
 
605
11111111        11111111
 
606
drop table bug15583;
 
607
create table t1(a bit(1), b smallint unsigned);
 
608
insert into t1 (b, a) values ('2', '1');
 
609
Warnings:
 
610
Warning 1264    Out of range value for column 'a' at row 1
 
611
select hex(a), b from t1;
 
612
hex(a)  b
 
613
1       2
 
614
drop table t1;
 
615
create table t1(bit_field bit(2), int_field int, key a(bit_field));
 
616
insert into t1 values (1,2);
 
617
handler t1 open as t1;
 
618
handler t1 read a=(1);
 
619
bit_field       int_field
 
620
       2
 
621
handler t1 close;
 
622
drop table t1;
 
623
CREATE TABLE t1 (b BIT(2), a VARCHAR(5));
 
624
INSERT INTO t1 (b, a) VALUES (1, "x"), (3, "zz"), (0, "y"), (3, "z");
 
625
SELECT b+0, COUNT(DISTINCT a) FROM t1 GROUP BY b;
 
626
b+0     COUNT(DISTINCT a)
 
627
0       1
 
628
1       1
 
629
3       2
 
630
DROP TABLE t1;
 
631
CREATE TABLE t1 (a CHAR(5), b BIT(2));
 
632
INSERT INTO t1 (b, a) VALUES (1, "x"), (3, "zz"), (0, "y"), (3, "z");
 
633
SELECT b+0, COUNT(DISTINCT a) FROM t1 GROUP BY b;
 
634
b+0     COUNT(DISTINCT a)
 
635
0       1
 
636
1       1
 
637
3       2
 
638
DROP TABLE t1;
 
639
CREATE TABLE t1 (a INT, b BIT(2));
 
640
INSERT INTO t1 (b, a) VALUES (1, 1), (3, 2), (0, 3), (3, 4);
 
641
SELECT b+0, COUNT(DISTINCT a) FROM t1 GROUP BY b;
 
642
b+0     COUNT(DISTINCT a)
 
643
0       1
 
644
1       1
 
645
3       2
 
646
DROP TABLE t1;
 
647
CREATE TABLE t1 (b BIT);
 
648
INSERT INTO t1 (b) VALUES (1), (0);
 
649
SELECT DISTINCT b FROM t1;
 
650
Catalog Database        Table   Table_alias     Column  Column_alias    Type    Length  Max length      Is_null Flags   Decimals        Charsetnr
 
651
def     test    t1      t1      b       b       16      1       1       Y       32      0       63
 
652
b
 
653
#
 
654
#
 
655
SELECT b FROM t1 GROUP BY b;
 
656
Catalog Database        Table   Table_alias     Column  Column_alias    Type    Length  Max length      Is_null Flags   Decimals        Charsetnr
 
657
def     test    t1      t1      b       b       16      1       1       Y       32      0       63
 
658
b
 
659
#
 
660
#
 
661
DROP TABLE t1;
 
662
CREATE TABLE t1 (a int, b bit(2));
 
663
INSERT INTO t1 VALUES (3, 2), (2, 3), (2, 0), (3, 2), (3, 1);
 
664
SELECT COUNT(DISTINCT b) FROM t1 GROUP BY a;
 
665
COUNT(DISTINCT b)
 
666
2
 
667
2
 
668
DROP TABLE t1;
 
669
create table t2 (a int, b bit(2), c char(10));
 
670
INSERT INTO t2 VALUES (3, 2, 'two'), (2, 3, 'three'), (2, 0, 'zero'), 
 
671
(3, 2, 'two'), (3, 1, 'one');
 
672
SELECT COUNT(DISTINCT b,c) FROM t2 GROUP BY a;
 
673
COUNT(DISTINCT b,c)
 
674
2
 
675
2
 
676
DROP TABLE t2;
 
677
CREATE TABLE t1(a BIT(13), KEY(a));
 
678
INSERT INTO t1(a) VALUES
 
679
(65535),(65525),(65535),(65535),(65535),(65535),(65535),(65535),(65535),(65535);
 
680
EXPLAIN SELECT 1 FROM t1 GROUP BY a;
 
681
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
682
1       SIMPLE  t1      range   NULL    a       3       NULL    6       Using index for group-by
 
683
SELECT 1 FROM t1 GROUP BY a;
 
684
1
 
685
1
 
686
DROP TABLE t1;
 
687
CREATE TABLE t1 (b BIT NOT NULL, i2 INTEGER NOT NULL, s VARCHAR(255) NOT NULL);
 
688
INSERT INTO t1 VALUES(0x01,100,''), (0x00,300,''), (0x01,200,''), (0x00,100,'');
 
689
SELECT HEX(b), i2 FROM t1 WHERE (i2>=100 AND i2<201) AND b=TRUE;
 
690
HEX(b)  i2
 
691
1       100
 
692
1       200
 
693
CREATE TABLE t2 (b1 BIT NOT NULL, b2 BIT NOT NULL, i2 INTEGER NOT NULL,
 
694
s VARCHAR(255) NOT NULL);
 
695
INSERT INTO t2 VALUES (0x01,0x00,100,''), (0x00,0x01,300,''),
 
696
(0x01,0x00,200,''), (0x00,0x01,100,'');
 
697
SELECT HEX(b1), i2 FROM t2 WHERE (i2>=100 AND i2<201) AND b1=TRUE;
 
698
HEX(b1) i2
 
699
1       100
 
700
1       200
 
701
SELECT HEX(b2), i2 FROM t2 WHERE (i2>=100 AND i2<201) AND b2=FALSE;
 
702
HEX(b2) i2
 
703
0       100
 
704
0       200
 
705
SELECT HEX(b1), HEX(b2), i2 FROM t2
 
706
WHERE (i2>=100 AND i2<201) AND b1=TRUE AND b2=FALSE;
 
707
HEX(b1) HEX(b2) i2
 
708
1       0       100
 
709
1       0       200
 
710
DROP TABLE t1, t2;
 
711
CREATE TABLE IF NOT EXISTS t1 (
 
712
f1 bit(2) NOT NULL default b'10',
 
713
f2 bit(14) NOT NULL default b'11110000111100'
 
714
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
715
SHOW CREATE TABLE t1;
 
716
Table   Create Table
 
717
t1      CREATE TABLE `t1` (
 
718
  `f1` bit(2) NOT NULL DEFAULT b'10',
 
719
  `f2` bit(14) NOT NULL DEFAULT b'11110000111100'
 
720
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
 
721
DROP TABLE t1;
 
722
CREATE TABLE IF NOT EXISTS t1 (
 
723
f1 bit(2) NOT NULL default b''
 
724
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
725
ERROR 42000: Invalid default value for 'f1'
 
726
create table t1bit7 (a1 bit(7) not null) engine=MyISAM;
 
727
create table t2bit7 (b1 bit(7)) engine=MyISAM;
 
728
insert into t1bit7 values (b'1100000');
 
729
insert into t1bit7 values (b'1100001');
 
730
insert into t1bit7 values (b'1100010');
 
731
insert into t2bit7 values (b'1100001');
 
732
insert into t2bit7 values (b'1100010');
 
733
insert into t2bit7 values (b'1100110');
 
734
select bin(a1) from t1bit7, t2bit7 where t1bit7.a1=t2bit7.b1;
 
735
bin(a1)
 
736
1100001
 
737
1100010
 
738
drop table t1bit7, t2bit7;
 
739
create table t1bit7 (a1 bit(15) not null) engine=MyISAM;
 
740
create table t2bit7 (b1 bit(15)) engine=MyISAM;
 
741
insert into t1bit7 values (b'110000011111111');
 
742
insert into t1bit7 values (b'110000111111111');
 
743
insert into t1bit7 values (b'110001011111111');
 
744
insert into t2bit7 values (b'110000111111111');
 
745
insert into t2bit7 values (b'110001011111111');
 
746
insert into t2bit7 values (b'110011011111111');
 
747
select bin(a1) from t1bit7, t2bit7 where t1bit7.a1=t2bit7.b1;
 
748
bin(a1)
 
749
110000111111111
 
750
110001011111111
 
751
drop table t1bit7, t2bit7;
 
752
#
 
753
# Bug42803: Field_bit does not have unsigned_flag field, 
 
754
# can lead to bad memory access
 
755
#
 
756
CREATE TABLE t1 (a BIT(7), b BIT(9), KEY(a, b));
 
757
INSERT INTO t1 VALUES(0, 0), (5, 3), (5, 6), (6, 4), (7, 0);
 
758
EXPLAIN SELECT a+0, b+0 FROM t1 WHERE a > 4 and b < 7 ORDER BY 2;
 
759
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
760
1       SIMPLE  t1      range   a       a       2       NULL    4       Using where; Using index; Using filesort
 
761
DROP TABLE t1;
 
762
End of 5.0 tests
 
763
create table t1(a bit(7));
 
764
insert into t1 values(0x40);
 
765
alter table t1 modify column a bit(8);
 
766
select hex(a) from t1;
 
767
hex(a)
 
768
40
 
769
insert into t1 values(0x80);
 
770
select hex(a) from t1;
 
771
hex(a)
 
772
40
 
773
80
 
774
create index a on t1(a);
 
775
insert into t1 values(0x81);
 
776
select hex(a) from t1;
 
777
hex(a)
 
778
40
 
779
80
 
780
81
 
781
show create table t1;
 
782
Table   Create Table
 
783
t1      CREATE TABLE `t1` (
 
784
  `a` bit(8) DEFAULT NULL,
 
785
  KEY `a` (`a`)
 
786
) ENGINE=MyISAM DEFAULT CHARSET=latin1
 
787
drop table t1;
 
788
#
 
789
# Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'
 
790
#
 
791
CREATE TABLE t1(a INT, b BIT(7) NOT NULL);
 
792
INSERT INTO t1 VALUES (NULL, 0),(NULL, 0);
 
793
SELECT SUM(a) FROM t1 GROUP BY b, a;
 
794
SUM(a)
 
795
NULL
 
796
DROP TABLE t1;
 
797
CREATE TABLE t1(a INT, b BIT(7) NOT NULL, c BIT(8) NOT NULL);
 
798
INSERT INTO t1 VALUES (NULL, 0, 0),(NULL, 0, 0);
 
799
SELECT SUM(a) FROM t1 GROUP BY c, b, a;
 
800
SUM(a)
 
801
NULL
 
802
DROP TABLE t1;
 
803
End of 5.1 tests