Finding rows in table T1 that DO NOT MATCH any row in table T2

Поиск
Список
Период
Сортировка
От Shaul Dar
Тема Finding rows in table T1 that DO NOT MATCH any row in table T2
Дата
Msg-id 234efe30910200537rbdaebaft88052b5f51a0a43b@mail.gmail.com
обсуждение исходный текст
Ответы Re: Finding rows in table T1 that DO NOT MATCH any row in table T2  (Shaul Dar <shauldar@gmail.com>)
Re: Finding rows in table T1 that DO NOT MATCH any row in table T2  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: Finding rows in table T1 that DO NOT MATCH any row in table T2  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-performance
Hi,

I have two large tables T1 and T2, such that T2 has a FK to T1 (i.e. T2.FK --> T1.PK, possibly multiple T2 rows may reference the same T1 row). I have deleted about 2/3 of table T2. I now want to delete all rows in T1 that are not referenced by T2, i.e. all rows in T1 that cannot join with (any row in) T2 on the condition T2.FK = T1.PK (the opposite of a join...)

I assume this will work but will take a long time:

DELETE * FROM T1 where T1.PK NOT IN
(SELECT T1.PK FROM T1, T2 where T1.PK = T2.FK)

What is an efficient way to do this?
Thanks,

-- Shaul

В списке pgsql-performance по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Domain vs table
Следующее
От: Shaul Dar
Дата:
Сообщение: Re: Finding rows in table T1 that DO NOT MATCH any row in table T2