Fix query execution and log error for unknown queries