何百万ものデータを含む大きなテーブルがあります (大きすぎます)。
表は次のとおりです。
Post
post_id,user_id,description,creation_date, xyz, abc ,etc
primarykey for post :post_id
partition key for Post : creation_date
index on Post : user_id
Comment:
commentid,post_id, comment_creation_date,comment_type,last_modified_date
Primary key of comment = commentid
indexed colums on Comment = commentid, postid
partition key for Comment table = comment_creation_date
注:テーブルスキーマを変更せずに新しいインデックスを作成することはできません
コメントのタイプは文字列です
comment_type のリストと comment_creation_date の範囲が与えられたので、そのタイプの comment_type を持つすべての投稿を見つける必要があります。
単純な非常に非効率的なソリューションは次のようになります
select * from post p, comment c where c.post_id = p.post_id where c.comment_creation_date > ? and c.comment_creation_date < ?
and p.posttype IN (some list)
このクエリを最適化するにはどうすればよいですか? comment_date ではなく、コメントの last_modified_date で同じことが起こったらどうなるでしょうか。ノート:
last_modified_date is NOT indexed and comment_date Is
クエリが成功したら、1 つの投稿のすべてのコメントをまとめて取得したいと考えています。c1、c2、c3 の post1 の場合の例
PS: 私はクエリの設計が苦手です。IN はパフォーマンスが良くないことを知っています。