Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding INTERLEAVE in Cloud Spanner INDEX (indices)

What is difference between

CREATE INDEX SongsBySingerSongName 
          ON Songs(SingerId, SongName),
          INTERLEAVE IN Singers

and

CREATE INDEX SongsBySingerSongName 
          ON Songs(SingerId, SongName)
like image 874
Chipintoza Avatar asked Mar 08 '17 18:03

Chipintoza


People also ask

What is interleave in spanner?

There are two types of tables in Spanner: root tables (sometimes called top-level tables), and interleaved tables. Interleaved tables are defined by specifying another table as its parent, causing rows in the interleaved table to be clustered with the parent row.

How are secondary indexes stored?

Secondary indexes can be built for a column in a table. These indexes are stored locally on each node in a hidden table and built in a background process.

What is primary index and secondary index?

Definition. A primary index is an index on a set of fields that includes the unique primary key and is guaranteed not to contain duplicates. In contrast, a secondary index is an index that is not a primary index and may have duplicates.

What is an index explain its role in improving database access?

Indexes are used to quickly locate data without having to search every row in a database table every time a database table is accessed. Indexes can be created using one or more columns of a database table, providing the basis for both rapid random lookups and efficient access of ordered records.


1 Answers

Cloud Spanner will interleave the indexes entries in with the data table.

This means the SongsBySingerSongName index entries for each SingerId are colocated together.

From Spanner > Documentation > Data Definition Language :

Like interleaved tables, entries in an interleaved indexes are stored with the corresponding row of the parent table. See database splits for more details.

and

When should you create an interleaved index? If the index key that you want to use for index operations matches the key of a table, you might want to interleave the index in that table if the row in the table should have a data locality relationship with the corresponding indexed rows.

like image 148
Dan McGrath Avatar answered Sep 29 '22 07:09

Dan McGrath