select "hints".*,
(select count(*)
from "tags"
inner join "hint_tag_assignment" on "tags"."id" = "hint_tag_assignment"."tag_id"
where "hints"."id" = "hint_tag_assignment"."hint_id"
and "require" = true) as "require_tags_count",
(select count(*)
from "tags"
inner join "hint_tag_assignment" on "tags"."id" = "hint_tag_assignment"."tag_id"
where "hints"."id" = "hint_tag_assignment"."hint_id"
and ("name" in ('sit', 'sed') or exists(select * from "tag_synonyms" where "tags"."id" = "tag_synonyms"."tag_id" and "name" in ('sit', 'sed')))
and "require" = true) as "matched_require_tags_count",
(select count(*)
from "tags"
inner join "hint_tag_assignment" on "tags"."id" = "hint_tag_assignment"."tag_id"
where "hints"."id" = "hint_tag_assignment"."hint_id"
and ("name" in ('sit', 'sed') or exists(select * from "tag_synonyms" where "tags"."id" = "tag_synonyms"."tag_id" and "name" in ('sit', 'sed')))
and "require" = true) as "matched_not_require_tags_count"
from "hints"
where exists(select *
from "tags"
inner join "hint_tag_assignment" on "tags"."id" = "hint_tag_assignment"."tag_id"
where "hints"."id" = "hint_tag_assignment"."hint_id"
and ("name" in ('sit', 'sed') or exists(select * from "tag_synonyms" where "tags"."id" = "tag_synonyms"."tag_id" and "name" in ('sit', 'sed'))))