Skip to content
Permalink
Browse files

Fix condition to enable pgsql insert optimization

Fixes a condition to enable Postgis provider insert optimization
(by skipping the PK column if its default is a sequence)
The check must ensure that each row value is also not the SQL
default of nextval('seq'::regclass), otherwise the condition will
not be met
  • Loading branch information
AchilleAsh authored and nyalldawson committed Feb 6, 2019
1 parent 8c18a5c commit f071030019ea6c7b3fa448ec17607663f329f5c8
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/providers/postgres/qgspostgresprovider.cpp
@@ -2040,19 +2040,22 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )
if ( mPrimaryKeyAttrs.size() == 1 &&
defaultValueClause( mPrimaryKeyAttrs[0] ).startsWith( "nextval(" ) )
{
bool foundNonNullPK = false;
bool foundNonEmptyPK = false;
int idx = mPrimaryKeyAttrs[0];
QString defaultValue = defaultValueClause( idx );
for ( int i = 0; i < flist.size(); i++ )
{
QgsAttributes attrs2 = flist[i].attributes();
QVariant v2 = attrs2.value( idx, QVariant( QVariant::Int ) );
if ( !v2.isNull() )
// a PK field with a sequence val is auto populate by QGIS with this default
// we are only interested in non default values
if ( !v2.isNull() && v2.toString() != defaultValue )
{
foundNonNullPK = true;
foundNonEmptyPK = true;
break;
}
}
skipSinglePKField = !foundNonNullPK;
skipSinglePKField = !foundNonEmptyPK;
}

if ( !skipSinglePKField )

0 comments on commit f071030

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