limit recursive calls for query generation to avoid stack overflow