Skip to content
Permalink
Browse files

Fixes #37342 : manage Postgres parallel plans when estimating row count

  • Loading branch information
troopa81 authored and wonder-sk committed Jul 20, 2020
1 parent 3af038f commit 45251db5b854a41a238d30e6d3660d0e53a7ab53
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/providers/postgres/qgspostgresprovider.cpp
@@ -3511,14 +3511,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();

0 comments on commit 45251db

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