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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
|
create table t1 (a int, b int, v int as (a+1), index idx(b));
insert into t1(a, b) values
(4, 40), (3, 30), (5, 50), (7, 70), (8, 80), (2, 20), (1, 10);
select * from t1 order by b;
a b v
1 10 2
2 20 3
3 30 4
4 40 5
5 50 6
7 70 8
8 80 9
delete from t1 where v > 6 order by b limit 1;
select * from t1 order by b;
a b v
1 10 2
2 20 3
3 30 4
4 40 5
5 50 6
8 80 9
update t1 set a=v order by b limit 1;
select * from t1 order by b;
a b v
2 10 3
2 20 3
3 30 4
4 40 5
5 50 6
8 80 9
drop table t1;
CREATE TABLE t1 (
a int NOT NULL DEFAULT '0',
v double AS ((1, a)) VIRTUAL
);
ERROR 21000: Operand should contain 1 column(s)
CREATE TABLE t1 (
a CHAR(255) BINARY NOT NULL DEFAULT 0,
b CHAR(255) BINARY NOT NULL DEFAULT 0,
v CHAR(255) BINARY AS (CONCAT(a,b)) VIRTUAL );
INSERT INTO t1(a,b) VALUES ('4','7'), ('4','6');
SELECT 1 AS C FROM t1 ORDER BY v;
C
1
1
DROP TABLE t1;
CREATE TABLE t1(a int, b int DEFAULT 0, v INT AS (b+10) PERSISTENT);
INSERT INTO t1(a) VALUES (1);
SELECT b, v FROM t1;
b v
0 10
DROP TABLE t1;
CREATE TABLE t1(a int DEFAULT 100, v int AS (a+1) PERSISTENT);
INSERT INTO t1 () VALUES ();
CREATE TABLE t2(a int DEFAULT 100 , v int AS (a+1));
INSERT INTO t2 () VALUES ();
SELECT a, v FROM t1;
a v
100 101
SELECT a, v FROM t2;
a v
100 101
DROP TABLE t1,t2;
CREATE TABLE t1 (
a datetime NOT NULL DEFAULT '2000-01-01',
v boolean AS (a < '2001-01-01')
);
INSERT INTO t1(a) VALUES ('2002-02-15');
INSERT INTO t1(a) VALUES ('2000-10-15');
SELECT a, v FROM t1;
a v
2002-02-15 00:00:00 0
2000-10-15 00:00:00 1
SELECT a, v FROM t1;
a v
2002-02-15 00:00:00 0
2000-10-15 00:00:00 1
CREATE TABLE t2 (
a datetime NOT NULL DEFAULT '2000-01-01',
v boolean AS (a < '2001-01-01') PERSISTENT
);
INSERT INTO t2(a) VALUES ('2002-02-15');
INSERT INTO t2(a) VALUES ('2000-10-15');
SELECT * FROM t2;
a v
2002-02-15 00:00:00 0
2000-10-15 00:00:00 1
DROP TABLE t1, t2;
CREATE TABLE t1 (
a char(255), b char(255), c char(255), d char(255),
v char(255) AS (CONCAT(c,d) ) VIRTUAL
);
INSERT INTO t1(a,b,c,d) VALUES ('w','x','y','z'), ('W','X','Y','Z');
SELECT v FROM t1 ORDER BY CONCAT(a,b);
v
yz
YZ
DROP TABLE t1;
CREATE TABLE t1 (f1 INTEGER, v1 INTEGER AS (f1) VIRTUAL);
CREATE TABLE t2 AS SELECT v1 FROM t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`v1` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
DROP TABLE t1,t2;
CREATE TABLE t1 (p int, a double NOT NULL, v double AS (ROUND(a,p)) VIRTUAL);
INSERT IGNORE INTO t1 VALUES (0,1,0);
Warnings:
Warning 1906 The value specified for generated column 'v' in table 't1' has been ignored
INSERT IGNORE INTO t1 VALUES (NULL,0,0);
Warnings:
Warning 1906 The value specified for generated column 'v' in table 't1' has been ignored
SELECT a, p, v, ROUND(a,p), ROUND(a,p+NULL) FROM t1;
a p v ROUND(a,p) ROUND(a,p+NULL)
1 0 1 1 NULL
0 NULL NULL NULL NULL
DROP TABLE t1;
CREATE TABLE t1 (p int, a double NOT NULL);
INSERT INTO t1(p,a) VALUES (0,1);
INSERT INTO t1(p,a) VALUES (NULL,0);
SELECT a, p, ROUND(a,p), ROUND(a,p+NULL) FROM t1;
a p ROUND(a,p) ROUND(a,p+NULL)
1 0 1 NULL
0 NULL NULL NULL
DROP TABLE t1;
CREATE TABLE t1 (a char(32), v char(32) CHARACTER SET ucs2 AS (a) VIRTUAL);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(32) DEFAULT NULL,
`v` char(32) CHARACTER SET ucs2 COLLATE ucs2_uca1400_ai_ci GENERATED ALWAYS AS (`a`) VIRTUAL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
DROP TABLE t1;
CREATE TABLE t1 (a int, b int);
CREATE TABLE t2 (a int, b int as (a+1) VIRTUAL);
SELECT table_schema, table_name, column_name, column_type, extra
FROM information_schema.columns WHERE table_name = 't1';
table_schema table_name column_name column_type extra
test t1 a int(11)
test t1 b int(11)
SELECT table_schema, table_name, column_name, column_type, extra
FROM information_schema.columns WHERE table_name = 't2';
table_schema table_name column_name column_type extra
test t2 a int(11)
test t2 b int(11) VIRTUAL GENERATED
DROP TABLE t1,t2;
create table t1 (
a int not null, b char(2) not null,
c enum('Y','N') as (case when b = 'aa' then 'Y' else 'N' end) persistent
);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` char(2) NOT NULL,
`c` enum('Y','N') GENERATED ALWAYS AS (case when `b` = 'aa' then 'Y' else 'N' end) STORED
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert into t1(a,b) values (1,'bb'), (2,'aa'), (3,'cc');
select * from t1;
a b c
1 bb N
2 aa Y
3 cc N
create table t2 (
a int, b int,
c set("y","n")
as (if(a=0,if(b=0,('n,n'),('n,y')),if(b=0,('y,n'),('y,y')))) persistent
);
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
`c` set('y','n') GENERATED ALWAYS AS (if(`a` = 0,if(`b` = 0,'n,n','n,y'),if(`b` = 0,'y,n','y,y'))) STORED
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert into t2(a,b) values (7,0), (2,3), (0,1);
select * from t2;
a b c
7 0 y,n
2 3 y
0 1 y,n
drop table t1,t2;
SET @old_debug= @@global.debug_dbug;
SET @old_debug= @@global.debug_dbug;
SET GLOBAL debug_dbug= "+d,write_delay_wakeup";
CREATE TABLE t1 (a int,
ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
tsv TIMESTAMP AS (ADDDATE(ts, INTERVAL 1 DAY)) VIRTUAL
) ENGINE=MyISAM;
# First test FLUSH TABLES
INSERT INTO t1 (a,tsv) VALUES (1,DEFAULT);
INSERT DELAYED INTO t1 (a,tsv) VALUES (2,DEFAULT);
FLUSH TABLES;
SELECT COUNT(*) > 0 FROM t1;
COUNT(*) > 0
1
# Then test FLUSH TABLES t1;
INSERT INTO t1 (a,tsv) VALUES (3,DEFAULT);
INSERT DELAYED INTO t1 (a,tsv) VALUES (4,DEFAULT);
FLUSH TABLES t1;
SELECT COUNT(*) FROM t1;
COUNT(*)
4
# Then test FLUSH TABLES WITH READ LOCK;
INSERT INTO t1 (a,tsv) VALUES (5,DEFAULT);
INSERT DELAYED INTO t1 (a,tsv) VALUES (6,DEFAULT);
FLUSH TABLES WITH READ LOCK;
SELECT COUNT(*) FROM t1;
COUNT(*)
6
set GLOBAL debug_dbug= @old_debug;
unlock tables;
DROP TABLE t1;
#
# MDEV-4823 Server crashes in Item_func_not::fix_fields on
# creating a table with a virtual column using NOT
#
CREATE TABLE t1 ( f1 INT, v4 INT AS ( NOT f1 ) VIRTUAL );
drop table t1;
# end of 5.2 tests
create table t1 (a int, b int);
insert into t1 values (3, 30), (4, 20), (1, 20);
create table t2 (c int, d int, v int as (d+1), index idx(c));
insert into t2(c,d) values
(20, 100), (20, 300), (30, 100), (30, 200), (40, 500),
(70, 100), (40, 300), (60, 100), (40, 100), (70, 100);
insert into t2(c,d) values
(120, 100), (150, 300), (130, 100), (130, 200), (140, 500),
(170, 100), (180, 300), (160, 100), (40, 100), (170, 100);
set join_cache_level=6;
explain
select * from t1,t2 where t1.b=t2.c and d <= 100;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where
1 SIMPLE t2 ref idx idx 5 test.t1.b 2 Using where
select * from t1,t2 where t1.b=t2.c and d <= 100;
a b c d v
3 30 30 100 101
4 20 20 100 101
1 20 20 100 101
set join_cache_level=default;
drop table t1, t2;
create table t1 (a bigint, b bigint as (a > '2'));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) DEFAULT NULL,
`b` bigint(20) GENERATED ALWAYS AS (`a` > 2) VIRTUAL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert into t1 (a) values (1),(3);
select * from t1;
a b
1 0
3 1
select * from t1;
a b
1 0
3 1
drop table t1;
create table t1 (a bigint, b bigint as (a between 0 and 2));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` bigint(20) DEFAULT NULL,
`b` bigint(20) GENERATED ALWAYS AS (`a` between 0 and 2) VIRTUAL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert into t1 (a) values (1),(3);
select * from t1;
a b
1 1
3 0
select * from t1;
a b
1 1
3 0
drop table t1;
create table t1 (a char(10), b char(10) as (a between 0 and 2));
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` char(10) DEFAULT NULL,
`b` char(10) GENERATED ALWAYS AS (`a` between 0 and 2) VIRTUAL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
insert into t1 (a) values (1),(3);
select * from t1;
a b
1 1
3 0
select * from t1;
a b
1 1
3 0
drop table t1;
CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` varchar(32) DEFAULT NULL,
`c` int(11) AS (a MOD 10) VIRTUAL,
`d` varchar(5) AS (LEFT(b,5)) PERSISTENT
) ENGINE=MyISAM;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` varchar(32) DEFAULT NULL,
`c` int(11) GENERATED ALWAYS AS (`a` MOD 10) VIRTUAL,
`d` varchar(5) GENERATED ALWAYS AS (left(`b`,5)) STORED
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
show columns from t1;
Field Type Null Key Default Extra
a int(11) NO NULL
b varchar(32) YES NULL
c int(11) YES NULL VIRTUAL GENERATED
d varchar(5) YES NULL STORED GENERATED
show full columns from t1;
Field Type Collation Null Key Default Extra Privileges Comment
a int(11) NULL NO NULL #
b varchar(32) utf8mb4_uca1400_ai_ci YES NULL #
c int(11) NULL YES NULL VIRTUAL GENERATED #
d varchar(5) utf8mb4_uca1400_ai_ci YES NULL STORED GENERATED #
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,NULL);
UPDATE IGNORE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
Warnings:
Warning 1906 The value specified for generated column 'd' in table 't1' has been ignored
INSERT IGNORE INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
Warnings:
Warning 1906 The value specified for generated column 'd' in table 't1' has been ignored
set sql_mode='strict_all_tables';
UPDATE `test`.`t1` SET `d`='b' WHERE `a`='1' AND `b`='a' AND `c`='1' AND `d`='a';
ERROR HY000: The value specified for generated column 'd' in table 't1' has been ignored
INSERT INTO `test`.`t1`(`a`,`b`,`c`,`d`) VALUES ( '1','a',NULL,'a');
ERROR HY000: The value specified for generated column 'd' in table 't1' has been ignored
drop table t1;
#
# MDEV-5611: self-referencing virtual column
#
create table t1 (a int, b int as (b is null) virtual);
ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
create table t1 (a int as (1+1), b int as (a is null) virtual);
drop table t1;
# end of 5.3 tests
create table t1 (v1 varchar(255) as (c1) persistent, c1 varchar(50)) collate=latin1_general_ci;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`v1` varchar(255) GENERATED ALWAYS AS (`c1`) STORED,
`c1` varchar(50) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
drop table t1;
set sql_mode='no_zero_date';
create table t1 (
ts timestamp not null default current_timestamp,
tsv timestamp as (adddate(ts, interval 1 day)) virtual
);
drop table t1;
set sql_mode=default;
#
# MDEV-11819 NO_ZERO_IN_DATE: Incorrect generated column value
#
SET sql_mode='NO_ZERO_IN_DATE';
CREATE TABLE t1
(
a datetime DEFAULT NULL,
b datetime DEFAULT NULL,
c time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL
);
INSERT INTO t1 VALUES ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',DEFAULT);
SELECT * FROM t1;
a b c
2008-12-31 23:59:59 2008-12-30 01:01:01 46:58:58
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
# MDEV-15834 The code in TABLE_SHARE::init_from_binary_frm_image() is not safe
#
SHOW TABLES;
Tables_in_test
t1
SHOW CREATE TABLE t1;
ERROR HY000: Incorrect information in file: './test/t1.frm'
ALTER TABLE t1;
ERROR HY000: Incorrect information in file: './test/t1.frm'
#
# End of 5.5 tests
#
#
# End of 10.0 tests
#
#
# MDEV-8441 Bad SHOW CREATE TABLE output for a table with a virtual column
#
CREATE TABLE t1 (a DATETIME, b TIMESTAMP AS (TIMESTAMP(a)));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` datetime DEFAULT NULL,
`b` timestamp GENERATED ALWAYS AS (cast(`a` as datetime)) VIRTUAL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
DROP TABLE t1;
CREATE TABLE t1 (a DATETIME, b TIMESTAMP AS (TIMESTAMP(a)),c TIMESTAMP);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` datetime DEFAULT NULL,
`b` timestamp GENERATED ALWAYS AS (cast(`a` as datetime)) VIRTUAL,
`c` timestamp NULL DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
DROP TABLE t1;
#
# MDEV-8839 COLUMN_GET() produces warnings with no data
#
SET @aaa= COLUMN_CREATE('price', _binary 0xF0F1F2F3F4F5F6F7);
SELECT COLUMN_GET(@aaa, 'price' AS DECIMAL) aaa;
aaa
0
Warnings:
Warning 1918 Encountered illegal value '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7' when converting to DECIMAL
SELECT COLUMN_GET(@aaa, 'price' AS INT) aaa;
aaa
0
Warnings:
Warning 1918 Encountered illegal value '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7' when converting to INT
SELECT COLUMN_GET(@aaa, 'price' AS DOUBLE) aaa;
aaa
0
Warnings:
Warning 1918 Encountered illegal value '\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7' when converting to DOUBLE
#
# MDEV-22579 No error when inserting DEFAULT(non_virtual_column) into a virtual column
#
SET sql_mode=STRICT_ALL_TABLES;
CREATE OR REPLACE TABLE t1 (
a INT NOT NULL DEFAULT 10,
b INT AS (a+1) VIRTUAL
) ENGINE=MyISAM;
INSERT INTO t1 (b) VALUES (10);
ERROR HY000: The value specified for generated column 'b' in table 't1' has been ignored
INSERT INTO t1 (b) VALUES (DEFAULT(a));
ERROR HY000: The value specified for generated column 'b' in table 't1' has been ignored
INSERT INTO t1 (b) VALUES (DEFAULT);
INSERT INTO t1 VALUES (10,10);
ERROR HY000: The value specified for generated column 'b' in table 't1' has been ignored
INSERT INTO t1 VALUES (10,DEFAULT(a));
ERROR HY000: The value specified for generated column 'b' in table 't1' has been ignored
INSERT INTO t1 VALUES (10, DEFAULT);
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
# End of 10.1 tests
#
#
# MDEV-16518 MYSQL57_GENERATED_FIELD: The code in TABLE_SHARE::init_from_binary_frm_image() is not safe
#
SHOW TABLES;
Tables_in_test
t1
SHOW CREATE TABLE t1;
ERROR HY000: Incorrect information in file: './test/t1.frm'
ALTER TABLE t1;
ERROR HY000: Incorrect information in file: './test/t1.frm'
#
# MDEV-19771 REPLACE on table with virtual_field can cause crash in set_ok_status()
create or replace table t1 (pk int primary key, col_bit bit(15) default null,
vcol_bit bit(10) GENERATED ALWAYS AS (`col_bit`) VIRTUAL);
replace INTO `t1` (`pk`,col_bit) VALUES (99,1000);
select pk, col_bit+0, vcol_bit+0 from t1;
pk col_bit+0 vcol_bit+0
99 1000 1000
replace INTO `t1` (`pk`,col_bit) VALUES (99,10000);
select pk, col_bit+0, vcol_bit+0 from t1;
pk col_bit+0 vcol_bit+0
99 10000 1023
REPLACE LOW_PRIORITY INTO `t1` (`pk`) VALUES (99);
ERROR 22001: Data too long for column 'vcol_bit' at row 1
drop table t1;
#
# MDEV-17837 REPLACE on table with virtual_field can cause crash in set_ok_status()
#
SET @old_sql_mode=@@sql_mode;
SET sql_mode= STRICT_ALL_TABLES;
CREATE TABLE t1 (
pk INT,
i TINYINT,
vi TINYINT AS (i+1) PERSISTENT,
PRIMARY KEY(pk)
);
INSERT INTO t1 (pk,i) VALUES (1,1);
TRUNCATE TABLE t1;
INSERT IGNORE INTO t1 (pk,i) VALUES (1,127);
Warnings:
Warning 1264 Out of range value for column 'vi' at row 1
REPLACE INTO t1 (pk,i) VALUES (1,2);
ERROR 22003: Out of range value for column 'vi' at row 1
DROP TABLE t1;
SET @sql_mode=@old_sql_mode;
#
# MDEV-22579 No error when inserting DEFAULT(non_virtual_column) into a virtual column
# 10.2+ specific part
#
SET sql_mode=STRICT_ALL_TABLES;
CREATE OR REPLACE TABLE t1 (
a INT NOT NULL DEFAULT 10,
b INT AS (a+1) VIRTUAL
) ENGINE=MyISAM;
EXECUTE IMMEDIATE 'INSERT INTO t1 (b) VALUES(?)' USING DEFAULT;
EXECUTE IMMEDIATE 'INSERT INTO t1 (b) VALUES(?)' USING IGNORE;
INSERT INTO t1 (b) VALUES (DEFAULT);
INSERT INTO t1 (b) VALUES (IGNORE);
SELECT * FROM t1;
a b
10 11
10 11
10 11
10 11
DELETE FROM t1;
EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES(10,?)' USING DEFAULT;
EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES(11,?)' USING IGNORE;
INSERT INTO t1 VALUES (12,DEFAULT);
INSERT INTO t1 VALUES (13,IGNORE);
SELECT * FROM t1;
a b
10 11
11 12
12 13
13 14
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
# CONTEXT_ANALYSIS_ONLY_VCOL_EXPR
#
call mtr.add_suppression("Charset id.*trying to replace");
create table t1 (c1 char(1) character set ucs2 collate ucs2_test_ci,
v1 char(1) character set ucs2 collate ucs2_test_ci as (c1),
v2 int as (c1 = 'b'),
v3 int as (v1 = 'b'));
insert into t1 (c1) values ('a');
select * from t1 where v1 = 'b';
c1 v1 v2 v3
a a 1 1
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` char(1) CHARACTER SET ucs2 COLLATE ucs2_test_ci DEFAULT NULL,
`v1` char(1) CHARACTER SET ucs2 COLLATE ucs2_test_ci GENERATED ALWAYS AS (`c1`) VIRTUAL,
`v2` int(11) GENERATED ALWAYS AS (`c1` = 'b') VIRTUAL,
`v3` int(11) GENERATED ALWAYS AS (`v1` = 'b') VIRTUAL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
#
# End of 10.2 tests
#
#
# RAND is session func
#
create table t1 (a int, b float default rand(1));
insert into t1 (a) values (1);
insert into t1 (a) values (2);
insert into t1 (a) values (3);
select * from t1;
a b
1 0.405404
2 0.405404
3 0.405404
drop table t1;
#
# End of 10.3 tests
#
#
# MDEV-31112 vcol circular references lead to stack overflow
#
create table t (a int, c int as (a));
alter table t alter column c drop default;
alter table t modify column a int as (c) stored;
ERROR 01000: Expression for field `a` is referring to uninitialized field `c`
drop table t;
#
# End of 10.4 tests
#
#
# MDEV-26891 Segfault in Field::register_field_in_read_map upon INSERT DELAYED with virtual columns
#
CREATE TABLE t (
id INT AUTO_INCREMENT,
a varchar(16) NOT NULL DEFAULT '',
b varchar(16) GENERATED ALWAYS AS (a) VIRTUAL,
KEY `col_year` (b(8),id)
) ENGINE=MyISAM;
INSERT DELAYED INTO t (a) VALUES ('foo'),('bar');
DROP TABLE t;
#
# End of 10.5 tests
#
|