Revert "Remove unused function"

This reverts commit 09e8b91028f0f4d8bdd2677b6363a7ea6aedfd21.
Make a copy of the query