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 h开发者_Go百科ashed ID, yet the performance gains of sequential ID's.
I don't think a workaround is possible.
View key lookups are only a tiny bit slower than document id lookups. (See benchmarks.) 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 MUST 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.
精彩评论