Skip to content

Conversation

@rmloveland
Copy link
Contributor

This was not stated explicitly enough in the CREATE SEQUENCE docs and led to performance issues for a customer who had migrated from PG with sequence usage.

Fixes DOC-15768

This was not stated explicitly enough in the `CREATE SEQUENCE` docs and
led to performance issues for a customer who had migrated from PG with
sequence usage.

Fixes DOC-15768
@rmloveland rmloveland requested a review from jonstjohn January 6, 2026 20:40
@netlify
Copy link

netlify bot commented Jan 6, 2026

Deploy Preview for cockroachdb-api-docs canceled.

Name Link
🔨 Latest commit 46c0d0e
🔍 Latest deploy log https://app.netlify.com/projects/cockroachdb-api-docs/deploys/695eb4d5b6c4a400080f52e6

@netlify
Copy link

netlify bot commented Jan 6, 2026

Deploy Preview for cockroachdb-interactivetutorials-docs canceled.

Name Link
🔨 Latest commit 46c0d0e
🔍 Latest deploy log https://app.netlify.com/projects/cockroachdb-interactivetutorials-docs/deploys/695eb4d55a33200008f4deda

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Files changed:

@netlify
Copy link

netlify bot commented Jan 6, 2026

Netlify Preview

Name Link
🔨 Latest commit 46c0d0e
🔍 Latest deploy log https://app.netlify.com/projects/cockroachdb-docs/deploys/695eb4d577db1a00080e2423
😎 Deploy Preview https://deploy-preview-22039--cockroachdb-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

## Considerations

- Using a sequence is slower than [auto-generating unique IDs with the `gen_random_uuid()`, `uuid_v4()` or `unique_rowid()` built-in functions]({% link {{ page.version.version }}/sql-faqs.md %}#how-do-i-auto-generate-unique-row-ids-in-cockroachdb) and is likely to cause performance problems due to [hotspots]({% link {{ page.version.version }}/understand-hotspots.md %}). Incrementing a sequence requires a write to persistent storage, whereas auto-generating a unique ID does not. Therefore, use auto-generated unique IDs unless an incremental sequence is preferred or required. For more information, see [Unique ID best practices]({% link {{ page.version.version }}/performance-best-practices-overview.md %}#unique-id-best-practices).
- Using a sequence is slower than [auto-generating unique IDs with the `gen_random_uuid()`, `uuid_v4()` or `unique_rowid()` built-in functions]({% link {{ page.version.version }}/sql-faqs.md %}#how-do-i-auto-generate-unique-row-ids-in-cockroachdb) and is likely to cause performance problems due to [hotspots]({% link {{ page.version.version }}/understand-hotspots.md %}). Incrementing a sequence requires a write to persistent storage. In CockroachDB, all writes are [replicated and must reach a write quorum]({% link {{ page.version.version }}/architecture/replication-layer.md %}). This means that in [multi-region deployments]({% link {{ page.version.version }}/multiregion-overview.md %}), this can add cross-region latency (for example, in a [region survival]({% link {{ page.version.version }}/multiregion-survival-goals.md %}) configuration) and can become a throughput bottleneck for write-heavy workloads. Auto-generating a unique ID does not require a replicated write. Therefore, use auto-generated unique IDs unless an incremental sequence is preferred or required. For more information, see [Unique ID best practices]({% link {{ page.version.version }}/performance-best-practices-overview.md %}#unique-id-best-practices).
Copy link
Contributor

Choose a reason for hiding this comment

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

this lgtm!

it may be worth mentioning something about cached sequences too. something to the effect of: [Cached sequences](#link-to-cached-sequence-docs) can reduce the frequency of these writes, though gaps in sequence values may occur if cached values are lost

(These will perform better than normal sequences, but not as good as the ID generation functions)

@rmloveland
Copy link
Contributor Author

rmloveland commented Jan 7, 2026 via email

@rmloveland
Copy link
Contributor Author

PS @rafiss after docs team review I am planning to backport this change to the docs for all supported versions v23.2 and later - please let me know if you disagree for any reason! i suspect it's still true on those older versions too, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants