SQLite ORDER BY performance issue

落花浮王杯 提交于 2019-12-13 21:18:53

问题


I have a query with two joins (connecting three tables) that runs fairly fast (usually less than 1ms). If I sort the results based on an indexed column of any of the three tables, it still runs in less than 1 ms. However, when I use a combination of two columns (from two different tables) for sorting, the running time is around 240ms.

Do I need something like a composite index for columns from different tables? I assume this is not possible. Do I have to use indexed views to achieve a similar goal? Or, is there something wrong with my design?

I'm using SQLite, and this is what my query looks like:

SELECT image.title,
       project.title,
       video.title
FROM image
JOIN video ON image.video_id=video.id
JOIN project ON project.id=video.project_id
ORDER BY image.video_id,
         project.title LIMIT 5000;

回答1:


It is not possible to use indexes to speed up sorting by columns from two different tables.



来源:https://stackoverflow.com/questions/23302129/sqlite-order-by-performance-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!