← Back to team overview

maria-developers team mailing list archive

Re: MDEV-28152: Features for sequence

 

Hi Oleksandr,

Thanks for your comments. I am working through addressing them. I have
done one pass and working through a list of about a dozen tasks as a
result.

While most of the tasks seem to be straightforward, there's one thing I
would like to discuss, about a behaviour of sequences that exists before
my work on MDEV-28152. I came across this while addressing one of your
comments requesting adding tests.

Below are tested at commit ce4a289f1c3.

If you create a sequence, then select its next value, then alter it in
anyway, then select the next value again, it will skip everything before
the next_not_cached_value:

--8<---------------cut here---------------start------------->8---
create sequence s;
select next value for s; # 1
alter sequence s maxvalue cycle;
select next value for s; # 1001, because cache size is 1000 and reserved_until is 1001
drop sequence s;
--8<---------------cut here---------------end--------------->8---

This is a peculiar behaviour or a bug depending on how you see it,
whether you consider the alter action as sort of a "reset" similar to
server restart, and whether a "reset" like server restart should cause
the sequence to skip all values before the next not cached
value.

But it becomes worse when we throw in as <type> , because now it may
report error when the cache size is bigger than the type:

--8<---------------cut here---------------start------------->8---
create sequence s as tinyint;
select next value for s;
alter sequence s maxvalue 63;
select next value for s; # error: ER_SEQUENCE_RUN_OUT
drop sequence s;
--8<---------------cut here---------------end--------------->8---

A quick workaround would be having the default cache size depending on
the type, but I'm not sure if it is a good idea.

I think we need a consensus whether the reset-skip behaviour is (still)
ok. If we want to continue with this behaviour, then I suppose this
workaround may be ok. It will fix the error in the previous testcase but
still report error in the following case but we can say it is intended
given the cache size is too big after the alter which "resets" the
sequence.

--8<---------------cut here---------------start------------->8---
create sequence s;
select next value for s;
alter sequence s maxvalue 500;
select next value for s; # error: ER_SEQUENCE_RUN_OUT
drop sequence s;
--8<---------------cut here---------------end--------------->8---

If we want to make the sequence increment continuously without skipping,
then bigger changes are needed.

What do you think?

P.S. While testing with the above, I found something buggy in the
existing sequence implementation which I may also need to fix:

--8<---------------cut here---------------start------------->8---
create sequence s maxvalue 500;
select next value for s; # 1
alter sequence s cycle;
select next value for s; # still 1 (?!)
drop sequence s;
--8<---------------cut here---------------end--------------->8---

Best,
Yuchen


Follow ups

References