The error message "Failed to execute query" is returned when executing a query operation on a map service table with large data and using an ESRI_OID range in the where clause.
Duplicate of BUG-000119828.
The ESRI_OID field is a pseudo field with values randomly assigned to each feature, so using ESRI_OID as a regular field is not recommended. Beginning with ArcGIS Enterprise 11.5, map services return uniqueIdInfo in the layer’s REST resources; use the field(s) from this element when constructing queries. In this workflow, use uniqueIds or returnUniqueIdsOnly instead of objectIds or returnIdsOnly.