U
U
udi2014-07-29 11:57:59
SQL
udi, 2014-07-29 11:57:59

How to optimize sqlite query?

Hello
There is a request (sqlite .net). It takes an unacceptably long time (more than 30 seconds), although there is only one left join and it costs limit 0.1000. The amount of data is approximately 100,000 records in each of the tables. Can you suggest how to optimize it?

select
G.lemma as lemma,
G.id as id,
group_concat(distinct G.words) as words,
case when sum(K.some_data) is not null then sum(K.some_data) else 0 end as summ,
count(K.id) as cnt,
G.status as status,
G.stop_out as stop_out,
group_concat(K.id) as spl_id,
group_concat(K.keyword) as spl_kw,
group_concat(K.some_data) as spl_data,
group_concat(K.status) as spl_status
from [source_green_groups] G
left join [source_green_keywords] K on K.sg_id = G.id 
group by G.lemma
order by cnt desc
limit 0,1000

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Koltcov, 2014-08-07
@Vityarik

Check for an index on the field
source_green_keywords.sg_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question