From bf1c52d762c6d576880141a6cc571c127feae704 Mon Sep 17 00:00:00 2001 From: Thierry Bordaz Date: Wed, 15 May 2024 11:34:30 +0200 Subject: [PATCH] Issue 6172 - RFE: improve the performance of evaluation of filter component when tested against a large valueset (like group members) Bug description: Before returning an entry (to a SRCH) the server checks that the entry matches the SRCH filter. If a filter component (equality) is testing the value (ava) against a large valueset (like uniquemember values), it takes a long time because of the large number of values and required normalization of the values. This can be improved taking benefit of sorted valueset. Those sorted valueset were created to improve updates of large valueset (groups) but at that time not implemented in SRCH path. Fix description: In case of LDAP_FILTER_EQUALITY component, the server can get benefit of the sorted valuearray. To limit the risk of regression, we use the sorted valuearray only for the DN syntax attribute. Indeed the sorted valuearray was designed for those type of attribute. With those two limitations, there is no need of a toggle and the call to plugin_call_syntax_filter_ava can be replaced by a call to slapi_valueset_find. In both cases, sorted valueset and plugin_call_syntax_filter_ava, ava and values are normalized. In sorted valueset, the values have been normalized to insert the index in the sorted array and then comparison is done on normalized values. In plugin_call_syntax_filter_ava, all values in valuearray (of valueset) are normalized before comparison. relates: #6172 Reviewed by: Pierre Rogier (Big Thanks !!!) --- ldap/servers/slapd/filterentry.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ldap/servers/slapd/filterentry.c b/ldap/servers/slapd/filterentry.c index 2a7102828a..a8035e5025 100644 --- a/ldap/servers/slapd/filterentry.c +++ b/ldap/servers/slapd/filterentry.c @@ -296,7 +296,29 @@ test_ava_filter( rc = -1; for (; a != NULL; a = a->a_next) { if (slapi_attr_type_cmp(ava->ava_type, a->a_type, SLAPI_TYPE_CMP_SUBTYPE) == 0) { - rc = plugin_call_syntax_filter_ava(a, ftype, ava); + if ((ftype == LDAP_FILTER_EQUALITY) && + (slapi_attr_is_dn_syntax_type(a->a_type))) { + /* This path is for a performance improvement */ + + /* In case of equality filter we can get benefit of the + * sorted valuearray (from valueset). + * This improvement is limited to DN syntax attributes for + * which the sorted valueset was designed. + */ + Slapi_Value *sval = NULL; + sval = slapi_value_new_berval(&ava->ava_value); + if (slapi_valueset_find((const Slapi_Attr *)a, &a->a_present_values, sval)) { + rc = 0; + } + slapi_value_free(&sval); + } else { + /* This is a fallback condition: the use of sorted valuearray + * is possibly not valid. + * It uses directly the valuearray and then have to go through + * all the values, normalize them until it matches the ava. + */ + rc = plugin_call_syntax_filter_ava(a, ftype, ava); + } if (rc == 0) { break; }