Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence caching and misc updates to SERIAL and CREATE/ALTER SEQUENCE pages #10219

Merged
merged 2 commits into from
Apr 21, 2021

Conversation

ericharmeling
Copy link
Contributor

Fixes #7741.
Fixes #10094.
Fixes #10093.
Coupled with cockroachdb/cockroach#62877.

This PR includes:

  • New SQL diagrams for CREATE SEQUENCE and ALTER SEQUENCE.
  • Updated examples and output for CREATE SEQUENCE and ALTER SEQUENCE pages.
  • Docs for sequence caching statement parameters and serial sequence caching session variables/cluster settings.

I intentionally did not include an example for sequence caching, as I am not sure how/that we expose cached values, through system catalogs or otherwise...

To this point, CACHE does not appear in the SHOW CREATE output:

> CREATE SEQUENCE cache_test CACHE 10;
> SHOW CREATE SEQUENCE cache_test;

  table_name |                                       create_statement
-------------+------------------------------------------------------------------------------------------------
  cache_test | CREATE SEQUENCE public.cache_test MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1
(1 row)

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ericharmeling ericharmeling requested a review from ajwerner April 1, 2021 14:48
@ericharmeling
Copy link
Contributor Author

@ajwerner
Adding you for review here, as you were the primary reviewer on cockroachdb/cockroach#56954.

@ajwerner
Copy link
Contributor

ajwerner commented Apr 1, 2021

Big yikes on not showing the cache value. Nice job finding that.

@ericharmeling
Copy link
Contributor Author

@ajwerner Ping on review

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: I'll backport the below PR into 21.1.1

cockroachdb/cockroach#63548

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

Copy link
Contributor

@ianjevans ianjevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some small nits and added links.

v20.1/serial.md Outdated

In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative feature, introduced in v2.0, is the [`SEQUENCE`](create-sequence.html).
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative feature is the [`SEQUENCE`](create-sequence.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative feature is the [`SEQUENCE`](create-sequence.html).
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative is to use [`SEQUENCE`](create-sequence.html).


In this example, we create a sequence that starts at -1 and descends in increments of 2.
In this example, we [create a table](create-table.html), using the `nextval()` function for a [default value](default-value.html), with the `customer_seq` sequence as its input:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this example, we [create a table](create-table.html), using the `nextval()` function for a [default value](default-value.html), with the `customer_seq` sequence as its input:
In this example, we [create a table](create-table.html), using the [`nextval()` function](functions-and-operators.html#sequence-functions) for a [default value](default-value.html), with the `customer_seq` sequence as its input:


### Set the next value of a sequence

In this example, we're going to change the next value of `customer_seq` using the `setval()` function. Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this example, we're going to change the next value of `customer_seq` using the `setval()` function. Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.
In this example, we're going to change the next value of `customer_seq` using the [`setval()` function](functions-and-operators.html#sequence-functions). Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.

v20.2/serial.md Outdated

In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative feature, introduced in v2.0, is the [`SEQUENCE`](create-sequence.html).
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative feature is the [`SEQUENCE`](create-sequence.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative feature is the [`SEQUENCE`](create-sequence.html).
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative is to use [`SEQUENCE`](create-sequence.html).


In this example, we create a sequence that starts at -1 and descends in increments of 2.
In this example, we [create a table](create-table.html), using the `nextval()` function for a [default value](default-value.html), with the `customer_seq` sequence as its input:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this example, we [create a table](create-table.html), using the `nextval()` function for a [default value](default-value.html), with the `customer_seq` sequence as its input:
In this example, we [create a table](create-table.html), using the [`nextval()` function](functions-and-operators.html#sequence-functions) for a [default value](default-value.html), with the `customer_seq` sequence as its input:


### Set the next value of a sequence

In this example, we're going to change the next value of `customer_seq` using the `setval()` function. Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In this example, we're going to change the next value of `customer_seq` using the `setval()` function. Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.
In this example, we're going to change the next value of `customer_seq` using the [`setval()` function](functions-and-operators.html#sequence-functions). Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.

Copy link
Contributor Author

@ericharmeling ericharmeling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR @ianjevans !

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ianjevans)


v20.1/serial.md, line 238 at r1 (raw file):

Previously, ianjevans (Ian Evans) wrote…
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative is to use [`SEQUENCE`](create-sequence.html).

Done.


v20.2/create-sequence.md, line 134 at r1 (raw file):

Previously, ianjevans (Ian Evans) wrote…
In this example, we [create a table](create-table.html), using the [`nextval()` function](functions-and-operators.html#sequence-functions) for a [default value](default-value.html), with the `customer_seq` sequence as its input:

Done.


v20.2/create-sequence.md, line 198 at r1 (raw file):

Previously, ianjevans (Ian Evans) wrote…
In this example, we're going to change the next value of `customer_seq` using the [`setval()` function](functions-and-operators.html#sequence-functions). Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.

Done.


v20.2/serial.md, line 228 at r1 (raw file):

Previously, ianjevans (Ian Evans) wrote…
In summary, the `SERIAL` type in PostgreSQL and CockroachDB, and the `AUTO_INCREMENT` type in MySQL, all behave the same in that they do not create strict sequences. CockroachDB will likely create more gaps than these other databases, but will generate these values much faster. An alternative is to use [`SEQUENCE`](create-sequence.html).

Done.


v21.1/create-sequence.md, line 134 at r1 (raw file):

Previously, ianjevans (Ian Evans) wrote…
In this example, we [create a table](create-table.html), using the [`nextval()` function](functions-and-operators.html#sequence-functions) for a [default value](default-value.html), with the `customer_seq` sequence as its input:

Done.


v21.1/create-sequence.md, line 198 at r1 (raw file):

Previously, ianjevans (Ian Evans) wrote…
In this example, we're going to change the next value of `customer_seq` using the [`setval()` function](functions-and-operators.html#sequence-functions). Currently, the next value will be `3` (i.e., `2` + `INCREMENT 1`). We will change the next value to `5`.

Done.

@ericharmeling ericharmeling merged commit aee7b84 into master Apr 21, 2021
@ericharmeling ericharmeling deleted the sequence-caching branch April 21, 2021 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants