云数据库 GEMINIDB-如何使用二级索引:二级索引原理

时间:2023-11-22 09:19:08

二级索引原理

二级索引的实现其实就是创建一张隐式的表,该表的Primary Key是创建索引的列,该表的值是原表的Primary Key。

假设有一张playlists表,表结构如下:

CREATE TABLE playlists (
id int,
song_id int,
song_order int,
album text,
artist text,
title text,
PRIMARY KEY (id, song_id));

查询结果如下:

图1 查询结果

如果对artist字段建立索引,则索引隐式的表的结构如下所示:

图2 查询结果

其中,artist是索引表的Primary Key,id列、song_id列是索引表的普通列,即原表的Primary Key。

support.huaweicloud.com/cassandraug-nosql/cassandra_faq_0009.html