I think this is a limitation of your database engine. In most databases, docs
would be in scope for the entire subquery -- including both the where
and in
clauses.
However, you do not need to worry about where you put the particular clause. SQL is a descriptive language, not a procedural language. The purpose of SQL is to describe the output. The SQL engine, parser, and compiler should be choosing the most optimal execution path. Not always true. But, move the condition to the where
clause and don't worry about it.