### 14.1.1. Example: Fast Node-Counts by Label

Counts by label are quickly provided by the counts-store, but only if they are the the single thing in the query, like

    MATCH (:Person) RETURN count(*);

It also works to combine several with `UNION ALL`, but not via `WITH`

Doesn’t work.

    MATCH (:Person) WITH count(*) as people
    MATCH (:Movie) RETURN people, count(*) as movies;

Works.

    MATCH (:Person) RETURN count(*)
    UNION ALL
    MATCH (:Movie) RETURN count(*);

But with `apoc.cypher.run` we can construct the statement and run each of them individually, so it completes in a few ms.

    call db.labels() yield label
    call apoc.cypher.run("match (:`"+label+"`) return count(*) as count", null) yield value
    return label, value.count as count

You can use a similar approach to get the property-keys per label:

    CALL db.labels() yield label
    call apoc.cypher.run("MATCH (n:`"+label+"`) RETURN keys(n) as keys LIMIT 1",null) yield value
    RETURN label, value.keys as keys