I have big tables containing MILLIONS of data ( its too too huge).
Tables are as follows
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
Note:I cant build new index not alter table schema in any way
comment type is of String
Now given a list of comment_type and a comment_creation_date range i need to find all post which has that type of comment_type.
A simple very inefficient solution will be
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)
How can i optimize this query? What if same thing by last_modified_date of comment rather then comment_date. Note:
last_modified_date is NOT indexed and comment_date Is
Once the query succeeds i want to get all comments of one post together. Example if post1 with c1,c2,c3
PS:I am not good at designing queries .I know IN in not good for performance.