I want to use an adaptive index like this one :
CREATE INDEX stats_email_message_index
ON stats
((distinct (pairs({
“date”: (((data
).email
).date
),
“senderDomainId”: (((((data
).email
).sender
).domain
).id
),
“recipientDomainId”: (((((data
).email
).recipient
).domain
).id
),
“recipientMail”: ((((data
).email
).recipient
).mail
),
“senderMail”: ((((data
).email
).sender
).mail
),
“subject”: (((data
).email
).subject
)}))))
WHERE (type
= “email”)
For some reason I can never get the index been use even when querying for all values on the index.
explain select stats.*
from stats
use index(stats_email_message_index)
where data.email.date =0
and data.email.messageId =0
and data.email.sender.domain.id =""
and data.email.recipient.domain.id =""
and data.email.recipient.mail =""
and data.email.sender.mail = “”
and data.email.subject
and type
= “email”
[
{
“plan”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “PrimaryScan”,
“index”: “#primary”,
“keyspace”: “stats”,
“namespace”: “default”,
“using”: “gsi”
},
{
“#operator”: “Fetch”,
“keyspace”: “stats”,
“namespace”: “default”
},
{
“#operator”: “Parallel”,
“~child”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “Filter”,
“condition”: “((((((((((stats
.data
).email
).date
) = 0) and ((((((stats
.data
).email
).sender
).domain
).id
) = “”)) and ((((((stats
.data
).email
).recipient
).domain
).id
) = “”)) and (((((stats
.data
).email
).recipient
).mail
) = “”)) and (((((stats
.data
).email
).sender
).mail
) = “”)) and ((((stats
.data
).email
).subject
) = “”)) and ((stats
.type
) = “email”))”
},
{
“#operator”: “InitialProject”,
“result_terms”: [
{
“expr”: “stats
”,
“star”: true
}
]
},
{
“#operator”: “FinalProject”
}
]
}
}
]
},
“text”: “select stats.*\nfrom stats\nuse index(stats_email_message_index)\nwhere data.email.date =0\nand data.email.sender.domain.id =”"\nand data.email.recipient.domain.id =""\nand data.email.recipient.mail =""\nand data.email.sender.mail = “”\nand data.email.subject = “”\nand type
= “email”"
}
]