From: Jonathan Gardner <jgardner@jonathangardner.net>
To: pgsql-performance@postgresql.org
Subject: DELETE ... WHERE ctid IN (...) vs. Iteration
Date: Tue, 30 Dec 2003 08:32:38 -0800
Message-ID: <200312300832.44945.jgardner@jonathangardner.net> (raw)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I guess this may have come up before, but now that 7.4 has the IN with
improved performance, it may be time to revisit this topic.
Compare these two algorithms (in plpgsql):
(a)
DELETE FROM foo WHERE ctid IN (
SELECT foo.ctid
FROM ... WHERE ...
);
(b)
FOR result IN SELECT foo.ctid FROM ... WHERE ... LOOP
DELETE FROM foo WHERE ctid = result;
END LOOP;
My poor understanding of how the IN operator works leaves me to believe
that for a large set of data in the IN group, a hash is used and a
tablescan done on foo. However, for a small set of data in the IN group,
no tablescan is performed.
I assume that (a) works at O(ln(N)) for large N, and O(N) for small N,
while (b) works at O(N) universally. Therefore, (a) is the superior
algorithm. I welcome criticism and correction.
- --
Jonathan Gardner
jgardner@jonathangardner.net
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/8aipWgwF3QvpWNwRAk8GAJoDWISjxG7LMB1FdCFmwlOafsmZTwCePx18
lyHLNBJ8nP0RHzv6WfRzQ+M=
=FPdW
-----END PGP SIGNATURE-----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: jgardner@jonathangardner.net
Subject: Re: DELETE ... WHERE ctid IN (...) vs. Iteration
In-Reply-To: <200312300832.44945.jgardner@jonathangardner.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox