Here is my index with changes you said
create index def_index_inv_services on stitchit_data_bucket (DISTINCT ARRAY ins.service_id FOR v IN invoice_services END);
it is scanning my other indexes not the this one here is the list of indexes its scanning
stitchit_data_bucket.def_actual_sale_no_express
stitchit_data_bucket.cash_register_payment
here is the plan text
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IntersectScan",
"scans": [
{
"#operator": "IndexScan3",
"as": "invoice",
"index": "def_actual_sale_no_express",
"index_id": "12af0f7b380004f9",
"index_projection": {
"primary_key": true
},
"keyspace": "stitchit_data_bucket",
"namespace": "default",
"spans": [
{
"exact": true,
"range": [
{
"high": "\"invoice\"",
"inclusion": 3,
"low": "\"invoice\""
}
]
}
],
"using": "gsi"
},
{
"#operator": "IndexScan3",
"as": "invoice",
"index": "cash_register_payment",
"index_id": "6306044bcb82ea37",
"index_projection": {
"primary_key": true
},
"keyspace": "stitchit_data_bucket",
"namespace": "default",
"spans": [
{
"exact": true,
"range": [
{
"high": "\"3221\"",
"inclusion": 3,
"low": "\"3221\""
}
]
}
],
"using": "gsi"
}
]
},
{
"#operator": "Fetch",
"as": "invoice",
"keyspace": "stitchit_data_bucket",
"namespace": "default"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Unnest",
"as": "ins",
"expr": "(`invoice`.`invoice_services`)"
}
]
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "NestedLoopJoin",
"alias": "service",
"on_clause": "(cover ((`service`.`id`)) = (`ins`.`service_id`))",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan3",
"as": "service",
"covers": [
"cover ((`service`.`id`))",
"cover ((`service`.`name`))",
"cover ((`service`.`picture`))",
"cover ((`service`.`status`))",
"cover ((meta(`service`).`id`))"
],
"filter_covers": {
"cover ((`service`.`type`))": "service"
},
"index": "def_service_details",
"index_id": "92af9f8cade3ad97",
"index_projection": {
"entry_keys": [
0,
1
],
"primary_key": true
},
"keyspace": "stitchit_initialization_hq",
"namespace": "default",
"nested_loop": true,
"spans": [
{
"exact": true,
"range": [
{
"high": "(`ins`.`service_id`)",
"inclusion": 3,
"low": "(`ins`.`service_id`)"
}
]
}
],
"using": "gsi"
}
]
}
},
{
"#operator": "Filter",
"condition": "(((cover ((`service`.`type`)) = \"service\") and ((`invoice`.`store_id`) = \"3221\")) and ((`invoice`.`type`) = \"invoice\"))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "cover ((`service`.`name`))"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
},
"text": "SELECT service.name\r\nFROM stitchit_data_bucket invoice UNNEST invoice.invoice_services as ins\r\nJOIN stitchit_initialization_hq service ON service.id = ins.service_id WHERE service.type = \"service\"\r\nAND invoice.store_id = \"3221\" AND invoice.type = \"invoice\""
}