Subject | Table update's speed |
---|---|
Author | Riho-Rene Ellermaa |
Post date | 2004-10-07T13:56:13Z |
I have 200 MB database that contains amon other things table
stat_history
CREATE TABLE STAT_HISTORY (
ACCID INTEGER NOT NULL,
SDATE DATE NOT NULL,
ROW INTEGER NOT NULL,
....
(10 VARCHAR(50) fields)
....
DETAILS LT_DETAILS, (varchar(300))
NAME LT_BENNAME, (varchar(200))
UNAME LT_BENNAME, (varchar(200))
PRIMARY KEY (ACCID,SDATE,ROW)
);
The table contains 100 000 records.
When I run the script to change 3 fields, the first update takes approx.
4 min, but second update takes more than 40 min.
Is it because the database gets more mixed up after first update and new
fields?
Is there any solutions how to do it better?
SCRIPT:
Set autoddl on;
ALTER TABLE stat_history add TEMP lt_details,add TEMP2 lt_benname, add
TEMP3 lt_benname;
commit;
update stat_history set temp=details, temp2=name, temp3=uname; /* 4 min
*/
ALTER TABLE stat_history drop details,drop name,drop uname;
commit;
ALTER TABLE stat_history add details lt_details,add name lt_benname, add
uname lt_benname;
commit;
update stat_history set details=TEMP,name=temp2,uname=temp3; /* 40 min
*/
commit;
ALTER TABLE stat_history drop TEMP,DROP temp2, DROP temp3;
commit;
Riho Ellermaa
stat_history
CREATE TABLE STAT_HISTORY (
ACCID INTEGER NOT NULL,
SDATE DATE NOT NULL,
ROW INTEGER NOT NULL,
....
(10 VARCHAR(50) fields)
....
DETAILS LT_DETAILS, (varchar(300))
NAME LT_BENNAME, (varchar(200))
UNAME LT_BENNAME, (varchar(200))
PRIMARY KEY (ACCID,SDATE,ROW)
);
The table contains 100 000 records.
When I run the script to change 3 fields, the first update takes approx.
4 min, but second update takes more than 40 min.
Is it because the database gets more mixed up after first update and new
fields?
Is there any solutions how to do it better?
SCRIPT:
Set autoddl on;
ALTER TABLE stat_history add TEMP lt_details,add TEMP2 lt_benname, add
TEMP3 lt_benname;
commit;
update stat_history set temp=details, temp2=name, temp3=uname; /* 4 min
*/
ALTER TABLE stat_history drop details,drop name,drop uname;
commit;
ALTER TABLE stat_history add details lt_details,add name lt_benname, add
uname lt_benname;
commit;
update stat_history set details=TEMP,name=temp2,uname=temp3; /* 40 min
*/
commit;
ALTER TABLE stat_history drop TEMP,DROP temp2, DROP temp3;
commit;
Riho Ellermaa