sql - Inner join order by performance issue in Android 2.3 -
i have used sql select query in android app works fine on newer versions of android i.e takes 30 40 seconds on samsung galaxy tab( android 4.0.3) retreive data sqlite database, on device older version of android 2.3 takes 18 minutes retreive data. if remove "order x_unitperson.unitseq" performance not decreases on android 2.3. how can increase performance on android 2.3 without removing order clause.
my sql is:
select person_id, commander, citizen, rank, given, surname, isor, (select group_concat(name_short, '\n') units inner join (select * x_unitperson person_id = people.person_id order x_unitperson.unitseq) xunits units.unit_id = xunits.unit_id) name_short, (select fname photos person_id = people.person_id) fname people order surname, given
i not familiar sqlite optimiser, if correlated subquery rewritten join optimisers create same execution plan both queries, , not sure if sqlite 1 of these, may worth converting query use joins rather correlated subqueries, see if avoids:
select people.person_id, people.commander, people.citizen, people.rank, people.given, people.surname, people.isor, ns.name_short, photos.fnane people left join ( select units.person_id, group_concat(name_short, '\n') name_short units inner join ( select unit_id, name_short x_unitperson order unit_id, x_unitperson.unitseq ) xunits on units.unit_id = xunits.unit_id group units.person_id ) ns on ns.person_id = people.person_id left join photos on photos.person_id = people.person_id order people.surname, people.given;
in addition (using can gather schema) have removed select *
query, bad practice in production code, have prefixed column references table name/alias, again safeguards query against future schema changes.