Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #40094 from tomtor/LimitRows
Limit number of rows for Postgis retrieveLayerTypes
  • Loading branch information
elpaso committed Nov 19, 2020
2 parents a5ac126 + 3fba3ff commit 2c1468a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1925,6 +1925,11 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
QgsWkbTypes::Type type = layerProperty.types.value( 0, QgsWkbTypes::Unknown );
if ( type == QgsWkbTypes::Unknown )
{
// Note that we would like to apply a "LIMIT GEOM_TYPE_SELECT_LIMIT"
// here, so that the previous "array_agg(DISTINCT" does not scan the
// full table. However SQL does not allow that.
// So we have to do a subselect on the table to add the LIMIT,
// see comment in the following code.
sql += QStringLiteral( "UPPER(geometrytype(%1%2))" )
.arg( quotedIdentifier( layerProperty.geometryColName ),
castToGeometry ? "::geometry" : "" );
Expand All @@ -1938,7 +1943,18 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l

sql += QLatin1String( ") " );

sql += " FROM " + table;
if ( type == QgsWkbTypes::Unknown )
{
// Subselect to limit the "array_agg(DISTINCT", see previous comment.
sql += QStringLiteral( " FROM (SELECT %1 from %2 LIMIT %3) as _unused" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( table )
.arg( GEOM_TYPE_SELECT_LIMIT );
}
else
{
sql += " FROM " + table;
}

QgsDebugMsgLevel( "Geometry types,srids and dims query: " + sql, 2 );

Expand Down

0 comments on commit 2c1468a

Please sign in to comment.