Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slow PG raster SRID identify backport #34288

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/gui/layertree/qgscustomlayerorderwidget.cpp
Expand Up @@ -132,13 +132,14 @@ QVariant CustomLayerOrderModel::data( const QModelIndex &index, int role ) const

bool CustomLayerOrderModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
Q_UNUSED( value ); // Toggle
if ( role == Qt::CheckStateRole )
{
QString id = mOrder.at( index.row() );
QgsLayerTreeLayer *nodeLayer = mBridge->rootGroup()->findLayer( id );
if ( nodeLayer )
{
nodeLayer->setItemVisibilityChecked( static_cast< Qt::CheckState >( value.toInt() ) == Qt::Checked );
nodeLayer->setItemVisibilityChecked( ! nodeLayer->itemVisibilityChecked() );
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layertree/qgscustomlayerorderwidget.h
Expand Up @@ -53,7 +53,7 @@ class GUI_EXPORT QgsCustomLayerOrderWidget : public QWidget
private slots:
void bridgeHasCustomLayerOrderChanged( bool state );
void bridgeCustomLayerOrderChanged();
//! Slot triggered when the ivsibility of a node changes
//! Slot triggered when the visibility of a node changes
void nodeVisibilityChanged( QgsLayerTreeNode *node );

void modelUpdated();
Expand Down
49 changes: 40 additions & 9 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1682,12 +1682,44 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l

if ( layerProperty.isRaster )
{
QString sql = QStringLiteral( "SELECT %3, "
"array_agg(DISTINCT 'RASTER:' || ST_SRID( %1 ))"
" FROM %2" )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( table )
.arg( i - 1 );
QString sql;

int srid = layerProperty.srids.value( 0, std::numeric_limits<int>::min() );
// SRID is already known
if ( srid != std::numeric_limits<int>::min() )
{
sql += QStringLiteral( "SELECT %1, array_agg( '%2:RASTER'::text )" )
.arg( i - 1 )
.arg( srid );
}
else
{
if ( useEstimatedMetadata )
{
sql = QStringLiteral( "SELECT %1, "
"array_agg( srid || ':RASTER') "
"FROM raster_columns "
"WHERE r_raster_column = %2 AND r_table_schema = %3 AND r_table_name = %4" )
.arg( i - 1 )
.arg( quotedValue( layerProperty.geometryColName ) )
.arg( quotedValue( layerProperty.schemaName ) )
.arg( quotedValue( layerProperty.tableName ) );
}
else
{
sql = QStringLiteral( "SELECT %1, "
"array_agg( DISTINCT ST_SRID( %2 ) || ':RASTER' ) "
"FROM %3 "
"%2 IS NOT NULL "
"%4 " // SQL clause
"LIMIT %5" )
.arg( i - 1 )
.arg( quotedIdentifier( layerProperty.geometryColName ) )
.arg( table )
.arg( layerProperty.sql.isEmpty() ? QString() : QStringLiteral( " AND %1" ).arg( layerProperty.sql ) )
.arg( GEOM_TYPE_SELECT_LIMIT );
}
}

QgsDebugMsg( "Raster srids query: " + sql );
query += sql;
Expand All @@ -1697,11 +1729,10 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
// our estimatation ignores that a where clause might restrict the feature type or srid
if ( useEstimatedMetadata )
{
table = QStringLiteral( "(SELECT %1 FROM %2%3 WHERE %4 IS NOT NULL LIMIT %5) AS t" )
table = QStringLiteral( "(SELECT %1 FROM %2%3 WHERE %1 IS NOT NULL LIMIT %4) AS t" )
.arg( quotedIdentifier( layerProperty.geometryColName ),
table,
layerProperty.sql.isEmpty() ? QString() : QStringLiteral( " WHERE %1" ).arg( layerProperty.sql ) )
.arg( layerProperty.geometryColName )
.arg( GEOM_TYPE_SELECT_LIMIT );
}
else if ( !layerProperty.sql.isEmpty() )
Expand All @@ -1717,7 +1748,7 @@ void QgsPostgresConn::retrieveLayerTypes( QVector<QgsPostgresLayerProperty *> &l
sql += QStringLiteral( "array_agg(DISTINCT " );

int srid = layerProperty.srids.value( 0, std::numeric_limits<int>::min() );
if ( srid == std::numeric_limits<int>::min() )
if ( srid == std::numeric_limits<int>::min() )
{
sql += QStringLiteral( "%1(%2%3)::text" )
.arg( majorVersion() < 2 ? "srid" : "st_srid",
Expand Down