Skip to content

Commit f34bd0b

Browse files
committedApr 6, 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 644478c commit f34bd0b

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
@@ -497,9 +497,9 @@ long long QgsPostgresProviderResultIterator::rowCountPrivate() const
497497
void QgsPostgresProviderConnection::vacuum( const QString &schema, const QString &name ) const
498498
{
499499
checkCapability( Capability::Vacuum );
500-
executeSql( QStringLiteral( "VACUUM FULL ANALYZE %1.%2" )
501-
.arg( QgsPostgresConn::quotedIdentifier( schema ),
502-
QgsPostgresConn::quotedIdentifier( name ) ) );
500+
executeSqlPrivate( QStringLiteral( "VACUUM FULL ANALYZE %1.%2" )
501+
.arg( QgsPostgresConn::quotedIdentifier( schema ),
502+
QgsPostgresConn::quotedIdentifier( name ) ), false );
503503
}
504504

505505
void QgsPostgresProviderConnection::createSpatialIndex( const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options ) const
@@ -527,11 +527,11 @@ void QgsPostgresProviderConnection::createSpatialIndex( const QString &schema, c
527527
}
528528

529529
const QString indexName = QStringLiteral( "sidx_%1_%2" ).arg( name, geometryColumnName );
530-
executeSql( QStringLiteral( "CREATE INDEX %1 ON %2.%3 USING GIST (%4);" )
531-
.arg( QgsPostgresConn::quotedIdentifier( indexName ),
532-
QgsPostgresConn::quotedIdentifier( schema ),
533-
QgsPostgresConn::quotedIdentifier( name ),
534-
QgsPostgresConn::quotedIdentifier( geometryColumnName ) ) );
530+
executeSqlPrivate( QStringLiteral( "CREATE INDEX %1 ON %2.%3 USING GIST (%4);" )
531+
.arg( QgsPostgresConn::quotedIdentifier( indexName ),
532+
QgsPostgresConn::quotedIdentifier( schema ),
533+
QgsPostgresConn::quotedIdentifier( name ),
534+
QgsPostgresConn::quotedIdentifier( geometryColumnName ) ), false );
535535
}
536536

537537
bool QgsPostgresProviderConnection::spatialIndexExists( const QString &schema, const QString &name, const QString &geometryColumn ) const
@@ -582,8 +582,8 @@ void QgsPostgresProviderConnection::deleteSpatialIndex( const QString &schema, c
582582

583583
const QString indexName = res.at( 0 ).at( 0 ).toString();
584584

585-
executeSql( QStringLiteral( "DROP INDEX %1.%2" ).arg( QgsPostgresConn::quotedIdentifier( schema ),
586-
QgsPostgresConn::quotedIdentifier( indexName ) ) );
585+
executeSqlPrivate( QStringLiteral( "DROP INDEX %1.%2" ).arg( QgsPostgresConn::quotedIdentifier( schema ),
586+
QgsPostgresConn::quotedIdentifier( indexName ) ), false );
587587
}
588588

589589
QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnection::tables( const QString &schema, const TableFlags &flags ) const
@@ -676,16 +676,16 @@ QList<QgsPostgresProviderConnection::TableProperty> QgsPostgresProviderConnectio
676676
{
677677
try
678678
{
679-
const auto pks = executeSql( QStringLiteral( R"(
679+
const QList<QVariantList> pks = executeSqlPrivate( QStringLiteral( R"(
680680
WITH pkrelid AS (
681681
SELECT indexrelid AS idxri FROM pg_index WHERE indrelid='%1.%2'::regclass AND (indisprimary OR indisunique)
682682
ORDER BY CASE WHEN indisprimary THEN 1 ELSE 2 END LIMIT 1)
683683
SELECT attname FROM pg_index,pg_attribute, pkrelid
684684
WHERE indexrelid=pkrelid.idxri AND indrelid=attrelid AND pg_attribute.attnum=any(pg_index.indkey);
685685
)" ).arg( QgsPostgresConn::quotedIdentifier( pr.schemaName ),
686-
QgsPostgresConn::quotedIdentifier( pr.tableName ) ) );
686+
QgsPostgresConn::quotedIdentifier( pr.tableName ) ), false );
687687
QStringList pkNames;
688-
for ( const auto &pk : std::as_const( pks ) )
688+
for ( const QVariantList &pk : std::as_const( pks ) )
689689
{
690690
pkNames.push_back( pk.first().toString() );
691691
}

0 commit comments

Comments
 (0)
Please sign in to comment.