Skip to content

Commit

Permalink
Small optimisations to postgres provider when using FastInsert
Browse files Browse the repository at this point in the history
Although ideally we should use COPY mode in this case for best
possible speed.
  • Loading branch information
nyalldawson committed Jun 15, 2017
1 parent 72ef452 commit f6ccdc1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -2084,15 +2084,18 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )

insert += values + ')';

if ( mPrimaryKeyType == PktFidMap || mPrimaryKeyType == PktInt || mPrimaryKeyType == PktUint64 )
if ( !( flags & QgsFeatureSink::FastInsert ) )
{
insert += QLatin1String( " RETURNING " );

QString delim;
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
if ( mPrimaryKeyType == PktFidMap || mPrimaryKeyType == PktInt || mPrimaryKeyType == PktUint64 )
{
insert += delim + quotedIdentifier( mAttributeFields.at( idx ).name() );
delim = ',';
insert += QLatin1String( " RETURNING " );

QString delim;
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
{
insert += delim + quotedIdentifier( mAttributeFields.at( idx ).name() );
delim = ',';
}
}
}

Expand Down Expand Up @@ -2141,7 +2144,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )

QgsPostgresResult result( conn->PQexecPrepared( QStringLiteral( "addfeatures" ), params ) );

if ( result.PQresultStatus() == PGRES_TUPLES_OK )
if ( !( flags & QgsFeatureSink::FastInsert ) && result.PQresultStatus() == PGRES_TUPLES_OK )
{
for ( int i = 0; i < mPrimaryKeyAttrs.size(); ++i )
{
Expand All @@ -2153,7 +2156,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )
else if ( result.PQresultStatus() != PGRES_COMMAND_OK )
throw PGException( result );

if ( mPrimaryKeyType == PktOid )
if ( !( flags & QgsFeatureSink::FastInsert ) && mPrimaryKeyType == PktOid )
{
features->setId( result.PQoidValue() );
QgsDebugMsgLevel( QString( "new fid=%1" ).arg( features->id() ), 4 );
Expand Down

0 comments on commit f6ccdc1

Please sign in to comment.