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

Postgis add layer dialog: Cancel slow operations #15541

Closed
qgib opened this issue Aug 20, 2012 · 8 comments
Closed

Postgis add layer dialog: Cancel slow operations #15541

qgib opened this issue Aug 20, 2012 · 8 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers
Milestone

Comments

@qgib
Copy link
Contributor

qgib commented Aug 20, 2012

Author Name: Matthias Kuhn (@m-kuhn)
Original Redmine Issue: 6232
Affected QGIS version: master
Redmine category:data_provider/postgis


When I click on "Add postgis layer" and select a database and click "Connect", all the schemes appear pretty fast and I can select a table (in ~2s). To fully "load" the database (i.e. when the text of the button "Stop" changes to "Connect" and the button "Add" is enabled) it takes much longer (>20s). I don't know, what information is loaded in the additional time.

There are a number of problems with this associated here:

Problems:

  • Why am I not allowed to select a table, although QGIS already knows its name and primary key?
  • If I click "Close" before the database is fully "loaded", it still waits for this time to pass, before allowing me any further action on the UI. (Making the application appear slow and unresponsive)
  • If I click "Close" before the database is fully "loaded", the cursor does not turn back from hourglass to pointer. This indicates to me that I should not continue my work, although you can continue to work after this timeout has passed.

Questions:

  • What could it be, that the dialog is waiting for this long time and is it necessary to wait for this?
  • If the user hits "Close" can this process be stopped immediately (let's say within max. 3s)?
  • Can the ongoing process be forced to the background? (It's a thread that QgsPgSourceSelect waits for in its destructor.)
  • If the above can not be accomplished, I think at least we should:
  • keep the select dialog open until the operation finished. So the user knows, what he is waiting for.
  • reset the cursor to it's default state when the operation completed
@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2012

Author Name: Jürgen Fischer (@jef-n)


What could it be, that the dialog is waiting for this long time and is it necessary to wait for this?

If your geometry type and srids are not fully - either because it's not in @geometry_columns@ or not listed with a point, line or polygon type in @geometry_columns@, QGIS needs to find which geometry types and srids are available.

If the user hits "Close" can this process be stopped immediately (let's say within max. 3s)?

If you close the detection thread is notified to not run any more queries - but as the queries are blocking (that's why there is a thread) the thread can only react on that once the running query finishes.

Can the ongoing process be forced to the background? (It's a thread that QgsPgSourceSelect waits for in its destructor.)

Not sure. That might into race conditions.

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2012

Author Name: Matthias Kuhn (@m-kuhn)


??If your geometry type and srids are not fully - either because it's not in geometry_columns or not listed with a point, line or polygon type in geometry_columns, QGIS needs to find which geometry types and srids are available.??
Yes, we have a couple of views here that have not yet been inserted into the geometry_columns. As far as I can see, there is no way to add them automated (http://postgis.org/documentation/manual-1.5/Probe_Geometry_Columns.html states it does not scan for views)

So maybe in addition to this bug there should be a feature request, to
a) only scan for geometry_columns once a schema has been opened
b) ask the user if he really wants to scan for this (on bigger databases this can easily take a couple of minutes)
c) inform the user, how this can be improved and maybe even offer the possibility to add the missing entries.


Concerning the cancellation of a request. I've looked at the PG docs and found the method PQcancel. I've never worked with this lib but this method looks promising to me and should be thread-safe. I think there is no reason to let the query complete, as the result will be discarded anyway?

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2012

Author Name: Jürgen Fischer (@jef-n)


Matthias Kuhn wrote:

So maybe in addition to this bug there should be a feature request, to
a) only scan for geometry_columns once a schema has been opened

That only helps if you have multiple schemas and even then a single schema might be enough to show the same behaviour.

b) ask the user if he really wants to scan for this (on bigger databases this can easily take a couple of minutes)

You can already setup your connection that way - and use check "use estimated metadata", which should help a lot, if you're dealing with large databases.

c) inform the user, how this can be improved and maybe even offer the possibility to add the missing entries.

In PostGIS 2.0 @geometry_columns@ isn't a table anymore anyway.

Concerning the cancellation of a request. I've looked at the PG docs and found the method PQcancel. I've never worked with this lib but this method looks promising to me and should be thread-safe. I think there is no reason to let the query complete, as the result will be discarded anyway?

Good point. I'll take a look at that.

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2012

Author Name: Matthias Kuhn (@m-kuhn)


Jürgen Fischer wrote:

Matthias Kuhn wrote:
That only helps if you have multiple schemas and even then a single schema might be enough to show the same behaviour.

True. It's probably the wrong approach.

You can already setup your connection that way - and use check "use estimated metadata", which should help a lot, if you're dealing with large database.

Yes, I've just been told about this possibility. It's just not too intuitive. I wouldn't know if I didn't have somebody to tell me. I still think it would be a good idea to print some information next to the affected tables/views and tell the user, what the problem is, and what can be done about it. A yellow warning triangle and a popup with a short explanation would be good.

In PostGIS 2.0 @geometry_columns@ isn't a table anymore anyway.

So this problem is solved there by design? I wonder how many people are still using PG 1.x and when everybody will have updated?

Good point. I'll take a look at that.

Great

@qgib
Copy link
Contributor Author

qgib commented Aug 21, 2012

Author Name: Jürgen Fischer (@jef-n)


Matthias Kuhn wrote:

Good point. I'll take a look at that.

Great

implemented in b6760ce

@qgib
Copy link
Contributor Author

qgib commented Aug 22, 2012

Author Name: Matthias Kuhn (@m-kuhn)


Perfect. Works like a charm.

I'll mark this closed as the issue in the title is fixed.


  • status_id was changed from Open to Closed
  • resolution was changed from to fixed

@qgib
Copy link
Contributor Author

qgib commented Sep 19, 2012

Author Name: hamish - (hamish -)


Hi,

just as a point of info for anyone in the same situation as me:

I had to change the geometry_columns type to MULTILINESTRING instead of LINE, otherwise it just got stuck on "Detecting..." forever (or at least >10 minutes, when I canceled it). POINTS was fine as POINTS, I haven't needed to try POLYGON vs. MULTIPOLYGON but perhaps there are similar issues there.

Thanks for the tip, connecting to the PostGIS db (and/or going into the Query Builder) now takes 2 seconds instead of 4 minutes for these large datasets, even without turning on the 'estimate table metadata' tick box in the server settings (glad to know about that trick too).

regards,
Hamish

@qgib
Copy link
Contributor Author

qgib commented Sep 19, 2012

Author Name: Jürgen Fischer (@jef-n)


hamish - wrote:

I had to change the geometry_columns type to MULTILINESTRING instead of LINE,

Was that originally @line@ or @LINESTRING@?

@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers labels May 24, 2019
@qgib qgib added this to the Version 2.0.0 milestone May 24, 2019
@qgib qgib closed this as completed May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Data Provider Related to specific vector, raster or mesh data providers
Projects
None yet
Development

No branches or pull requests

1 participant