Book a Demo Start Instantly

Understanding the concept of cardinality in databases is crucial for designing efficient, reliable, and scalable data models. It has a profound impact on query performance, data integrity, and overall database design. But what exactly is cardinality, and why is it so important in databases? In this article, we’ll delve into the depths of cardinality, exploring its definition, types, and its importance in database systems, including distributed databases like TiDB.

Understanding Cardinality

Cardinality, in the realm of databases, refers to the uniqueness of data values that can be contained in a particular column. In essence, it’s a measure of the distinct values a column holds. High cardinality means that a column contains a large proportion of entirely unique values, whereas low cardinality indicates that the data within a column are more repeated and not as unique.

Cardinality in Data Modeling

In data modeling, cardinality is employed to describe the relationships between tables within a database. Understanding the cardinality between tables is pivotal in shaping the structure of a database and ensuring that the relationships between tables are accurately represented.

Cardinality in SQL

In SQL, cardinality influences how database systems execute queries. It plays a significant role in the query optimization process, helping the SQL engine decide the most efficient way to execute a query based on the distinctiveness of the data within the involved columns.

Cardinality in Distributed Databases

For distributed databases like TiDB, cardinality takes on an extra layer of complexity. High cardinality can be beneficial in distributed databases as it helps in evenly distributing data across multiple nodes, enhancing load balancing, reducing hotspots, and improving query performance.

High vs. Low Cardinality

High Cardinality Examples

  • User IDs: Typically, each user has a unique ID, resulting in high cardinality.
  • Email Addresses: Given their uniqueness, email addresses also exemplify high cardinality.

Low Cardinality Examples

  • Gender: A classic example of low cardinality, as the range of values is often limited to ‘male’, ‘female’, and sometimes ‘other’.
  • Marital Status: Similar to gender, marital status has limited options like ‘married’, ‘single’, ‘divorced’, contributing to low cardinality.

Types of Cardinality


A one-to-one relationship occurs when a record in one table is related to only one record in another table. This type could be used for storing sensitive information separately, such as storing user passwords in a distinct table from other user details.


This is the most common type of relationship, where a record in one table can be associated with one or more records in another table. An example is an e-commerce platform where a single customer (one) can place multiple orders (many).


In a many-to-many relationship, records in one table can relate to multiple records in another table and vice versa. A practical example would be the relationship between products and orders; a single product can appear in multiple orders, and an order can contain multiple products.

Importance of Cardinality

Query Performance

Understanding and optimizing cardinality can significantly impact query performance. High-cardinality columns are often indexed to expedite search operations, making the database’s response to queries faster and more efficient.

Data Integrity

Cardinality plays a role in maintaining the integrity of data within a database. By accurately modeling the relationships between tables according to their cardinality restrictions, it’s easier to maintain accurate and consistent data throughout the database.

Database Design

The consideration of cardinality is vital in database design. It influences the decisions on primary keys, indexing strategies, and the overall relational model. Correctly employing cardinality concepts ensures that the database is optimized for its intended use cases, providing both flexibility and scalability.

Understanding the nuanced role of cardinality in databases, including emerging distributed database technologies like TiDB, empowers developers and database architects to design robust, efficient, and scalable systems. By acknowledging the importance of cardinality in query performance, data integrity, and database design, you’re equipped to tackle the challenges of modern database applications, ensuring they’re not only performant but also reliable and scalable.

Last updated May 31, 2024

Spin up a Serverless database with 25GiB free resources.

Start Now