forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: make cached sequences bounds-related semantics match pg semantics
Previously, cached sequences did not obey pg semantics with respect to exceeding bounds. For example, if there were a sequence with a cache size of 5 and max value of 2, calling nextval(...) would immediately cause an error due to exceeded bounds. According to postgres, nextval(...) should return 1, then 2, then finally return an error due to the max value of 2 being reached. This change alters sequence caching behavior to match the above semantics. Additionally, this change now makes it possible for sequences to exceed the bounds set by MAXVALUE and MINVALUE. This is because calling nextval(...) should be as fast as possible, and the fastest way to do this is to let nextval(...) always succeed on incrementing a sequence. Despite this, a user will never see any values that exceed a sequence's bounds. To make a sequence incrementable again after exceeding its bounds, there are two options: 1. The user changes the sequence's value by calling setval(...). 2. The user performs a schema change to alter the sequences MinValue or MaxValue. If the value of a sequence exceeds its bounds, it must be restored to the original MinValue or MaxValue in the same transaction as the schema change. This change adds code to handle case 2 above. Release note: None
- Loading branch information
1 parent
4379fcf
commit 91c162a
Showing
3 changed files
with
275 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters