Skip to content


Browse files Browse the repository at this point in the history
Mark common postgresql types as non-enumerable upon load
This fixes a big performance issue when loading projects with PostgreSQL layers.
In the last stage of project loading, code in QgisApp would run code
to resolve broken layer dependencies, which in turn tried to find out best
edit widget for all columns of all layers, and the enumeration widget tried
to figure out all enum values, doing two SQL calls for each column for each layer.

We know what are types of columns when loading a layer, so enumValues() can leave
early without doing the excessive queries when it's not necessary.

Testing on a real world QGIS project with 300+ layers (but not all PostgreSQL):
- before: ~35 minutes to load / ~8K PostgreSQL queries
- after: ~10 minutes to load / ~2K PostgreSQL queries
  • Loading branch information
wonder-sk authored and nyalldawson committed May 18, 2023
1 parent eeb7820 commit 0229d8d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -1387,6 +1387,11 @@ bool QgsPostgresProvider::loadFields()

mIdentityFields.insert( mAttributeFields.size(), identityMap[tableoid][attnum][0].toLatin1() );
mAttributeFields.append( newField );

// if we know for sure that this field is not enumerated type or a domain type, let's
// mark it here, so that enumValues() does not need to check it again (for types like int, text, ...)
if ( fieldTType != QLatin1String( "e" ) && !isDomain )
mShared->setFieldSupportsEnumValues( fields.count() - 1, false );

Expand Down

0 comments on commit 0229d8d

Please sign in to comment.