User:DWalden (WMF)/(Un)delete associated talk page/sql mcr

SET @pageid=<page id>;
SELECT rev_id, rev_page, role_name, model_name, content_address, content_size, old_text, comment_text, comment_data
FROM
(
 SELECT rev_id, rev_page, rev_comment_id
 FROM revision
 WHERE rev_page=@pageid
 UNION ALL
 SELECT ar_rev_id AS rev_id, ar_page_id AS rev_page, ar_comment_id AS rev_comment_id
 FROM archive
 WHERE ar_page_id=@pageid
) AS rev
LEFT JOIN slots ON rev_id=slot_revision_id
LEFT JOIN slot_roles ON slot_role_id=role_id
LEFT JOIN content ON slot_content_id=content_id
LEFT JOIN content_models ON content_model=model_id
LEFT JOIN text ON SUBSTRING(content_address, 4)=old_id
LEFT JOIN revision_comment_temp ON rev_id=revcomment_rev
LEFT JOIN comment ON rev_comment_id=comment_id OR revcomment_comment_id=comment_id;