lib/shiba/index_stats.rb in shiba-0.2.3 vs lib/shiba/index_stats.rb in shiba-0.3.0
- old
+ new
@@ -95,13 +95,12 @@
def encode_with(coder)
coder.map = {'column' => @column}
count = table_count
count = 1 if count == 0
- ratio_per_item = self.rows_per / count.to_f rescue debugger
+ ratio_per_item = self.rows_per / count.to_f
-
if count <= 10
ratio_threshold = 1_000_0000 # always show a number
elsif count <= 1000
ratio_threshold = 0.1
elsif count <= 1_000_000
@@ -156,14 +155,19 @@
def estimate_key(table_name, key, parts)
index = fetch_index(table_name, key)
return nil unless index
- index_part = index.columns.detect do |p|
- p.column == parts.last
+ index_part = nil
+ index.columns.each do |c|
+ break unless parts.include?(c.column)
+ index_part = c
end
- return nil unless index_part
+ # postgres can claim to use the right hand side of an index
+ # in a bitmap scan, which seems to be a side-effect of forcing
+ # seq-scan off. In these cases we'll say it's a full scan.
+ return table_count(table_name) unless index_part
index_part.rows_per
end
def convert_rows_per_to_output!