Skip to content

Commit f462564

Browse files
fix: add index for session_info on user_id, app_id (#246)
* fix: add index for session_info on user_id, app_id * Update CHANGELOG.md --------- Co-authored-by: Sattvik Chakravarthy <[email protected]>
1 parent d77cf3b commit f462564

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111

1212
- Adds tables and queries for Bulk Import
1313
- Optimize getUserIdMappingWithEitherSuperTokensUserIdOrExternalUserId query
14+
- Adds indexing for `session_info` table on `user_id, app_id` columns
1415

1516
### Migration
1617

@@ -34,6 +35,8 @@ CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index1 ON bulk_import_us
3435
id DESC);
3536
3637
CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index2 ON bulk_import_users (app_id, created_at DESC, id DESC);
38+
39+
CREATE INDEX IF NOT EXISTS session_info_user_id_app_id_index ON session_info (user_id, app_id);
3740
```
3841
3942
## [7.2.0] - 2024-10-03

src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public static void createTablesIfNotExists(Start start, Connection con) throws S
335335

336336
// index
337337
update(con, getQueryToCreateSessionExpiryIndex(start), NO_OP_SETTER);
338+
update(con, getQueryToCreateSessionAppIdUserIdIndex(start), NO_OP_SETTER);
338339
update(con, getQueryToCreateTenantIdIndexForSessionInfoTable(start), NO_OP_SETTER);
339340
}
340341

src/main/java/io/supertokens/storage/postgresql/queries/SessionQueries.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ static String getQueryToCreateSessionExpiryIndex(Start start) {
100100
+ Config.getConfig(start).getSessionInfoTable() + "(expires_at);";
101101
}
102102

103+
static String getQueryToCreateSessionAppIdUserIdIndex(Start start) {
104+
return "CREATE INDEX IF NOT EXISTS session_info_user_id_app_id_index ON "
105+
+ Config.getConfig(start).getSessionInfoTable() + "(user_id, app_id);";
106+
}
107+
103108
public static void createNewSession(Start start, TenantIdentifier tenantIdentifier, String sessionHandle,
104109
String userId, String refreshTokenHash2,
105110
JsonObject userDataInDatabase, long expiry, JsonObject userDataInJWT,

0 commit comments

Comments
 (0)