Similar.
I've been thinking about rewriting queries like this to consolidate them (and be somewhat more efficient) when they can be.
This works with "authors" because no two events can match the same author, but it doesn't work for other queries.
For example, [..., {"#p": ["a", "b"]] and [..., {"#p": ["a"]}, {"#p": ["b"]}] are not quite the same.
scsibug (npub1xhf…4xw3) you are probably getting away with UNION in these cases and letting db engine do the de-duplicating for you.
But once you implement cursor/"pagination" of queries, leaning on UNION for deduplication won't work.
I'm doing pagination/cursor-based query results now, which means you might get duplicate events in some cases for a separated "#p" query like that.
However, once I implement query rewriting this will be partially fixed by rewriting [..., {"#p": ["a"]}, {"#p": ["b"]}] to [..., {"#p": ["a", "b"]], which will be more efficient and naturally produce non-duplicate results.
For query filters that can't be consolidated -- e.g., [..., {"#p": ["a"]}, {"#p": ["b"], "authors": ["dead"]}}] -- deduplication is kinda tricky and not ideal, so will have to figure that out at some point or live with it.