TECHNOLOGIESTieInn Technologies

Columnar storage, partitioning, and clustering

Data Warehousing · 11 questions

Short notes

Key idea

Analytical queries read a few columns from many rows. Columnar storage stores each column together, so only needed columns are read and they compress well. Partitioning and clustering let the engine skip data entirely.

Syntax

  • Columnar: SELECT city, amount reads 2 columns out of 40.
  • Partitioning: split a table by a column, usually date (one partition per day). A filter on it prunes whole partitions.
  • Clustering: sort data within partitions by up to a few columns (customer_id, city) so blocks can be skipped.
CREATE TABLE sales.orders
PARTITION BY DATE(order_ts)
CLUSTER BY city, customer_id AS SELECT ...

Example

A 2 TB orders table partitioned by day: a query for last week with WHERE DATE(order_ts) >= ... reads 7 partitions, about 40 GB, not 2 TB.

Traps

  • SELECT * reads every column and costs the most.
  • Filtering on a function of the partition column can stop pruning in some engines.
  • Too many tiny partitions slow things down; partition by day or month, not by customer.
  • Cluster on columns you filter or join by, in order of how often.

Want the full lesson with step-by-step examples, a project and a certificate? Data Warehousing course, ₹120 →

Questions

5 free questions
5 questions

    Columnar storage, partitioning, and clustering

  1. Question 1easy

    A table has 50 columns. A query uses 3 of them. What does columnar storage let the warehouse do?

  2. Columnar storage, partitioning, and clustering

  3. Question 2medium

    In BigQuery, does SELECT * FROM big_table LIMIT 10 scan less data than SELECT * FROM big_table?

  4. Columnar storage, partitioning, and clustering

  5. Question 3hard

    A table is partitioned by DATE(order_ts). Which filter lets BigQuery prune partitions?

  6. Columnar storage, partitioning, and clustering

  7. Question 4medium

    Queries on fact_sales usually filter by customer_id or product_id. What should you cluster by?

  8. Columnar storage, partitioning, and clustering

  9. Question 5medium

    A BigQuery table has 60 columns of similar size. Query A selects 3 columns; query B is SELECT *. Roughly how do their bytes scanned compare?

6 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.