bubblegum.anarchy Posted May 11, 2007 Share Posted May 11, 2007 I thought using the default value of a table column would be a good way to store a semi static variable (rarely updated) but I seem to have come upon a problem when the record count is increase greatly. The following query to update the default value startes to take over a second to process once the record count is over 100,000 (>500,000 takes about 3 seconds and over a million would take over 6 seconds since the process time is very proportional): ALTER TABLE reimbursement MODIFY rate FLOAT NOT NULL DEFAULT 0.95 COMMENT 'currency rate per kilometre'; The fact that updates are very rare to being with and the process time is arbitrary is beside the point here... the point is, why is the result of the above query: (655360 row(s)affected) (0 ms taken) ... or what ever record count row(s)affected ???? All that needs changing is the default value... ... why is there any affect on current records? ... and is there a simpler way to change the default value (with no affect on current records)? EDIT: What the heck does this mean?: ALTER COLUMN specifies a new default value for a column or removes the old default value. If the old default is removed and the column can be NULL, the new default is NULL. If the column cannot be NULL, MySQL assigns a default value, as described in Section 13.1.5, “CREATE TABLE Syntax”. Quote Link to comment https://forums.phpfreaks.com/topic/50898-default-value-to-store-semi-static-variable/ Share on other sites More sharing options...
fenway Posted May 11, 2007 Share Posted May 11, 2007 Almost every alter table command requires touching the entire table. Quote Link to comment https://forums.phpfreaks.com/topic/50898-default-value-to-store-semi-static-variable/#findComment-250644 Share on other sites More sharing options...
bubblegum.anarchy Posted May 11, 2007 Author Share Posted May 11, 2007 How is ALTER COLUMN implemented? Quote Link to comment https://forums.phpfreaks.com/topic/50898-default-value-to-store-semi-static-variable/#findComment-250978 Share on other sites More sharing options...
bubblegum.anarchy Posted May 12, 2007 Author Share Posted May 12, 2007 Found the usage: ALTER TABLE reimbursement ALTER COLUMN rate SET DEFAULT .55 But the entire table is affected. I do not understand why, especially since the above query is so explicit. Quote Link to comment https://forums.phpfreaks.com/topic/50898-default-value-to-store-semi-static-variable/#findComment-251016 Share on other sites More sharing options...
fenway Posted May 14, 2007 Share Posted May 14, 2007 In fact, the only alter command that doesn't touch the table & the indexes is a straight rename column. Quote Link to comment https://forums.phpfreaks.com/topic/50898-default-value-to-store-semi-static-variable/#findComment-253068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.