* attribute's values are already sorted. If the MDB_AT_MULTI bit of the
* attr index is set, the values are stored separately.
*
+ * Unfortunately, MDB_AT_MULTI and MDB_AT_SORTED are mutually exclusive;
+ * the DB stores big multi-valued attrs in sorted order but the sorting
+ * is according to the DB order which is not guaranteed to match the
+ * attribute's matching rule ordering. So, drop the sorted flag on big
+ * multi-val attributes, the values will need to be resorted when the
+ * entry is read again.
+ *
* If the MDB_AT_NVALS bit of numvals is set, the attribute also has
* normalized values present. (Note - a_numvals is an unsigned int, so this
* means it's possible to receive an attribute that we can't encode due
if (!a->a_desc->ad_index)
return LDAP_UNDEFINED_TYPE;
l = mdb->mi_adxs[a->a_desc->ad_index];
- if (a->a_flags & SLAP_ATTR_SORTED_VALS)
- l |= MDB_AT_SORTED;
if (a->a_flags & SLAP_ATTR_BIG_MULTI)
l |= MDB_AT_MULTI;
+ else if (a->a_flags & SLAP_ATTR_SORTED_VALS)
+ l |= MDB_AT_SORTED;
*lp++ = l;
l = a->a_numvals;
if (a->a_nvals != a->a_vals)