def METHOD_NAME(chdb, category_name_id_and_page_ids):
    def insert(cursor, chunk):
        cursor.executemany('''
            INSERT IGNORE INTO categories VALUES (%s, %s)
        ''', ((category_id, category_name)
            for category_name, category_id, _ in chunk))
        cursor.executemany('''
            INSERT INTO articles_categories VALUES (%s, %s)
        ''', ((pageid, catid)
            for _, catid, pageids in chunk for pageid in pageids))
        database.populate_snippets_links(cursor,
            category_ids = (cid for (_, cid, _) in chunk))
    for c in ichunk(category_name_id_and_page_ids, 4096):
        chdb.execute_with_retry(insert, list(c))
    chdb.execute_with_retry_s('''
        INSERT INTO category_article_count
        SELECT category_id, COUNT(*) AS article_count
        FROM articles_categories GROUP BY category_id''')