-----BEGIN PGP SIGNED MESSAGE-----
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):
DELETE FROM foo WHERE ctid IN (
FROM ... WHERE ...
FOR result IN SELECT foo.ctid FROM ... WHERE ... LOOP
DELETE FROM foo WHERE ctid = result;
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.
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
-----END PGP SIGNATURE-----
pgsql-performance by date
|Next:||From: Vivek Khera||Date: 2003-12-31 17:17:50|
|Subject: Re: deferred foreign keys|
|Previous:||From: Nicholas Shanny||Date: 2003-12-30 15:00:30|
|Subject: Re: Question about difference in performance of 2 queries |