mariadb/mysql-test/suite/sql_sequence/other.result
Monty c4cad8d50c MDEV-33449 improving repair of tables
This task is to ensure we have a clear definition and rules of how to
repair or optimize a table.

The rules are:

- REPAIR should be used with tables that are crashed and are
  unreadable (hardware issues with not readable blocks, blocks with
  'unexpected data' etc)
- OPTIMIZE table should be used to optimize the storage layout for the
  table (recover space for delete rows and optimize the index
  structure.
- ALTER TABLE table_name FORCE should be used to rebuild the .frm file
  (the table definition) and the table (with the original table row
  format). If the table is from and older MariaDB/MySQL release with a
  different storage format, it will convert the data to the new
  format. ALTER TABLE ... FORCE is used as part of mariadb-upgrade

Here follows some more background:

The 3 ways to repair a table are:
1) ALTER TABLE table_name FORCE" (not other options).
   As an alias we allow: "ALTER TABLE table_name ENGINE=original_engine"
2) "REPAIR TABLE" (without FORCE)
3) "OPTIMIZE TABLE"

All of the above commands will optimize row space usage (which means that
space will be needed to hold a temporary copy of the table) and
re-generate all indexes. They will also try to replicate the original
table definition as exact as possible.

For ALTER TABLE and "REPAIR TABLE without FORCE", the following will hold:
If the table is from an older MariaDB version and data conversion is
needed (for example for old type HASH columns, MySQL JSON type or new
TIMESTAMP format) "ALTER TABLE table_name FORCE, algorithm=COPY" will be
used.

The differences between the algorithms are
1) Will use the fastest algorithm the engine supports to do a full repair
   of the table (except if data conversions are is needed).
2) Will use the storage engine internal REPAIR facility (MyISAM, Aria).
   If the engine does not support REPAIR then
   "ALTER TABLE FORCE, ALGORITHM=COPY" will be used.
   If there was data incompatibilities (which means that FORCE was used)
   then there will be a warning after REPAIR that ALTER TABLE FORCE is
   still needed.
   The reason for this is that REPAIR may be able to go around data
   errors (wrong incompatible data, crashed or unreadable sectors) that
   ALTER TABLE cannot do.
3) Will use the storage engine internal OPTIMIZE. If engine does not
   support optimize, then "ALTER TABLE FORCE" is used.

The above will ensure that ALTER TABLE FORCE is able to
correct almost any errors in the row or index data.  In case of
corrupted blocks then REPAIR possible followed by ALTER TABLE is needed.
This is important as mariadb-upgrade executes ALTER TABLE table_name
FORCE for any table that must be re-created.

Bugs fixed with InnoDB tables when using ALTER TABLE FORCE:
- No error for INNODB_DEFAULT_ROW_FORMAT=COMPACT even if row length
  would be too wide. (Independent of innodb_strict_mode).
- Tables using symlinks will be symlinked after any of the above commands
  (Independent of the setting of --symbolic-links)

If one specifies an algorithm together with ALTER TABLE FORCE, things
will work as before (except if data conversion is required as then
the COPY algorithm is enforced).

ALTER TABLE .. OPTIMIZE ALL PARTITIONS will work as before.

Other things:
- FORCE argument added to REPAIR to allow one to first run internal
  repair to fix damaged blocks and then follow it with ALTER TABLE.
- REPAIR will not update frm_version if ha_check_for_upgrade() finds
  that table is still incompatible with current version. In this case the
  REPAIR will end with an error.
- REPAIR for storage engines that does not have native repair, like InnoDB,
  is now using ALTER TABLE FORCE.
- REPAIR csv-table USE_FRM now works.
  - It did not work before as CSV tables had extension list in wrong
    order.
- Default error messages length for %M increased from 128 to 256 to not
  cut information from REPAIR.
- Documented HA_ADMIN_XX variables related to repair.
- Added HA_ADMIN_NEEDS_DATA_CONVERSION to signal that we have to
  do data conversions when converting the table (and thus ALTER TABLE
  copy algorithm is needed).
- Fixed typo in error message (caused test changes).
2024-05-27 12:39:03 +02:00

391 lines
14 KiB
Text

