Tim
Tim

Reputation: 99428

Can a key-value store and a relational table be converted to each other?

  1. Can a key-value store be converted into a relational table, where there are just two columns, with the primary key of the table being the "key" of the key-value store?
  2. Can a relational table be converted into a key-value store, where the key is the primary key, and the value is the other columns in the table?
  3. For example, Spanner is a columnary database. From https://research.google.com/archive/spanner-osdi2012.pdf, Why can Spanner be considered as a key-value store, not relational? I don't quite understand "rows must have names. More precisely, every table is required to have an ordered set of one or more primary-key columns"

    Spanner’s data model is not purely relational, in that rows must have names. More precisely, every table is required to have an ordered set of one or more primary-key columns. This requirement is where Spanner still looks like a key-value store: the primary keys form the name for a row, and each table defines a mapping from the primary-key columns to the non-primary-key columns. A row has existence only if some value (even if it is NULL) is defined for the row’s keys. Imposing this structure is useful because it lets applications control data locality through their choices of keys.

Upvotes: 0

Views: 358

Answers (1)

adi
adi

Reputation: 590

Re:3, The paper's assertion is that Spanner's data model cannot be considered 'Relational' in the strictest sense of the word because the Relational model has no notion of row names (i.e. primary keys). In the Relational model, a Relation is defined as a set of n-ary tuples. That means that a relation by definition cannot have duplicate rows and does not order its rows (a set cannot have duplicate elements and does not define any order between its elements), Therefore, in the Relational data model, a row name aka 'primary key' is not needed to identify a row (the entire row is basically a primary key) whereas Spanner requires every table(an RDBMS's approximation to the theoretical concept of a 'relation') to either have a unique primary key or have only a single row.

The requirement of having a 'row name' or 'key' is characteristic of a key-value store and therefore in that sense, Spanner can be thought of as a key-value store.

Upvotes: 1

Related Questions