更新SQL
This commit is contained in:
		@@ -1,3 +1,4 @@
 | 
			
		||||
-- 更新统计数据
 | 
			
		||||
INSERT INTO analysis (`key`, `value`) VALUES ('songCount', (SELECT count(*) as count FROM song) ) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`);
 | 
			
		||||
INSERT INTO analysis (`key`, `value`) VALUES ('songWaiting', (SELECT count(DISTINCT song_id) AS count
 | 
			
		||||
                FROM ( SELECT song_id FROM song_artist_relation UNION SELECT song_id FROM song_album_relation ) t_tmp
 | 
			
		||||
@@ -17,6 +18,16 @@ INSERT INTO analysis (`key`, `value`) VALUES ('songArtistCount', (SELECT count(*
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- 更新后初次全表扫描
 | 
			
		||||
INSERT IGNORE INTO wait_song (song_id) SELECT song_id FROM song_artist_relation   WHERE song_id NOT IN ( SELECT song_id FROM song )
 | 
			
		||||
INSERT IGNORE INTO wait_song (song_id) SELECT song_id FROM song_album_relation    WHERE song_id NOT IN ( SELECT song_id FROM song )
 | 
			
		||||
INSERT IGNORE INTO wait_song (song_id) SELECT song_id FROM song_playlist_relation WHERE song_id NOT IN ( SELECT song_id FROM song )
 | 
			
		||||
 | 
			
		||||
-- 后续只需要扫描 wait_check 表
 | 
			
		||||
INSERT IGNORE INTO wait_song (song_id) SELECT song_id FROM wait_check_song WHERE song_id NOT IN ( SELECT song_id FROM song )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- 查看需要爬取的 song 的分布
 | 
			
		||||
SELECT cast( format( t_tmp.song_id / 10000000, 0) * 10000000 as UNSIGNED ) as s, count(*) as count
 | 
			
		||||
FROM (
 | 
			
		||||
@@ -59,6 +70,7 @@ ORDER BY s DESC
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- optimize table
 | 
			
		||||
optimize table analysis;
 | 
			
		||||
optimize table album;
 | 
			
		||||
optimize table artist;
 | 
			
		||||
optimize table category;
 | 
			
		||||
@@ -83,6 +95,33 @@ optimize table wait_fetch_song;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- 移动数据库
 | 
			
		||||
RENAME TABLE neteasemusic.analysis TO neteasemusic_develop.analysis;
 | 
			
		||||
RENAME TABLE neteasemusic.album TO neteasemusic_develop.album;
 | 
			
		||||
RENAME TABLE neteasemusic.artist TO neteasemusic_develop.artist;
 | 
			
		||||
RENAME TABLE neteasemusic.category TO neteasemusic_develop.category;
 | 
			
		||||
RENAME TABLE neteasemusic.comment TO neteasemusic_develop.comment;
 | 
			
		||||
RENAME TABLE neteasemusic.comment_progress TO neteasemusic_develop.comment_progress;
 | 
			
		||||
RENAME TABLE neteasemusic.log TO neteasemusic_develop.log;
 | 
			
		||||
RENAME TABLE neteasemusic.lyric TO neteasemusic_develop.lyric;
 | 
			
		||||
RENAME TABLE neteasemusic.playlist TO neteasemusic_develop.playlist;
 | 
			
		||||
RENAME TABLE neteasemusic.song TO neteasemusic_develop.song;
 | 
			
		||||
RENAME TABLE neteasemusic.song_album_relation TO neteasemusic_develop.song_album_relation;
 | 
			
		||||
RENAME TABLE neteasemusic.song_artist_relation TO neteasemusic_develop.song_artist_relation;
 | 
			
		||||
RENAME TABLE neteasemusic.song_playlist_relation TO neteasemusic_develop.song_playlist_relation;
 | 
			
		||||
RENAME TABLE neteasemusic.user TO neteasemusic_develop.user;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_check_album TO neteasemusic_develop.wait_check_album;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_check_artist TO neteasemusic_develop.wait_check_artist;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_check_lyric TO neteasemusic_develop.wait_check_lyric;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_check_song TO neteasemusic_develop.wait_check_song;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_fetch_album TO neteasemusic_develop.wait_fetch_album;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_fetch_artist TO neteasemusic_develop.wait_fetch_artist;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_fetch_lyric TO neteasemusic_develop.wait_fetch_lyric;
 | 
			
		||||
RENAME TABLE neteasemusic.wait_fetch_song TO neteasemusic_develop.wait_fetch_song;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- 查询单个数据库里面各个表所占磁盘空间大小包括其索引的大小
 | 
			
		||||
SELECT
 | 
			
		||||
    table_schema AS '数据库',
 | 
			
		||||
@@ -96,4 +135,29 @@ FROM
 | 
			
		||||
WHERE
 | 
			
		||||
    table_schema = 'neteasemusic'
 | 
			
		||||
ORDER BY
 | 
			
		||||
    table_rows DESC;
 | 
			
		||||
    table_rows DESC;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- analysis
 | 
			
		||||
-- album
 | 
			
		||||
-- artist
 | 
			
		||||
-- category
 | 
			
		||||
-- comment
 | 
			
		||||
-- comment_progress
 | 
			
		||||
-- log
 | 
			
		||||
-- lyric
 | 
			
		||||
-- playlist
 | 
			
		||||
-- song
 | 
			
		||||
-- song_album_relation
 | 
			
		||||
-- song_artist_relation
 | 
			
		||||
-- song_playlist_relation
 | 
			
		||||
-- user
 | 
			
		||||
-- wait_check_album
 | 
			
		||||
-- wait_check_artist
 | 
			
		||||
-- wait_check_lyric
 | 
			
		||||
-- wait_check_song
 | 
			
		||||
-- wait_fetch_album
 | 
			
		||||
-- wait_fetch_artist
 | 
			
		||||
-- wait_fetch_lyric
 | 
			
		||||
-- wait_fetch_song
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user