Skip to content
Permalink
Browse files

0003751: PostgreSQL 9.5 can use "insert on conflict do nothing" for

better performance
  • Loading branch information...
erilong committed Oct 10, 2018
1 parent e6c5464 commit f6c842a49c74edba04fe29f14518c74c88be4f47
@@ -52,6 +52,7 @@ public IDataWriter getDataWriter(String sourceNodeId, ISymmetricDialect symmetri
return new OracleBulkDataLoaderFactory(engine).getDataWriter(sourceNodeId, symmetricDialect, transformWriter,
filters, errorHandlers, conflictSettings, resolvedData);
} else if (DatabaseNamesConstants.POSTGRESQL.equals(engine.getSymmetricDialect().getTargetPlatform().getName())
|| DatabaseNamesConstants.POSTGRESQL95.equals(engine.getSymmetricDialect().getTargetPlatform().getName())
|| DatabaseNamesConstants.GREENPLUM.equals(engine.getSymmetricDialect().getTargetPlatform().getName())) {
return new PostgresBulkDataLoaderFactory(engine).getDataWriter(sourceNodeId, symmetricDialect, transformWriter,
filters, errorHandlers, conflictSettings, resolvedData);
@@ -65,6 +65,7 @@ public IDataWriter getDataWriter(String sourceNodeId, ISymmetricDialect symmetri

public boolean isPlatformSupported(IDatabasePlatform platform) {
return DatabaseNamesConstants.POSTGRESQL.equals(platform.getName()) ||
DatabaseNamesConstants.POSTGRESQL95.equals(platform.getName()) ||
DatabaseNamesConstants.GREENPLUM.equals(platform.getName());
}

@@ -45,6 +45,7 @@ private DatabaseNamesConstants() {
public final static String DB2ZOS = "db2zos";
public final static String DB2AS400 = "db2as400";
public final static String POSTGRESQL = "postgres";
public final static String POSTGRESQL95 = "postgres95";
public final static String ASE = "ase";
public final static String SQLANYWHERE = "sqlanywhere";
public final static String MARIADB = "mariadb";
@@ -86,7 +86,8 @@ public static final IDdlBuilder createDdlBuilder(String databaseName) {
return new MySqlDdlBuilder();
} else if (DatabaseNamesConstants.ORACLE.equalsIgnoreCase(databaseName)) {
return new OracleDdlBuilder();
} else if (DatabaseNamesConstants.POSTGRESQL.equalsIgnoreCase(databaseName)) {
} else if (DatabaseNamesConstants.POSTGRESQL.equalsIgnoreCase(databaseName)
|| DatabaseNamesConstants.POSTGRESQL95.equalsIgnoreCase(databaseName)) {
return new PostgreSqlDdlBuilder();
} else if (DatabaseNamesConstants.SQLITE.equalsIgnoreCase(databaseName)) {
return new SqliteDdlBuilder();
@@ -27,6 +27,7 @@
import org.jumpmind.db.platform.mysql.MySqlDmlStatement;
import org.jumpmind.db.platform.oracle.OracleDmlStatement;
import org.jumpmind.db.platform.postgresql.PostgreSqlDmlStatement;
import org.jumpmind.db.platform.postgresql.PostgreSqlDmlStatement95;
import org.jumpmind.db.platform.redshift.RedshiftDmlStatement;
import org.jumpmind.db.platform.sqlanywhere.SqlAnywhereDmlStatement;
import org.jumpmind.db.platform.sqlite.SqliteDmlStatement;
@@ -70,6 +71,10 @@ public static DmlStatement createDmlStatement(String databaseName, DmlType dmlTy
return new PostgreSqlDmlStatement(dmlType, catalogName, schemaName, tableName, keys,
columns, nullKeyValues, ddlBuilder.getDatabaseInfo(),
ddlBuilder.isDelimitedIdentifierModeOn(), textColumnExpression);
} else if (DatabaseNamesConstants.POSTGRESQL95.equals(databaseName)) {
return new PostgreSqlDmlStatement95(dmlType, catalogName, schemaName, tableName, keys,
columns, nullKeyValues, ddlBuilder.getDatabaseInfo(),
ddlBuilder.isDelimitedIdentifierModeOn(), textColumnExpression);
} else if (DatabaseNamesConstants.REDSHIFT.equals(databaseName)) {
return new RedshiftDmlStatement(dmlType, catalogName, schemaName, tableName, keys,
columns, nullKeyValues, ddlBuilder.getDatabaseInfo(),
@@ -0,0 +1,67 @@
package org.jumpmind.db.platform.postgresql;

import java.util.Map;

import org.jumpmind.db.model.Column;
import org.jumpmind.db.platform.DatabaseInfo;

public class PostgreSqlDmlStatement95 extends PostgreSqlDmlStatement {

public PostgreSqlDmlStatement95(DmlType type, String catalogName, String schemaName, String tableName,
Column[] keysColumns, Column[] columns, boolean[] nullKeyValues, DatabaseInfo databaseInfo,
boolean useQuotedIdentifiers, String textColumnExpression) {
super(type, catalogName, schemaName, tableName, keysColumns, columns, nullKeyValues, databaseInfo, useQuotedIdentifiers,
textColumnExpression);
}

@Override
public String buildInsertSql(String tableName, Column[] keys, Column[] columns) {
StringBuilder sql = new StringBuilder("insert into " + tableName + " (");
appendColumns(sql, columns, false);
sql.append(") values (");
appendColumnParameters(sql, columns);
sql.append(") on conflict do nothing");
return sql.toString();
}

@Override
public Column[] getMetaData() {
if (dmlType == DmlType.INSERT) {
return getColumns();
} else {
return super.getMetaData();
}
}

@Override
public <T> T[] getValueArray(T[] columnValues, T[] keyValues) {
if (dmlType == DmlType.INSERT) {
return columnValues;
} else {
return super.getValueArray(columnValues, keyValues);
}
}

@Override
public Object[] getValueArray(Map<String, Object> params) {
if (dmlType == DmlType.INSERT) {
int index = 0;
Object[] args = new Object[columns.length];
for (Column column : columns) {
args[index++] = params.get(column.getName());
}
return args;
}
return super.getValueArray(params);
}

@Override
protected int[] buildTypes(Column[] keys, Column[] columns, boolean isDateOverrideToTimestamp) {
if (dmlType == DmlType.INSERT) {
return buildTypes(columns, isDateOverrideToTimestamp);
} else {
return super.buildTypes(keys, columns, isDateOverrideToTimestamp);
}
}

}
@@ -65,7 +65,7 @@
};

public enum Compatible {
DB2, DB2ZOS, DERBY, FIREBIRD, FIREBIRD_DIALECT1, GREENPLUM, H2, HSQLDB, HSQLDB2, INFORMIX, INTERBASE, MSSQL, MSSQL2000, MSSQL2005, MSSQL2008, MYSQL, ORACLE, POSTGRES, SYBASE, SQLITE, MARIADB, ASE, SQLANYWHERE, REDSHIFT, VOLTDB, NUODB, TIBERO, GENERIC
DB2, DB2ZOS, DERBY, FIREBIRD, FIREBIRD_DIALECT1, GREENPLUM, H2, HSQLDB, HSQLDB2, INFORMIX, INTERBASE, MSSQL, MSSQL2000, MSSQL2005, MSSQL2008, MYSQL, ORACLE, POSTGRES, POSTGRES95, SYBASE, SQLITE, MARIADB, ASE, SQLANYWHERE, REDSHIFT, VOLTDB, NUODB, TIBERO, GENERIC
};

private Format format = Format.SQL;
@@ -53,6 +53,7 @@
import org.jumpmind.db.platform.mysql.MySqlDatabasePlatform;
import org.jumpmind.db.platform.nuodb.NuoDbDatabasePlatform;
import org.jumpmind.db.platform.oracle.OracleDatabasePlatform;
import org.jumpmind.db.platform.postgresql.PostgreSql95DatabasePlatform;
import org.jumpmind.db.platform.postgresql.PostgreSqlDatabasePlatform;
import org.jumpmind.db.platform.raima.RaimaDatabasePlatform;
import org.jumpmind.db.platform.redshift.RedshiftDatabasePlatform;
@@ -105,6 +106,7 @@
addPlatform(platforms, "MySQL", MySqlDatabasePlatform.class);
addPlatform(platforms, "Oracle", OracleDatabasePlatform.class);
addPlatform(platforms, "PostgreSql", PostgreSqlDatabasePlatform.class);
addPlatform(platforms, DatabaseNamesConstants.POSTGRESQL95, PostgreSql95DatabasePlatform.class);
addPlatform(platforms, "Adaptive Server Enterprise", AseDatabasePlatform.class);
addPlatform(platforms, "Adaptive Server Anywhere", SqlAnywhereDatabasePlatform.class);
addPlatform(platforms, "SQL Anywhere", SqlAnywhereDatabasePlatform.class);
@@ -237,6 +239,9 @@ public static synchronized IDatabasePlatform createNewPlatformInstance(DataSourc
nameVersion[1] = Integer.toString(getGreenplumVersion(connection));
} else if (isRedshiftDatabase(connection)) {
nameVersion[0] = DatabaseNamesConstants.REDSHIFT;
} else if (metaData.getDatabaseMajorVersion() > 9
|| (metaData.getDatabaseMajorVersion() == 9 && metaData.getDatabaseMinorVersion() >= 5)) {
nameVersion[0] = DatabaseNamesConstants.POSTGRESQL95;
}
}

@@ -0,0 +1,36 @@
package org.jumpmind.db.platform.postgresql;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import javax.sql.DataSource;

import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.sql.SqlTemplateSettings;

public class PostgreSql95DatabasePlatform extends PostgreSqlDatabasePlatform {

public PostgreSql95DatabasePlatform(DataSource dataSource, SqlTemplateSettings settings) {
super(dataSource, settings);
}

public String getName() {
return DatabaseNamesConstants.POSTGRESQL95;
}

}

0 comments on commit f6c842a

Please sign in to comment.
You can’t perform that action at this time.