Skip to content

Commit

Permalink
Handle Percona compressed column extension
Browse files Browse the repository at this point in the history
Percona has a custom extension where you can set compression at a column
level, see:

https://docs.percona.com/percona-server/5.7/flexibility/compressed_columns.html

This is an extension of the parser as well. As we also support Percona,
we should be able to parse this too and not fail with a syntax error.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
  • Loading branch information
dbussink committed Jan 30, 2025
1 parent be677ef commit 25ac865
Show file tree
Hide file tree
Showing 5 changed files with 5,056 additions and 5,067 deletions.
2 changes: 2 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,8 @@ func (columnFormat ColumnFormat) ToString() string {
return keywordStrings[DYNAMIC]
case DefaultFormat:
return keywordStrings[DEFAULT]
case CompressedFormat:
return keywordStrings[COMPRESSED]
default:
return "Unknown column format type"
}
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ const (
FixedFormat
DynamicFormat
DefaultFormat
CompressedFormat
)

// Transaction access mode
Expand Down
13 changes: 12 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6347,14 +6347,25 @@ func TestParseVersionedComments(t *testing.T) {
partition by range (id)
(partition x values less than (5) engine InnoDB,
partition t values less than (20) engine InnoDB)`,
}, {
input: "CREATE TABLE `TABLE_NAME` (\n `col1` longblob /*!50633 COLUMN_FORMAT COMPRESSED */,\n `id` bigint unsigned NOT NULL,\n PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED",
mysqlVersion: "8.0.1",
output: `create table TABLE_NAME (
col1 longblob column_format compressed,
id bigint unsigned not null,
primary key (id)
) ENGINE InnoDB,
CHARSET utf8mb4,
COLLATE utf8mb4_bin,
ROW_FORMAT COMPRESSED`,
},
}

for _, testcase := range testcases {
t.Run(testcase.input+":"+testcase.mysqlVersion, func(t *testing.T) {
parser, err := New(Options{MySQLServerVersion: testcase.mysqlVersion})
require.NoError(t, err)
tree, err := parser.Parse(testcase.input)
tree, err := parser.ParseStrictDDL(testcase.input)
require.NoError(t, err, testcase.input)
out := String(tree)
require.Equal(t, testcase.output, out)
Expand Down
Loading

0 comments on commit 25ac865

Please sign in to comment.