选择查询加入是从android中的数据库慢慢选择数据

时间:2012-03-27 12:13:44

标签: android sqlite

我有选择查询如下

SELECT DISTINCT tt.firstname, 
                tt.lastname, 
                tc.caseid, 
                tt.courtcode                AS courtid, 
                tcou.courtname, 
                (SELECT COUNT(*) 
                 FROM   tblcasetrafficticketlink 
                 WHERE  caseid = tc.caseid) AS ticketcount, 
                Max(tt.violationdate)       AS violationdate, 
                ( tt.address1 
                   || ',' 
                   || tt.address2 )         AS address, 
                tt.city, 
                tt.state, 
                tt.zip, 
                tt.dob, 
                tt.sex 
FROM   tblcase tc 
       LEFT OUTER JOIN tblcasetrafficticketlink tcttl 
         ON tc.caseid = tcttl.caseid 
       LEFT OUTER JOIN tbltraffictickets tt 
         ON tcttl.courtid = tt.courtcode 
            AND tt.ticketnumber = tcttl.ticketnumber 
            AND ( tcttl.ticketextension = tt.ticketnumberex 
                   OR tt.ticketnumberex IS NULL ) 
       LEFT OUTER JOIN tblcourts tcou 
         ON tcou.courtid = tt.courtcode 
WHERE  tc.casetype = 'TRAFFIC' 
       AND tc.caseid<='"+recent_min_caseID+"' 
GROUP  BY tc.caseid, 
          tt.firstname, 
          tt.lastname, 
          tt.dob, 
          tt.sex, 
          tt.courtcode, 
          tcou.courtname, 
          tt.city, 
          tt.state, 
          tt.zip, 
          tc.casestatus, 
          tt.address1, 
          tt.address2 
ORDER  BY tc.caseid DESC 
LIMIT  100; 

这需要花费很多时间来获取数据。任何人都可以帮助提高性能。这PRAGMA有用吗?如果是这样的话?如果没有,请告诉我修复此问题的方法。

1 个答案:

答案 0 :(得分:0)

我发现Android上的SQLite似乎有一些......意想不到的怪癖。在我的例子中,事实证明,执行像select * from Foo where Bar is null这样的直接查询比仅选择 ID然后逐个ID地获取每一行要慢得多。 YMMV。