Without access to underlying databases, the only way to make a search to retrieve data is by using Search API. Enhanced Search works by making simple queries to available APIs, and processing the results in various ways (using pattern matching, comparing, aggregation etc).

For example:

assignee = currentUser() AND issueFunction in dateCompare("project = DEMO", "created +1w < firstCommented") AND status = "In progress"

This contains a nested query. As you can see, the dateCompare function in the middle of the expression is not natively supported by Jira Cloud. The query is parsed and the dateCompare subquery is processed first. A standard search is made using the subquery "project = DEMO", then a comparision expression is applied to the results. Finally, a search is made to Jira Cloud with the structure:

assignee = currentUser() AND issue in ("DEMO-12", "DEMO-13", "DEMO-55") AND status = "In progress"

As seen above, the dateCompare query has been replaced by another query:`issue in (..)`. It contains issue ids/keys that were evaluated from the subquery.

If you specify more than one advanced subquery, all of them are evaluated and replaced in the final search.