Solved

Alter Table Problem - over 125 million rows in table and query takes to long.

Posted on 2010-09-06
4
318 Views
Last Modified: 2013-11-10
Hi,
I have a table with 125million rows in it on the live db
i replicate ths db to a mysql db daily
For reporting reaons, i want to pull in the data from this table into my SQL SERVER db.
i only pull in the previous days entries to the SQL SERVER.

however to do this i want to add a colunm called DW_TIMESTAMP

So i would use this syntax
ALTER TABLE MYTABLENAME
ADD COLUMN dw_timestamp TIMESTAMP
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

however because there are soo many rows this is taking forever, in fact it stopped the Mysql server because i believe it timmed out.

Can anyone suggest how i can speed up this process.

I was thinking if i could add a where clause but i don't believe that would work.

Kind Regards,
Putoch
0
Comment
Question by:Putoch
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
please clarify: is this MS SQL Server, or MySQL?
which version / sp ?

this "alter table" should not take "forever", unless it's blocked all the time by other processes issuing schema locks on the table ...
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Maybe if you add the column, allowing nulls first.

Then assign the default value as a separate transaction.

If this is a always live DB, then you may just have to wait it out. You should only need to do it once.

0
 

Author Comment

by:Putoch
Comment Utility
Its a MYSQL db (version 5.1.44 )

i was able to alter any other table i needed to with out any trouble, it seems to only be this table.
i will try to do it seperatly now and see how this works.

Something strange though happened with the other tables.
i set up the timestamp to Default current_timestamp on update.
however when i updated all those other tables the timestamp defaulted to 0000-00-00.

Why would this happen do you know?
Is there something i'm missing on my syntax.
the timestamp is set up as NOT NULL.

ALTER TABLE MYTABLENAME
ADD COLUMN dw_timestamp TIMESTAMP
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

Thanks a million,
putoch
0
 
LVL 1

Accepted Solution

by:
colin_o_brien earned 500 total points
Comment Utility
you could try renaming the table,  adding the new column using a SELECT INTO statement into MYTABLENAME, and then re-adding whatever indexes/constraints you have.  
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now