Оптимизация SQL скрипта

325
18 января 2018, 18:23

Подскажите, пожалуста, как можно оптимизировать участок sql query? Если много подзапросов, то работает очень долго:

select distinct u.id,
    SQRT(POW(69.1 * (l.Latitude - 49.8147253578057), 2) +    POW(69.1 * (24.0197496861219 - l.Longitude) * COS(l.Latitude / 57.3), 2)) AS distance 
FROM user u 
    join location l on 
        (l.id = u.location_id and acos(sin(l.Latitude * 0.0175) * sin(49.8147253578057 * 0.0175)  + cos(l.Latitude * 0.0175) * cos(49.8147253578057 * 0.0175) *  
 cos((24.0197496861219 * 0.0175) - (l.Longitude * 0.0175))) * 3959 <= 25) 
    join current_subject c on 
        (c.id in (select id_current_subject from  user_current_subject where id_user = u.id) and c.subject_id = 2
      and 3 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
      and 4 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
        and 7 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
         and 13 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
         and 15 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
         and 16 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
         and 17 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
         and 18 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
         and 25 in (select id_curriculum from current_subject_curriculum where c.id = id_current_subject)
     ) 
 where u.role = 1 
    and u.status >= 103 
    and u.status != 105 
    and u.status != 106 
ORDER BY distance LIMIT 30 OFFSET 0
READ ALSO
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 01

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 01

Никак не могу подключится к MySQL с помощью JDBC c емулятора Nox

329
Почему MODx выводит кракозябры?

Почему MODx выводит кракозябры?

Использую для сайта движок MODx REVOЛокально всё работает, а на сервере выводит так:

270
Помогите перевести Python код в c# [требует правки]

Помогите перевести Python код в c# [требует правки]

ПожалуйстаКод переведен (С небольшими исправлениями для C#):

303
Создание экземпляра model во viewmodel

Создание экземпляра model во viewmodel

Можно ли создавать экземпляр model внутри viewmodel ? Допустим в целях использования методов модели во viewmodelНе нарушает ли это паттерн mvvm ? И , если...

246