-
Notifications
You must be signed in to change notification settings - Fork 0
N1QL queries and indices
This file documents the N1QL queries being used in the application and the indices required to make them work
SELECT authToken.*
FROM `dashboard-data` AS authToken
WHERE authToken.type = 'AuthToken'
AND authToken.userId = <userId>
CREATE INDEX `IDX_userId` ON `dashboard-data`(`userId`)
This index covers the userId
property on all documents including those of the Auth Token type.
SELECT b.*
FROM `dashboard-data` AS b
WHERE firstName = <first name>
AND lastName = <last name>
AND email = <email address>
CREATE INDEX `IDX_email` ON `dashboard-data`(`email`)
The email
property is sufficient to cover documents needed to be queried by this query.
Also, only User documents have the email
property so no need to make it a partial index to limit the documents indexed.
SELECT b.* FROM `%s` AS b WHERE email = <email address>
See above
See above
SELECT club.id AS clubId,
club.name,
club.logo,
club.createdDate
FROM `dashboard-data` AS club
WHERE club.type = 'Club'
AND club.userId = <userId>
Same as the index used when fetching auth token data. Since userId
is covered for all documents, it is covered for this query as well.
SELECT player.metadata.name,
player.metadata.country,
player.id,
player.metadata.countryLogo AS countryFlag,
player.ability.`current` AS currentAbility,
player.roles,
matchPerformance.matchRating.history AS matchRatingHistory
FROM `dashboard-data` player
JOIN `dashboard-data` matchPerformance ON player.id = matchPerformance.playerId
WHERE player.type = 'Player'
AND matchPerformance.type = 'MatchPerformance'
AND player.clubId = <clubId>
CREATE INDEX `IDX_playerId` ON `dashboard-data`(`playerId`) WHERE (`type` = "MatchPerformance")
This index covers the playerId
property on documents of type MatchPerformance. It is mandatory since we need to cover the keys on the RHS on an ANSI join.
SELECT club.userId
FROM `dashboard-data` AS player
JOIN `dashboard-data` AS club ON player.clubId = club.id
WHERE club.type = 'Club'
AND player.type = 'Player'
AND player.id = <playerId>
1. CREATE INDEX `IDX_playerClubId` ON `dashboard-data`(`clubId`) WHERE (`type` = "Player")
2. CREATE INDEX `IDX_clubId` ON `dashboard-data`(`id`) WHERE (`type` = "Club")
The first index covers the clubId property in documents of type Player
and the second one covers the id property in documents of type Club
.
The latter is mandatory since we need to cover the keys on the RHS on an ANSI join.
SELECT club.userId
FROM `dashboard-data` AS boardObjective
JOIN `dashboard-data` AS club ON boardObjective.clubId = club.id
WHERE club.type = 'Club'
AND boardObjective.type = 'BoardObjective'
AND boardObjective.id = <boardObjectiveId>
1. CREATE INDEX `IDX_boardObjectiveClubId` ON `dashboard-data`(`clubId`) WHERE (`type` = "BoardObjective")
2. CREATE INDEX `IDX_clubId` ON `dashboard-data`(`id`) WHERE (`type` = "Club")
Similar to the IDX_playerClubId index, the first one covers the clubId property in documents of type BoardObjective
.
The second one covers the id property in documents of type Club and is mandatory for the same reasons as mentioned above.
SELECT boardObjective.*
FROM `dashboard-data` AS boardObjective
WHERE boardObjective.type = 'BoardObjective'
AND boardObjective.clubId = <clubId>
The IDX_boardObjectiveId index is used here to cover the properties used in the WHERE clause.