optimalisation with EXCEPT clause - Mailing list pgsql-general

From Kincel, Martin
Subject optimalisation with EXCEPT clause
Date
Msg-id A5ED43533E983E4685C9E6156BE8874F0840D83D@kenya.tronet.as
Whole thread Raw
Responses Re: optimalisation with EXCEPT clause  (Grzegorz Jaśkiewicz <gryzman@gmail.com>)
List pgsql-general
Hello,


everyday I collect a couple of thousands rows of unique data from our
systems and I INSERT them into the table. Since I need no duplicate
data, I use EXCEPT clause when INSERTing, like this:

===
INSERT INTO data SELECT * FROM new_collected_data() EXCEPT SELECT * FROM
data;
===

It works exactly as I need, but there is a small issue I am thinking
about how to improve. Yes it's performance, what else? :)

Since I am INSERTing new_collected_data() in 10000-rows chunks into a
table already containing millions of rows, it takes a few minutes
(literally), which is something I understand and accept.
However, I am wondering whether there is any way how to improve the
performance, either via indices, or ALTERing TABLE with UNIQUE
constraint or something else I might have completely forgot about.

Does anyone have any recommended approach how to speed up queries
containing EXCEPT clause?


Thanks a lot,
Winco

pgsql-general by date:

Previous
From:
Date:
Subject: Re: [ADMIN] Query is stuck
Next
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: optimalisation with EXCEPT clause