从sqlite FTS表中删除行很慢

时间:2014-11-10 02:19:42

标签: sql sqlite full-text-search

我正在使用 sqlite 3.8.2 ,我试图从我的全文表 media_fts中删除大量行,其中包含以下内容查询:

 DELETE FROM `media_fts`
  WHERE docid IN
        ( SELECT id
            FROM media
           WHERE is_in_music_folder = 1)

查询计划查询如下:

SCAN TABLE media_fts VIRTUAL TABLE INDEX 1: 
EXECUTE LIST SUBQUERY 0
SEARCH TABLE media USING COVERING INDEX media_idx_extra_1 (is_in_music_folder=?)

如您所见,正确使用了索引media_idx_extra_1

删除涉及 500 000行并且 34s 这非常慢;为了进行比较,删除media数据库中相同数量的行需要 89ms

FTS表非常简单:

    CREATE VIRTUAL TABLE IF NOT EXISTS media_fts
        USING fts4 (
            media_id,
            album_id,
            title,
            artist,
            album_artist,
            album,
            comment,
            lyrics,
            is_in_music_folder  INT NOT NULL DEFAULT 0
        ) ;

我的查询有什么问题?

  

注意:我的数据库已经过VACUUMED和ANALYZED

更新 根据@ ah_hau的建议,我尝试了以下查询:

DELETE FROM `media_fts`            
 WHERE docid IN        
     ( SELECT id            
     FROM media           
     INNER JOIN media_fts ON (media.id = media_fts.docid)            
     WHERE  media.is_in_music_folder = 1)

计划:

SCAN TABLE media_fts VIRTUAL TABLE INDEX 1: 
EXECUTE LIST SUBQUERY 0 
SEARCH TABLE media USING COVERING INDEX media_idx_extra_1 (is_in_music_folder=?) 
SCAN TABLE media_fts VIRTUAL TABLE INDEX 1: 

新查询需要 54s ,所以不是改进

0 个答案:

没有答案