$query = "
select t.board, t.reply_file, t.reply_file_type, t.reply_file_w, t.reply_file_h, t.post_file, t.post_file_type, t.post_file_h, t.post_file_w, t.reply_time, t.time, t.reply_name, t.p_name as 'name', t.post_id as 'post_id', @pv := t.reply_on as 'reply_id', t.message, t.reply_message
from
(select
b.name as 'board', p.file as 'post_file', p.file_type as 'post_file_type', p.thumb_w as 'post_file_w', p.thumb_h as 'post_file_h', p2.file as 'reply_file', p2.file_type as 'reply_file_type', p2.thumb_w as 'reply_file_w', p2.thumb_h as 'reply_file_h', p.timestamp as 'time', p2.timestamp as 'reply_time',
p.name as 'p_name',
p2.name as 'reply_name', p.message, p2.message as reply_message,
p.id as 'post_id',
p.name, pr1.replyid as 'reply_on',
p2.name as 'reply_to' from posts p
left join boards b on p.boardid =
b.id
inner join posts_replies pr1 on pr1.postid =
p.id
inner join posts p2 on
p2.id = pr1.replyid
where
b.name = ".$tc_db->qstr($_GET['b'])." and (p.session_md5 = ".$tc_db->qstr($rcpt_session_md5)." or p.session_md5 = md5(".$tc_db->qstr($session).")) and (p2.session_md5 = md5(".$tc_db->qstr($session).") or p2.session_md5 = ".$tc_db->qstr($rcpt_session_md5).") and p.email != 'sage' order by
p.id desc limit 100) t
join
(select @pv := ".$tc_db->qstr($_GET['p']).") t2 where @pv = t.post_id;";
[/quote]
ну ты понял, да. там в этом запросе к сожалению в одном месте получается полная выборка, как ни крути.
я добавил поля с session_md прямо в posts_reply и ключ на них, таким образом выборка по posts_reply двух людей идёт мгновенно:
[code]
MariaDB [ponyach]> select * from posts_replies where (session_md5 = '26a9bd77bbe7f9af1638e879b49aa501' and reply_md5 = '32fc9ed72eeae6634ef6b22be68fc623') or (session_md5= '32fc9ed72eeae6634ef6b22be68fc623' and reply_md5 = '26a9bd77bbe7f9af1638e879b49aa501') order by postid;
+---------+---------+----------+---------+----------------------------------+----------------------------------+
| boardid | postid | replybid | replyid | session_md5 | reply_md5 |
+---------+---------+----------+---------+----------------------------------+----------------------------------+
| 7 | 1056590 | 7 | 1056589 | 32fc9ed72eeae6634ef6b22be68fc623 | 26a9bd77bbe7f9af1638e879b49aa501 |
| 7 | 1056593 | 7 | 1056590 | 26a9bd77bbe7f9af1638e879b49aa501 | 32fc9ed72eeae6634ef6b22be68fc623 |
| 7 | 1056597 | 7 | 1056593 | 32fc9ed72eeae6634ef6b22be68fc623 | 26a9bd77bbe7f9af1638e879b49aa501 |
| 7 | 1056604 | 7 | 1056597 | 26a9bd77bbe7f9af1638e879b49aa501 | 32fc9ed72eeae6634ef6b22be68fc623 |
| 7 | 1056605 | 7 | 1056604 | 32fc9ed72eeae6634ef6b22be68fc623 | 26a9bd77bbe7f9af1638e879b49aa501 |
| 7 | 1056606 | 7 | 1056605 | 26a9bd77bbe7f9af1638e879b49aa501 | 32fc9ed72eeae6634ef6b22be68fc623 |
| 7 | 1056610 | 7 | 1056606 | 32fc9ed72eeae6634ef6b22be68fc623 | 26a9bd77bbe7f9af1638e879b49aa501 |
| 7 | 1056616 | 7 | 1056610 | 26a9bd77bbe7f9af1638e879b49aa501 | 32fc9ed72eeae6634ef6b22be68fc623 |
| 7 | 1056622 | 7 | 1056616 | 32fc9ed72eeae6634ef6b22be68fc623 | 26a9bd77bbe7f9af1638e879b49aa501 |
| 7 | 1056638 | 7 | 1056622 | 26a9bd77bbe7f9af1638e879b49aa501 | 32fc9ed72eeae6634ef6b22be68fc623 |
| 7 | 1056646 | 7 | 1056638 | 32fc9ed72eeae6634ef6b22be68fc623 | 26a9bd77bbe7f9af1638e879b49aa501 |
+---------+---------+----------+---------+----------------------------------+----------------------------------+
11 rows in set (0.02 sec)
MariaDB [ponyach]>