My function creates filtering query from following dictionary input with fixed ordered keys
input = {
"A": ["string"],
"B": [
"1234",
"4567"
],
"C": ["string"],
"D": ["string"]
}
Each keys represents column names of sqlite file and value is the values that want to filter. There is another column called idx
for index in sqlite db file.
I initially created indexes for all combinations of columns, but it's been pointed out that it's way too much (see my previous question for reference if you need)
The filtering query usually follows like these:
SELECT * FROM result_table WHERE idx >= 1900 AND (B in (1234)) LIMIT 100
SELECT * FROM result_table WHERE idx >= 1900 AND (B in (1234,5678)) LIMIT 100
SELECT * FROM result_table WHERE idx >= 1900 AND (B in (1234) and D in ('somestring')) LIMIT 100
SELECT * FROM result_table WHERE idx >= 1900 AND (B in (1234,5678)) ORDER BY A ASC, ORDER BY D DESC LIMIT 100
SELECT * FROM result_table WHERE idx >= 1900 AND (B in (1234,5678) and C in ('somestring2')) ORDER BY A ASC, ORDER BY C DESC LIMIT 100
and so on
so it's mix and match of single or multiple of WHERE and ORDER BY clauses
From the comments I got my previous question, I understood how I should create indexes when I don't use ORDER BY clause, but as I put ORDER BY, the query does not use any indexes I created.
The indexes I created are following:
(with/without idx)
(idx,) A, B, C, D
(idx,) A, C, D
(idx,) A, D
(idx,) B, C, D
(idx,) B, D
(idx,) C, D
(idx,) D
Which indexes I should create more to apply for query with combination of WHERE and ORDER BY clauses?