Complex queries are moved to script.