Could anyone help? I have a a query that doesn’t want to hit my tailored index. Below is the query I’m running and the index it should be hitting and also the index that gets hit instead.
Below is my query:
SELECT a.*
FROM assets a
WHERE ANY name IN SUFFIXES(LOWER(a.displayName)) SATISFIES name LIKE ‘metadata%’ END
AND a.type = ‘asset’
AND a.workspaceId IN [102,103]
ORDER BY a.createdOn DESC
LIMIT 5000
Index:
CREATE INDEX asset-search ON assets((distinct (array name for name in suffixes(lower(displayName)) end)),workspaceId,type,createdOn) WHERE (type = “asset”)
Hits this index instead:
CREATE INDEX asset-workspaceId ON assets(workspaceId) WHERE ((self.type) = “asset”)
Post the EXPLAIN. It should have used asset-search.
Also try with
SELECT a.*
FROM asset a USE INDEX (`asset-search` )
WHERE ANY name IN SUFFIXES(LOWER(a.displayName)) SATISFIES name LIKE "metadata%" END
AND a.type = "asset"
AND a.workspaceId IN [102,103]
ORDER BY a.createdOn DESC
LIMIT 5000;
If u need SUFFIXES only when you have leading wildcard characters.
Post exact Index definition of asset-search. If use index not using means it is not qualified. Go to UI and Indexes and post the definition from there. Or
select * from system:indexes where name = “asset-search”;
CREATE INDEX 'asset-search' ON assets ((distinct (array 'name' for 'name' in suffixes(lower('displayName')) end)),'workspaceId','type','createdOn') WHERE ('type' = "asset")
CREATE INDEX `asset-search` ON assets((distinct (array name for name in suffixes(lower(displayName)) end)),workspaceId,type,createdOn)
WHERE (type = "asset");
CREATE INDEX `asset-search` ON `assets`((distinct (array `name` for `name` in suffixes(lower(`displayName`)) end)),`workspaceId`,`type`,`createdOn`) WHERE (`type` = "asset")
So recreating the asset-search index worked, but the strange thing is that this actually worked on initial setup and then a few days later it stopped working.