#
# Create and check
#
create sequence s1 engine=innodb;
check table s1;
Table Op Msg_type Msg_text
test.s1 check note The storage engine for the table doesn't support check
select next value for s1;
next value for s1
1
flush tables;
check table s1;
Table Op Msg_type Msg_text
test.s1 check note The storage engine for the table doesn't support check
select next value for s1;
next value for s1
1001
flush tables;
repair table s1;
Table Op Msg_type Msg_text
test.s1 repair status OK
select next value for s1;
next value for s1
2001
drop sequence s1;
create or replace sequence s1 engine=innodb;
select next value for s1;
next value for s1
1
repair table s1;
Table Op Msg_type Msg_text
test.s1 repair status OK
check table s1;
Table Op Msg_type Msg_text
test.s1 check note The storage engine for the table doesn't support check
select next value for s1;
next value for s1
1001
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
2001 1 9223372036854775806 1 1 1000 0 0
drop sequence s1;
#
# INSERT
#
create sequence s1;
create sequence s2;
insert into s1 (next_not_cached_value, minimum_value) values (100,1000);
ERROR HY000: Field 'maximum_value' doesn't have a default value
insert into s1 values (next value for s1, 1,9223372036854775806,1,1,1000,0,0);
ERROR HY000: Table 's1' is specified twice, both as a target for 'INSERT' and as a separate source for data
insert into s1 values(1000,9223372036854775806,1,1,1,1000,0,0);
ERROR HY000: Sequence 'test.s1' has out of range value for options
insert into s1 values(0,9223372036854775806,1,1,1,1000,0,0);
ERROR HY000: Sequence 'test.s1' has out of range value for options
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
insert into s1 values(1000,1,9223372036854775806,1,1,1000,0,0);
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1000 1 9223372036854775806 1 1 1000 0 0
select next value for s1;
next value for s1
1000
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
2000 1 9223372036854775806 1 1 1000 0 0
insert into s2 values(0, 1, 10, 1, 2, 1, 1, 0);
ERROR HY000: Sequence 'test.s2' has out of range value for options
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
2000 1 9223372036854775806 1 1 1000 0 0
insert into s1 values (next value for s2, 1,9223372036854775806,1,1,1000,0,0);
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
select * from s2;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1001 1 9223372036854775806 1 1 1000 0 0
insert into s1 select * from s2;
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1001 1 9223372036854775806 1 1 1000 0 0
drop sequence s1,s2;
#
# UPDATE and DELETE
#
create sequence s1;
update s1 set next_not_cached_value=100;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s1` doesn't have this option
delete from s1 where next_not_cached_value > 0;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s1` doesn't have this option
drop sequence s1;
#
# SHOW TABLES
#
create sequence s1;
create table t1 (a int);
create view v1 as select * from s1;
show full tables;
Tables_in_test Table_type
s1 SEQUENCE
t1 BASE TABLE
v1 VIEW
SELECT TABLE_TYPE,ENGINE FROM INFORMATION_SCHEMA.TABLES where table_schema="test" ORDER BY TABLE_NAME;
TABLE_TYPE ENGINE
SEQUENCE MyISAM
BASE TABLE MyISAM
VIEW NULL
drop table t1,s1;
drop view v1;
#
# LOCK TABLES (as in mysqldump)
#
create sequence s1 engine=innodb;
LOCK TABLES s1 READ;
SELECT * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 1000 0 0
UNLOCK TABLES;
LOCK TABLES s1 WRITE;
insert into s1 values (1,1,9223372036854775806, 1, 1, 1000, 0, 0);
UNLOCK TABLES;
drop table s1;
#
# Many sequence calls with innodb
#
create sequence s1 cache=1000 engine=innodb;
start transaction;
select count(nextval(s1)) from seq_1_to_2000;
count(nextval(s1))
2000
commit;
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
2001 1 9223372036854775806 1 1 1000 0 0
drop sequence s1;
create sequence s1 cache=1000 engine=innodb;
start transaction;
select count(nextval(s1)) from seq_1_to_2000;
count(nextval(s1))
2000
connect addconroot, localhost, root,,;
connection addconroot;
start transaction;
select count(nextval(s1)) from seq_1_to_2000;
count(nextval(s1))
2000
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
4001 1 9223372036854775806 1 1 1000 0 0
commit;
disconnect addconroot;
connection default;
select * from s1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
4001 1 9223372036854775806 1 1 1000 0 0
commit;
drop sequence s1;
#
# Flush tables with read lock
#
create sequence s1;
select next value for s1;
next value for s1
1
flush tables with read lock;
create sequence s2;
ERROR HY000: Can't execute the query because you have a conflicting read lock
select next value for s1;
ERROR HY000: Can't execute the query because you have a conflicting read lock
unlock tables;
drop sequence s1;
#
# MDEV-14761
# Assertion `!mysql_parse_status || thd->is_error() ||
# thd->get_internal_handler()' failed in parse_sql
#
CREATE SEQUENCE s1;
ALTER SEQUENCE s1 MAXVALUE 100 NO MAXVALUE;
ERROR HY000: Option 'MAXVALUE' used twice in statement
DROP SEQUENCE s1;
#
# Don't allow SEQUENCE to be used with CHECK or virtual fields
#
CREATE SEQUENCE s1 nocache engine=myisam;
CREATE table t1 (a int check (next value for s1 > 0));
ERROR HY000: Function or expression 'nextval()' cannot be used in the CHECK clause of `a`
CREATE table t1 (a int check (previous value for s1 > 0));
ERROR HY000: Function or expression 'lastval()' cannot be used in the CHECK clause of `a`
CREATE table t1 (a int check (setval(s1,10)));
ERROR HY000: Function or expression 'setval()' cannot be used in the CHECK clause of `a`
CREATE TABLE t1 (a int, b int as (next value for s1 > 0));
ERROR HY000: Function or expression 'nextval()' cannot be used in the GENERATED ALWAYS AS clause of `b`
drop sequence s1;
#
# MDEV-13024: Server crashes in my_store_ptr upon DELETE from
# sequence in multi-table format
#
CREATE SEQUENCE s;
CREATE table t1 (a int);
insert into t1 values (1),(2);
DELETE s FROM s;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s` doesn't have this option
delete t1,s from s,t1;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s` doesn't have this option
delete s,t1 from t1,s;
ERROR HY000: Storage engine SEQUENCE of the table `test`.`s` doesn't have this option
DROP SEQUENCE s;
DROP TABLE t1;
#
# MDEV-20074: Lost connection on update trigger
#
# INSERT & table
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');
CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
INSERT INTO t2(a_p_name, a_p_first_name) VALUES(old.p_name, old.p_first_name);
END;
$$
update t1 set p_first_name='Yunxi' where p_id=1;
drop sequence s1;
drop table t1,t2;
# INSERT & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;
insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');
CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
INSERT INTO v2(a_p_name, a_p_first_name) VALUES(old.p_name, old.p_first_name);
END;
$$
update t1 set p_first_name='Yunxi' where p_id=1;
drop view v2;
drop table t1,t2;
drop sequence s1;
# INSERT SELECT & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;
insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');
CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
INSERT INTO v2(a_p_name, a_p_first_name) SELECT old.p_name, old.p_first_name;
END;
$$
update t1 set p_first_name='Yunxi' where p_id=1;
drop view v2;
drop table t1,t2;
drop sequence s1;
# REPLACE & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;
insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');
CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
REPLACE INTO v2(a_p_name, a_p_first_name) VALUES(old.p_name, old.p_first_name);
END;
$$
update t1 set p_first_name='Yunxi' where p_id=1;
drop view v2;
drop table t1,t2;
drop sequence s1;
# REPLACE SELECT & view
create sequence s1 increment by 1 start with 1;
create table t1 (p_id integer, p_name varchar(128), p_first_name varchar(128));
create table t2 (a_id integer default nextval(s1), a_p_name varchar(128), a_p_first_name varchar(128), t timestamp default current_timestamp);
create view v2 as select * from t2;
insert into t1 values
(1, 'Luo','Frank'),(2, 'Xe','Emma'),(3, 'Li','Anna'),(4, 'Lun','Serg'),(5, 'Xu','Nils'),(6, 'Ja','Ute'),(7, 'Jin','Mike'),(8, 'Lio','Carl'),(9, 'Lang','Kevin'),(10, 'Ling','Lisa'),(11, 'Fang','Frank'),(12, 'Feng','Emma'),(13, 'Tuo','Anna'),(14, 'Tua','Serg'),(15, 'Moa','Nils'),(16, 'Hua','Ute'),(17, 'Xufa','Mike'),(18, 'Lulu','Carl'),(19, 'Hoho','Kevin'),(20, 'Tata','Lisa');
CREATE TRIGGER tr_upd
BEFORE UPDATE on t1
FOR EACH ROW
BEGIN
REPLACE INTO v2(a_p_name, a_p_first_name) SELECT old.p_name, old.p_first_name;
END;
$$
update t1 set p_first_name='Yunxi' where p_id=1;
drop view v2;
drop table t1,t2;
drop sequence s1;
#
# MDEV-19273:Server crash in MDL_ticket::has_stronger_or_equal_type or
# Assertion `thd->mdl_context.is_lock_owner(MDL_key::TABLE,
# table->db.str, table->table_name.str, MDL_SHARED)' failed
# in mysql_rm_table_no_locks
#
CREATE TABLE t1 (a INT);
CREATE TEMPORARY TABLE tmp (b INT);
LOCK TABLE t1 READ;
DROP SEQUENCE tmp;
ERROR 42S02: Unknown SEQUENCE: 'test.tmp'
DROP TEMPORARY SEQUENCE tmp;
ERROR 42S02: Unknown SEQUENCE: 'test.tmp'
DROP SEQUENCE t1;
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
DROP TEMPORARY SEQUENCE t1;
ERROR 42S02: Unknown SEQUENCE: 'test.t1'
UNLOCK TABLES;
DROP SEQUENCE t1;
ERROR 42S02: 'test.t1' is not a SEQUENCE
DROP TEMPORARY SEQUENCE t1;
ERROR 42S02: Unknown SEQUENCE: 'test.t1'
DROP TABLE t1;
CREATE TABLE t (a INT);
CREATE SEQUENCE s;
LOCK TABLE t WRITE;
DROP SEQUENCE s;
ERROR HY000: Table 's' was not locked with LOCK TABLES
DROP TEMPORARY SEQUENCE s;
ERROR 42S02: Unknown SEQUENCE: 'test.s'
UNLOCK TABLES;
CREATE TEMPORARY SEQUENCE s;
LOCK TABLE t WRITE;
DROP TEMPORARY SEQUENCE s;
UNLOCK TABLES;
DROP SEQUENCE s;
create table s(a INT);
CREATE TEMPORARY TABLE s (f INT);
LOCK TABLE t WRITE;
DROP TEMPORARY TABLE s;
CREATE TEMPORARY TABLE s (f INT);
DROP TABLE s;
DROP TABLE s;
ERROR HY000: Table 's' was not locked with LOCK TABLES
UNLOCK TABLES;
DROP TABLE s;
CREATE VIEW v1 as SELECT * FROM t;
CREATE SEQUENCE s;
DROP SEQUENCE IF EXISTS v1;
Warnings:
Note 1965 'test.v1' is a view
DROP VIEW IF EXISTS s;
Warnings:
Warning 1347 'test.s' is not of type 'VIEW'
Note 4092 Unknown VIEW: 'test.s'
DROP VIEW v1;
DROP SEQUENCE s;
DROP TABLE t;
#
# End of 10.3 tests
#
#
# MDEV-32541 Assertion `!(thd->server_status & (1U | 8192U))' failed in MDL_context::release_transactional_locks
#
create sequence s1;
create sequence s2;
connect con1,localhost,root,,;
set session transaction read only;
start transaction;
connection default;
start transaction;
insert into s2 values (1, 1, 10000, 100, 1, 1000, 0, 0);
connection con1;
select lastval(s1);
lastval(s1)
NULL
select lastval(s2);;
connection default;
set lock_wait_timeout= 1;
insert into s1 values (1, 1, 10000, 100, 1, 1000, 0, 0);
connection con1;
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
disconnect con1;
connection default;
drop sequence s1;
drop sequence s2;
#
# End of 10.4 tests
#