Here pid generated a unique primary id for each player.
CREATE TABLE players_mv (pid UUID PRIMARY KEY, name text, age int, team text);
INSERT INTO players_mv (pid,name, age, team) VALUES (uuid(),'Mo Salah', 26, 'Liverpool');
INSERT INTO players_mv (pid,name, age, team) VALUES (uuid(),'Sadio Mane', 26, 'Liverpool');
INSERT INTO players_mv (pid,name, age, team) VALUES (uuid(),'Kylian Mbappe', 20, 'PSG');
INSERT INTO players_mv (pid,name, age, team) VALUES (uuid(),'Neymar', 26, 'PSG');
SELECT * FROM players_mv;
SELECT team, name, age FROM players_mv WHERE team = 'Liverpool';
CREATE MATERIALIZED VIEW player_by_team
AS SELECT name, age, team
FROM players_mv
WHERE team IS NOT NULL AND pid IS NOT NULL
PRIMARY KEY (team, pid);
team, it supports queries based on the players team. Try it
SELECT team, name, age FROM player_by_team WHERE team = 'Liverpool';
Why is the prefered over secondary indexes?
SELECT team, name, age FROM player_by_team WHERE age = 26;