directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre-Arnaud Marcelot ...@marcelot.net>
Subject Re: About reverse index ...
Date Wed, 12 May 2010 16:20:25 GMT

On 9 mai 2010, at 17:42, Emmanuel Lecharny wrote:

> Hi guys,
> 
> in an attempt to jump into the backend database, and due to the problem we have on the
add operation, I looked at the current implementation (based on JDBM) and the way we use it.
> 
> Right now, we have one master table containing all the entries, plus many indexes, some
of them being system indexes (CSN, UUID, RDN, etc) and other being user defined.
> 
> Each of these index are a composition of two tables :
> - a forward index : from a  key, you get a link to entries in the Master Table (MT)
> - a reverse index : from an entry ID, you get a link to all the contained values
> 
> As soon as you consider that a delete operation will need to update all the index the
deleted entry uses, you see that you can benefit from having such reverse index : you don't
have to grab the entry from the backend, as you already have it's ID, which is all what you
need. Thus, a delete operation is just about doing :
> - get the entry ID
> - for each index, if we have an <Entry ID> stored, then grab the associated values,
and for each value, delete them from the forward index.
> - delete the entry from the MT
> 
> Sounds like you have avoid a fetch from the MT, but you have to pay an heavy penalty
for that :
> - first, has you have no idea about how many index are used for this entry (suppose that
the entry does not contain the optional indexed 'cn' attribute), you still have to check in
the index.
> - second, you have to maintain 2 tables for each index
> 
> IMO, the cost is way to expensive compared to the basic approach : grab the entry.
> 
> Now, it's not enough to say 'kill the reverse index !'. There is one more reason why
we want to have this reverse index, the question is : does it brings a lot of benefit ?
> 
> So why do we need this reverse index ? We discussed about it with Stefan, and here is
what it is used for : Suppose you have a search request with a filter like (&(ObjectClass=XXX)(cn=YYY)).
> 
> The search engine will evaluate the number of entries each of those filters node will
get back. Suppose it's N for the OC filter, and M for the cn filter. Let's say that N >
M.
> Now, we will loop on the M entries to check if they fit the OC filter.
> 
> How do we do that ? The first approach would be to grab the entry, and check in memory
of the filter (ObjectClass=XXX) match the entry. If not, we ditch the entry, otherwise, itas
a valid candidate.
> 
> The second option is to use the reverse index : we have the entry ID (we havdn't grabbed
the entry from disk yet), and we can see if the OC table contains a reference for this entry
ID. If not, we can move to the next entry ID. Otherwise, we can grab the entry and return
it.
> 

I would add a third option where you only get the Entry IDs from the first filter and use
these IDs to verify the presence of these entries in the BTree obtained from the forward index
of the other filter.
At the end you only grab entries from the master table that are really matching the full filter.

> Obviously there is some potential for a speedup. Now, let's consider the cases where
we benefit from not grabbing the entry.
> 
> 1) We grab all the entry using the smallest set selected with the filters
> pros :
> - Fast entry filtering, it's just a question on applying the filters on the entry
> - It can be used very late, as we have already grabbed the entry. The entry selection
can not only be based on the filter, but can also be combined with virtual attributes which
has been added on the grabbed entry
> - That means we can move the search engine out of the backend, and have it working on
the top of the Interceptor chain
> 
> cons :
> - We may read way more entries than necessary
> 
> 2) we just get the Entry ID and use the reverse index to select the entries
> pros :
> - we don't grab the entries unless absolutely necessary
> 
> cons :
> - we may have to check in many indexes (as many as we have exprNodes in the filter expression,
assuming that each of them are indexed), which means lot of O(log(N)) operations on these
index (assuming that all those index are in memory, otherwise, if we hit the disk, the benefit
is null)
> - as soon as we have one single non indexed exprNode in the filter we have to check,
then we will have to grab the entry anyway. The benefit is that we may save some disk access.
> - of course, we have to maintain all the reverse indexes.
> - if the exprNode is associated with an attribute not present in te entry, we do a lookup
in the index for nothing
> - if the intersection between the two exprNode is big (ie Nb(ObjectClass=XXX) inter Nb(cn=YYY)),
then the gin will be low, and if this itersection is small, then it's likely that the smallest
set has been already selected as the main index to use to grab entries, thus leading to a
small number of entries to grab.
> 
> 
> So here is what I suggest :
> - get rid of those reverse index
> - or, at least, make it optionnal
> 
> thoughts ?

I think we can live without them.
If the implementation without them is too slow, then we could bring them back.

My 2 cents,
Pierre-Arnaud 

> 
> -- 
> Regards,
> Cordialement,
> Emmanuel L├ęcharny
> www.nextury.com
> 
> 


Mime
View raw message