Search code examples
oracle-databaseplsqlquery-optimizationoracle12c

update big table with 200mn data


I want to update NULL TFLAG column with 0 . what would be the efficient way to update the column as the table is big.

stats:
-----
Size             144 GB
Num Rows         235,676,098
Number of nulls   33408624

create table ticket (hkey number , tflag number);
alter table ticket add constraint hkey_p primary key (hkey);

Insert into TICKET (HKEY,TFLAG) values (1,1);
Insert into TICKET (HKEY,TFLAG) values (2,1);
Insert into TICKET (HKEY,TFLAG) values (3,null);
Insert into TICKET (HKEY,TFLAG) values (4,null);
Insert into TICKET (HKEY,TFLAG) values (5,null);
Insert into TICKET (HKEY,TFLAG) values (6,null);
Insert into TICKET (HKEY,TFLAG) values (7,null);
Insert into TICKET (HKEY,TFLAG) values (8,1);
Insert into TICKET (HKEY,TFLAG) values (9,null);
Insert into TICKET (HKEY,TFLAG) values (10,1);
Insert i

Solution

  • The simple answer is

    update ticket
    set hflag = 0
    where hflag is null;
    

    The long answer is, it depends. Is the table experiencing a lot of transactions concurrently? You could add a and rownum < 10000 (or any other number you deem appropriate) to make the transaction size smaller. Add commits between updates to not keep the records locked. But if concurrent transactions are not an issue, I would just use above update statement and let the database do its thing.