0

I need to add 3 columns having default value in a table with 1.70 billion records in Oracle 11g. What is the best option to do this with minimum time?

4

1 回答 1

0

添加列值时无法提高性能。如果您只选择行的子集,那么您可以尝试在那里进行优化。

如果这些列确实有一个值,那么当您(a)不在列列表中命名该列或(b)将其值指定为时DEFAULT,Oracle 将实际放置该值:INSERTDEFAULT

CREATE TABLE MyTable (
  Col1 NUMBER(5) DEFAULT 10 NOT NULL,
  Col2 NUMBER(5) DEFAULT 20 NOT NULL,
  Col3 NUMBER(5) DEFAULT 30 NOT NULL
);

INSERT INTO MyTable VALUES (DEFAULT, DEFAULT, DEFAULT);
INSERT INTO MyTable (Col2, Col3) VALUES (21, 31);
INSERT INTO MyTable (Col2, Col3) VALUES (22, DEFAULT);
INSERT INTO MyTable (Col1) VALUES (11);

SELECT * FROM MyTable;

 COL1  COL2  COL3
----- ----- -----
   10    20    30  <-- VALUES (DEFAULT, DEFAULT, DEFAULT)
   10    21    31  <-- (Col2, Col3) VALUES (21, 31); Col1 defaults because not named
   10    22    30  <-- (Col2, Col3) VALUES (22, DEFAULT); Col1 defaults because not named
   11    20    30  <-- (Col1) VALUES (11); Col2 and Col3 default because not named

NULL因此,如果您担心的是,则无需检查:

SELECT Col1, Col2, Col3, Col1+Col2+Col3 AS TotCols
FROM MyTable;

      COL1       COL2       COL3    TOTCOLS
---------- ---------- ---------- ----------
        10         20         30         60
        10         21         31         62
        10         22         30         62
        11         20         30         61

如果您的问题是关于如何优化行子集,请添加更多信息。

于 2013-06-10T16:57:41.977 回答