To avoid confusion, let's recreate the user_follows table with a different name:
CREATE TABLE "user_follows_base" ( "followed_username" text, "follower_username" text, PRIMARY KEY ("followed_username", "follower_username") );
Primarily, the preceding table lets us query the list of followers of a person. To query a list of persons someone is following, we created a secondary index earlier. Let's create a materialized view for the same:
CREATE MATERIALIZED VIEW "user_follows_view" AS SELECT followed_username, follower_username FROM "user_follows_base" WHERE follower_username IS NOT NULL AND followed_username IS NOT NULL PRIMARY KEY (follower_username, followed_username);
This CREATE MATERIALIZED VIEW statement has several ...