Misplaced Pages

Data orientation

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Tabular data representation in memory

Data orientation refers to how tabular data is represented in a linear memory model such as in-disk or in-memory.The two most common representations are column-oriented (columnar format) and row-oriented (row format).

The choice of data orientation is a trade-off and an architectural decision in databases, query engines, and numerical simulations. As a result of these tradeoffs, row-oriented formats are more commonly used in Online transaction processing (OLTP) and column-oriented formats are more commonly used in Online analytical processing (OLAP).

Examples of column-oriented formats include Apache ORC, Apache Parquet, Apache Arrow, formats used by BigQuery, Amazon Redshift and Snowflake. Predominant examples of row-oriented formats include CSV, formats used in most relational databases, in-memory format of Apache Spark, and Apache Avro.

Description

Tabular data is two dimensional in nature - data is represented in rows and columns. However, modern operating systems logically represent data in a linear memory model, both in-disk and in-memory. Therefore, a table in a linear memory model requires projecting its two-dimensional items in a one-dimensional space. Data orientation refers to the decision taken in this projection. There are two prominent choices of orientation: row-oriented and column-oriented.

Row-oriented

In row-oriented, the elements of the table

column 1 column 2 column 3
item 11 item 12 item 13
item 21 item 22 item 23

are stored linearly as

item 11 item 12 item 13 item 21 item 22 item 23

I.e. each row of the table is located one after the other. In this orientation, values on the same row are close in space (e.g. similar address in an addressable space).

Examples

Column-oriented

In column-oriented, the elements of the table

column 1 column 2 column 3
item 11 item 12 item 13
item 21 item 22 item 23

are stored linearly as

item 11 item 21 item 12 item 22 item 13 item 23

I.e. each column of the table is located one after the other. In this orientation, values on the same column are close in space (e.g. similar address in an addressable space).

Examples

See list of column-oriented DBMSes for more examples.

Tradeoff

The data orientation is an important architectural decision of systems handling data because it results in important tradeoffs in performance and storage. Below are selected dimensions of this tradeoff.

Random access

Row-oriented benefits from fast random access of rows. Column-oriented benefits from fast random access of columns. In both cases, this is the result of fewer page or cache misses when accessing the data.

Insert

Row-oriented benefits from fast insertion of a new row. Column-oriented benefits from fast insertion of a new column.

This dimension is an important reason why row-oriented formats are more commonly used in Online transaction processing (OLTP), as it results in faster transactions in comparison to column-oriented.

Conditional access

Row-oriented benefits from fast access under a filter. Column-oriented benefits from fast access under a projection.

Compute performance

Column-oriented benefits from fast analytics operations. This is the result of being able to leverage SIMD instructions.

Uncompressed size

Column-oriented benefits from smaller uncompressed size. This is the result of the possibility that this orientation offers to represent certain data types with dedicated encodings.

For example, a table of 128 rows with a Boolean column requires 128 bytes a row-oriented format (one byte per Boolean) but 128 bits (16 bytes) in a column-oriented format (via a bitmap). Another example is the use of run-length encoding to encode a column.

Compressed size

Column-oriented benefits from smaller compressed size. This is the result of a higher homogeneity within a column than within multiple rows.

Conversion and interchange

Because both orientations represent the same data, it is possible to convert a row-oriented dataset to a column-oriented dataset and vice-versa at the expense of compute. In particular, advanced query engines often leverage each orientation's advantages, and convert from one orientation to the other as part of their execution. As an example, an Apache Spark query may

  1. read data from Apache Parquet (column-oriented)
  2. load it into Spark internal in-memory format (row-oriented)
  3. convert it to Apache Arrow for a specific computation (column-oriented)
  4. write it to Apache Avro for streaming (row-oriented)

References

  1. ^ Abadi, Daniel J.; Madden, Samuel R.; Hachem, Nabil (2008). "Column-stores vs. Row-stores: How different are they really?". Proceedings of the 2008 ACM SIGMOD international conference on Management of data. pp. 967–980. doi:10.1145/1376616.1376712. ISBN 978-1-60558-102-6.
  2. ^ Funke, Florian; Kemper, Alfons; Neumann, Thomas (2012). "Compacting Transactional Data in Hybrid OLTP&OLAP Databases". Proceedings of the VLDB Endowment. 5 (11): 1424–1435. doi:10.14778/2350229.2350258.
  3. ^ "Apache ORC". Retrieved 2024-05-21.
  4. ^ "Apache Parquet". Retrieved 2024-05-21.
  5. ^ "Apache Arrow". Retrieved 2024-05-21.
  6. "Apache Avro". Retrieved 2024-05-21.
  7. Richard, Golden G.; Case, Andrew (2014). "In lieu of swap: Analyzing compressed RAM in Mac OS X and Linux". Digital Investigation. 11: S3–S12. doi:10.1016/j.diin.2014.05.011.
  8. ^ M. Frans Kaashoek, Jerome H. Saltzer (2009). Principles of Computer System Design. Morgan Kaufmann. ISBN 978-0-12-374957-4.
  9. "Chapter 4 Process Address Space (Linux kernel documentation)". Retrieved 2024-05-21.
Database models
Common models
Other models
Implementations
Category: