0

私は単純なテーブルを持っています (MYSQL - MyISAM):

編集: これは 50M レコード テーブルです。新しいインデックスを追加することは、実際にはできることではありません。

actions (PRIMARY action_id, user_id, item_id, created_at)

指標:

action_id (action_id, PRIMARY)
user (user_id)
item_user (user_id, item)
created_user (user_id, created_at)

そしてクエリ:

SELECT count(distinct item_id) as c_c from actions where user_id = 1

説明:

 1  SIMPLE  action  ref user_id,created_user    user_id 4   const   1415    

1,000 を超えるエントリを持つユーザーの場合、このクエリの実行には約 7 秒かかります。これを改善する方法はありますか?

私は次のことを試しましたが、それらはすべて悪いです:

SELECT count(*) from actions where user_id =1 group by item_id
SELECT count(item_id) from actions USE INDEX (item_user) where user_id = 1 group by item_Id 
4

2 に答える 2

0

以下をテストできますか。

SELECT count(*) as c_c 
   from (
       SELECT distinct item_id 
       from actions where user_id = 1
        ) as T1
于 2013-10-25T17:04:36.960 に答える