Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

sql - MySQL: how to keep track of changes in a view

In my MySQL database, I have a massive view built from a very complex query (+5 million rows, 118 columns), which changes part of its content daily. Every day, I have to query this view and insert its whole content into an even bigger table, this operation can take from 3.5 to 5 hours.

I tried to export the data to CSV files in chunks and then use LOAD DATA INFILE to load the records in a faster fashion, but the export stage is painfully slow.

Is there a way to detect what changed in the view and only update those records in the bigger table? Any recommendations to deal with that amount of records stored in a view?

Thanks

question from:https://stackoverflow.com/questions/65924538/mysql-how-to-keep-track-of-changes-in-a-view

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Strictly speaking, a view contains no records. Rather it presents a, well, view of the underlying tables.

Can you tell which rows changed in the underlying tables? Do any of those tables have columns defined like this?

changetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

If so, you may be able to generate a divergent view, containing the same columns as your existing view, hat only has the rows that changed since a certain time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...