ну не знаю, в последней стабильной 2.7 немеряно утечек памяти в actors, даже банальный List.equals может вылететь со Stack Overflow Exception, в HashMap вообще ужас что творится.
окей, в 2.8 всё это будет исправлено, но сама 2.8 настолько сырая, настолько значительно меняется, что использовать её невозможно. по масштабам изменений тянет больше на 3.0 чем на 2.8. боюсь с 2.7 она будет не совместима, вплоть до того что код, который компилировался на 2.7 не будет компилироваться на 2.8.
select c.id as c_id, g.id as g_id, ifnull(i2.id,
(select id from photo_image i3 where i3.g_id=g.id and is_published=1 limit 1)
) as photo_id
from (
select c.id, c.ordi, (select ordi from photo_gallery g
where g.c_id = c.id and g.is_published=1
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by ordi desc limit ..., 1) min_ordi
from photo_category c where c.is_published=1
) c
join photo_gallery g on g.c_id = c.id and g.is_published=1
and (g.ordi > min_ordi or min_ordi is null)
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
left join photo_image i2 on i2.g_id=g.id and i2.is_main_foto=1
order by c.ordi desc, g.ordi desc
вроде работает, в многоточие надо поставить нужное ограничение на число групп
P.S. внутренний конечно, self-fix
P.P.S. всю ночь без интернета просидел
да, виноват, писал из головы, запускать даже не пробовал.
внутринний подзапрос, выбирающий ограничение на ordi должен быть таким:
select id, (select ordi from photo_gallery g
where g.c_id = c.id and g.is_published=1
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by ordi desc limit 5, 1) x
from photo_category c where c.is_published=1
сейчас попробую проверить что не только ошибок нет, но и что на данных результат правильный
эксплейны только представляю в голове, на реальной базе не пробовал. для 3й задачи возможно лучше:
select c.id as c_id, g.id as g_id, ifnull(i.id,
(select id from photo_image i where i.i.g_id=g.id and is_published=1 limit 1)
) as photo_id
from (select id, (select min(ordi) as min_ordi
from (select ordi from photo_gallery g
where g.c_id = c.id and g.is_published=1
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by ordi desc limit ...))
from photo_category c where c.is_published=1) c
join join photo_gallery g on g.c_id = c.id and g.is_published=1 and g.ordi >= min_ordi
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
left join photo_image i on i.g_id=g.id and is_main_foto=1
order by c.ordi desc, g.ordi desc
select g.id, ifnull(
(select id from photo_image i where i.i.g_id=g.id and is_main_foto=1),
(select id from photo_image i where i.i.g_id=g.id and is_published=1 limit 1)
) as photo_id
from photo_gallery g
where g.c_id = ...
and g.is_published = 1
and exists(select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by g.ordi
комментарий: в photo_image проиндексировать g_id
или хотя бы одну из пар (g_id, is_published) (g_id, is_main_foto)
вторая:
select (select i2.id from photo_image i2
where i1.g_id = i2.g_id and i2.ordi > i1.ordi
and (i2.is_published = 1 or i2.is_main_foto = 1)
order by i2.ordi asc limit 1) as next_id,
(select i2.id from photo_image i2
where i1.g_id = i2.g_id and i2.ordi < i1.ordi
and (i2.is_published = 1 or i2.is_main_foto = 1)
order by i2.ordi desc limit 1) as prev_id
from photo_image i1 where i1.id = ...
комментарий: проиндексировать (g_id, ordi)
третья:
select c.id as c_id, g.id as g_id, ifnull(
(select id from photo_image i where i.i.g_id=g.id and is_main_foto=1),
(select id from photo_image i where i.i.g_id=g.id and is_published=1 limit 1)
) as photo_id
from photo_category c
join photo_gallery g on g.c_id = c.id
where c.is_published=1 and g.is_published=1
and exists(select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
and g.id in (select g2.id from photo_gallery g2 where g2.c_id = c.id order by ordi desc limit ...)
order by c.ordi desc, g.ordi desc
комментарий: поможет составной индекс (c_id asc, ordi desc) у photo_gallery
чёрт знает. каналы у всех настолько разные, начиная от LAN/модемов, заканчивая всякими твиками например с помощью TCPOptimizer. влияет также максимальное число соединений в торренте (там есть общее, на торрент, и чисто на отдачу), их может быть стоит поднять
падает очень быстро, где-то за пару секунд, восстанавливается дольше, там счёт скорее на десятки секунд идёт.
даже не знаю что посоветовать, можно попробовать поднять net.utp_target_delay или почитать официальный форум, если там решения не найдётся — описать там свою проблему
с другой — есть же OCaml например…
окей, в 2.8 всё это будет исправлено, но сама 2.8 настолько сырая, настолько значительно меняется, что использовать её невозможно. по масштабам изменений тянет больше на 3.0 чем на 2.8. боюсь с 2.7 она будет не совместима, вплоть до того что код, который компилировался на 2.7 не будет компилироваться на 2.8.
String strRes = (new java.util.StringTokenizer(strOrig, " ", true) {
public String toString() {
StringBuilder sb = new StringBuilder();
while (hasMoreTokens()) {
String token = nextToken();
sb.append (Character.toUpperCase(token.charAt(0)));
sb.append (token.substring(1));
}
return sb.toString();
}
}).toString();
strOrig split "\\b" map {_.capitalize} mkString
val strRes = strOrig split "\\b" filter {_.length > 0} map {x => x.charAt(0).toUpperCase + x.substring(1)} mkString
select c.id as c_id, g.id as g_id, ifnull(i2.id,
(select id from photo_image i3 where i3.g_id=g.id and is_published=1 limit 1)
) as photo_id
from (
select c.id, c.ordi, (select ordi from photo_gallery g
where g.c_id = c.id and g.is_published=1
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by ordi desc limit ..., 1) min_ordi
from photo_category c where c.is_published=1
) c
join photo_gallery g on g.c_id = c.id and g.is_published=1
and (g.ordi > min_ordi or min_ordi is null)
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
left join photo_image i2 on i2.g_id=g.id and i2.is_main_foto=1
order by c.ordi desc, g.ordi desc
вроде работает, в многоточие надо поставить нужное ограничение на число групп
P.S. внутренний конечно, self-fix
P.P.S. всю ночь без интернета просидел
внутринний подзапрос, выбирающий ограничение на ordi должен быть таким:
select id, (select ordi from photo_gallery g
where g.c_id = c.id and g.is_published=1
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by ordi desc limit 5, 1) x
from photo_category c where c.is_published=1
сейчас попробую проверить что не только ошибок нет, но и что на данных результат правильный
select c.id as c_id, g.id as g_id, ifnull(i.id,
(select id from photo_image i where i.i.g_id=g.id and is_published=1 limit 1)
) as photo_id
from (select id, (select min(ordi) as min_ordi
from (select ordi from photo_gallery g
where g.c_id = c.id and g.is_published=1
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by ordi desc limit ...))
from photo_category c where c.is_published=1) c
join join photo_gallery g on g.c_id = c.id and g.is_published=1 and g.ordi >= min_ordi
and exists (select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
left join photo_image i on i.g_id=g.id and is_main_foto=1
order by c.ordi desc, g.ordi desc
select g.id, ifnull(
(select id from photo_image i where i.i.g_id=g.id and is_main_foto=1),
(select id from photo_image i where i.i.g_id=g.id and is_published=1 limit 1)
) as photo_id
from photo_gallery g
where g.c_id = ...
and g.is_published = 1
and exists(select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
order by g.ordi
комментарий: в photo_image проиндексировать g_id
или хотя бы одну из пар (g_id, is_published) (g_id, is_main_foto)
вторая:
select (select i2.id from photo_image i2
where i1.g_id = i2.g_id and i2.ordi > i1.ordi
and (i2.is_published = 1 or i2.is_main_foto = 1)
order by i2.ordi asc limit 1) as next_id,
(select i2.id from photo_image i2
where i1.g_id = i2.g_id and i2.ordi < i1.ordi
and (i2.is_published = 1 or i2.is_main_foto = 1)
order by i2.ordi desc limit 1) as prev_id
from photo_image i1 where i1.id = ...
комментарий: проиндексировать (g_id, ordi)
третья:
select c.id as c_id, g.id as g_id, ifnull(
(select id from photo_image i where i.i.g_id=g.id and is_main_foto=1),
(select id from photo_image i where i.i.g_id=g.id and is_published=1 limit 1)
) as photo_id
from photo_category c
join photo_gallery g on g.c_id = c.id
where c.is_published=1 and g.is_published=1
and exists(select 1 from photo_image i where i.g_id=g.id and i.is_published=1)
and g.id in (select g2.id from photo_gallery g2 where g2.c_id = c.id order by ordi desc limit ...)
order by c.ordi desc, g.ordi desc
комментарий: поможет составной индекс (c_id asc, ordi desc) у photo_gallery
утверждается что от этого даже увеличивается производительность:
www.mainsoft.com/static/solutions/pdfs/PerformanceStudy.pdf
вот тут подробнее об этом: www.nnm-club.ru/forum/viewtopic.php?t=68634
даже не знаю что посоветовать, можно попробовать поднять net.utp_target_delay или почитать официальный форум, если там решения не найдётся — описать там свою проблему