Skip to content
Advertisement

SQLite: optimize query with union

This is my table definition:

And this is my query + plan:

So the index is used, but there is still a scan and a b-tree involved in the order by. I tried getting rid of them by adding more indexes, but I don’t get it working.

Any ideas of an index which gets rid of the scan?

Advertisement

Answer

Your query can be simplified to:

and the query plan will be:

I don’t see how you can get better than B-TREE in the ORDER BY clause since you are using a custom expression to sort by.

See the demo.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement