def METHOD_NAME(context: Context, sql: str):
    '''Parses the output of EXPLAIN (FORMAT JSON) looking for table and
    function names
    It performs an EXPLAIN query against the provided SQL, and parses
    the output recusively.
    Note that this requires Postgres 9.x.
    :param context: a CKAN context dict. It must contain a 'connection' key
        with the current DB connection.
    :type context: dict
    :param sql: the SQL statement to parse for table and function names
    :type sql: string
    :rtype: a tuple with two list of strings, one for table and one for
    function names
    '''
    queries = [sql]
    table_names: list[str] = []
    function_names: list[str] = []
    while queries:
        sql = queries.pop()
        function_names.extend(_get_function_names_from_sql(sql))
        result = context['connection'].execute(
            'EXPLAIN (VERBOSE, FORMAT JSON) {0}'.format(
                str(sql))).fetchone()
        try:
            query_plan = json.loads(result['QUERY PLAN'])
            plan = query_plan[0]['Plan']
            t, q, f = _parse_query_plan(plan)
            table_names.extend(t)
            queries.extend(q)
            function_names = list(set(function_names) | set(f))
        except ValueError:
            log.error('Could not parse query plan')
            raise
    return table_names, function_names