def METHOD_NAME(rows, metrics, key):
    """
    Given a list of query rows, merge all duplicate rows as determined by the key function into a single row
    with the sum of the stats of all duplicates. This is motivated by database integrations such as postgres
    that can report many instances of a query that are considered the same after the agent normalization.
    - **rows** (_List[dict]_) - rows from current check run
    - **metrics** (_List[str]_) - the metrics to compute for each row
    - **key** (_callable_) - function for an ID which uniquely identifies a query row across runs
    """
    queries_by_key = {}
    for row in rows:
        merged_row = dict(row)
        query_key = key(merged_row)
        if query_key in queries_by_key:
            merged_state = queries_by_key[query_key]
            queries_by_key[query_key] = {
                k: merged_row[k] + merged_state[k] if k in metrics else merged_state[k] for k in merged_state.keys()
            }
        else:
            queries_by_key[query_key] = merged_row
    return list(queries_by_key.values())