mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV 13679 Enabled sequences to be used in DEFAULT
Other changes done to get this to work: - Added 'internal_tables' to TABLE object to list which sequence tables is needed to use the table. - Mark any expression using DEFAULT() with LEX->default_used. This is needed when deciding if we should open internal sequence tables when a table is opened (we don't need to open sequence tables if the main table is only used with SELECT). - Create_and_open_temporary_table() can now also open all internal sequence tables. - Added option MYSQL_LOCK_USE_MALLOC to mysql_lock_tables() to force memory allocation to be used with malloc instead of memroot. - Added flag to MYSQL_LOCK to remember if allocation was done with malloc or memroot (makes code simpler and safer). - init_one_table_for_prelocking() now takes argument for what lock to use instead of it's a routine or something else. - Renamed prelocking placeholders to make them more understandable as they are now used in more code. - Changed test in check_lock_and_start_stmt() if found table has correct locks. The old test didn't work for tables that has lock TL_WRITE_ALLOW_WRITE, which is what sequence tables are using. - Added VCOL_NOT_VIRTUAL option to ensure that sequence functions can't be used with virtual columns - More sequence tests
This commit is contained in:
171
mysql-test/suite/sql_sequence/default.result
Normal file
171
mysql-test/suite/sql_sequence/default.result
Normal file
@ -0,0 +1,171 @@
|
||||
drop table if exists t1,s1,s2;
|
||||
Warnings:
|
||||
Note 1051 Unknown table 'test.t1'
|
||||
Note 1051 Unknown table 'test.s1'
|
||||
Note 1051 Unknown table 'test.s2'
|
||||
drop view if exists v1;
|
||||
Warnings:
|
||||
Note 4092 Unknown VIEW: 'test.v1'
|
||||
#
|
||||
# Test DEFAULT
|
||||
#
|
||||
CREATE SEQUENCE s1 nocache engine=myisam;
|
||||
CREATE table t1 (a int default next value for s1, b int);
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` int(11) DEFAULT nextval(`test`.`s1`),
|
||||
`b` int(11) DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
insert into t1 SET b=1;
|
||||
insert into t1 SET b=2;
|
||||
insert into t1 (b) values (3),(4);
|
||||
select * from t1;
|
||||
a b
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
update t1 set b=5 where a=1;
|
||||
delete from t1 where b=1;
|
||||
select * from t1;
|
||||
a b
|
||||
1 5
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
#
|
||||
# Executing DEFAULT function
|
||||
#
|
||||
INSERT into t1 values(default(a),10);
|
||||
INSERT into t1 values(default(a),default(a));
|
||||
update t1 set a=default(a), b=12 where b=2;
|
||||
select * from t1;
|
||||
a b
|
||||
1 5
|
||||
8 12
|
||||
3 3
|
||||
4 4
|
||||
5 10
|
||||
6 7
|
||||
select default(a), a, b from t1;
|
||||
default(a) a b
|
||||
9 1 5
|
||||
10 8 12
|
||||
11 3 3
|
||||
12 4 4
|
||||
13 5 10
|
||||
14 6 7
|
||||
select * from s1;
|
||||
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
|
||||
15 1 9223372036854775806 1 1 0 0 0
|
||||
select * from t1 where default(a) > 0;
|
||||
a b
|
||||
1 5
|
||||
8 12
|
||||
3 3
|
||||
4 4
|
||||
5 10
|
||||
6 7
|
||||
select * from s1;
|
||||
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
|
||||
16 1 9223372036854775806 1 1 0 0 0
|
||||
#
|
||||
# View
|
||||
#
|
||||
create view v1 as select * from t1;
|
||||
insert into v1 set b=20;
|
||||
select * from v1;
|
||||
a b
|
||||
1 5
|
||||
8 12
|
||||
3 3
|
||||
4 4
|
||||
5 10
|
||||
6 7
|
||||
16 20
|
||||
drop view v1;
|
||||
#
|
||||
# Alter table
|
||||
#
|
||||
CREATE SEQUENCE s2 nocache engine=myisam;
|
||||
alter table t1 add column c int default next value for s2, add column d int default previous value for s2;
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` int(11) DEFAULT nextval(`test`.`s1`),
|
||||
`b` int(11) DEFAULT NULL,
|
||||
`c` int(11) DEFAULT nextval(`test`.`s2`),
|
||||
`d` int(11) DEFAULT lastval(`test`.`s2`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
select * from t1;
|
||||
a b c d
|
||||
1 5 1 1
|
||||
8 12 2 2
|
||||
3 3 3 3
|
||||
4 4 4 4
|
||||
5 10 5 5
|
||||
6 7 6 6
|
||||
16 20 7 7
|
||||
drop sequence s2;
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` int(11) DEFAULT nextval(`test`.`s1`),
|
||||
`b` int(11) DEFAULT NULL,
|
||||
`c` int(11) DEFAULT nextval(`test`.`s2`),
|
||||
`d` int(11) DEFAULT lastval(`test`.`s2`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
drop table t1;
|
||||
drop sequence s1;
|
||||
#
|
||||
# LOCK TABLES
|
||||
#
|
||||
CREATE SEQUENCE s1 nocache engine=myisam;
|
||||
CREATE table t1 (a int default next value for s1, b int);
|
||||
insert into t1 (b) values (3),(4);
|
||||
LOCK TABLE t1 WRITE;
|
||||
insert into t1 (b) values (5),(6);
|
||||
ERROR HY000: Table 's1' was not locked with LOCK TABLES
|
||||
UNLOCK TABLES;
|
||||
LOCK TABLE t1 WRITE, s1 WRITE;
|
||||
insert into t1 (b) values (5),(6);
|
||||
select default(a) from t1;
|
||||
default(a)
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
UNLOCK TABLES;
|
||||
LOCK TABLE t1 READ;
|
||||
insert into t1 (b) values (5),(6);
|
||||
ERROR HY000: Table 's1' was not locked with LOCK TABLES
|
||||
select default(a) from t1;
|
||||
ERROR HY000: Table 's1' was not locked with LOCK TABLES
|
||||
UNLOCK TABLES;
|
||||
LOCK TABLE t1 READ, s1 read;
|
||||
insert into t1 (b) values (5),(6);
|
||||
ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
|
||||
select default(a) from t1;
|
||||
ERROR HY000: Table 's1' was locked with a READ lock and can't be updated
|
||||
UNLOCK TABLES;
|
||||
drop table t1;
|
||||
drop sequence s1;
|
||||
#
|
||||
# Wrong usage of default
|
||||
#
|
||||
CREATE table t1 (a int default next value for s1, b int);
|
||||
ERROR 42S02: Table 'test.s1' doesn't exist
|
||||
CREATE SEQUENCE s1 nocache engine=myisam;
|
||||
CREATE table t1 (a int default next value for s1, b int);
|
||||
DROP SEQUENCE s1;
|
||||
insert into t1 (b) values (5),(6);
|
||||
ERROR 42S02: Table 'test.s1' doesn't exist
|
||||
ALTER TABLE t1 add column c int;
|
||||
ERROR 42S02: Table 'test.s1' doesn't exist
|
||||
CREATE SEQUENCE s1 nocache engine=myisam;
|
||||
ALTER TABLE t1 add column c int;
|
||||
ALTER TABLE t1 add column d int default next value for s_not_exits;
|
||||
ERROR 42S02: Table 'test.s_not_exits' doesn't exist
|
||||
drop table t1;
|
||||
drop sequence s1;
|
Reference in New Issue
Block a user