Skip to content

Commit

Permalink
Manage Postgres parallel plans when estimating row count
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Aug 4, 2020
1 parent cca77d5 commit 0573499
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3588,14 +3588,13 @@ long QgsPostgresProvider::featureCount() const
{
// parse explain output to estimate feature count
// we don't use pg_class reltuples because it returns 0 for view
sql = QStringLiteral( "EXPLAIN (FORMAT JSON) SELECT count(*) FROM %1%2" ).arg( mQuery, filterWhereClause() );
sql = QStringLiteral( "EXPLAIN (FORMAT JSON) SELECT 1 FROM %1%2" ).arg( mQuery, filterWhereClause() );
QgsPostgresResult result( connectionRO()->PQexec( sql ) );

const QString json = result.PQgetvalue( 0, 0 );
const QVariantList explain = QgsJsonUtils::parseJson( json ).toList();
const QVariantMap countPlan = explain.count() ? explain[0].toMap().value( "Plan" ).toMap() : QVariantMap();
const QVariantList queryPlan = countPlan.value( "Plans" ).toList();
const QVariant nbRows = queryPlan.count() ? queryPlan[0].toMap().value( "Plan Rows" ) : QVariant();
const QVariantMap countPlan = !explain.isEmpty() ? explain[0].toMap().value( "Plan" ).toMap() : QVariantMap();
const QVariant nbRows = countPlan.value( "Plan Rows" );

if ( nbRows.isValid() )
num = nbRows.toInt();
Expand Down

0 comments on commit 0573499

Please sign in to comment.