Created
March 26, 2021 14:33
-
-
Save ZempTime/66fb6757ef3d8326f3e31f6aafb73250 to your computer and use it in GitHub Desktop.
Redshift cost analyzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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