[MDEV-10139] Support for SEQUENCE objects Created: 2016-05-27 Updated: 2023-11-13 Resolved: 2018-02-13 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Sequences |
| Fix Version/s: | 10.3.1 |
| Type: | Task | Priority: | Critical |
| Reporter: | Michael Widenius | Assignee: | Michael Widenius |
| Resolution: | Fixed | Votes: | 12 |
| Labels: | 10.3-beta | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Sub-Tasks: |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Epic Link: | Compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
Add support for SEQUENCES, like in PostgreSQL or Oracle:
See https://www.postgresql.org/docs/8.1/static/sql-createsequence.html The main part of the task is to add support for sequence tables in the storage engine interface. The main difference between transactional tables are only that they don't roll back when issuing a ROLLBACK statement. Example:
Supported statements:
|
| Comments |
| Comment by Alvin Richards (Inactive) [ 2016-12-08 ] | |||||||||||||||
|
Additional examples, combining sequences with expressions / functions
| |||||||||||||||
| Comment by Michael Widenius [ 2017-01-17 ] | |||||||||||||||
|
The idea I have, from the interface point of view, is to implement CREATE SEQUENCE foo; As internally do: CREATE TABLE foo (seq longlong) ROLLBACK=OFF; (The user will never see this syntax: The handler will get one new flag And implement all value handling in the SQL level, including value caching. What the engine needs to do is:
| |||||||||||||||
| Comment by Marko Mäkelä [ 2017-01-18 ] | |||||||||||||||
|
This is almost aligned with my thinking. I would prefer to omit the INSERT, and I would prefer to some other methods than handler::write_row() or handler::read*() to access the seqeuence object. I would like to see the proposed API. I think that the minimum that we need is a table entry (both a .frm file and InnoDB data dictionary records, with a flag identifying the table as a sequence pseudo-table. On disk, the data would look like an empty InnoDB table consisting of an empty clustered index root page where PAGE_ROOT_AUTO_INC (introduced in | |||||||||||||||
| Comment by Anders Karlsson [ 2017-01-31 ] | |||||||||||||||
|
If we want to be Oracle compatible, note that nextval is incremented at most once per row processed. This is rather odd and this isn't something used much I guess but it is worth noting and should possibly go into the documentation. See this example:
This will result in:
And not:
As you might be expecting. | |||||||||||||||
| Comment by Peter Gulutzan [ 2017-02-19 ] | |||||||||||||||
|
Regarding the comment from Mr Karlsson: Oracle's behaviour – incrementing once per row – is standard and I believe is what other DBMSs do – except PostgreSQL. PostgreSQL exposes a function so its behaviour is "once per invocation". | |||||||||||||||
| Comment by Anders Karlsson [ 2017-02-20 ] | |||||||||||||||
|
Peter is absolutely right that this is standard, and that is my mistake of not checking this first. SQL-2003 says this "If there are multiple instances of <next value expression>s specifying the same sequence generator within a single SQL-statement, all those instances return the same value for a given row processed by that SQL-statement.", also this is the behavior exposed by Oracle and SQL Server, as far as I can see. That said, I still think it is somewhat odd but makes some sense. My initial reaction to this was that if you wanted this behavior you really should use currval (which is the Oracle way of asking for the current value from a sequence, in SQL-2003 there is no such construct), but actually that would actually introduce a few issues. For example it would assume a particular execution order inside a particular SQL statement, so there is a reason why the SQL standard actually omits currval completely. Thanks Peter for catching this! | |||||||||||||||
| Comment by Marko Mäkelä [ 2017-03-24 ] | |||||||||||||||
|
alvinr, I do not know who will do the design review. I implemented the InnoDB part of this yesterday and slightly revised today. The InnoDB changes are almost trivial; the real work takes place above the storage engine layer. As far as I understood, the code by monty is still somewhat incomplete. | |||||||||||||||
| Comment by Michael Widenius [ 2017-03-26 ] | |||||||||||||||
|
First version of sequences is pushed to bb-10.2-sequence. It should be merged to bb-10.2-compatilbity and then to 10.3 shortly (1-2 weeks). What is working for the moment: CREATE OR REPLACE [TEMPORARY] SEQUENCE [IF NOT EXISTS] name SHOW CREATE SEQUENCE sequence_name; CREATE SEQUENCE is documented at: | |||||||||||||||
| Comment by Alexander Barkov [ 2017-04-09 ] | |||||||||||||||
|
Pushed into bb-10.2-ext. | |||||||||||||||
| Comment by Jérôme Brauge [ 2017-05-10 ] | |||||||||||||||
|
Hi, Example: ERROR 1030 (HY000): Got error 169 "Record was not update. Original values was same as new values" from storage engine InnoDB Regards. | |||||||||||||||
| Comment by Michael Widenius [ 2017-05-24 ] | |||||||||||||||
|
Still some work to be done. Current state is:
| |||||||||||||||
| Comment by Michaël de groot [ 2017-05-30 ] | |||||||||||||||
|
Cool!! I have a question about this, does auto_increment_increment and _offset change anything to sequence behaviour? I guess it could otherwise lead to conflicts in a multi-master cluster. | |||||||||||||||
| Comment by Michael Widenius [ 2017-06-06 ] | |||||||||||||||
|
Yes, auto_increment_increment and _offset will work for sequences defined with INCREMENT=0. | |||||||||||||||
| Comment by Michael Widenius [ 2017-06-06 ] | |||||||||||||||
|
About GRANT. Sequences uses normal table grants. To read from state of a sequence, one needs SELECT privilege, | |||||||||||||||
| Comment by Alexander Bienemann (Inactive) [ 2017-10-11 ] | |||||||||||||||
|
For migrations from Oracle: Access to SEQUENCE objects through migrated SYNONYM constructs should be checked, e.g. through FederatedX and VIEWs. | |||||||||||||||
| Comment by Michael Widenius [ 2018-02-13 ] | |||||||||||||||
|
Pushed into 10.3 tree a long time ago |