我的应用程序中有许多看起来像这样的查询;
SELECT DISTINCT STREET_NUMBER, STREET_NAME
FROM leads
WHERE STREET_NAME || ',' || SUBURB IN (select VAL from streetFilter)
AND USER_ID IN (%@)
AND TIMESTAMP >= '%@'
AND TIMESTAMP <= '%@'
AND GEO_LAT <> '0'
ORDER BY STREET_NAME, CAST(`STREET_NUMBER` AS SIGNED) ASC
我的问题是,我应该向哪些值或值集添加索引。
到目前为止,我刚刚添加了所有内容,即 CREATE INDEX temp ON 线索('见下文')
- (STREET_NUMBER,STREET_NAME)
- (街道,郊区)
- (STREET_NAME || ',' || 郊区)
- (用户身份)
- (时间戳)
- (GEO_LAT)
- (街道、郊区、USER_ID、TIMESTAMP、GEO_LAT)
- (STREET_NAME || ',' || SUBURB、USER_ID、TIMESTAMP、GEO_LAT)
- (街道名称)
- (街道号码)
- (演员(
STREET_NUMBER
已签名)) - (STREET_NAME,STREET_NUMBER)
- (STREET_NAME,演员(已
STREET_NUMBER
签名))
但我知道这不可能。谁能指出其中哪些不起作用或不会使我的查询更快,哪些会?
数据库是sqlite
我的创建语句:@“CREATE TABLE IF NOT EXISTS 线索(LEAD_ID BIGINT PRIMARY KEY, USER_ID INTEGER, GEO_LAT, GEO_LONG, CUSTOMER_NAME, UNIT_NUMBER, STREET_NUMBER, STREET_NAME, SUBURB, STATE, POSTCODE INTEGER, NMI, DPI_MIRN, STATUS, STATUS_INT INTEGER, OUTCOME INTEGER, OUTCOME_FULL INTEGER, FINAL_CODE INTEGER, NOTES, NOTES_EXTRA, TIMESTAMP)"];
719130;50;-32.933871;151.774978;Mr David Lee;1;34;LEMNOS PDE;NEWCASTLE;NSW;2300;;;P;0;0;;0;;0:0:0;20120602174036 719233;50;- 32.9307183;151.7803428;Mr Mitch James;1;1-7;TYRRELL ST;THE HILL;NSW;2300;;;P;0;0;;0;;0:0:0;20120602174036 719234;50;-32.933155; 151.777351;Ben Foster 先生;;4;BINGLE ST;NEWCASTLE;NSW;2300;41021027208;52404368858;C;0;0;;0;;0:0:0;20120602174036 719300;50;-32.9291125;151.785025;Mslyn; Rajakulenthiran;U 12;3;KING ST;NEWCASTLE;NSW;2300;;;P;0;0;;0;;0:0:0;20120602174036
查询现在是 SELECT LEAD_ID, USER_ID, UNIT_NUMBER, STREET_NUMBER, STREET_NAME, SUBURB, STATE, POSTCODE, STATUS_INT, OUTCOME, CUSTOMER_NAME, NOTES FROM Leads JOIN resultsFilter ON Leads.OUTCOME = 结果过滤器.VAL JOIN郊区过滤器打开线索.SUBPOST =郊区过滤器.VAL USER_ID IN (%@) AND TIMESTAMP BETWEEN '%@' AND '%@' ORDER BY SUBURB, STREET_NAME, CAST(STREET_NUMBER AS SIGNED)
我最初的情况仍然没有改善。似乎是最慢的顺序