コード例 #1
0
 private static function update_table_partitions($ofs1, $ofs3, $old_schema, $old_table, $new_schema, $new_table)
 {
     $new_part = mysql5_table::get_partition_sql($new_schema, $new_table);
     $old_part = mysql5_table::get_partition_sql($old_schema, $old_table);
     $table_name = mysql5::get_fully_qualified_table_name($new_schema, $new_table['name']);
     if (strcasecmp($new_part, $old_part)) {
         if (is_null($new_part)) {
             $ofs1->write("ALTER TABLE {$table_name}\n  REMOVE PARTITIONING;\n\n");
         } else {
             $ofs1->write("ALTER TABLE {$table_name}\n  {$new_part};\n\n");
         }
     }
 }
コード例 #2
0
    public function testListRangePartitionSql()
    {
        $xml = <<<XML
<schema name="public" owner="NOBODY">
  <table name="test" primaryKey="id" owner="NOBODY">
    <column name="id" type="int auto_increment"/>
    <column name="foo" type="int"/>
    <tablePartition type="LIST">
      <tablePartitionOption name="column" value="id"/>
      <tablePartitionSegment name="p0" value="1, 2, 3"/>
      <tablePartitionSegment name="p1" value="4, 5, 6"/>
    </tablePartition>
  </table>
</schema>
XML;
        $schema = simplexml_load_string($xml);
        $table = $schema->table;
        $get_sql = function () use(&$schema, &$table) {
            return mysql5_table::get_partition_sql($schema, $table);
        };
        $this->assertEquals("PARTITION BY LIST (`id`) (\n  PARTITION `p0` VALUES IN (1, 2, 3),\n  PARTITION `p1` VALUES IN (4, 5, 6)\n)", $get_sql());
        $table->tablePartition['type'] = 'RANGE';
        $table->tablePartition->tablePartitionSegment[0]['value'] = '4';
        $table->tablePartition->tablePartitionSegment[1]['value'] = '6';
        $p2 = $table->tablePartition->addChild('tablePartitionSegment');
        $p2['name'] = 'p2';
        $p2['value'] = 'MAXVALUE';
        $this->assertEquals("PARTITION BY RANGE (`id`) (\n  PARTITION `p0` VALUES LESS THAN (4),\n  PARTITION `p1` VALUES LESS THAN (6),\n  PARTITION `p2` VALUES LESS THAN (MAXVALUE)\n)", $get_sql());
        $table->tablePartition['type'] = 'RANGE COLUMNS';
        $table->tablePartition->tablePartitionOption[0]['name'] = 'columns';
        $table->tablePartition->tablePartitionOption[0]['value'] = 'id,foo';
        $table->tablePartition->tablePartitionSegment[0]['value'] = '4,10';
        $table->tablePartition->tablePartitionSegment[1]['value'] = '6,20';
        $table->tablePartition->tablePartitionSegment[2]['value'] = 'MAXVALUE,MAXVALUE';
        $this->assertEquals("PARTITION BY RANGE COLUMNS (`id`, `foo`) (\n  PARTITION `p0` VALUES LESS THAN (4,10),\n  PARTITION `p1` VALUES LESS THAN (6,20),\n  PARTITION `p2` VALUES LESS THAN (MAXVALUE,MAXVALUE)\n)", $get_sql());
    }