I ran the same report query regularly and most of the time the query completes within minutes. However, it sometimes gets stuck for hours in a nondeterministic way. When it got stuck, I repeated the same query with EXPLAIN ANALYZE, but the latter finished quickly.
Why is it so? How can get the execution plan of a running query?