It's an impedance mismatch, you have a long-running background operation (sql query) that is running within the context of an event driven system (a windowing GUI). In this case the problem is that the sub-system that runs the query will only receive cycles when the main thread for the app fires mouse events. This is due to poor application design, of course, though not necessarily to the extent that it may seem, sometimes this sort of thing can be a harder problem than it may seem.
Raymond Chen has a great example of a similar bug here: http://blogs.msdn.com/b/oldnewthing/archive/2005/02/17/37530...
But yes, I have seen a similar case involving linux /dev/random - the user reported that outgoing emails were sometimes delayed for hours and that moving a mouse over a VNC window would sometimes speed it up. I did not believe that at first, but it was exim4 running out of entropy when generating TLS session keys. Worse, it was on a VPS with about 20 exim4 processes competing for the entropy.