Stage-2 per-channel UNION ALL fetching writes from writes.
One branch per channel with a non-empty chain. Each branch inlines its
own IN (?, ?, ...) placeholder list because sqlite has no array-bind
equivalent of postgres's = ANY(%s). Caller passes parameters in
matching order: [thread_id, checkpoint_ns, channel, *chain_cids] per
branch.
Returns an empty string when no channel has a chain (caller skips
executing in that case). Per-channel UNION ALL avoids the over-fetch
of a single channel = ANY(channels) filter when channels have
different chain depths — same rationale as postgres.