Skip to content

Instantly share code, notes, and snippets.

@ZempTime
Created March 26, 2021 14:33
Show Gist options
  • Save ZempTime/66fb6757ef3d8326f3e31f6aafb73250 to your computer and use it in GitHub Desktop.
Save ZempTime/66fb6757ef3d8326f3e31f6aafb73250 to your computer and use it in GitHub Desktop.
Redshift cost analyzer
# ex: ruby ./costsort.rb /path/to/query.txt
# look for biggest change furthest in middle of tree
path = ARGV[0]
line_number = 0
results = []
File.open(path, 'r').each_line do |line|
if line.include?("cost=")
lower, upper = line[/cost=(.*?)rows/, 1].split("..")
results.push(
{
cost: (upper.to_f - lower.to_f),
line_number: line_number,
line: line
}
)
end
line_number += 1
end
results.each do |r|
puts "#{r[:line_number]} @ #{r[:cost]} -> #{r[:line]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment