Content Deep Dive
Should I Use the Primary Key in All Queries? How Will I Find the Right Tablet Without the Primary Key?
Blog post from Yugabyte
Post Details
Company
Date Published
Author
Marko Rajcevic
Word Count
421
Language
English
Hacker News Points
-
Source URL
Summary
If you're using a table in YugabyteDB, the system automatically assigns a key to it, whether user-defined or not. When querying this table, specifying the primary key can significantly improve performance by avoiding a sequential scan of all rows. On the other hand, if the primary key is not specified, YugabyteDB will perform a full scan, which can incur heavy latencies and slow down query execution. To optimize query performance, it's recommended to create a primary key for user-defined tables and consider creating indexes on additional columns or using the INCLUDE *keyword* when necessary.