user3373474
user3373474

Reputation: 13

Netezza delete using JOIN

I have two tables in Netezza. Table A have ~70B records and table B have ~15K records. Delete need to happen on table A however I have to join on 2 columns. My query looks like this

Delete from A where (a.col1, a.col2) in (select col1, col2 from B).

I see plan is very costly and looking for alternative approach. Does netezza supports JOIN ON DELETE? Does anybody have any other approach??

Upvotes: 1

Views: 7375

Answers (3)

Jason Ridenour
Jason Ridenour

Reputation: 329

You can also use EXISTS() as an alternative syntax:

delete from table_A a
where exists(select 1 from table_b b
    where b.col1=a.col1
      and b.col2=a.col2
)

Edit: The overhead of this is fairly low because it doesn't have to build the join or collect anything, it just has to check if the record is there.

Upvotes: 2

Aparna
Aparna

Reputation: 286

An alternative approach would be to create a table using CTAS without the records and rename it .I believe the cost incurred will be less here .

create table T1 as select 
col1,col2 from A where (col1,col2) 
not in (select col1,col2 from B);

drop table A;

alter table T1 rename to A;

Upvotes: 0

Niederee
Niederee

Reputation: 4295

You can use the rowid to achieve what you are looking for:

delete from table_A
where rowid in (select a.rowid
from table_A a inner join
table_B b
on a.col1=b.col1
and a.col2=b.col2)

Upvotes: 2

Related Questions