Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(branch): get design schema for MySQL partition (#11086)

h3n4l9277c750a552
diff --git a/backend/plugin/schema/mysql/get_design_schema_test.go b/backend/plugin/schema/mysql/get_design_schema_test.go
index 9314c80040..7fdc73cdb3 100644
--- a/backend/plugin/schema/mysql/get_design_schema_test.go
+++ b/backend/plugin/schema/mysql/get_design_schema_test.go
@@ -27,7 +27,10 @@ func TestGetDesignSchema(t *testing.T) {
var (
filepaths = []string{
"testdata/get-design-schema/get_design_schema.yaml",
- "testdata/get-design-schema/partition.yaml",
+ "testdata/get-design-schema/partition/range.yaml",
+ "testdata/get-design-schema/partition/list.yaml",
+ "testdata/get-design-schema/partition/hash.yaml",
+ "testdata/get-design-schema/partition/key.yaml",
}
)
@@ -49,13 +52,13 @@ func TestGetDesignSchema(t *testing.T) {
a.NoError(err)
// Addintional parse stage to verify the result is parsable.
- _, err = parser.ParseMySQL(t.Result)
- a.NoError(err)
+ _, err = parser.ParseMySQL(result)
+ a.NoErrorf(err, "[%s] test case %d: %s\n content:\n%s", filepath, i, t.Description, result)
if record {
tests[i].Result = result
} else {
- a.Equalf(t.Result, result, "test case %d: %s", i, t.Description)
+ a.Equalf(t.Result, result, "[%s] test case %d: %s", filepath, i, t.Description)
}
}
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index e87eb4d6bf..53461faec6 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -573,108 +573,263 @@ func convertToPartitionStateWrapper(partitions []*storepb.TablePartitionMetadata
return wrapper
}
+// toString() writes the partition state as SHOW CREATE TABLE syntax to buf, referencing MySQL source code:
+// https://sourcegraph.com/github.com/mysql/mysql-server@824e2b4064053f7daf17d7f3f84b7a3ed92e5fb4/-/blob/sql/sql_show.cc?L2528-2550
func (p *partitionStateWrapper) toString(buf io.StringWriter) error {
// Write version specific comment.
- if _, err := buf.WriteString("/*!50100 PARTITION BY "); err != nil {
+ vsc := p.getVersionSpecificComment()
+ if _, err := buf.WriteString(vsc); err != nil {
return err
}
-
- tp, err := partitionTypeToString(p.tp)
- if err != nil {
- return err
- }
-
- if _, err := buf.WriteString(tp); err != nil {
- return err
- }
-
- if _, err := buf.WriteString(fmt.Sprintf(" (%s)", p.expr)); err != nil {
+ if _, err := buf.WriteString(" PARTITION BY "); err != nil {
return err
}
- // Write subpartition type if any.
- if has, subTp, subExpr := p.hasSubpartitions(); has {
- if _, err := buf.WriteString("\nSUBPARTITION BY "); err != nil {
+ switch p.tp {
+ case storepb.TablePartitionMetadata_RANGE, storepb.TablePartitionMetadata_RANGE_COLUMNS:
+ if _, err := buf.WriteString("RANGE "); err != nil {
return err
}
- subTp, err := partitionTypeToString(subTp)
- if err != nil {
- return err
+ if p.tp == storepb.TablePartitionMetadata_RANGE {
+ fields := splitPartitionExprIntoFields(p.expr)
+ for i, field := range fields {
+ fields[i] = fmt.Sprintf("`%s`", field)
+ }
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ } else {
+ // I think MySQL need to write "COLUMNS " instead of " COLUMNS" here...
+ if _, err := buf.WriteString(" COLUMNS"); err != nil {
+ return err
+ }
+ fields := splitPartitionExprIntoFields(p.expr)
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
}
- if _, err := buf.WriteString(subTp); err != nil {
+ case storepb.TablePartitionMetadata_LIST, storepb.TablePartitionMetadata_LIST_COLUMNS:
+ if _, err := buf.WriteString("LIST "); err != nil {
return err
}
- if _, err := buf.WriteString(fmt.Sprintf(" (%s)", subExpr)); err != nil {
+ if p.tp == storepb.TablePartitionMetadata_LIST {
+ fields := splitPartitionExprIntoFields(p.expr)
+ for i, field := range fields {
+ fields[i] = fmt.Sprintf("`%s`", field)
+ }
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ } else {
+ // I think MySQL need to write "COLUMNS " instead of " COLUMNS" here...
+ if _, err := buf.WriteString(" COLUMNS"); err != nil {
+ return err
+ }
+ fields := splitPartitionExprIntoFields(p.expr)
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ }
+ case storepb.TablePartitionMetadata_HASH, storepb.TablePartitionMetadata_KEY, storepb.TablePartitionMetadata_LINEAR_HASH, storepb.TablePartitionMetadata_LINEAR_KEY:
+ if p.tp == storepb.TablePartitionMetadata_LINEAR_HASH || p.tp == storepb.TablePartitionMetadata_LINEAR_KEY {
+ if _, err := buf.WriteString("LINEAR "); err != nil {
+ return err
+ }
+ }
+ if p.tp == storepb.TablePartitionMetadata_KEY || p.tp == storepb.TablePartitionMetadata_LINEAR_KEY {
+ if _, err := buf.WriteString("KEY "); err != nil {
+ return err
+ }
+ // TODO(zp): MySQL supports an ALGORITHM option with [SUB]PARTITION BY [LINEAR KEY]. ALGORITHM=1 causes the server to use the same key-hashing function as MYSQL 5.1, and ALGORITHM=1 is the only possible output in
+ // the following code. Sadly, I do not know how to get the key_algorithm from the INFORMATION_SCHEMA, AND 5.1 IS TOO LEGACY TO SUPPORT! So skip it.
+ /*
+ current_comment_start is given when called from SHOW CREATE TABLE,
+ Then only add ALGORITHM = 1, not the default 2 or non-set 0!
+ For .frm current_comment_start is NULL, then add ALGORITHM if != 0.
+ */
+ // if (part_info->key_algorithm ==
+ // enum_key_algorithm::KEY_ALGORITHM_51 || // SHOW
+ // (!current_comment_start && // .frm
+ // (part_info->key_algorithm != enum_key_algorithm::KEY_ALGORITHM_NONE))) {
+ // /* If we already are within a comment, end that comment first. */
+ // if (current_comment_start) err += add_string(fptr, "*/ ");
+ // err += add_string(fptr, "/*!50611 ");
+ // err += add_part_key_word(fptr, partition_keywords[PKW_ALGORITHM].str);
+ // err += add_equal(fptr);
+ // err += add_space(fptr);
+ // err += add_int(fptr, static_cast<longlong>(part_info->key_algorithm));
+ // err += add_space(fptr);
+ // err += add_string(fptr, "*/ ");
+ // if (current_comment_start) {
+ // /* Skip new line. */
+ // if (current_comment_start[0] == '\n') current_comment_start++;
+ // err += add_string(fptr, current_comment_start);
+ // err += add_space(fptr);
+ // }
+ // }
+ // HACK(zp): Write the part field list. In the MySQL source code, it calls append_identifier(), which considers the quote character. We should figure out the logic of it later.
+ // Currently, I just found that if the expr contains more than one field, it would not be quoted by '`'.
+ // KEY and LINEAR KEY can take the field list.
+ // While MySQL calls append_field_list() to write the field list, it unmask the OPTION_QUOTE_SHOW_CREATE flag,
+ // for us, we do the best effort to split the expr by ',' and trim the leading and trailing '`', and write it to the buffer after joining them with ','.
+ fields := splitPartitionExprIntoFields(p.expr)
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ } else {
+ if _, err := buf.WriteString("HASH "); err != nil {
+ return err
+ }
+ fields := splitPartitionExprIntoFields(p.expr)
+ for i, field := range fields {
+ fields[i] = fmt.Sprintf("`%s`", field)
+ }
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ }
+ default:
+ return errors.Errorf("unsupported partition type: %v", p.tp)
+ }
+
+ // TODO(zp): MySQL writes the default partitions in the following code, which means that the server
+ // takes the responsibility to generate the partitions. Sadly, we cannot get whether the user
+ // use this or not in the metadata. So we skip it.
+ /*
+ if ((!part_info->use_default_num_partitions) &&
+ part_info->use_default_partitions) {
+ err += add_string(fptr, "\n");
+ err += add_string(fptr, "PARTITIONS ");
+ err += add_int(fptr, part_info->num_parts);
+ }
+ */
+
+ isSubpartitioned, subPartitionTp, subPartitionFieldList := p.hasSubpartitions()
+ if isSubpartitioned {
+ if _, err := buf.WriteString("\nSUBPARTITION BY "); err != nil {
return err
}
}
+ // Subpartition must be hash or key.
+ if isSubpartitioned {
+ switch subPartitionTp {
+ case storepb.TablePartitionMetadata_HASH, storepb.TablePartitionMetadata_LINEAR_HASH:
+ if subPartitionTp == storepb.TablePartitionMetadata_LINEAR_HASH {
+ if _, err := buf.WriteString("LINEAR "); err != nil {
+ return err
+ }
+ }
+ if _, err := buf.WriteString("HASH "); err != nil {
+ return err
+ }
+ fields := splitPartitionExprIntoFields(subPartitionFieldList)
+ for i, field := range fields {
+ fields[i] = fmt.Sprintf("`%s`", field)
+ }
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ case storepb.TablePartitionMetadata_KEY, storepb.TablePartitionMetadata_LINEAR_KEY:
+ if subPartitionTp == storepb.TablePartitionMetadata_LINEAR_KEY {
+ if _, err := buf.WriteString("LINEAR "); err != nil {
+ return err
+ }
+ }
+ if _, err := buf.WriteString("KEY "); err != nil {
+ return err
+ }
+ fields := splitPartitionExprIntoFields(subPartitionFieldList)
+ if _, err := buf.WriteString(fmt.Sprintf("(%s)", strings.Join(fields, ","))); err != nil {
+ return err
+ }
+ default:
+ return errors.Errorf("invalid subpartition type: %v", subPartitionTp)
+ }
+ }
- parititonSlice := make([]*partitionState, 0, len(p.partitions))
+ // TODO(zp): MySQL writes the default subpartitions in the following code, which means that the server
+ // takes the responsibility to generate the subpartitions. Sadly, we cannot get whether the user
+ // use this or not in the metadata. So we skip it.
+ /*
+ if ((!part_info->use_default_num_subpartitions) &&
+ part_info->use_default_subpartitions) {
+ err += add_string(fptr, "\n");
+ err += add_string(fptr, "SUBPARTITIONS ");
+ err += add_int(fptr, part_info->num_subparts);
+ }
+ */
+
+ // Write the partition list.
+ if len(p.partitions) == 0 {
+ return errors.New("empty partition list")
+ }
+ sortedPartitions := make([]*partitionState, 0, len(p.partitions))
for _, partition := range p.partitions {
- parititonSlice = append(parititonSlice, partition)
+ sortedPartitions = append(sortedPartitions, partition)
}
- sort.Slice(parititonSlice, func(i, j int) bool {
- return parititonSlice[i].id < parititonSlice[j].id
+ sort.Slice(sortedPartitions, func(i, j int) bool {
+ return sortedPartitions[i].id < sortedPartitions[j].id
})
-
- for idx, partition := range parititonSlice {
- prefix := "("
- if idx > 0 {
- prefix = strings.Repeat(" ", 1)
- }
- suffix := ","
- if idx == len(parititonSlice)-1 {
- suffix = ")"
+ if _, err := buf.WriteString("\n("); err != nil {
+ return err
+ }
+ preposition, err := getPrepositionByType(p.tp)
+ if err != nil {
+ return err
+ }
+ for i, partition := range sortedPartitions {
+ if i != 0 {
+ if _, err := buf.WriteString(",\n "); err != nil {
+ return err
+ }
}
-
- if _, err := buf.WriteString(fmt.Sprintf("\n%s", prefix)); err != nil {
+ if _, err := buf.WriteString(fmt.Sprintf("PARTITION %s", partition.name)); err != nil {
return err
}
-
- var valuesWrap string
- if strings.EqualFold(partition.value, "MAXVALUE") {
- valuesWrap = "MAXVALUE"
- } else {
- valuesWrap = fmt.Sprintf("(%s)", partition.value)
- }
- if _, err := buf.WriteString(fmt.Sprintf("PARTITION %s VALUES LESS THAN %s", partition.name, valuesWrap)); err != nil {
- return err
+ if preposition != "" {
+ if _, err := buf.WriteString(fmt.Sprintf(" VALUES %s (%s)", preposition, partition.value)); err != nil {
+ return err
+ }
}
- if partition.subPartition == nil {
- if _, err := buf.WriteString(" ENGINE = InnoDB"); err != nil {
+
+ if isSubpartitioned {
+ if _, err := buf.WriteString("\n ("); err != nil {
return err
}
- } else {
- subPartitionSlice := make([]*partitionState, 0, len(partition.subPartition.partitions))
+ sortedSubpartitions := make([]*partitionState, 0, len(partition.subPartition.partitions))
for _, subPartition := range partition.subPartition.partitions {
- subPartitionSlice = append(subPartitionSlice, subPartition)
+ sortedSubpartitions = append(sortedSubpartitions, subPartition)
}
- sort.Slice(subPartitionSlice, func(i, j int) bool {
- return subPartitionSlice[i].id < subPartitionSlice[j].id
+ sort.Slice(sortedSubpartitions, func(i, j int) bool {
+ return sortedSubpartitions[i].id < sortedSubpartitions[j].id
})
-
- for subIdx, subPartition := range subPartitionSlice {
- prefix := " ("
- if subIdx > 0 {
- prefix = strings.Repeat(" ", 2)
- }
- suffix := ","
- if subIdx == len(subPartitionSlice)-1 {
- suffix = ")"
- }
- if _, err := buf.WriteString(fmt.Sprintf("\n%s", prefix)); err != nil {
+ for j, subPartition := range sortedSubpartitions {
+ if _, err := buf.WriteString(fmt.Sprintf("SUBPARTITION %s", subPartition.name)); err != nil {
return err
}
- if _, err := buf.WriteString(fmt.Sprintf("SUBPARTITION %s ENGINE = InnoDB", subPartition.name)); err != nil {
+ if err := p.writePartitionOptions(buf); err != nil {
return err
}
- if _, err := buf.WriteString(suffix); err != nil {
- return err
+ if j == len(sortedSubpartitions)-1 {
+ if _, err := buf.WriteString(")"); err != nil {
+ return err
+ }
+ } else {
+ if _, err := buf.WriteString(",\n "); err != nil {
+ return err
+ }
}
}
+ } else {
+ if err := p.writePartitionOptions(buf); err != nil {
+ return err
+ }
}
- if _, err := buf.WriteString(suffix); err != nil {
- return err
+
+ if i == len(sortedPartitions)-1 {
+ if _, err := buf.WriteString(")"); err != nil {
+ return err
+ }
}
}
@@ -685,24 +840,71 @@ func (p *partitionStateWrapper) toString(buf io.StringWriter) error {
return nil
}
-func partitionTypeToString(tp storepb.TablePartitionMetadata_Type) (string, error) {
+func (*partitionStateWrapper) writePartitionOptions(buf io.StringWriter) error {
+ /*
+ int err = 0;
+ err += add_space(fptr);
+ if (p_elem->tablespace_name) {
+ err += add_string(fptr, "TABLESPACE = ");
+ err += add_ident_string(fptr, p_elem->tablespace_name);
+ err += add_space(fptr);
+ }
+ if (p_elem->nodegroup_id != UNDEF_NODEGROUP)
+ err += add_keyword_int(fptr, "NODEGROUP", (longlong)p_elem->nodegroup_id);
+ if (p_elem->part_max_rows)
+ err += add_keyword_int(fptr, "MAX_ROWS", (longlong)p_elem->part_max_rows);
+ if (p_elem->part_min_rows)
+ err += add_keyword_int(fptr, "MIN_ROWS", (longlong)p_elem->part_min_rows);
+ if (!(current_thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE)) {
+ if (p_elem->data_file_name)
+ err += add_keyword_path(fptr, "DATA DIRECTORY", p_elem->data_file_name);
+ if (p_elem->index_file_name)
+ err += add_keyword_path(fptr, "INDEX DIRECTORY", p_elem->index_file_name);
+ }
+ if (p_elem->part_comment)
+ err += add_keyword_string(fptr, "COMMENT", true, p_elem->part_comment);
+ return err + add_engine(fptr, p_elem->engine_type);
+ */
+ // TODO(zp): Get all the partition options from the metadata is too complex, just write ENGINE=InnoDB for now.
+ if _, err := buf.WriteString(" ENGINE=InnoDB"); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// getVersionSpecificComment is the go code equivalent of MySQL void partition_info::set_show_version_string(String *packet).
+func (p *partitionStateWrapper) getVersionSpecificComment() string {
+ if p.tp == storepb.TablePartitionMetadata_RANGE_COLUMNS || p.tp == storepb.TablePartitionMetadata_LIST_COLUMNS {
+ // MySQL introduce columns partitioning in 5.5+.
+ return "/*!50500"
+ }
+
+ /*
+ if (part_expr)
+ part_expr->walk(&Item::intro_version, enum_walk::POSTFIX,
+ (uchar *)&version);
+ if (subpart_expr)
+ subpart_expr->walk(&Item::intro_version, enum_walk::POSTFIX,
+ (uchar *)&version);
+ */
+ // TODO(zp): Users can use function in partition expr or subpartition expr, and the intro version of function should be the infimum of the version.
+ // But sadly, it's a huge work for us to copy the intro version for each function in MySQL. So we skip it.
+ return "/*!50100"
+}
+
+func getPrepositionByType(tp storepb.TablePartitionMetadata_Type) (string, error) {
switch tp {
case storepb.TablePartitionMetadata_RANGE:
- return "RANGE", nil
+ return "LESS THAN", nil
case storepb.TablePartitionMetadata_RANGE_COLUMNS:
- return "RANGE COLUMNS", nil
+ return "LESS THAN", nil
case storepb.TablePartitionMetadata_LIST:
- return "LIST", nil
+ return "IN", nil
case storepb.TablePartitionMetadata_LIST_COLUMNS:
- return "LIST COLUMNS", nil
- case storepb.TablePartitionMetadata_HASH:
- return "HASH", nil
- case storepb.TablePartitionMetadata_KEY:
- return "KEY", nil
- case storepb.TablePartitionMetadata_LINEAR_HASH:
- return "LINEAR HASH", nil
- case storepb.TablePartitionMetadata_LINEAR_KEY:
- return "LINEAR KEY", nil
+ return "IN", nil
+ case storepb.TablePartitionMetadata_HASH, storepb.TablePartitionMetadata_KEY, storepb.TablePartitionMetadata_LINEAR_HASH, storepb.TablePartitionMetadata_LINEAR_KEY:
+ return "", nil
default:
return "", errors.Errorf("unsupported partition type: %v", tp)
}
@@ -837,3 +1039,15 @@ func convertToColumnState(id int, column *storepb.ColumnMetadata) *columnState {
}
return result
}
+
+// splitPartitioNExprIntoFields splits the partition expression by ',', and trims the leading and trailing '`' for each element.
+func splitPartitionExprIntoFields(expr string) []string {
+ // We do not support the expression contains parentheses, so we can split the expression by ','.
+ ss := strings.Split(expr, ",")
+ for i, s := range ss {
+ if strings.HasPrefix(s, "`") && strings.HasSuffix(s, "`") {
+ ss[i] = s[1 : len(s)-1]
+ }
+ }
+ return ss
+}
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/partition/hash.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/hash.yaml
new file mode 100644
index 0000000000..f50390ed48
--- /dev/null
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/hash.yaml
@@ -0,0 +1,63 @@
+- description: Easy Hash Partition
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `hash_partition`
+ --
+ CREATE TABLE `hash_partition` (
+ `id` int DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "hash_partition",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "nullable": true,
+ "position": 1,
+ "defaultNull": true
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "HASH",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1",
+ "type": "HASH",
+ "expression": "`id`"
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `hash_partition`
+ --
+ CREATE TABLE `hash_partition` (
+ `id` int DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
+ /*!50100 PARTITION BY HASH (`id`)
+ (PARTITION p0 ENGINE=InnoDB,
+ PARTITION p1 ENGINE=InnoDB) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/partition.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/key.yaml
similarity index 58%
rename from backend/plugin/schema/mysql/testdata/get-design-schema/partition.yaml
rename to backend/plugin/schema/mysql/testdata/get-design-schema/partition/key.yaml
index c655f51f30..239d1e814a 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/partition.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/key.yaml
@@ -1,13 +1,13 @@
-- description: Easy Partition
+- description: Easy Key Partition
baseline: |-
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
--
- -- Table structure for `u`
+ -- Table structure for `key_partition_multiple`
--
- CREATE TABLE `u` (
+ CREATE TABLE `key_partition_multiple` (
`id` int DEFAULT NULL,
- `name` varchar(10) DEFAULT NULL
+ `id2` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
@@ -18,7 +18,7 @@
{
"tables": [
{
- "name": "u",
+ "name": "key_partition_multiple",
"engine": "InnoDB",
"columns": [
{
@@ -29,33 +29,23 @@
"defaultNull": true
},
{
- "name": "name",
- "type": "varchar(10)",
+ "name": "id2",
+ "type": "int",
"nullable": true,
"position": 2,
- "collation": "utf8mb4_0900_ai_ci",
- "defaultNull": true,
- "characterSet": "utf8mb4"
+ "defaultNull": true
}
],
"partitions": [
{
"name": "p0",
- "type": "RANGE",
- "value": "100",
- "expression": "`id`"
+ "type": "KEY",
+ "expression": "`id`,`id2`"
},
{
"name": "p1",
- "type": "RANGE",
- "value": "200",
- "expression": "`id`"
- },
- {
- "name": "p2",
- "type": "RANGE",
- "value": "MAXVALUE",
- "expression": "`id`"
+ "type": "KEY",
+ "expression": "`id`,`id2`"
}
],
"collation": "utf8mb4_0900_ai_ci"
@@ -68,16 +58,15 @@
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
--
- -- Table structure for `u`
+ -- Table structure for `key_partition_multiple`
--
- CREATE TABLE `u` (
+ CREATE TABLE `key_partition_multiple` (
`id` int DEFAULT NULL,
- `name` varchar(10) DEFAULT NULL
+ `id2` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
- /*!50100 PARTITION BY RANGE (`id`)
- (PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
- PARTITION p1 VALUES LESS THAN (200) ENGINE = InnoDB,
- PARTITION p2 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */;
+ /*!50100 PARTITION BY KEY (id,id2)
+ (PARTITION p0 ENGINE=InnoDB,
+ PARTITION p1 ENGINE=InnoDB) */;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/partition/list.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/list.yaml
new file mode 100644
index 0000000000..8650980655
--- /dev/null
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/list.yaml
@@ -0,0 +1,335 @@
+- description: List Columns Partition Hash Subpartition
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `list_columns_partition_hash_subpartition`
+ --
+ CREATE TABLE `list_columns_partition_hash_subpartition` (
+ `id` int DEFAULT NULL,
+ `d` date DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "list_columns_partition_hash_subpartition",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "position": 1
+ },
+ {
+ "name": "d",
+ "type": "date",
+ "position": 2
+ }
+ ],
+ "indexes": [
+ {
+ "name": "PRIMARY",
+ "type": "BTREE",
+ "unique": true,
+ "primary": true,
+ "visible": true,
+ "keyLength": [
+ "-1",
+ "-1"
+ ],
+ "expressions": [
+ "id",
+ "d"
+ ]
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "LIST_COLUMNS",
+ "value": "(1,'2012-01-01'),(2,'2012-01-02'),(3,'2012-01-03')",
+ "expression": "`id`,`d`",
+ "subpartitions": [
+ {
+ "name": "p0sp0",
+ "type": "HASH",
+ "value": "(1,'2012-01-01'),(2,'2012-01-02'),(3,'2012-01-03')",
+ "expression": "`id`"
+ },
+ {
+ "name": "p0sp1",
+ "type": "HASH",
+ "value": "(1,'2012-01-01'),(2,'2012-01-02'),(3,'2012-01-03')",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p1",
+ "type": "LIST_COLUMNS",
+ "value": "(4,'2012-01-01'),(5,'2012-01-02'),(6,'2012-01-03')",
+ "expression": "`id`,`d`",
+ "subpartitions": [
+ {
+ "name": "p1sp0",
+ "type": "HASH",
+ "value": "(4,'2012-01-01'),(5,'2012-01-02'),(6,'2012-01-03')",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1sp1",
+ "type": "HASH",
+ "value": "(4,'2012-01-01'),(5,'2012-01-02'),(6,'2012-01-03')",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p2",
+ "type": "LIST_COLUMNS",
+ "value": "(7,'2012-01-01'),(8,'2012-01-02'),(9,'2012-01-03')",
+ "expression": "`id`,`d`",
+ "subpartitions": [
+ {
+ "name": "p2sp0",
+ "type": "HASH",
+ "value": "(7,'2012-01-01'),(8,'2012-01-02'),(9,'2012-01-03')",
+ "expression": "`id`"
+ },
+ {
+ "name": "p2sp1",
+ "type": "HASH",
+ "value": "(7,'2012-01-01'),(8,'2012-01-02'),(9,'2012-01-03')",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p_null",
+ "type": "LIST_COLUMNS",
+ "value": "(NULL,NULL)",
+ "expression": "`id`,`d`",
+ "subpartitions": [
+ {
+ "name": "p3sp0",
+ "type": "HASH",
+ "value": "(NULL,NULL)",
+ "expression": "`id`"
+ },
+ {
+ "name": "p3sp1",
+ "type": "HASH",
+ "value": "(NULL,NULL)",
+ "expression": "`id`"
+ }
+ ]
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `list_columns_partition_hash_subpartition`
+ --
+ CREATE TABLE `list_columns_partition_hash_subpartition` (
+ `id` int NOT NULL,
+ `d` date NOT NULL,
+ PRIMARY KEY (`id`, `d`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
+ /*!50500 PARTITION BY LIST COLUMNS(id,d)
+ SUBPARTITION BY HASH (`id`)
+ (PARTITION p0 VALUES IN ((1,'2012-01-01'),(2,'2012-01-02'),(3,'2012-01-03'))
+ (SUBPARTITION p0sp0 ENGINE=InnoDB,
+ SUBPARTITION p0sp1 ENGINE=InnoDB),
+ PARTITION p1 VALUES IN ((4,'2012-01-01'),(5,'2012-01-02'),(6,'2012-01-03'))
+ (SUBPARTITION p1sp0 ENGINE=InnoDB,
+ SUBPARTITION p1sp1 ENGINE=InnoDB),
+ PARTITION p2 VALUES IN ((7,'2012-01-01'),(8,'2012-01-02'),(9,'2012-01-03'))
+ (SUBPARTITION p2sp0 ENGINE=InnoDB,
+ SUBPARTITION p2sp1 ENGINE=InnoDB),
+ PARTITION p_null VALUES IN ((NULL,NULL))
+ (SUBPARTITION p3sp0 ENGINE=InnoDB,
+ SUBPARTITION p3sp1 ENGINE=InnoDB)) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+- description: List Columns Partition
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `list_columns_partition`
+ --
+ CREATE TABLE `list_columns_partition` (
+ `id` int DEFAULT NULL,
+ `d` date DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "list_columns_partition",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "nullable": true,
+ "position": 1,
+ "defaultNull": true
+ },
+ {
+ "name": "d",
+ "type": "date",
+ "nullable": true,
+ "position": 2,
+ "defaultNull": true
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "LIST_COLUMNS",
+ "value": "(1,'2012-01-01'),(2,'2012-01-02'),(3,'2012-01-03')",
+ "expression": "`id`,`d`"
+ },
+ {
+ "name": "p1",
+ "type": "LIST_COLUMNS",
+ "value": "(4,'2012-01-01'),(5,'2012-01-02'),(6,'2012-01-03')",
+ "expression": "`id`,`d`"
+ },
+ {
+ "name": "p2",
+ "type": "LIST_COLUMNS",
+ "value": "(7,'2012-01-01'),(8,'2012-01-02'),(9,'2012-01-03')",
+ "expression": "`id`,`d`"
+ },
+ {
+ "name": "p_null",
+ "type": "LIST_COLUMNS",
+ "value": "(NULL,NULL)",
+ "expression": "`id`,`d`"
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `list_columns_partition`
+ --
+ CREATE TABLE `list_columns_partition` (
+ `id` int DEFAULT NULL,
+ `d` date DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
+ /*!50500 PARTITION BY LIST COLUMNS(id,d)
+ (PARTITION p0 VALUES IN ((1,'2012-01-01'),(2,'2012-01-02'),(3,'2012-01-03')) ENGINE=InnoDB,
+ PARTITION p1 VALUES IN ((4,'2012-01-01'),(5,'2012-01-02'),(6,'2012-01-03')) ENGINE=InnoDB,
+ PARTITION p2 VALUES IN ((7,'2012-01-01'),(8,'2012-01-02'),(9,'2012-01-03')) ENGINE=InnoDB,
+ PARTITION p_null VALUES IN ((NULL,NULL)) ENGINE=InnoDB) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+- description: Easy List Partition
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `list_partition`
+ --
+ CREATE TABLE `list_partition` (
+ `id` int DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "u",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "nullable": true,
+ "position": 1,
+ "defaultNull": true
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "LIST",
+ "value": "1,2,3",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1",
+ "type": "LIST",
+ "value": "4,5,6",
+ "expression": "`id`"
+ },
+ {
+ "name": "p2",
+ "type": "LIST",
+ "value": "7,8,9",
+ "expression": "`id`"
+ },
+ {
+ "name": "p_null",
+ "type": "LIST",
+ "value": "NULL",
+ "expression": "`id`"
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+
+ --
+ -- Table structure for `u`
+ --
+ CREATE TABLE `u` (
+ `id` int DEFAULT NULL
+ ) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci
+ /*!50100 PARTITION BY LIST (`id`)
+ (PARTITION p0 VALUES IN (1,2,3) ENGINE=InnoDB,
+ PARTITION p1 VALUES IN (4,5,6) ENGINE=InnoDB,
+ PARTITION p2 VALUES IN (7,8,9) ENGINE=InnoDB,
+ PARTITION p_null VALUES IN (NULL) ENGINE=InnoDB) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/partition/range.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/range.yaml
new file mode 100644
index 0000000000..f19d1ec002
--- /dev/null
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/partition/range.yaml
@@ -0,0 +1,300 @@
+- description: Range Columns
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `u`
+ --
+ CREATE TABLE `u` (
+ `id` int DEFAULT NULL,
+ `name` varchar(10) DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "range_columns_partition_hash_subpartition",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "nullable": true,
+ "position": 1,
+ "defaultNull": true
+ },
+ {
+ "name": "d",
+ "type": "date",
+ "nullable": true,
+ "position": 2,
+ "defaultNull": true
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "RANGE_COLUMNS",
+ "value": "1,'2012-01-01 00:00:00'",
+ "expression": "`id`,`d`",
+ "subpartitions": [
+ {
+ "name": "p0sp0",
+ "type": "KEY",
+ "value": "1,'2012-01-01 00:00:00'",
+ "expression": "`id`"
+ },
+ {
+ "name": "p0sp1",
+ "type": "KEY",
+ "value": "1,'2012-01-01 00:00:00'",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p1",
+ "type": "RANGE_COLUMNS",
+ "value": "2,'2012-01-02 00:00:00'",
+ "expression": "`id`,`d`",
+ "subpartitions": [
+ {
+ "name": "p1sp0",
+ "type": "KEY",
+ "value": "2,'2012-01-02 00:00:00'",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1sp1",
+ "type": "KEY",
+ "value": "2,'2012-01-02 00:00:00'",
+ "expression": "`id`"
+ }
+ ]
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+
+ --
+ -- Table structure for `range_columns_partition_hash_subpartition`
+ --
+ CREATE TABLE `range_columns_partition_hash_subpartition` (
+ `id` int DEFAULT NULL,
+ `d` date DEFAULT NULL
+ ) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci
+ /*!50500 PARTITION BY RANGE COLUMNS(id,d)
+ SUBPARTITION BY KEY (id)
+ (PARTITION p0 VALUES LESS THAN (1,'2012-01-01 00:00:00')
+ (SUBPARTITION p0sp0 ENGINE=InnoDB,
+ SUBPARTITION p0sp1 ENGINE=InnoDB),
+ PARTITION p1 VALUES LESS THAN (2,'2012-01-02 00:00:00')
+ (SUBPARTITION p1sp0 ENGINE=InnoDB,
+ SUBPARTITION p1sp1 ENGINE=InnoDB)) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+- description: Subpartition
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `range_partition_hash_subpartition`
+ --
+ CREATE TABLE `range_partition_hash_subpartition` (
+ `id` int DEFAULT NULL,
+ `name` varchar(10) DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "range_partition_hash_subpartition",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "nullable": true,
+ "position": 1,
+ "defaultNull": true
+ },
+ {
+ "name": "name",
+ "type": "varchar(10)",
+ "nullable": true,
+ "position": 2,
+ "collation": "utf8mb4_0900_ai_ci",
+ "defaultNull": true,
+ "characterSet": "utf8mb4"
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "RANGE",
+ "value": "10",
+ "expression": "`id`",
+ "subpartitions": [
+ {
+ "name": "p0s0",
+ "type": "HASH",
+ "value": "10",
+ "expression": "`id`"
+ },
+ {
+ "name": "p0s1",
+ "type": "HASH",
+ "value": "10",
+ "expression": "`id`"
+ }
+ ]
+ },
+ {
+ "name": "p1",
+ "type": "RANGE",
+ "value": "MAXVALUE",
+ "expression": "`id`",
+ "subpartitions": [
+ {
+ "name": "p1s0",
+ "type": "HASH",
+ "value": "MAXVALUE",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1s1",
+ "type": "HASH",
+ "value": "MAXVALUE",
+ "expression": "`id`"
+ }
+ ]
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `range_partition_hash_subpartition`
+ --
+ CREATE TABLE `range_partition_hash_subpartition` (
+ `id` int DEFAULT NULL,
+ `name` varchar(10) DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
+ /*!50100 PARTITION BY RANGE (`id`)
+ SUBPARTITION BY HASH (`id`)
+ (PARTITION p0 VALUES LESS THAN (10)
+ (SUBPARTITION p0s0 ENGINE=InnoDB,
+ SUBPARTITION p0s1 ENGINE=InnoDB),
+ PARTITION p1 VALUES LESS THAN (MAXVALUE)
+ (SUBPARTITION p1s0 ENGINE=InnoDB,
+ SUBPARTITION p1s1 ENGINE=InnoDB)) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+- description: Easy Range Partition
+ baseline: |-
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `range_partition`
+ --
+ CREATE TABLE `range_partition` (
+ `id` int DEFAULT NULL,
+ `name` varchar(10) DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
+ target: |-
+ {
+ "schemas": [
+ {
+ "tables": [
+ {
+ "name": "range_partition",
+ "engine": "InnoDB",
+ "columns": [
+ {
+ "name": "id",
+ "type": "int",
+ "nullable": true,
+ "position": 1,
+ "defaultNull": true
+ },
+ {
+ "name": "name",
+ "type": "varchar(10)",
+ "nullable": true,
+ "position": 2,
+ "collation": "utf8mb4_0900_ai_ci",
+ "defaultNull": true,
+ "characterSet": "utf8mb4"
+ }
+ ],
+ "partitions": [
+ {
+ "name": "p0",
+ "type": "RANGE",
+ "value": "100",
+ "expression": "`id`"
+ },
+ {
+ "name": "p1",
+ "type": "RANGE",
+ "value": "200",
+ "expression": "`id`"
+ },
+ {
+ "name": "p2",
+ "type": "RANGE",
+ "value": "MAXVALUE",
+ "expression": "`id`"
+ }
+ ],
+ "collation": "utf8mb4_0900_ai_ci"
+ }
+ ]
+ }
+ ]
+ }
+ result: |
+ SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
+ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
+ --
+ -- Table structure for `range_partition`
+ --
+ CREATE TABLE `range_partition` (
+ `id` int DEFAULT NULL,
+ `name` varchar(10) DEFAULT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
+ /*!50100 PARTITION BY RANGE (`id`)
+ (PARTITION p0 VALUES LESS THAN (100) ENGINE=InnoDB,
+ PARTITION p1 VALUES LESS THAN (200) ENGINE=InnoDB,
+ PARTITION p2 VALUES LESS THAN (MAXVALUE) ENGINE=InnoDB) */;
+
+ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
+ SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;