Try using a LEFT JOIN
.
SELECT ps.*,
convert(bit, CASE
WHEN psl.userid IS NULL
THEN 0
ELSE 1
END) isliked
FROM post.post
LEFT JOIN post.postlike psl
ON ps1.postid = ps.id
AND psl.userid = @userid;
And then create an index on post.post.id
(unless it already has one, which should be the case for a primary key column) and an index on post.postlike.postid
and post.postlike.userid
(again unless such an index already exists, which might be the case it the columns are the primary key, which is reasonable).
CREATE INDEX post_id
ON post.post
(id);
CREATE INDEX postlike_postid_userid
ON post.postlike
(postid,
userid);
Or alternatively change the last one to
CREATE INDEX postlike_userid_postid
ON post.postlike
(userid,
postid);
if there are more users than posts.
Check the execution plan if the indexes help.