COUNT(t3.id) as one_referals, count( t4.id) as two_referals, count( t5.id) as three_referals
FROM tb_users tb1
LEFT JOIN tb_users t3 ON t3.id_referer = tb1.id
LEFT JOIN tb_users t4 ON t4.id_referer = t3.id
LEFT JOIN tb_users t5 ON t5.id_referer = t4.id
GROUP BY tb1.id
LIMIT 0, 20
CREATE TABLE tb_users (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
id_referer INT NULL,
) TYPE=InnoDB DEFAULT CHARSET=utf8;
CREATE INDEX fk_tree_tree ON tb_users (id_referer);
ALTER TABLE tb_users ADD CONSTRAINT fk_tree_tree FOREIGN KEY (id_referer) REFERENCES tb_users (id) ON UPDATE CASCADE ON DELETE CASCADE
При EXPLAIN format=json
имеется вот такие косты, это нормально и ли чет делаю не так ?
В таблице tb_users = 70к записей
косты, а не касты
Обсуждают сегодня