Commit b2f60ae
[Feature] Issue alibaba#41 Sequence Engine
Description:
------------
SEQUENCE engine as an embedded logical engine, it mainly used to generate unique number,
it is the middle layer engine that use InnoDB or other storage engine as the based table engine,
All query on sequence table will be changed into the operation on based table.
the cache or other sequence value management is decided by SEQUENCE engine handler.
According to the setting which is defined by 'CREATE SEQUENCE ... ' or 'CREATE SEQUENCE TABLE... + INSERT VALUES'.
user can query the nextval or currval from sequence.
In order to distinguish the normal SELECT statement, we supply new Syntax 'SELECT NEXTVAL FOR SEQUENCE';
1. 'SELECT NEXTVAL FROM SEQUENCE' will return the based table record directly.
2. 'SELECT NEXTVAL FOR SEQUENCE' will return the iteratored record.
Syntax:
-------
CREATE SEQUENCE SYNTAX:
CREATE SEQUENCE [IF NOT EXISTS] schema.sequence_name
[START WITH <constant>]
[MINVALUE <constant>]
[MAXVALUE <constant>]
[INCREMENT BY <constant>]
[CACHE <constant> | NOCACHE]
[CYCLE | NOCYCLE]
;
OR:
CREATE SEQUENCE schema.sequence_name (
`currval` bigint(21) NOT NULL COMMENT 'current value',
`nextval` bigint(21) NOT NULL COMMENT 'next value',
`minvalue` bigint(21) NOT NULL COMMENT 'min value',
`maxvalue` bigint(21) NOT NULL COMMENT 'max value',
`start` bigint(21) NOT NULL COMMENT 'start value',
`increment` bigint(21) NOT NULL COMMENT 'increment value',
`cache` bigint(21) NOT NULL COMMENT 'cache size',
`cycle` bigint(21) NOT NULL COMMENT 'cycle state',
`round` bigint(21) NOT NULL COMMENT 'already how many round'
) ENGINE=InnoDB DEFAULT CHARSET=latin1
INSERT INTO schema.sequence_name VALUES(0,0,1,9223372036854775807,1,1,10000,1,0);
COMMIT;
Strongly recommend the first CREATE SEQUENCE syntax.
SHOW SYNTAX:
SHOW CREATE SEQUENCE schema.sequence_name;
SHOW CREATE TABLE schema.sequence_name;
QUERY SYNTAX:
SELECT [nextval | currval | *] FOR schema.sequence_name;
SELECT [nextval | currval | *] FROM schema.sequence_name;
Usage:
------
FOR EXAMPLE:
create sequence s;
create table t(id int);
select nextval for s;
insert into t select nextval for s;1 parent 02a5207 commit b2f60ae
File tree
50 files changed
+6597
-17
lines changed- include
- mysql
- mysql-test
- r
- t
- mysys
- sql
- storage/innobase
- handler
- include
- lock
- trx
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
50 files changed
+6597
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
492 | 495 | | |
493 | 496 | | |
494 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
673 | 673 | | |
674 | 674 | | |
675 | 675 | | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
676 | 680 | | |
677 | 681 | | |
678 | 682 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
0 commit comments