Drop Column from Large Table

前端 未结 3 1093
悲哀的现实
悲哀的现实 2020-12-29 04:09

I have this largish table with three columns as such:

+-----+-----+----------+
| id1 | id2 | associd  |
+-----+-----+----------+
|   1 |  38 | 73157604 |
|           


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 04:46

    Anything that you do is going to require reading and writing 38m rows, so nothing is going to be real fast. Probably the fastest method is probably to put the data into a new table:

    create table newTable as
        select id1, id2
        from oldTable;
    

    Or, if you want to be sure that you preserve types and indexes:

    create table newTable like oldTable;
    
    alter table newTable drop column assocId;
    
    insert into newTable(id1, id2)
        select id1, id2
        from oldTable;
    

    However, it is usually faster to drop all index on a table before loading a bunch of data and then recreate the indexes afterwards.

提交回复
热议问题