Performance of count() vs count() in a window function
why there is such a performance difference between executing a SELECT + a count() and selecting and counting in the same query?


Because PostgreSQL isn't optimized to do what you want, clearly. The count(*) OVER () is subject to WindowAgg which presumably does more (perhaps even with an exposed  accumulator) than the PartialAggregate. And, moreover, as you pointed out one of them is subject to Parallel Seq Scan, presumably Window Functions are not subject to Parallel queries yet.

I'm sure patches are accepted.


  What surprises me is that the planner chooses to do a sequential scan, then a window aggregation, and finally a limit over the whole set.


That's to be expected, what's surprising? The LIMIT always runs last.


  creating an btree index didn't help,