[QGIS-Developer] Disable primary key unicity check
Tom Vanzieleghem
tom.vanzieleghem at gmail.com
Tue Apr 16 00:42:48 PDT 2019
Hi,
I posted this earlier in the QGis Issue Tracker (
https://issues.qgis.org/issues/21839 ) but it did not gain much traction.
I noticed that initial loading time of large PostgreSQL views (> 10 million
records) seems to have increased considerably compared to QGis 2. After
observing the db logs, seems the sql query for checking primary key unicity
is one of the causes for this. From the API documentation I had the
impression that this behaviour could be disabled by setting the property
TrustLayerMetadata on the project to true (in the GUI under project
properties or through pyqgis). This only makes a difference while opening a
project, not when loading new PG layers in an open project.
So I tried setting the parameter checkPrimaryKeyUnicity to '0' in several
ways (editing an exported QLR layer definition file and through pyqgis) but
also without result. The parameter checkPrimaryKeyUnicity in the edited URI
of the QLR file is ignored. For pyqgis, it seems, in case of a postgres
provider, the parameter checkPrimaryKeyUnicity set on the QgsDatasourecUri
instance is overriden depending on the provided layerOptions (more specific
the readExtentFromXml option) specified on the QgsVectorLayer class:
*bool QgsVectorLayer::setDataProvider( QString const &provider, const
QgsDataProvider::ProviderOptions &options )*
*{*
* mProviderKey = provider; // XXX is this necessary? Usually already
set*
* // primary key unicity is tested at construction time, so it has to be
set*
* // before initializing postgres provider*
* QString checkUnicityKey = QStringLiteral( "checkPrimaryKeyUnicity" );*
* QString dataSource = mDataSource;*
* if ( provider.compare( QLatin1String( "postgres" ) ) == 0 )*
* {*
* QgsDataSourceUri uri( dataSource );*
* if ( uri.hasParam( checkUnicityKey ) )*
* uri.removeParam( checkUnicityKey );*
* uri.setParam( checkUnicityKey, mReadExtentFromXml ? "0" : "1" );*
* dataSource = uri.uri( false );*
* }*
*...*
So the only way to influence the parameter is by specifying the
readExtentFromXml layeroption. Is there a reason for this construction?
I always was impressed with the loading of postgis layers in QGis 2 but
this has considerably changed in QGis 3. Therefore I wonder if there's a
way to specify the checkPrimaryKeyUnicity in the GUI or by changing the URI
strig of a datasource?
best regards and keep up the good work,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190416/2d79f32a/attachment.html>
More information about the QGIS-Developer
mailing list