def global_usage_count(main=False):
    """
    Returns global usage query

    Args:
        category (str): category name
        main (bool): optional in order to account only for file used in main namespaces
    """
    query = """
            SELECT /* SLOW_OK */
                COUNT(page.page_title) AS total_usage,
                COUNT(DISTINCT page.page_title) AS images_used,
                COUNT(DISTINCT gil.gil_wiki) AS nb_wiki
            FROM image
            CROSS JOIN page ON image.img_name = page.page_title
            CROSS JOIN categorylinks ON page.page_id = categorylinks.cl_from
            CROSS JOIN globalimagelinks gil ON gil.gil_to = image.img_name
            WHERE
                categorylinks.cl_to = %s"""
    if main:
        return query + " AND gil.gil_page_namespace_id = 0 AND (gil.gil_wiki!='metawiki')"
    else:
        return query