#2743 - Postgres DDL - For create table, improve column ordering for tighter storage

This commit is contained in:
Rob Bygrave
2022-07-07 22:06:21 +12:00
parent 110bc614e4
commit 5f6efd29ef
3 changed files with 11 additions and 3 deletions
@@ -198,7 +198,9 @@ public class PlatformDdl {
* Write all the table columns converting to platform types as necessary.
*/
public void writeTableColumns(DdlBuffer apply, List<Column> columns, DdlIdentity identity) {
columns = sortColumns(columns);
if ("true".equalsIgnoreCase(System.getProperty("ebean.ddl.sortColumns", "true"))) {
columns = sortColumns(columns);
}
for (int i = 0; i < columns.size(); i++) {
if (i > 0) {
apply.append(",");
@@ -106,7 +106,7 @@ public class PostgresDdl extends PlatformDdl {
}
private boolean isVariableLength(String type) {
return type.startsWith("varchar") || type.startsWith("varbinary");
return type.startsWith("varchar") || type.startsWith("varbinary") || type.startsWith("json");
}
static final class DDLColumnSort implements Comparable<DDLColumnSort> {
@@ -11,7 +11,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class PostgresDdlTest {
private PostgresDdl postgresDdl = new PostgresDdl(new PostgresPlatform());
final PostgresDdl postgresDdl = new PostgresDdl(new PostgresPlatform());
@Test
void setLockTimeout() {
@@ -40,6 +40,12 @@ class PostgresDdlTest {
assertThat(cols).extracting("type").containsExactly("int", "decimal(1)", "decimal(2)", "varbinary(1)", "varbinary(2)");
}
@Test
void sortColumns_json() {
List<Column> cols = postgresDdl.sortColumns(columns("json", "jsonb", "int"));
assertThat(cols).extracting("type").containsExactly("int", "json", "jsonb");
}
@Test
void sortColumns_clobs() {
List<Column> cols = postgresDdl.sortColumns(columns("clob", "blob", "longvarchar(1)", "int", "longvarbinary(2)"));