CouchDB utiliza ID secuenciales, pero puede determinar instantáneamente la ID en función del contenido

Couchdb exhibits extremely beneficial performance gains by using sequential ID's. However, there is something to be said for being able to instantaneously "know" the ID of an object simply by looking at the content (for example hashing a user name into an ID). How can I more or less achieve the convenience of the hashed ID, yet the performance gains of sequential ID's.

preguntado el 08 de enero de 11 a las 21:01

1 Respuestas

I don't think a workaround is possible.

View key lookups are only a tiny bit slower than document id lookups. (See los puntos de referencia.) My understanding is that the type of document _id does not impact performance in the case of a view lookup because it relies on its own independent B-tree structure. So for actually looking up user information, view lookups over sequentially-identified documents are totally fine.

But I understand that you would like to be able to register users and guarantee that there can be no username conflicts. So you DEBE have the username in the document id.

This is the appropriate thing to do if you decide to rebel against CouchDB's eventual consistency approach.

Also, my understanding is that you are not likely to experience degraded performance unless you are doing bulk inserts of random usernames or handling a high number of new user registrations per second.

This is the same performance trade-off other databases make. You can insert data faster without locks/transactions than you can by imposing them.

Respondido el 09 de enero de 11 a las 09:01

A crazy idea I just had might also work, though it's hard to say what the performance would be like in practice without trying it out. Instead of storing usernames in their own documents, you could store them together in a single document (or even sharded into the a-doc, b-doc, etc.) and use document update handlers to guarantee newly registered usernames are added/rejected atomically. This naturally leads to another idea...keeping a document that contains a journal of username->sequential doc id mappings. If you can't insert it in the journal doc then you simply don't proceed to add the user. - Ben Damman

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.