-
Notifications
You must be signed in to change notification settings - Fork 469
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
Updated primary key performance guidance #8756
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r1.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @ericharmeling)
v20.1/primary-key.md, line 95 at r1 (raw file):
- Define a primary key for every table. If you create a table without defining a primary key, CockroachDB generates a unique identifier for each row, which it then uses for the `primary` index. Because you cannot meaningfully use this unique row identifier column to filter table data, it does not offer any performance optimization. This means you will always have improved performance by defining a primary key for a table. For more information, see our blog post [Index Selection in CockroachDB](https://www.cockroachlabs.com/blog/index-selection-cockroachdb-2/).
Can you mention that unique_rowid()
which is used to generate the rowid
value will be sequential in nature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR @ajwerner ! Please review the latest commit.
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner)
v20.1/primary-key.md, line 95 at r1 (raw file):
Previously, ajwerner wrote…
Can you mention that
unique_rowid()
which is used to generate therowid
value will be sequential in nature?
Sure. I added a little more to that section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @ajwerner and @ericharmeling)
v20.1/primary-key.md, line 97 at r2 (raw file):
If you create a table without defining a primary key, CockroachDB will automatically create a primary key over a hidden, [`INT`](int.html)-typed column named `rowid`. By default, sequential, unique identifiers are generated for each row in the `rowid` column with the [`unique_rowid()` function](functions-and-operators.html#built-in-functions). The sequential nature of the `rowid` values can lead to a poor distribution of the data across a cluster, which can negatively affect performance. Furthermore, because you cannot meaningfully use the `rowid` column to filter table data, the primary key index on `rowid` does not offer any performance optimization. This means you will always have improved performance by defining a primary key for a table. For more information, see our blog post [Index Selection in CockroachDB](https://www.cockroachlabs.com/blog/index-selection-cockroachdb-2/). - Define primary key constraints over multiple columns (i.e. use [composite primary keys](https://en.wikipedia.org/wiki/Composite_key)).
nit: i.e.,
1436b70
to
789403d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTRs!
Reviewable status: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @ajwerner)
v20.1/primary-key.md, line 97 at r2 (raw file):
Previously, lnhsingh (Lauren Hirata Singh) wrote…
nit:
i.e.,
Done.
Fixes #3420.
Fixes #4911.
Additional suggestions are welcome.
I'll propagate these changes to 20.2 when they are approved for 20.1.
@ajwerner Adding you for engineering review. If you think someone else should review this instead, please tag the appropriate engineer.