class Mysql::Partitioner::Operation::Range

Public Instance Methods

add_partitions(partitions) click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 28
def add_partitions(partitions)
  return if partitions.empty?
  partition_defs = partitions.select.map {|item|
    item.to_partition_def
  }.join(",\n  ")
  self.session.alter("ALTER TABLE #{self.table} REORGANIZE PARTITION pmax INTO ( #{partition_defs }, PARTITION pmax VALUES LESS THAN MAXVALUE )" )
end
check!() click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 7
def check!
  type = get_partition_type()
  if type != "RANGE" and type != nil
    raise "Partition type mismatch #{type}"
  end
end
create_partitions(key, partitions) click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 36
        def create_partitions(key, partitions)
          
          partition_defs = partitions.select.map {|item|
            item.to_partition_def
          }.join(",\n  ")
          self.session.alter(<<SQL)
ALTER TABLE #{self.table} PARTITION BY RANGE (#{key}) (
  #{partition_defs},
  PARTITION pmax VALUES LESS THAN MAXVALUE)
SQL
        
        end
drop_partitions(partitions) click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 49
def drop_partitions(partitions)
  return if partitions.empty?
  names = partitions.map{|item| item.name }.join(",")
  self.session.alter("ALTER TABLE #{self.table} DROP PARTITION #{names}" )
end
get_current_bounded_partitions() click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 14
def get_current_bounded_partitions
  get_current_partitions.select {| item| item.bounded? }
end
get_current_partitions() click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 18
        def get_current_partitions
          results = self.session.query(<<SQL)
SELECT PARTITION_EXPRESSION, PARTITION_DESCRIPTION, PARTITION_ORDINAL_POSITION, PARTITION_METHOD, SUBPARTITION_EXPRESSION
FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME="#{ self.table }" AND TABLE_SCHEMA="#{ self.database }" ORDER BY PARTITION_ORDINAL_POSITION ASC
SQL
          results.map {|item|
            Mysql::Partitioner::Partition::Range.new(item["PARTITION_DESCRIPTION"])
          }
        end
migrate_partitions(old_partitions, new_partitions) click to toggle source
# File lib/mysql/partitioner/operation/range.rb, line 55
def migrate_partitions(old_partitions, new_partitions) 
  self.drop_partitions(old_partitions - new_partitions)
  self.add_partitions(new_partitions - old_partitions)
end