1356
1356
# End of 4.1 tests
1359
# Test REPAIR/CHECK TABLE (5.1)
1362
# Check that repair on the newly created table works fine
1364
CREATE TABLE test_repair_table ( val integer not null ) ENGINE = CSV;
1366
CHECK TABLE test_repair_table;
1367
REPAIR TABLE test_repair_table;
1369
DROP TABLE test_repair_table;
1372
# Check autorepair. Here we also check that we can work w/o metafile
1373
# restore the meta-file
1376
CREATE TABLE test_repair_table2 ( val integer not null ) ENGINE = CSV;
1377
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
1379
# Should give a warning and perform autorepair. We also disable ps-protocol
1380
# here, as mysql-test eats up warnings in ps-protocol mode
1382
--disable_ps_protocol
1383
SELECT * from test_repair_table2;
1384
--enable_ps_protocol
1385
# this should work ok, as the table is already repaired
1386
SELECT * from test_repair_table2;
1387
# check that the metafile appeared again.
1388
--file_exists $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
1389
CHECK TABLE test_repair_table2;
1390
DROP TABLE test_repair_table2;
1393
# Corrupt csv file and see if we can repair it
1394
CREATE TABLE test_repair_table3 ( val integer not null ) ENGINE = CSV;
1395
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
1396
--write_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
1401
CHECK TABLE test_repair_table3;
1402
REPAIR TABLE test_repair_table3;
1403
SELECT * FROM test_repair_table3;
1404
DROP TABLE test_repair_table3;
1406
# Test with more sophisticated table
1408
CREATE TABLE test_repair_table4 (
1410
magic_no int DEFAULT 0 NOT NULL,
1411
company_name char(30) DEFAULT '' NOT NULL,
1412
founded char(4) DEFAULT '' NOT NULL
1415
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table4.CSM
1416
--disable_ps_protocol
1417
SELECT * FROM test_repair_table4;
1418
--enable_ps_protocol
1419
SELECT * FROM test_repair_table4;
1420
CHECK TABLE test_repair_table4;
1422
INSERT INTO test_repair_table4 VALUES (2,101,'SAP','1972');
1423
INSERT INTO test_repair_table4 VALUES (1,101,'Microsoft','1978');
1424
INSERT INTO test_repair_table4 VALUES (2,101,'MySQL','1995');
1426
# list table content
1427
SELECT * FROM test_repair_table4;
1428
CHECK TABLE test_repair_table4;
1429
REPAIR TABLE test_repair_table4;
1430
# check that nothing changed
1431
SELECT * FROM test_repair_table4;
1432
# verify that check/repair did non corrupt the table itself
1433
CHECK TABLE test_repair_table4;
1434
REPAIR TABLE test_repair_table4;
1435
SELECT * FROM test_repair_table4;
1436
DROP TABLE test_repair_table4;
1438
# Run CHECK/REPAIR on the CSV file with a single row, which misses a column.
1440
CREATE TABLE test_repair_table5 (
1442
magic_no int DEFAULT 0 NOT NULL,
1443
company_name char(30) DEFAULT '' NOT NULL,
1444
founded char(4) DEFAULT '' NOT NULL
1447
# Corrupt a table -- put a file with wrong # of columns
1448
--remove_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1449
--write_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1453
CHECK TABLE test_repair_table5;
1454
REPAIR TABLE test_repair_table5;
1455
SELECT * FROM test_repair_table5;
1456
INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT", 1876);
1457
SELECT * FROM test_repair_table5;
1459
# Corrupt a table -- put a row with wrong # of columns at end of file
1460
--append_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1465
CHECK TABLE test_repair_table5;
1466
REPAIR TABLE test_repair_table5;
1467
# The correct record inserted should still be in the file
1468
SELECT * FROM test_repair_table5;
1469
INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT2", 1876);
1470
SELECT * FROM test_repair_table5;
1472
# Corrupt table again -- put a row with wrong # of columns at end of file
1473
--append_file $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
1478
CHECK TABLE test_repair_table5;
1479
REPAIR TABLE test_repair_table5;
1480
# The two correct records inserted should still be in the file
1481
SELECT * FROM test_repair_table5;
1482
DROP TABLE test_repair_table5;
1485
1359
# BUG#13406 - incorrect amount of "records deleted"
1488
create table t1 (a int not null) engine=csv;
1362
create temporary table t1 (a int not null) engine=csv;
1489
1363
insert t1 values (1);
1491
1365
delete from t1; # delete_row
1516
# Some additional tests for new, faster alter table. Note that most of the
1517
# whole alter table code is being tested all around the test suite already.
1520
create table t1 (v varchar(32) not null);
1521
insert into t1 values ('def'),('abc'),('hij'),('3r4f');
1523
# Fast alter, no copy performed
1524
alter table t1 change v v2 varchar(32);
1526
# Fast alter, no copy performed
1527
alter table t1 change v2 v varchar(64);
1529
update t1 set v = 'lmn' where v = 'hij';
1531
# Regular alter table
1532
alter table t1 add i int auto_increment not null primary key first;
1534
update t1 set i=5 where i=3;
1536
alter table t1 change i i bigint;
1538
alter table t1 add unique key (i, v);
1539
select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn');
1543
1390
# Bug #15205 Select from CSV table without the datafile causes crash
1545
1392
# NOTE: the bug is not deterministic
1567
1414
#drop table bug15205;
1568
1415
#drop table bug15205_2;
1572
# Bug#22080 "CHECK fails to identify some corruption"
1575
create table bug22080_1 (id int not null,string varchar(64) not null) Engine=CSV;
1576
create table bug22080_2 (id int not null,string varchar(64) not null) Engine=CSV;
1577
create table bug22080_3 (id int not null,string varchar(64) not null) Engine=CSV;
1578
insert into bug22080_1 values(1,'string');
1579
insert into bug22080_1 values(2,'string');
1580
insert into bug22080_1 values(3,'string');
1582
# Create first corrupt file as described in bug report
1583
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug22080_2.CSV
1584
--write_file $MYSQLTEST_VARDIR/master-data/test/bug22080_2.CSV
1590
# Create second corrupt file as described in bug report
1591
--remove_file $MYSQLTEST_VARDIR/master-data/test/bug22080_3.CSV
1592
--write_file $MYSQLTEST_VARDIR/master-data/test/bug22080_3.CSV
1598
check table bug22080_2;
1600
check table bug22080_3;
1602
drop tables bug22080_1,bug22080_2,bug22080_3;
1605
1418
# Testing float type
1607
create table float_test (id float not null,string varchar(64) not null) Engine=CSV;
1420
create temporary table float_test (id float not null,string varchar(64) not null) Engine=CSV;
1608
1421
insert into float_test values(1.0,'string');
1609
1422
insert into float_test values(2.23,'serg.g');
1610
1423
insert into float_test values(0.03,'string');
1680
1478
# Bug #31473: does not work with NULL value in datetime field
1682
create table t1(a datetime not null) engine=csv;
1684
insert into t1 values();
1687
create table t1(a varchar(32) not null) engine=csv;
1689
insert into t1 values();
1692
create table t1(a int not null) engine=csv;
1694
insert into t1 values();
1697
create table t1(a blob not null) engine=csv;
1480
create temporary table t1(a datetime not null) engine=csv;
1482
insert into t1 values();
1485
create temporary table t1(a varchar(32) not null) engine=csv;
1487
insert into t1 values();
1490
create temporary table t1(a int not null) engine=csv;
1492
insert into t1 values();
1495
create temporary table t1(a blob not null) engine=csv;
1699
1497
insert into t1 values();
1700
1498
select * from t1;
1702
1500
# We prevent creation of table with nullable ENUM
1703
1501
--error ER_CHECK_NOT_IMPLEMENTED
1704
create table t1(a enum('foo','bar') default null) engine=csv;
1502
create temporary table t1(a enum('foo','bar') default null) engine=csv;
1705
1503
--error ER_CHECK_NOT_IMPLEMENTED
1706
create table t1(a enum('foo','bar') default 'foo') engine=csv;
1504
create temporary table t1(a enum('foo','bar') default 'foo') engine=csv;
1707
1505
# Enum columns must be specified as NOT NULL
1708
create table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
1506
create temporary table t1(a enum('foo','bar') default 'foo' not null) engine=csv;
1709
1507
insert into t1 values();
1710
1508
select * from t1;