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

Updated primary key performance guidance #8756

Merged
merged 1 commit into from
Oct 28, 2020
Merged

Conversation

ericharmeling
Copy link
Contributor

Fixes #3420.
Fixes #4911.

  • Added new "Performance considerations" section to the Primary Key Constraint page.
  • Linked to the "Performance considerations" section to the Primary Key Constraint page and the SQL Performance Best Practices page from the CREATE TABLE page.
  • Some other misc updates.

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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

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:

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: 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?

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 @ajwerner ! Please review the latest commit.

Reviewable status: :shipit: 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 the rowid value will be sequential in nature?

Sure. I added a little more to that section.

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:

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

Copy link
Contributor

@lnhsingh lnhsingh left a comment

Choose a reason for hiding this comment

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

:lgtm: (one small nit)

Reviewable status: :shipit: 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.,

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.

TFTRs!

Reviewable status: :shipit: 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.

@ericharmeling ericharmeling merged commit 69aebae into master Oct 28, 2020
@ericharmeling ericharmeling deleted the pk-performance branch October 28, 2020 13:53
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