Hi
We have the below query and the attributes are arrays,
entity.locationDSL.parameters.clusters - clusters is an array
entity.condition.productGtins - productGtins is an array
Query:
SELECT META(promotions
).id AS _ID, META(promotions
).cas AS _CAS, promotions
.* FROM promotions
USE INDEX (tmp_nested_index_entity_state_cluster_gtin_class_PR_CL using GSI)
WHERE (_class = ‘XXXX’ OR _class = ‘YYYY’) AND entity.state IN [‘APPROVED’ , ‘ADVERTISED’]
AND entity.startDateTime >= 1539187800000
AND ANY clusterId IN entity.locationDSL.parameters.clusters SATISFIES
(ANY gtin IN entity.condition.productGtins SATISFIES [clusterId,gtin] = [“f9a5d04f-5980-4a0a-9ee4-5af726962f9e”,“31738147500004”] END) END
We first created 2 separate composite array indexes on above attributes which found to be less performant compared to nested array index created as below:
Index1:
CREATE INDEX nested_index_entity_state_cluster_gtin_class_PR_CL
ON promotions
(DISTINCT ARRAY (DISTINCT ARRAY [clster,gtin] FOR gtin IN entity.condition.productGtins END) FOR clster IN entity.locationDSL.parameters.clusters END, entity
.startDateTime
)
PARTITION BY HASH(entity.state)
WHERE ( _class = ‘XXXX’ OR _class = ‘YYYY’) AND entity
.state
IN [‘APPROVED’ , ‘ADVERTISED’]
using GSI with {‘num_replica’:1,‘num_partition’:6};
Now we have a change in data model and we have an addition attribute coming up along with above two attributes which is again an array
entity.condition.subConditions.productGtins - here subConditions and productGtins both are arrays.
To support the change in data model have created one more index as below,
CREATE INDEX tmp_nested_index_entity_state_cluster_subcondition_gtin_class_PR_CL
ON promotions
(DISTINCT ARRAY (DISTINCT ARRAY (DISTINCT ARRAY [clster,gtin] FOR gtin IN subCond.productGtins END) FOR subCond IN entity.condition.subConditions END) FOR clster IN entity.locationDSL.parameters.clusters END,
entity
.startDateTime
)
PARTITION BY HASH(entity.state)
WHERE ( _class = ‘XXXX’ OR _class = ‘YYYY’) AND entity
.state
IN [‘APPROVED’ , ‘ADVERTISED’]
using GSI with {‘num_replica’:1,‘num_partition’:6};
However, the below query is not taking up the above index,
New Query
SELECT META(promotions
).id AS _ID, META(promotions
).cas AS _CAS, promotions
.* FROM promotions
USE INDEX (tmp_nested_index_entity_state_cluster_gtin_class_PR_CL,
tmp_nested_index_entity_state_cluster_subcondition_gtin_class_PR_CL USING GSI)
WHERE (_class = ‘XXXX’ OR _class = 'YYYY) AND entity.state IN [‘APPROVED’ , ‘ADVERTISED’]
AND entity.startDateTime >= 1539187800000
AND (ANY clusterId IN entity.locationDSL.parameters.clusters SATISFIES
(ANY gtin IN entity.condition.productGtins SATISFIES [clusterId,gtin] = [“f9a5d04f-5980-4a0a-9ee4-5af726962f9e”,“31738147500004”] END)
OR (ANY subCond IN entity.condition.subConditions SATISFIES (ANY gtin IN subCond.productGtins SATISFIES [clusterId,gtin] = [“f9a5d04f-5980-4a0a-9ee4-5af726962f9e”,“31738147500004”] END) END) END)
Need help in doing things correctly in indexes and query??
Regards,
Venkat