Degenerate dimension
A dimension key stored in the fact table with no dimension table behind it, such as an order number or invoice number. It identifies the transaction a row belongs to, and everything else about that transaction already lives in other dimensions.
Also: degenerate dimensions · DD · degenerate key
On this page · 7 sections
- Category
- Data modeling
- Also known as
- degenerate dimensions, DD, degenerate key
- Goes deeper in
- Data Modeling
A degenerate dimension is what remains of a transaction header once its contents have been modeled elsewhere. Take an order with several line items. The order's date, customer, and store each become a foreign key on every line row. After that, the only thing left that belongs to the order itself is its number, and a table holding nothing except that number would add a join and no information.
So the number stays in the fact table as a plain column. That is Ralph Kimball's definition: a dimension key kept in the fact table on purpose, with no dimension table to join to. Order numbers, invoice numbers, and ticket numbers are typical. He notes that they turn up mostly in transaction and accumulating snapshot fact tables.
The column earns its place. It groups the line rows of one order, which is how you count orders or compute an average order value from a line-level table. It is also the link back to the source system when someone needs to trace a figure to the original document.
create table fct_order_lines (
date_key integer not null, -- joins to dim_dates
customer_key integer not null, -- joins to dim_customers
product_key integer not null, -- joins to dim_products
order_number varchar(20) not null, -- degenerate dimension: no table to join
quantity integer not null,
line_amount numeric(10, 2) not null
);
select
order_number,
count(*) as order_lines,
sum(line_amount) as order_total
from fct_order_lines
group by order_number
order by order_number;Without the degenerate dimension, a line-level fact table cannot answer order-level questions. Counting distinct order numbers is the only way to know how many orders the lines add up to.
Recognizing the pattern saves a table. A dimension with one column and as many rows as there are transactions grows as fast as the fact table, and it costs every query an extra join that returns nothing new.
- Building a dimension table that holds only the order number. If the header has real attributes of its own, such as a payment terms code, those belong in a dimension, and the number still stays in the fact table.
- Counting rows and calling the result orders. A line-level table has one row per line, so the order count is the number of distinct order numbers.
- Dropping the number during modeling because it is not a measure and has no dimension, which removes the only path back to the source document.
- Why is it called a degenerate dimension?
- The word describes a dimension reduced to its simplest possible form. A normal dimension has a key plus descriptive attributes. Here the attributes have all been moved into other dimensions, so nothing is left except the key, and that key is stored in the fact table instead of in a table of its own.
- Is a degenerate dimension a foreign key?
- No. A foreign key points to a row in another table, and a degenerate dimension has no table to point to. It is an identifier carried over from the source system, such as an order number. In an order-line table, the order number combined with a line number identifies exactly one row.
- Should an order number be a dimension or a fact?
- Neither in the usual sense. It is not a fact, because adding order numbers together means nothing, and it does not need a dimension table, because it has no attributes. Keep it as a degenerate dimension column in the fact table and use it to group lines or count distinct orders.
