Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #37342 : manage Postgres parallel plans when estimating row count
  • Loading branch information
troopa81 authored and nyalldawson committed Aug 15, 2020
1 parent 2cd4034 commit 9975cf0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3423,14 +3423,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( QStringLiteral( "Plan" ) ).toMap() : QVariantMap();
const QVariantList queryPlan = countPlan.value( QStringLiteral( "Plans" ) ).toList();
const QVariant nbRows = queryPlan.count() ? queryPlan[0].toMap().value( QStringLiteral( "Plan Rows" ) ) : QVariant();
const QVariantMap countPlan = !explain.isEmpty() ? explain[0].toMap().value( QStringLiteral( "Plan" ) ).toMap() : QVariantMap();
const QVariant nbRows = countPlan.value( QStringLiteral( "Plan Rows" ) );

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

0 comments on commit 9975cf0

Please sign in to comment.