dbTalk Databases Forums  

Temporarily dropping indexes for mass operations

comp.databases.postgresql comp.databases.postgresql


Discuss Temporarily dropping indexes for mass operations in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Schuerig
 
Posts: n/a

Default Temporarily dropping indexes for mass operations - 04-01-2009 , 03:14 AM







I'm considering the implications of dropping indexes temporarily during
mass operations such as imports and generation of sample data. The idea
is to avoid unnecessary incremental updates to indexes that aren't used
by the mass operation anyway.

I'm wondering how this interacts with transactions. Assuming that the
import/generation process is the only user of the DB, is it a good idea
to do everything, including dropping and creating of the indexes, in a
single transaction? Or no transaction at all?

If there are other processes accessing the DB, how are they affected by
the dropped indexes? Do they see the indexes as they were before the
import/generation transaction started?

Michael

--
Michael Schuerig
mailto:michael (AT) schuerig (DOT) de
http://www.schuerig.de/michael/

Reply With Quote
  #2  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Temporarily dropping indexes for mass operations - 04-01-2009 , 03:40 AM






Michael Schuerig <michael (AT) schuerig (DOT) de> wrote:
Quote:
I'm considering the implications of dropping indexes temporarily during
mass operations such as imports and generation of sample data. The idea
is to avoid unnecessary incremental updates to indexes that aren't used
by the mass operation anyway.

I'm wondering how this interacts with transactions. Assuming that the
import/generation process is the only user of the DB, is it a good idea
to do everything, including dropping and creating of the indexes, in a
single transaction? Or no transaction at all?
Yes, start a transaction, drop the index, insert the data, recreate the
index, commit.

Quote:
If there are other processes accessing the DB, how are they affected by
the dropped indexes? Do they see the indexes as they were before the
import/generation transaction started?
Other transactions can use the index, we have MVCC, yes!




Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°


Reply With Quote
  #3  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: Temporarily dropping indexes for mass operations - 04-01-2009 , 03:42 AM



Michael Schuerig wrote:
Quote:
I'm considering the implications of dropping indexes temporarily during
mass operations such as imports and generation of sample data. The idea
is to avoid unnecessary incremental updates to indexes that aren't used
by the mass operation anyway.

I'm wondering how this interacts with transactions. Assuming that the
import/generation process is the only user of the DB, is it a good idea
to do everything, including dropping and creating of the indexes, in a
single transaction? Or no transaction at all?
If you are the only one connected to the database, the only good reason
to run everything inside a transaction is that you can (and must) rollback
everything if there is an error. That way you cannot end up with
an inconsistent database if the import goes wrong.

Mind that you cannot run VACUUM inside a transaction. That is of
course irrelevant if all you do is add data.

Quote:
If there are other processes accessing the DB, how are they affected by
the dropped indexes? Do they see the indexes as they were before the
import/generation transaction started?
No, they will lock out each other.
Dropping an index will take an Access Exclusive Lock on both table and
index. SELECT requires an Access Share Lock on the table. These two locks
are incompatible.

So the DROP INDEX will have to wait for all previous SELECT or DML
statements to finish, and all following SELECT or DML statements will be blocked
until the transaction is committed or rolled back.

Yours,
Laurenz Albe




Reply With Quote
  #4  
Old   
Michael Schuerig
 
Posts: n/a

Default Re: Temporarily dropping indexes for mass operations - 04-01-2009 , 04:25 AM



Andreas Kretschmer wrote:

Quote:
Michael Schuerig <michael (AT) schuerig (DOT) de> wrote:

I'm considering the implications of dropping indexes temporarily
during mass operations such as imports and generation of sample data.
The idea is to avoid unnecessary incremental updates to indexes that
aren't used by the mass operation anyway.

I'm wondering how this interacts with transactions. Assuming that the
import/generation process is the only user of the DB, is it a good
idea to do everything, including dropping and creating of the
indexes, in a single transaction? Or no transaction at all?

Yes, start a transaction, drop the index, insert the data, recreate
the index, commit.
That's easy, then.

Quote:
If there are other processes accessing the DB, how are they affected
by the dropped indexes? Do they see the indexes as they were before
the import/generation transaction started?

Other transactions can use the index, we have MVCC, yes!
Apparently it works even better than advertised :-)

Michael

--
Michael Schuerig
mailto:michael (AT) schuerig (DOT) de
http://www.schuerig.de/michael/


Reply With Quote
  #5  
Old   
Andreas Kretschmer
 
Posts: n/a

Default Re: Temporarily dropping indexes for mass operations - 04-01-2009 , 05:22 AM



Andreas Kretschmer <akretschmer (AT) spamfence (DOT) net> wrote:

I'm sorry, it was wrong. See the other posting.



Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.