I wonder if there is a way to get Mercury to treat queries to an external database as a nondeterminate predicate, and yet arrange things so that cursors get cleaned up.