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

[Postgres provider] Speed up feature insertion when pkid column is not set (fixes #18976) #7144

Merged
merged 2 commits into from
Jun 2, 2018

Conversation

rouault
Copy link
Contributor

@rouault rouault commented Jun 1, 2018

When inserting features whose attribute column corresponding to the pkid
is empty, and tat this pkid column has a default value using a sequence,
then we can remove it from the INSERT statement completely, which save us
from doing a SELECT nextval(...) for each row. On the provided test case
of that ticket, on a debug build, this cuts down the insertion time from 5 minutes
to 1 minute 10s.

…t set (fixes qgis#18976)

When inserting features whose attribute column corresponding to the pkid
is empty, and tat this pkid column has a default value using a sequence,
then we can remove it from the INSERT statement completely, which save us
from doing a SELECT nextval(...) for each row. On the provided test case
of that ticket, on a debug build, this cuts down the insertion time from 5 minutes
to 1 minute 10s.

if ( !skipSinglePKField )
{
Q_FOREACH ( int idx, mPrimaryKeyAttrs )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range based for instead of Q_FOREACH

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, note that I didn't modify that code. Was just put inside a if ()

@nyalldawson
Copy link
Collaborator

Nice!

The biggest performance issue with postgres provider add features is that we don't features using copy. We should be able to detect if the FastInsert flag is set and in that case just throw all the features in via copy... That would speed up lots of postgres data operations, e.g. any method which exports/saves whole tables into postgres. But that's non trivial :)

@rouault
Copy link
Contributor Author

rouault commented Jun 1, 2018

is that we don't features using copy.

To benchmark I tried with ogr2ogr as well (optimized build). In insert mode, it takes ~30 seconds. In copy mode: ~10 seconds

@rouault rouault merged commit 7e2ca8f into qgis:master Jun 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants