DROP TABLE IF EXISTS channels;
DROP TABLE IF EXISTS permissions;
DROP TABLE IF EXISTS messages;
CREATE TABLE channels (
id int PRIMARY KEY,
name varchar(255)
);
CREATE TABLE permissions (
id int PRIMARY KEY,
channel_id int,
user_id int
);
CREATE TABLE messages (
id int PRIMARY KEY,
channel_id int,
content varchar(512),
FULLTEXT KEY (content)
);
INSERT INTO channels VALUES (11, "channel1");
INSERT INTO channels VALUES (12, "channel2");
INSERT INTO channels VALUES (13, "channel3");
INSERT INTO permissions VALUES (21, 11, 31);
INSERT INTO permissions VALUES (22, 12, 31);
INSERT INTO messages VALUES (41, 11, "message1");
INSERT INTO messages VALUES (42, 11, "message2");
INSERT INTO messages VALUES (43, 12, "message3");
INSERT INTO messages VALUES (44, 13, "message4");
SELECT *
FROM messages
WHERE channel_id IN
(SELECT channels.id
FROM channels
INNER JOIN permissions ON channels.id = permissions.channel_id
WHERE permissions.user_id = 31)
AND match(content) against('*D+ message' IN BOOLEAN MODE)
AND id > 40
ORDER BY id DESC
LIMIT 2;
id	channel_id	content
43	12	message3
42	11	message2
SHOW STATUS LIKE 'mroonga_fast_order_limit';
Variable_name	Value
Mroonga_fast_order_limit	0
DROP TABLE messages;
DROP TABLE permissions;
DROP TABLE channels;
