Not sure if this will help, but you mentioned "the database I'm querying is remote". In case the bandwidth of your connection is the bottleneck, it might be possible to activate compression so that the connection may work faster. When creating ssh tunnels this is possible by adding a -C flag and it is also possible by setting up a reverse proxy in the server.