lib/shiba/index_stats.rb in shiba-0.5.0 vs lib/shiba/index_stats.rb in shiba-0.6.0

- old
+ new

@@ -11,20 +11,21 @@ def any? @tables.any? end - Table = Struct.new(:name, :count, :indexes, :average_row_size) do + Table = Struct.new(:name, :count, :indexes) do def encode_with(coder) coder.map = self.to_h.stringify_keys coder.map.delete('name') if self.count.nil? #uuuugly. No unique keys. we'll take our best guess. self.count = indexes.map { |i, parts| parts.columns.map { |v| v.raw_cardinality } }.flatten.max end + coder.map['column_sizes'] = column_sizes coder.tag = nil end def build_index(index_name, is_unique) self.indexes[index_name] ||= Index.new(self, index_name, [], is_unique) @@ -37,10 +38,14 @@ if is_unique && !self.count # set row count from unique index self.count = cardinality end end + + def column_sizes + @column_sizes ||= {} + end end Index = Struct.new(:table, :name, :columns, :unique) do def add_column(column_name, cardinality) columns << Column.new(self, column_name, cardinality) @@ -148,9 +153,23 @@ end def add_index_column(table, index_name, column_name, cardinality, is_unique) table = build_table(table) table.add_index_column(index_name, column_name, nil, cardinality, is_unique) + end + + def get_column_size(table_name, column) + table = @tables[table_name] + return nil unless table + + table.column_sizes[column] + end + + def set_column_size(table_name, column, size) + table = @tables[table_name] + raise "couldn't find table: #{table_name}" unless table + + table.column_sizes[column] = size end def estimate_key(table_name, key, parts) index = fetch_index(table_name, key)