Skip to content

Commit ca01e9f

Browse files
committedApr 9, 2023
[postgres] Avoid unnecessary column type retrieval when sql
results are unused This avoids a lot of spurious "SELECT oid, typname FROM pg_type" queries being evaluated when populating postgres browser items
1 parent fdba204 commit ca01e9f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed
 

‎src/providers/postgres/qgspostgresproviderconnection.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ long long QgsPostgresProviderResultIterator::rowCountPrivate() const
486486
void QgsPostgresProviderConnection::vacuum( const QString &schema, const QString &name ) const
487487
{
488488
checkCapability( Capability::Vacuum );
489-
executeSql( QStringLiteral( "VACUUM FULL ANALYZE %1.%2" )
490-
.arg( QgsPostgresConn::quotedIdentifier( schema ),
491-
QgsPostgresConn::quotedIdentifier( name ) ) );
489+
executeSqlPrivate( QStringLiteral( "VACUUM FULL ANALYZE %1.%2" )
490+
.arg( QgsPostgresConn::quotedIdentifier( schema ),
491+
QgsPostgresConn::quotedIdentifier( name ) ), false );
492492
}
493493

494494
void QgsPostgresProviderConnection::createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options ) const
@@ -516,11 +516,11 @@ void QgsPostgresProviderConnection::createSpatialIndex( const QString &schema, c
516516
}
517517

518518
const QString indexName = QStringLiteral( "sidx_%1_%2" ).arg( name, geometryColumnName );
519-
executeSql( QStringLiteral( "CREATE INDEX %1 ON %2.%3 USING GIST (%4);" )
520-
.arg( QgsPostgresConn::quotedIdentifier( indexName ),
521-
QgsPostgresConn::quotedIdentifier( schema ),
522-
QgsPostgresConn::quotedIdentifier( name ),
523-
QgsPostgresConn::quotedIdentifier( geometryColumnName ) ) );
519+
executeSqlPrivate( QStringLiteral( "CREATE INDEX %1 ON %2.%3 USING GIST (%4);" )
520+
.arg( QgsPostgresConn::quotedIdentifier( indexName ),
521+
QgsPostgresConn::quotedIdentifier( schema ),
522+
QgsPostgresConn::quotedIdentifier( name ),
523+
QgsPostgresConn::quotedIdentifier( geometryColumnName ) ), false );
524524
}
525525

526526
bool QgsPostgresProviderConnection::spatialIndexExists( const QString &schema, const QString &name, const QString &geometryColumn ) const
@@ -571,8 +571,8 @@ void QgsPostgresProviderConnection::deleteSpatialIndex( const QString &schema, c
571571

572572
const QString indexName = res.at( 0 ).at( 0 ).toString();
573573

574-
executeSql( QStringLiteral( "DROP INDEX %1.%2" ).arg( QgsPostgresConn::quotedIdentifier( schema ),
575-
QgsPostgresConn::quotedIdentifier( indexName ) ) );
574+
executeSqlPrivate( QStringLiteral( "DROP INDEX %1.%2" ).arg( QgsPostgresConn::quotedIdentifier( schema ),
575+
QgsPostgresConn::quotedIdentifier( indexName ) ), false );
576576
}
577577

578578
QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
@@ -665,16 +665,16 @@ QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnectio
665665
{
666666
try
667667
{
668-
const auto pks = executeSql( QStringLiteral( R"(
668+
const QList<QVariantList> pks = executeSqlPrivate( QStringLiteral( R"(
669669
WITH pkrelid AS (
670670
SELECT indexrelid AS idxri FROM pg_index WHERE indrelid='%1.%2'::regclass AND (indisprimary OR indisunique)
671671
ORDER BY CASE WHEN indisprimary THEN 1 ELSE 2 END LIMIT 1)
672672
SELECT attname FROM pg_index,pg_attribute, pkrelid
673673
WHERE indexrelid=pkrelid.idxri AND indrelid=attrelid AND pg_attribute.attnum=any(pg_index.indkey);
674674
)" ).arg( QgsPostgresConn::quotedIdentifier( pr.schemaName ),
675-
QgsPostgresConn::quotedIdentifier( pr.tableName ) ) );
675+
QgsPostgresConn::quotedIdentifier( pr.tableName ) ), false );
676676
QStringList pkNames;
677-
for ( const auto &pk : std::as_const( pks ) )
677+
for ( const QVariantList &pk : std::as_const( pks ) )
678678
{
679679
pkNames.push_back( pk.first().toString() );
680680
}

0 commit comments

Comments
 (0)
Please sign in to comment.