Skip to content

Commit f6ccdc1

Browse files
committedJun 15, 2017
Small optimisations to postgres provider when using FastInsert
Although ideally we should use COPY mode in this case for best possible speed.
1 parent 72ef452 commit f6ccdc1

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,15 +2084,18 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )
20842084

20852085
insert += values + ')';
20862086

2087-
if ( mPrimaryKeyType == PktFidMap || mPrimaryKeyType == PktInt || mPrimaryKeyType == PktUint64 )
2087+
if ( !( flags & QgsFeatureSink::FastInsert ) )
20882088
{
2089-
insert += QLatin1String( " RETURNING " );
2090-
2091-
QString delim;
2092-
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
2089+
if ( mPrimaryKeyType == PktFidMap || mPrimaryKeyType == PktInt || mPrimaryKeyType == PktUint64 )
20932090
{
2094-
insert += delim + quotedIdentifier( mAttributeFields.at( idx ).name() );
2095-
delim = ',';
2091+
insert += QLatin1String( " RETURNING " );
2092+
2093+
QString delim;
2094+
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
2095+
{
2096+
insert += delim + quotedIdentifier( mAttributeFields.at( idx ).name() );
2097+
delim = ',';
2098+
}
20962099
}
20972100
}
20982101

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

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

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

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

0 commit comments

Comments
 (0)