How many rows in f
won't match a row in ft
? In the most extreme case, if pid
is unique in f
your target table fc
will contain >1.6m rows. If the bulk of the rows will end up in fc
you would be better off doing this in two stages:
CREATE TABLE fc AS
SELECT threadid,
title,
body,
date,
userlogin
FROM f
ORDER BY date;
DELETE FROM fc
WHERE pid
IN (SELECT pid FROM ft);
Incidentally, can you ditch the ORDER BY clause? That sort could cost a lot of cycles, again depending on how many rows there are in the target table.
Another thing to consider is the EXISTS clause...
CREATE TABLE fc AS
SELECT threadid,
title,
body,
date,
userlogin
FROM f
WHERE NOT EXISTS
(SELECT pid FROM ft
WHERE ft.pid = f.id)
ORDER BY date;
... or in my two-step version ...
DELETE FROM fc
WHERE EXISTS
(SELECT pid FROM ft
WHERE ft.pid = f.id);
EXISTS can be a lot faster than IN when the sub-query generates a lot of rows. However, as is always the case with tuning, benchmarking is key.