Skip to content

Commit 80a6518

Browse files
committed
Shorten popularity index names
PG automatically truncates long index names leading to conflicts during index creation in atomic table switches. To avoid these issues, shorten index names.
1 parent 5e5c086 commit 80a6518

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

listenbrainz/db/popularity.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def get_indices(self):
6464
else:
6565
prefix = "popularity"
6666
return [
67-
f"CREATE INDEX {prefix}_{self.entity}_listen_count_idx_{{suffix}} ON {{table}} (total_listen_count) INCLUDE ({self.entity_mbid})",
68-
f"CREATE INDEX {prefix}_{self.entity}_user_count_idx_{{suffix}} ON {{table}} (total_user_count) INCLUDE ({self.entity_mbid})",
69-
f"CREATE UNIQUE INDEX {prefix}_{self.entity}_{self.entity}_mbid_idx_{{suffix}} ON {{table}} ({self.entity}_mbid)"
67+
f"CREATE INDEX {prefix}_{self.entity}_lc_idx_{{suffix}} ON {{table}} (total_listen_count) INCLUDE ({self.entity_mbid})",
68+
f"CREATE INDEX {prefix}_{self.entity}_uc_idx_{{suffix}} ON {{table}} (total_user_count) INCLUDE ({self.entity_mbid})",
69+
f"CREATE UNIQUE INDEX {prefix}_{self.entity}_mbid_idx_{{suffix}} ON {{table}} ({self.entity}_mbid)"
7070
]
7171

7272

@@ -120,9 +120,9 @@ def get_indices(self):
120120
else:
121121
prefix = "popularity_top"
122122
return [
123-
f"CREATE INDEX {prefix}_{self.entity}_artist_mbid_listen_count_idx_{{suffix}} ON {{table}} (artist_mbid, total_listen_count) INCLUDE ({self.entity_mbid})",
124-
f"CREATE INDEX {prefix}_{self.entity}_artist_mbid_user_count_idx_{{suffix}} ON {{table}} (artist_mbid, total_user_count) INCLUDE ({self.entity_mbid})",
125-
f"CREATE UNIQUE INDEX {prefix}_{self.entity}_artist_mbid_idx_{{suffix}} ON {{table}} (artist_mbid, {self.entity_mbid})"
123+
f"CREATE INDEX {prefix}_{self.entity}_am_lc_idx_{{suffix}} ON {{table}} (artist_mbid, total_listen_count) INCLUDE ({self.entity_mbid})",
124+
f"CREATE INDEX {prefix}_{self.entity}_am_uc_idx_{{suffix}} ON {{table}} (artist_mbid, total_user_count) INCLUDE ({self.entity_mbid})",
125+
f"CREATE UNIQUE INDEX {prefix}_{self.entity}_am_idx_{{suffix}} ON {{table}} (artist_mbid, {self.entity_mbid})"
126126
]
127127

128128

0 commit comments

Comments
 (0)