What is difference between
CREATE INDEX SongsBySingerSongName
ON Songs(SingerId, SongName),
INTERLEAVE IN Singers
and
CREATE INDEX SongsBySingerSongName
ON Songs(SingerId, SongName)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With