And here are the plans for both queries.
First with the left join without the CASE WHEN :
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan3",
"as": "i",
"index": "pulse_invoice_search_adv8",
"index_id": "2d57629c909b4ef9",
"index_projection": {
"primary_key": true
},
"keyspace": "pulse",
"namespace": "default",
"optimizer_estimates": {
"cardinality": 0.000014786595593415846,
"cost": 61.88290754627935,
"fr_cost": 61.88290754627935,
"size": 50
},
"spans": [
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2b\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2b\""
},
{
"high": "\"error\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"error\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2b\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2b\""
},
{
"high": "\"pending\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"pending\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2c\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2c\""
},
{
"high": "\"error\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"error\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2c\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2c\""
},
{
"high": "\"pending\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"pending\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"cpam\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"cpam\""
},
{
"high": "\"error\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"error\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"cpam\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"cpam\""
},
{
"high": "\"pending\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"pending\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
}
],
"using": "gsi"
},
{
"#operator": "Fetch",
"as": "i",
"early_projection": [
"ageId",
"docId",
"id",
"invRecipientType",
"invRecordingDate",
"invStatus",
"orgId",
"proId",
"sysActive",
"type"
],
"keyspace": "pulse",
"namespace": "default",
"optimizer_estimates": {
"cardinality": 0.000014786595593415846,
"cost": 61.88311693097565,
"fr_cost": 61.88311693097565,
"size": 1867
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"alias": "i",
"condition": "(((`i`.`type`) = \"pulseInvoice\") and ((`i`.`invRecipientType`) in [\"cpam\", \"b2b\", \"b2c\"]) and ((`i`.`orgId`) = \"pulseOrganization::S00001\") and ((`i`.`ageId`) = \"pulseAgency::S00001\") and ((`i`.`invStatus`) in [\"pending\", \"error\"]) and ((`i`.`sysActive`) = true) and (\"2024-06-01\" <= (`i`.`invRecordingDate`)) and ((`i`.`invRecordingDate`) <= \"2024-06-07\"))",
"optimizer_estimates": {
"cardinality": 0.000014786595593415846,
"cost": 61.883117569886636,
"fr_cost": 61.883117569886636,
"size": 1867
}
}
]
}
},
{
"#operator": "Join",
"as": "p",
"keyspace": "pulse",
"namespace": "default",
"on_filter": "((meta(`p`).`id`) is not null)",
"on_keys": "(`i`.`proId`)",
"optimizer_estimates": {
"cardinality": 0.000021425809851642675,
"cost": 61.88333120772024,
"fr_cost": 61.88333120772024,
"size": 3734
},
"outer": true
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "InitialProject",
"discard_original": true,
"optimizer_estimates": {
"cardinality": 0.000021425809851642675,
"cost": 61.88333644474219,
"fr_cost": 61.88333644474219,
"size": 3734
},
"preserve_order": true,
"result_terms": [
{
"expr": "(`i`.`id`)"
},
{
"expr": "(`i`.`docId`)"
},
{
"expr": "(`i`.`proId`)"
},
{
"expr": "(`i`.`invRecipientType`)"
}
]
}
]
}
}
]
}
}
And now the left join with the CASE WHEN :
{
"plan": {
"#operator": "Sequence",
"~children": [
{
"#operator": "IndexScan3",
"as": "i",
"index": "pulse_invoice_search_adv8",
"index_id": "2d57629c909b4ef9",
"index_projection": {
"primary_key": true
},
"keyspace": "pulse",
"namespace": "default",
"optimizer_estimates": {
"cardinality": 0.000014786595593415846,
"cost": 61.88290754627935,
"fr_cost": 61.88290754627935,
"size": 50
},
"spans": [
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2b\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2b\""
},
{
"high": "\"error\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"error\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2b\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2b\""
},
{
"high": "\"pending\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"pending\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2c\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2c\""
},
{
"high": "\"error\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"error\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"b2c\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"b2c\""
},
{
"high": "\"pending\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"pending\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"cpam\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"cpam\""
},
{
"high": "\"error\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"error\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
},
{
"exact": true,
"range": [
{
"high": "\"pulseOrganization::S00001\"",
"inclusion": 3,
"index_key": "`orgId`",
"low": "\"pulseOrganization::S00001\""
},
{
"high": "\"pulseAgency::S00001\"",
"inclusion": 3,
"index_key": "`ageId`",
"low": "\"pulseAgency::S00001\""
},
{
"inclusion": 0,
"index_key": "`invType`"
},
{
"high": "\"cpam\"",
"inclusion": 3,
"index_key": "`invRecipientType`",
"low": "\"cpam\""
},
{
"high": "\"pending\"",
"inclusion": 3,
"index_key": "`invStatus`",
"low": "\"pending\""
},
{
"high": "\"2024-06-07\"",
"inclusion": 3,
"index_key": "`invRecordingDate`",
"low": "\"2024-06-01\""
}
]
}
],
"using": "gsi"
},
{
"#operator": "Fetch",
"as": "i",
"early_projection": [
"ageId",
"docId",
"id",
"invRecipientType",
"invRecordingDate",
"invStatus",
"orgId",
"proId",
"sysActive",
"type"
],
"keyspace": "pulse",
"namespace": "default",
"optimizer_estimates": {
"cardinality": 0.000014786595593415846,
"cost": 61.88311693097565,
"fr_cost": 61.88311693097565,
"size": 1867
}
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"alias": "i",
"condition": "(((`i`.`type`) = \"pulseInvoice\") and ((`i`.`invRecipientType`) in [\"cpam\", \"b2b\", \"b2c\"]) and ((`i`.`orgId`) = \"pulseOrganization::S00001\") and ((`i`.`ageId`) = \"pulseAgency::S00001\") and ((`i`.`invStatus`) in [\"pending\", \"error\"]) and ((`i`.`sysActive`) = true) and (\"2024-06-01\" <= (`i`.`invRecordingDate`)) and ((`i`.`invRecordingDate`) <= \"2024-06-07\"))",
"optimizer_estimates": {
"cardinality": 0.000014786595593415846,
"cost": 61.883117569886636,
"fr_cost": 61.883117569886636,
"size": 1867
}
}
]
}
},
{
"#operator": "Join",
"as": "p",
"keyspace": "pulse",
"namespace": "default",
"on_filter": "((meta(`p`).`id`) is not null)",
"on_keys": "case when (`i`.`docId`) then (`i`.`docId`) else (`i`.`proId`) end",
"optimizer_estimates": {
"cardinality": 0.10344145312464717,
"cost": 61.88333120772024,
"fr_cost": 61.88333120772024,
"size": 3734
},
"outer": true
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Filter",
"condition": "((meta(`p`).`id`) is not null)",
"optimizer_estimates": {
"cardinality": 0.10344145312464717,
"cost": 61.88965214920031,
"fr_cost": 61.88965214920031,
"size": 3734
}
},
{
"#operator": "InitialProject",
"discard_original": true,
"optimizer_estimates": {
"cardinality": 0.10344145312464717,
"cost": 61.91493591512057,
"fr_cost": 61.91493591512057,
"size": 3734
},
"preserve_order": true,
"result_terms": [
{
"expr": "(`i`.`id`)"
},
{
"expr": "(`i`.`docId`)"
},
{
"expr": "(`i`.`proId`)"
},
{
"expr": "(`i`.`invRecipientType`)"
}
]
}
]
}
}
]
}
}
There is a “Filter” in the "#operator": "Parallel"
which is not in the first plan.