I have started playing with the external index advisor. This leads to creating more indexes
However, then I would like to get rid of indexes that may not be used. The previous indexes have been created a while ago with more like a âguessâ approach (sometimes fueled by good advices here).
I suppose I shouldnât create a new index for each and every different type of query but ideally have some overlap - or what is the good advice?
A little more specific question about the index suggested by the advisor:
Here is an example. This query:
SELECT data.date,data.count,data.length
FROM data
WHERE type='Catch' AND year=2023
AND statslocation IN [ "150", "153", "647", "127", "605", "655", "641", "673", "597", "644", "643", "45", "671", "645", "8" ]
leads to a recommended index:
CREATE INDEX adv_type_year_statslocation ON `data`(`type`,`year`,`statslocation`)
I know that this index is only relevant for documents of type âCatchâ - so should I add a WHERE type='Catch'
phrase to the index creation statement - or doesnât it matter?
And another question/clarification. In the advisor I get this full response for the above query:
{
"results": [
{
"#operator": "Advise",
"advice": {
"#operator": "IndexAdvice",
"adviseinfo": {
"recommended_indexes": {
"covering_indexes": [
{
"index_statement": "CREATE INDEX adv_type_year_statslocation_date_count_length ON `data`(`type`,`year`,`statslocation`,`date`,`count`,`length`)",
"keyspace_alias": "data"
}
],
"indexes": [
{
"index_statement": "CREATE INDEX adv_type_year_statslocation ON `data`(`type`,`year`,`statslocation`)",
"keyspace_alias": "data",
"recommending_rule": "Index keys follow order of predicate types: 2. equality/null/missing, 3. in."
}
]
}
}
},
"query": "SELECT data.date,data.count,data.length\nFROM data\nWHERE type='Catch' AND year=2023\n AND statslocation IN [ \"150\", \"153\", \"647\", \"127\", \"605\", \"655\", \"641\", \"673\", \"597\", \"644\", \"643\", \"45\", \"671\", \"645\", \"8\" ]"
}
]
}
Does this mean that I should also create the first âcoveringâ index?