Hi, now that I know the context here are some more comments.If the purpose is to create a useful ldif file, which could eventually be used for import then formatting an entry correctly is not enough. Order of entries matters: parents need to come before children. We already handle this in db2ldif or replication total update.
That said, whenever you write an entry you always have seen the parent and could stack the dn with the parentid and createt the dn without using the entryrdn index.
You even need not to keep track of all the entry rdsn/dns - only the ones with children will be needed later, the presence of "numsubordinates"
identifies a parent.