Skip to content

Instantly share code, notes, and snippets.

@e0da

e0da/sql.rb

Created Feb 20, 2019
Embed
What would you like to do?
cur.execute(<<-'SQL'.gsub('%s', tablename))
INSERT INTO `%s`
SELECT cs.nodeid, dbs.name database, rels.name `table`,
reps.name `index`, sum(reads) reads,
sum(deletes+inserts+replaces) writes,
count(cs.replica) replicas
FROM system.`databases` AS dbs
JOIN system.`relations` AS rels USING (db)
JOIN system.`representations` AS reps
ON (reps.relation = rels.table)
JOIN system.`slices` AS s USING (representation)
JOIN system.`replicas` AS r USING (slice)
JOIN system.container_stats AS cs USING (replica)
GROUP BY nodeid, `database`, `table`, `index`
% tablename)
SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.