Commit 87cdc8f8 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-28152 create sequences with various signed value types

- Support signed types. Unsigned types to be worked out in the next patch.
- Sequence (definition) tables uses the value type for the field type
  of minvalue, maxvalue, startvalue, next_not_cached_value, so that
  the value type can be inferred from this type.
parent 84675ed9
......@@ -6369,16 +6369,16 @@ NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
# Show create before dump
show create sequence d.s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s2;
Table Create Table
s2 CREATE SEQUENCE `s2` start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
s2 CREATE SEQUENCE `s2` as bigint start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s3;
Table Create Table
s3 CREATE SEQUENCE `s3` start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
s3 CREATE SEQUENCE `s3` as bigint start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s4;
Table Create Table
s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
s4 CREATE SEQUENCE `s4` as bigint start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
# Dump sequence without `--no-data`
# Restore from mysqldump
SETVAL(`s1`, 1101, 0)
......@@ -6392,16 +6392,16 @@ SETVAL(`s4`, 1401, 0)
# Show create after restore
show create sequence d.s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s2;
Table Create Table
s2 CREATE SEQUENCE `s2` start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
s2 CREATE SEQUENCE `s2` as bigint start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s3;
Table Create Table
s3 CREATE SEQUENCE `s3` start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
s3 CREATE SEQUENCE `s3` as bigint start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s4;
Table Create Table
s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
s4 CREATE SEQUENCE `s4` as bigint start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
SELECT NEXTVAL(d.s1),NEXTVAL(d.s2),NEXTVAL(d.s3), NEXTVAL(d.s4);
NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
100 200 300 400
......@@ -6418,16 +6418,16 @@ SETVAL(`s4`, 1401, 0)
# Show create after restore `--no-data`
show create sequence d.s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s2;
Table Create Table
s2 CREATE SEQUENCE `s2` start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
s2 CREATE SEQUENCE `s2` as bigint start with 200 minvalue 200 maxvalue 1200 increment by 20 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s3;
Table Create Table
s3 CREATE SEQUENCE `s3` start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
s3 CREATE SEQUENCE `s3` as bigint start with 300 minvalue 300 maxvalue 1300 increment by 30 cache 1000 cycle ENGINE=MyISAM
show create sequence d.s4;
Table Create Table
s4 CREATE SEQUENCE `s4` start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
s4 CREATE SEQUENCE `s4` as bigint start with 400 minvalue 400 maxvalue 1400 increment by 40 cache 1000 cycle ENGINE=MyISAM
SELECT NEXTVAL(d.s1),NEXTVAL(d.s2),NEXTVAL(d.s3), NEXTVAL(d.s4);
NEXTVAL(d.s1) NEXTVAL(d.s2) NEXTVAL(d.s3) NEXTVAL(d.s4)
100 200 300 400
......@@ -6443,7 +6443,7 @@ SETVAL(`s4`, 1401, 0)
1401
show create sequence d2.s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
s1 CREATE SEQUENCE `s1` as bigint start with 100 minvalue 100 maxvalue 1100 increment by 10 cache 1000 cycle ENGINE=MyISAM
drop sequence d.s1, d.s2, d.s3, d.s4;
drop database d;
drop database d2;
......
......@@ -14,7 +14,7 @@ next value for t1
alter sequence t1 start=50;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 50 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 50 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
2 1 9223372036854775806 50 1 0 0 0
......@@ -24,7 +24,7 @@ next value for t1
alter sequence t1 minvalue=-100;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 50 minvalue -100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 50 minvalue -100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3 -100 9223372036854775806 50 1 0 0 0
......@@ -33,14 +33,14 @@ ERROR HY000: Sequence 'test.t1' has out of range value for options
alter sequence t1 minvalue=100 start=100 restart=100;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 100 minvalue 100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 100 minvalue 100 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
100 100 9223372036854775806 100 1 0 0 0
alter sequence t1 maxvalue=500;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 100 minvalue 100 maxvalue 500 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 100 minvalue 100 maxvalue 500 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
100 100 500 100 1 0 0 0
......@@ -49,20 +49,20 @@ CREATE SEQUENCE t1 engine=myisam;
alter sequence t1 nocache;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
alter sequence t1 cache=100;
flush tables;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 100 nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 100 nocycle ENGINE=MyISAM
alter sequence t1 nocache;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
flush tables;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 1 9223372036854775806 1 1 0 0 0
......@@ -83,19 +83,19 @@ CREATE SEQUENCE t1 maxvalue=100 engine=myisam;
alter sequence t1 no maxvalue;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
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
alter sequence t1 cycle;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 cycle ENGINE=MyISAM
alter sequence t1 nocycle;
alter sequence t1 start=15 restart minvalue=10 maxvalue=20 cycle;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 15 minvalue 10 maxvalue 20 increment by 1 cache 1000 cycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 15 minvalue 10 maxvalue 20 increment by 1 cache 1000 cycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
15 10 20 15 1 1000 1 0
......@@ -129,7 +129,7 @@ CREATE SEQUENCE t1 maxvalue=100;
alter sequence t1 increment=-2 start with 50 minvalue=-100;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 50 minvalue -100 maxvalue 100 increment by -2 cache 1000 nocycle ENGINE=MyISAM
t1 CREATE SEQUENCE `t1` as bigint start with 50 minvalue -100 maxvalue 100 increment by -2 cache 1000 nocycle ENGINE=MyISAM
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
1 -100 100 50 -2 1000 0 0
......@@ -159,7 +159,7 @@ next value for t1
alter sequence t1 start=100;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 100 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=InnoDB
t1 CREATE SEQUENCE `t1` as bigint start with 100 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=InnoDB
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
11 1 9223372036854775806 100 1 10 0 0
......@@ -185,15 +185,15 @@ next value for t1
alter table t1 comment="foo";
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
alter table t1 engine=myisam;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='foo'
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM COMMENT='foo'
alter table t1 engine=innodb;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB COMMENT='foo'
select * from t1;
next_not_cached_value minimum_value maximum_value start_value increment cache_size cycle_option cycle_count
3001 1 9223372036854775806 1 1 1000 0 0
......
......@@ -12,7 +12,7 @@ select nextval(s1);
ERROR 42000: INSERT command denied to user 'normal_1'@'localhost' for table `s_db`.`s1`
show create sequence s1;
Table Create Table
s1 CREATE SEQUENCE `s1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
s1 CREATE SEQUENCE `s1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
alter sequence s1 restart 50;
ERROR 42000: ALTER command denied to user 'normal_1'@'localhost' for table `s_db`.`s1`
connection default;
......
......@@ -2,7 +2,7 @@ set @@default_storage_engine="aria";
CREATE SEQUENCE t1 cache=10;
show create sequence t1;
Table Create Table
t1 CREATE SEQUENCE `t1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=Aria
t1 CREATE SEQUENCE `t1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 10 nocycle ENGINE=Aria
select NEXT VALUE for t1,seq from seq_1_to_20;
NEXT VALUE for t1 seq
1 1
......
This diff is collapsed.
......@@ -109,6 +109,18 @@ show create sequence t1;
# NO MINVALUE, NO MAXVALUE
create or replace sequence t1 start with 10 NO MAXVALUE NO MINVALUE;
# Create with value types
create or replace sequence t1 as tinyint;
show create sequence t1;
create or replace sequence t1 as smallint;
show create sequence t1;
create or replace sequence t1 as mediumint;
show create sequence t1;
create or replace sequence t1 as int;
show create sequence t1;
create or replace sequence t1 as bigint;
show create sequence t1;
# Some edge cases
create or replace sequence t1 start with 10 maxvalue 10;
create or replace sequence t1 start with 10 minvalue 10;
......
......@@ -3,9 +3,9 @@ CREATE TABLE t1(a INT, KEY (a)) KEY_BLOCK_SIZE=1024;
insert into t1 values (1),(2);
CREATE SEQUENCE x1 engine=innodb;
# dump whole database
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
......@@ -18,9 +18,9 @@ INSERT INTO `t1` VALUES
(1),
(2);
# dump by tables order 1
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
......@@ -33,9 +33,9 @@ INSERT INTO `t1` VALUES
(1),
(2);
# dump by tables order 2
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
......@@ -59,9 +59,9 @@ INSERT INTO `t1` VALUES
(1),
(2);
# dump by tables only sequences
CREATE SEQUENCE `a1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
CREATE SEQUENCE `a1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=Aria;
SELECT SETVAL(`a1`, 1, 0);
CREATE SEQUENCE `x1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
CREATE SEQUENCE `x1` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB;
SELECT SETVAL(`x1`, 1, 0);
# end of dumps
DROP TABLE a1,t1,x1;
......
......@@ -149,7 +149,7 @@ CREATE TABLE `s2` (
) ENGINE=myisam DEFAULT CHARSET=latin1 sequence=1;
show create sequence s2;
Table Create Table
s2 CREATE SEQUENCE `s2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
s2 CREATE SEQUENCE `s2` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
drop sequence s2;
###########################################
select sequence syntax test
......@@ -188,7 +188,7 @@ alter table s2 rename to s2_1;
rename table s2_1 to s2_2;
show create sequence s2_2;
Table Create Table
s2_2 CREATE SEQUENCE `s2_2` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
s2_2 CREATE SEQUENCE `s2_2` as bigint start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=MyISAM
select * from s2_2;
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
......
......@@ -4,7 +4,7 @@ CREATE SEQUENCE s;
INSERT INTO s VALUES (1,1,4,1,1,1,0,0);
show create sequence s;
Table Create Table
s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 4 increment by 1 cache 1 nocycle ENGINE=MyISAM
s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 4 increment by 1 cache 1 nocycle ENGINE=MyISAM
SELECT NEXTVAL(s);
NEXTVAL(s)
1
......@@ -38,7 +38,7 @@ CREATE SEQUENCE s;
INSERT INTO s VALUES (1,1,3,1,1,1,1,0);
show create sequence s;
Table Create Table
s CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 3 increment by 1 cache 1 cycle ENGINE=MyISAM
s CREATE SEQUENCE `s` as bigint start with 1 minvalue 1 maxvalue 3 increment by 1 cache 1 cycle ENGINE=MyISAM
SELECT NEXTVAL(s);
NEXTVAL(s)
1
......
......@@ -30,15 +30,6 @@
#include "wsrep_mysqld.h"
#endif
struct Field_definition
{
const char *field_name;
uint length;
const Type_handler *type_handler;
LEX_CSTRING comment;
ulong flags;
};
/*
Structure for all SEQUENCE tables
......@@ -48,30 +39,61 @@ struct Field_definition
a column named NEXTVAL.
*/
#define MAX_AUTO_INCREMENT_VALUE 65535
Sequence_row_definition sequence_structure(const Type_handler* handler)
{
// We don't really care about src because it is unused in max_display_length_for_field().
const Conv_source src(handler, 0, system_charset_info);
const uint32 len= handler->max_display_length_for_field(src) + 1;
const LEX_CSTRING empty= {STRING_WITH_LEN("")};
#define FL (NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG)
return {{{"next_not_cached_value", len, handler, empty, FL},
{"minimum_value", len, handler, empty, FL},
{"maximum_value", len, handler, empty, FL},
{"start_value", len, handler,
{STRING_WITH_LEN("start value when sequences is created or value "
"if RESTART is used")}, FL},
{"increment", 21, &type_handler_slonglong,
{STRING_WITH_LEN("increment value")}, FL},
{"cache_size", 21, &type_handler_ulonglong, empty,
FL | UNSIGNED_FLAG},
{"cycle_option", 1, &type_handler_utiny,
{STRING_WITH_LEN("0 if no cycles are allowed, 1 if the sequence " "should begin a new cycle when maximum_value is " "passed")}, FL | UNSIGNED_FLAG},
{"cycle_count", 21, &type_handler_slonglong,
{STRING_WITH_LEN("How many cycles have been done")}, FL},
{NULL, 0, &type_handler_slonglong, {STRING_WITH_LEN("")}, 0}}};
#undef FL
}
static Field_definition sequence_structure[]=
bool sequence_definition::is_allowed_value_type(enum_field_types type)
{
{"next_not_cached_value", 21, &type_handler_slonglong,
{STRING_WITH_LEN("")}, FL},
{"minimum_value", 21, &type_handler_slonglong, {STRING_WITH_LEN("")}, FL},
{"maximum_value", 21, &type_handler_slonglong, {STRING_WITH_LEN("")}, FL},
{"start_value", 21, &type_handler_slonglong, {STRING_WITH_LEN("start value when sequences is created or value if RESTART is used")}, FL},
{"increment", 21, &type_handler_slonglong,
{STRING_WITH_LEN("increment value")}, FL},
{"cache_size", 21, &type_handler_ulonglong, {STRING_WITH_LEN("")},
FL | UNSIGNED_FLAG},
{"cycle_option", 1, &type_handler_utiny, {STRING_WITH_LEN("0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed")},
FL | UNSIGNED_FLAG },
{"cycle_count", 21, &type_handler_slonglong,
{STRING_WITH_LEN("How many cycles have been done")}, FL},
{NULL, 0, &type_handler_slonglong, {STRING_WITH_LEN("")}, 0}
};
switch (type)
{
case MYSQL_TYPE_TINY:
case MYSQL_TYPE_SHORT:
case MYSQL_TYPE_LONG:
case MYSQL_TYPE_INT24:
case MYSQL_TYPE_LONGLONG:
return true;
default:
return false;
}
}
#undef FL
Type_handler const *sequence_definition::value_type_handler()
{
return Type_handler::get_handler_by_field_type(value_type);
}
longlong sequence_definition::value_type_max()
{
return ~ value_type_min();
}
#define MAX_AUTO_INCREMENT_VALUE 65535
longlong sequence_definition::value_type_min() {
return ~0ULL << (8 * value_type_handler()->calc_pack_length(0) - 1);
}
/*
Check whether sequence values are valid.
......@@ -85,7 +107,7 @@ static Field_definition sequence_structure[]=
bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
{
longlong max_increment;
DBUG_ENTER("sequence_definition::check");
DBUG_ENTER("sequence_definition::check_and_adjust");
if (!(real_increment= increment))
real_increment= global_system_variables.auto_increment_increment;
......@@ -94,30 +116,30 @@ bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
If min_value is not set, set it to LONGLONG_MIN or 1, depending on
real_increment
*/
if (!(used_fields & seq_field_used_min_value))
min_value= real_increment < 0 ? LONGLONG_MIN+1 : 1;
if (!(used_fields & seq_field_specified_min_value))
min_value= real_increment < 0 ? value_type_min()+1 : 1;
/*
If max_value is not set, set it to LONGLONG_MAX or -1, depending on
real_increment
*/
if (!(used_fields & seq_field_used_max_value))
max_value= real_increment < 0 ? -1 : LONGLONG_MAX-1;
if (!(used_fields & seq_field_specified_max_value))
max_value= real_increment < 0 ? -1 : value_type_max()-1;
if (max_value == LONGLONG_MAX)
if (max_value >= value_type_max())
{
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_TRUNCATED_WRONG_VALUE,
ER_THD(thd, ER_TRUNCATED_WRONG_VALUE),
"INTEGER", "MAXVALUE");
max_value= LONGLONG_MAX - 1;
max_value= value_type_max() - 1;
}
if (min_value == LONGLONG_MIN)
if (min_value <= value_type_min())
{
push_warning_printf(
thd, Sql_condition::WARN_LEVEL_NOTE, ER_TRUNCATED_WRONG_VALUE,
ER_THD(thd, ER_TRUNCATED_WRONG_VALUE), "INTEGER", "MINVALUE");
min_value= LONGLONG_MIN + 1;
min_value= value_type_min() + 1;
}
if (!(used_fields & seq_field_used_start))
......@@ -136,14 +158,11 @@ bool sequence_definition::check_and_adjust(THD *thd, bool set_reserved_until)
llabs(real_increment) :
MAX_AUTO_INCREMENT_VALUE);
if (max_value >= start &&
max_value > min_value &&
start >= min_value &&
max_value != LONGLONG_MAX &&
min_value != LONGLONG_MIN &&
if (max_value >= start && max_value > min_value && start >= min_value &&
cache >= 0 && cache < (LONGLONG_MAX - max_increment) / max_increment &&
((real_increment > 0 && reserved_until >= min_value) ||
(real_increment < 0 && reserved_until <= max_value)))
(real_increment < 0 && reserved_until <= max_value)) &&
is_allowed_value_type(value_type))
DBUG_RETURN(FALSE);
DBUG_RETURN(TRUE); // Error
......@@ -165,6 +184,7 @@ void sequence_definition::read_fields(TABLE *table)
cache= table->field[5]->val_int();
cycle= table->field[6]->val_int();
round= table->field[7]->val_int();
value_type= table->field[0]->type();
dbug_tmp_restore_column_map(&table->read_set, old_map);
used_fields= ~(uint) 0;
print_dbug();
......@@ -210,10 +230,17 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
uint field_count;
uint field_no;
const char *reason;
Sequence_row_definition row_structure;
DBUG_ENTER("check_sequence_fields");
field_count= fields->elements;
if (field_count != array_elements(sequence_structure)-1)
if (!field_count)
{
reason= "Wrong number of columns";
goto err;
}
row_structure= sequence_structure(fields->head()->type_handler());
if (field_count != array_elements(row_structure.fields)-1)
{
reason= "Wrong number of columns";
goto err;
......@@ -236,7 +263,7 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
for (field_no= 0; (field= it++); field_no++)
{
Field_definition *field_def= &sequence_structure[field_no];
const Sequence_field_definition *field_def= &row_structure.fields[field_no];
if (my_strcasecmp(system_charset_info, field_def->field_name,
field->field_name.str) ||
field->flags != field_def->flags ||
......@@ -265,12 +292,12 @@ bool check_sequence_fields(LEX *lex, List<Create_field> *fields)
true Failure (out of memory)
*/
bool prepare_sequence_fields(THD *thd, List<Create_field> *fields)
bool sequence_definition::prepare_sequence_fields(List<Create_field> *fields)
{
Field_definition *field_info;
Sequence_field_definition *field_info;
DBUG_ENTER("prepare_sequence_fields");
for (field_info= sequence_structure; field_info->field_name ; field_info++)
for (field_info= sequence_structure(value_type_handler()).fields; field_info->field_name ; field_info++)
{
Create_field *new_field;
LEX_CSTRING field_name= {field_info->field_name,
......
......@@ -25,12 +25,34 @@
#define seq_field_used_cycle 32
#define seq_field_used_restart 64
#define seq_field_used_restart_value 128
#define seq_field_used_as 256
#define seq_field_specified_min_value 512
#define seq_field_specified_max_value 1024
/* Field position in sequence table for some fields we refer to directly */
#define NEXT_FIELD_NO 0
#define MIN_VALUE_FIELD_NO 1
#define ROUND_FIELD_NO 7
#include "mysql_com.h"
class Create_field;
class Type_handler;
struct Sequence_field_definition
{
const char *field_name;
uint length;
const Type_handler *type_handler;
LEX_CSTRING comment;
ulong flags;
};
struct Sequence_row_definition
{
Sequence_field_definition fields[9];
};
/**
sequence_definition is used when defining a sequence as part of create
*/
......@@ -40,7 +62,7 @@ class sequence_definition :public Sql_alloc
public:
sequence_definition():
min_value(1), max_value(LONGLONG_MAX-1), start(1), increment(1),
cache(1000), round(0), restart(0), cycle(0), used_fields(0)
cache(1000), round(0), restart(0), cycle(0), used_fields(0), value_type(MYSQL_TYPE_LONGLONG)
{}
longlong reserved_until;
longlong min_value;
......@@ -52,7 +74,13 @@ class sequence_definition :public Sql_alloc
longlong restart; // alter sequence restart value
bool cycle;
uint used_fields; // Which fields where used in CREATE
enum_field_types value_type; // value type of the sequence
Type_handler const *value_type_handler();
// max value for the value type, e.g. 32767 for smallint.
longlong value_type_max();
// min value for the value type, e.g. -32768 for smallint.
longlong value_type_min();
bool check_and_adjust(THD *thd, bool set_reserved_until);
void store_fields(TABLE *table);
void read_fields(TABLE *table);
......@@ -66,6 +94,9 @@ class sequence_definition :public Sql_alloc
reserved_until, start, increment, min_value,
max_value, cache, round));
}
static bool is_allowed_value_type(enum_field_types type);
bool prepare_sequence_fields(List<Create_field> *fields);
protected:
/*
The following values are the values from sequence_definition
......@@ -159,9 +190,6 @@ class SEQUENCE_LAST_VALUE
uchar table_version[MY_UUID_SIZE];
};
class Create_field;
extern bool prepare_sequence_fields(THD *thd, List<Create_field> *fields);
extern bool check_sequence_fields(LEX *lex, List<Create_field> *fields);
extern bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *table_list);
#endif /* SQL_SEQUENCE_INCLUDED */
......@@ -2694,6 +2694,8 @@ static int show_create_sequence(THD *thd, TABLE_LIST *table_list,
packet->append(STRING_WITH_LEN("CREATE SEQUENCE "));
append_identifier(thd, packet, &alias);
packet->append(STRING_WITH_LEN(" as "));
packet->append(seq->value_type_handler()->name().lex_cstring());
packet->append(STRING_WITH_LEN(" start with "));
packet->append_longlong(seq->start);
packet->append(STRING_WITH_LEN(" minvalue "));
......
......@@ -2433,8 +2433,8 @@ create:
}
/* No fields specified, generate them */
if (unlikely(prepare_sequence_fields(thd,
&lex->alter_info.create_list)))
if (unlikely(lex->create_info.seq_create_info->prepare_sequence_fields(
&lex->alter_info.create_list)))
MYSQL_YYABORT;
/* CREATE SEQUENCE always creates a sequence */
......@@ -2609,7 +2609,14 @@ sequence_defs:
;
sequence_def:
MINVALUE_SYM opt_equal ulonglong_num
AS int_type
{
if (unlikely(Lex->create_info.seq_create_info->used_fields &
seq_field_used_as))
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "AS"));
Lex->create_info.seq_create_info->value_type = $2->field_type();
}
| MINVALUE_SYM opt_equal ulonglong_num
{
if (unlikely(Lex->create_info.seq_create_info->used_fields &
seq_field_used_min_value))
......@@ -2619,6 +2626,7 @@ sequence_def:
else
Lex->create_info.seq_create_info->min_value= (longlong) $3;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_min_value;
}
| MINVALUE_SYM opt_equal minus_ulonglong_num
{
......@@ -2630,6 +2638,7 @@ sequence_def:
else
Lex->create_info.seq_create_info->min_value= - (longlong) $3;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_min_value;
}
| MINVALUE_SYM opt_equal DECIMAL_NUM
{
......@@ -2638,6 +2647,7 @@ sequence_def:
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
Lex->create_info.seq_create_info->min_value= LONGLONG_MAX;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_min_value;
}
| MINVALUE_SYM opt_equal '-' DECIMAL_NUM
{
......@@ -2646,6 +2656,7 @@ sequence_def:
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MINVALUE"));
Lex->create_info.seq_create_info->min_value= LONGLONG_MIN;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_min_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_min_value;
}
| NO_SYM MINVALUE_SYM
{
......@@ -2669,6 +2680,7 @@ sequence_def:
else
Lex->create_info.seq_create_info->max_value= (longlong) $3;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_max_value;
}
| MAXVALUE_SYM opt_equal minus_ulonglong_num
{
......@@ -2680,6 +2692,7 @@ sequence_def:
else
Lex->create_info.seq_create_info->max_value= - (longlong) $3;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_max_value;
}
| MAXVALUE_SYM opt_equal DECIMAL_NUM
{
......@@ -2688,6 +2701,7 @@ sequence_def:
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
Lex->create_info.seq_create_info->max_value= LONGLONG_MAX;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_max_value;
}
| MAXVALUE_SYM opt_equal '-' DECIMAL_NUM
{
......@@ -2696,6 +2710,7 @@ sequence_def:
my_yyabort_error((ER_DUP_ARGUMENT, MYF(0), "MAXVALUE"));
Lex->create_info.seq_create_info->max_value= LONGLONG_MIN;
Lex->create_info.seq_create_info->used_fields|= seq_field_used_max_value;
Lex->create_info.seq_create_info->used_fields|= seq_field_specified_max_value;
}
| NO_SYM MAXVALUE_SYM
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment