Skip to content

Commit

Permalink
[postgres] Early exit iterator if there's nothing to fetch anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Oct 25, 2017
1 parent a8caf49 commit 62f2091
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/providers/postgres/qgspostgresfeatureiterator.cpp
Expand Up @@ -36,6 +36,13 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
, mLastFetch( false )
, mFilterRequiresGeometry( false )
{
if ( request.filterType() == QgsFeatureRequest::FilterFids && request.filterFids().isEmpty() )
{
mClosed = true;
iteratorClosed();
return;
}

if ( !source->mTransactionConnection )
{
mConn = QgsPostgresConnPool::instance()->acquireConnection( mSource->mConnInfo );
Expand Down Expand Up @@ -65,8 +72,7 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
catch ( QgsCsException & )
{
// can't reproject mFilterRect
mClosed = true;
iteratorClosed();
close();
return;
}

Expand Down Expand Up @@ -96,17 +102,9 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
}
else if ( request.filterType() == QgsFeatureRequest::FilterFids )
{
if ( request.filterFids().isEmpty() )
{
mClosed = true;
iteratorClosed();
}
else
{
QString fidsWhereClause = QgsPostgresUtils::whereClause( mRequest.filterFids(), mSource->mFields, mConn, mSource->mPrimaryKeyType, mSource->mPrimaryKeyAttrs, mSource->mShared );
QString fidsWhereClause = QgsPostgresUtils::whereClause( mRequest.filterFids(), mSource->mFields, mConn, mSource->mPrimaryKeyType, mSource->mPrimaryKeyAttrs, mSource->mShared );

whereClause = QgsPostgresUtils::andWhereClauses( whereClause, fidsWhereClause );
}
whereClause = QgsPostgresUtils::andWhereClauses( whereClause, fidsWhereClause );
}
else if ( request.filterType() == QgsFeatureRequest::FilterExpression )
{
Expand Down Expand Up @@ -237,8 +235,6 @@ QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource
if ( !success )
{
close();
mClosed = true;
iteratorClosed();
}
}

Expand Down

0 comments on commit 62f2091

Please sign in to comment.