我有一个包含超过 2.570.000 条记录的 SQLITE 表,我必须使用此查询来选择数据...
select * from table_1 where City = 'Roma' and dist <= 0
......这就是结果......
pgid City ptid osm_id name dist
4715 Roma 1 248528643 Pronto Soccorso Ospedale "Sandro Pertini" 0
4715 Roma 9 434692525 Aurelia Hospital 0
4715 Roma 24 1273194519 Pronto Soccorso Ospedale Oftalmico 0
4715 Roma 64 2318096925 Pronto Soccorso 0
4715 Roma 130 4839842653 Pronto Soccorso Policlinico Tor Vergata 0
4715 Roma 190 5220345821 Pronto Soccorso Ospedale Bambino Gesù 0
4715 Roma 192 5220405958 Pronto Soccorso CTO "Andrea Alesini" 0
4715 Roma 194 5220418538 Pronto Soccorso Ospedale "Cristo Re" 0
4715 Roma 197 5220461914 Pronto Soccorso Ospadale "Giovanni Battista Grassi" 0
4715 Roma 198 5220473819 Pronto Soccorso Ospedale "Madre G. Vannini" 0
4715 Roma 202 5222071850 Pronto Soccorso Policlinico "Agostino Gemelli" 0
4715 Roma 203 5222084908 Pronto Soccorso Policlinico Casilino 0
4715 Roma 206 5222104766 Pronto Soccorso Ospedale "San Camillo" 0
4715 Roma 207 5222113675 Pronto Soccorso Ospedale "San Filippo Neri" 0
4715 Roma 208 5222142783 Pronto Soccorso Ospedale "San Giovanni Calibita" 0
4715 Roma 213 5222229247 Pronto Soccorso Ospedale "Sant'Andrea" 0
4715 Roma 214 5222235383 Pronto Soccorso Ospedale "Sant'Eugenio" 0
它正在工作,但查询不是那么快(当我第一次进入 Sqlite 时有时会超过一分钟......),所以我必须对其进行优化。
我可以在某处创建索引吗?我可以用作唯一键的唯一字段是 osm_id 字段..所有其他字段都不是唯一的
我是 SQL 的新手,所以我需要一些建议/示例将不胜感激
对于此查询:
select *
from table_1
where City = 'Roma' and dist <= 0
您可以创建索引:
create index idx_table1_city_dist on table_1(city, dist);
索引中列的顺序很重要。city
必须是第一。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句