Questions tagged [cardinality]

In data modeling, the cardinality of one data table with respect to another data table is a critical aspect of database design. Relationships between data tables define cardinality when explaining how each table links to another. In the relational model, tables can be related as any of: many-to-many, many-to-one (rev. one-to-many), or one-to-one. This is said to be the cardinality of a given table in relation to another.

In data modeling, the cardinality of one data table with respect to another data table is a critical aspect of database design. Relationships between data tables define cardinality when explaining how each table links to another.

In the relational model, tables can be related as any of: many-to-many, many-to-one (rev. one-to-many), or one-to-one. This is said to be the cardinality of a given table in relation to another.

Wikipedia article

274 questions
120
votes
18 answers

Is it possible to determine the number of elements of a c++ enum class?

Is it possible to determine the cardinality of a c++ enum class: enum class Example { A, B, C, D, E }; I tried to use sizeof, however, it returns the size of an enum element. sizeof(Example); // Returns 4 (on my architecture) Is there a standard…
bquenin
  • 1,470
  • 2
  • 12
  • 12
107
votes
6 answers

What is cardinality in Databases?

Could somebody explain to me, with the help of examples, what is cardinality in databases?
Some Body
  • 1,881
  • 4
  • 19
  • 16
60
votes
5 answers

Does it make sense to use an index that will have a low cardinality?

From my understanding you don't gain much by setting an index in a column that will hold few distinct values. I have a column that holds a boolean value (actually it's a small int, but I'm using it as a flag), and this column is used in the WHERE…
Juan Pablo Califano
  • 12,213
  • 5
  • 29
  • 42
29
votes
4 answers

What is the definition of cardinality in SQL

My school book Database Systems defines cardinality as follows: The cardinality of a relation is the number of tuples it contains. By contrast, the number of tuples is called the cardinality of the relation and this changes as tuples are added or…
Tobias Schultz
  • 301
  • 1
  • 3
  • 4
28
votes
3 answers

How to *really* write UML cardinalities?

I would like to know once and for all how to write UML cardinalities, since I very often had to debate about them (so proofs and sources are very welcome :) If I want to explain that a Mother can have several Children but a Child has one and only…
sp00m
  • 47,968
  • 31
  • 142
  • 252
23
votes
1 answer

MySQL index cardinality - performance vs storage efficiency

Say you have a MySQL 5.0 MyISAM table with 100 million rows, with one index (other than primary key) on two integer columns. From my admittedly poor understanding of B-tree structure, I believe that a lower cardinality means the storage efficiency…
Sean
  • 781
  • 1
  • 4
  • 14
20
votes
4 answers

Why is using dplyr pipe (%>%) slower than an equivalent non-pipe expression, for high-cardinality group-by?

I thought that generally speaking using %>% wouldn't have a noticeable effect on speed. But in this case it runs 4x slower. library(dplyr) library(microbenchmark) set.seed(0) dummy_data <- dplyr::data_frame( id=floor(runif(10000, 1, 10000)) …
logworthy
  • 1,218
  • 2
  • 11
  • 23
16
votes
2 answers

How do you count cardinality of very large datasets efficiently in Python?

I have been playing at work with some very very large sets of data, typically several billions of elements, that are all maintained in a memcached cloud and periodically dumped into files, and for one of my tasks I'm trying to count the cardinality…
Charles Menguy
  • 40,830
  • 17
  • 95
  • 117
14
votes
2 answers

Is NULL cardinality in an index a problem - MySQL 5.x

I'm having performance problems on the live version of a system which I can't reproduce locally. In comparing a few EXPLAIN results on my local copies of the database with the live one, I note that multi-field indexes aren't used in some places on…
taliesinnuin
  • 189
  • 1
  • 5
12
votes
1 answer

high and low cardinality in Cassandra

I keep coming across these terms: high cardinality and low cardinality in Cassandra. I don't understand what exactly they mean. what effects they have on queries and what is preferred. Please explain with example since that will be be easy to…
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
11
votes
4 answers

PostgreSQL: How to implement minimum cardinality?

As answered in this question: Cardinality in PostgreSQL, cardinality is enfforced using constraints. Cardinality rules define the allowable counts of the relationships – one-to-many, many-to-many, etc. Many-to-many is achieved using join-tables and…
user1144616
  • 1,201
  • 2
  • 15
  • 16
10
votes
2 answers

Why does the cardinality of an index in MySQL remain unchanged when I add a new index?

I have added a FULLTEXT index to one of my MySQL database tables as follows: ALTER TABLE members ADD FULLTEXT(about,fname,lname,job_title); The problem is that using phpmyadmin I can see the cardinality of my new index is only 1. Does this mean the…
Tom
  • 14,041
  • 16
  • 64
  • 80
10
votes
3 answers

is there an ordinal to cardinal function in ruby or rails?

I'm trying to find a better way in expressing my cucumbers so I am looking for an ordinal to cardinal function that converts this: When I fill up the first passenger field Then I should see the passenger list update with the first passenger…
corroded
  • 21,406
  • 19
  • 83
  • 132
10
votes
1 answer

Difference between cardinality "*", and "0..*" - UML

What's the difference between the operator * and the operator 0..* in UML (unified modeling language)? I saw this two cardinality operators, but I don't now which one I must to use.
guisantogui
  • 4,017
  • 9
  • 49
  • 93
10
votes
1 answer

Why cardinality value in mysql indexes don't equal distinct count for column values

Not a long ago I started to optimize queries for mysql db. I created some indexes and decided to see their params, using show index from syntax. And saw that cardinality doesn't equal distinct count for some columns. So, I have the table CREATE…
Andrej Soroj
  • 1,103
  • 1
  • 9
  • 10
1
2 3
18 19