1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
#
# testing of the BIT column type
#
select 0 + b'1';
select 0 + b'0';
select 0 + b'000001';
select 0 + b'000011';
select 0 + b'000101';
select 0 + b'000000';
select 0 + b'10000000';
select 0 + b'11111111';
select 0 + b'10000001';
select 0 + b'1000000000000000';
select 0 + b'1111111111111111';
select 0 + b'1000000000000001';
--disable_warnings
drop table if exists t1;
--enable_warnings
--error 1439
create table t1 (a bit(65)) engine=innodb;
--error ER_INVALID_FIELD_SIZE
create table t1 (a bit(0)) engine=innodb;
create table t1 (a bit(64)) engine=innodb;
insert into t1 values
(b'1111111111111111111111111111111111111111111111111111111111111111'),
(b'1000000000000000000000000000000000000000000000000000000000000000'),
(b'0000000000000000000000000000000000000000000000000000000000000001'),
(b'1010101010101010101010101010101010101010101010101010101010101010'),
(b'0101010101010101010101010101010101010101010101010101010101010101');
select hex(a) from t1;
drop table t1;
create table t1 (a bit) engine=innodb;
insert ignore into t1 values (b'0'), (b'1'), (b'000'), (b'100'), (b'001');
select hex(a) from t1;
# It is not deterministic which duplicate will be seen first
--error ER_DUP_ENTRY
alter table t1 add unique (a);
drop table t1;
create table t1 (a bit(2)) engine=innodb;
insert ignore into t1 values (b'00'), (b'01'), (b'10'), (b'100');
--sorted_result
select a+0 from t1;
alter table t1 add key (a);
-- disable_result_log
analyze table t1;
-- enable_result_log
explain select a+0 from t1;
--sorted_result
select a+0 from t1;
drop table t1;
create table t1 (a bit(7), b bit(9), key(a, b)) engine=innodb;
insert into t1 values
(94, 46), (31, 438), (61, 152), (78, 123), (88, 411), (122, 118), (0, 177),
(75, 42), (108, 67), (79, 349), (59, 188), (68, 206), (49, 345), (118, 380),
(111, 368), (94, 468), (56, 379), (77, 133), (29, 399), (9, 363), (23, 36),
(116, 390), (119, 368), (87, 351), (123, 411), (24, 398), (34, 202), (28, 499),
(30, 83), (5, 178), (60, 343), (4, 245), (104, 280), (106, 446), (127, 403),
(44, 307), (68, 454), (57, 135);
-- disable_result_log
analyze table t1;
-- enable_result_log
explain select a+0 from t1;
--sorted_result
select a+0 from t1;
--sorted_result
explain select b+0 from t1;
--sorted_result
select b+0 from t1;
explain select a+0, b+0 from t1;
--sorted_result
select a+0, b+0 from t1;
explain select a+0, b+0 from t1 where a > 40 and b > 200 order by 1;
--partially_sorted_result 1
select a+0, b+0 from t1 where a > 40 and b > 200 order by 1;
explain select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;
select a+0, b+0 from t1 where a > 40 and a < 70 order by 2;
select hex(min(a)) from t1;
select hex(min(b)) from t1;
select hex(min(a)), hex(max(a)), hex(min(b)), hex(max(b)) from t1;
drop table t1;
create table t1 (a int not null, b bit, c bit(9), key(a, b, c)) engine=innodb;
insert into t1 values
(4, NULL, 1), (4, 0, 3), (2, 1, 4), (1, 1, 100), (4, 0, 23), (4, 0, 54),
(56, 0, 22), (4, 1, 100), (23, 0, 1), (4, 0, 34);
--sorted_result
select a+0, b+0, c+0 from t1;
select hex(min(b)) from t1 where a = 4;
select hex(min(c)) from t1 where a = 4 and b = 0;
select hex(max(b)) from t1;
select a+0, b+0, c+0 from t1 where a = 4 and b = 0 limit 2;
select a+0, b+0, c+0 from t1 where a = 4 and b = 1;
select a+0, b+0, c+0 from t1 where a = 4 and b = 1 and c=100;
--partially_sorted_result 1
select b+0, a+0, c+0 from t1 order by b desc;
--partially_sorted_result 1
select c+0, a+0, b+0 from t1 order by c;
drop table t1;
create table t1(a bit(2), b bit(2)) engine=innodb;
insert into t1 (a) values (0x01), (0x03), (0x02);
update t1 set b= concat(a);
select a+0, b+0 from t1;
drop table t1;
# Some magic numbers
create table t1 (a bit(7), key(a)) engine=innodb;
insert into t1 values (44), (57);
select a+0 from t1;
drop table t1;
#
# Test conversion to and from strings
#
create table t1 (a bit(3), b bit(12)) engine=innodb;
insert into t1 values (7,(1<<12)-2), (0x01,0x01ff);
select hex(a),hex(b) from t1;
select hex(concat(a)),hex(concat(b)) from t1;
drop table t1;
#
# Bug #9571: problem with primary key creation
#
create table t1(a int, b bit not null) engine=innodb;
alter table t1 add primary key (a);
drop table t1;
#
# altering tables
#
create table t1 (a bit, b bit(10)) engine=innodb;
show create table t1;
alter table t1 engine=heap;
show create table t1;
alter table t1 engine=innodb;
show create table t1;
drop table t1;
#
# Bug #13601: Wrong field length reported for BIT fields
#
create table t1 (a bit(7)) engine=innodb;
insert into t1 values (0x60);
--enable_metadata
select * from t1;
--disable_metadata
drop table t1;
--echo End of 5.0 tests
--echo #
--echo # Bug #31564742 LOST ULLONG_MAX VALUE IN TABLE WITH TYPE OF BIT(64)
--echo #
CREATE TABLE t1 (a BIT(64));
INSERT INTO t1 VALUES
(b'1111111111111111111111111111111111111111111111111111111111111111');
SELECT HEX(a) FROM t1 WHERE a =
b'1111111111111111111111111111111111111111111111111111111111111111';
DROP TABLE t1;
--echo #
--echo # Bug #31019130 CASTING DOUBLE TO LONGLONG CAUSES UB
--echo # IN FIELD_*::STORE(DOUBLE)
--echo #
CREATE TABLE t_double (a double not null);
INSERT INTO t_double (a) VALUES
(-20000000000000000000000000000.0001), (20000000000000000000000000000.0001);
CREATE TABLE t_bit (
b bit(3)
);
INSERT IGNORE INTO t_bit (b) SELECT a from t_double;
SELECT HEX(b) FROM t_bit;
DROP TABLE t_double, t_bit;
|