How to chose Azure Table ParitionKey and RowKey for table that already has a unique attribute

StackOverflow https://stackoverflow.com/questions/4778669

  •  23-10-2019
  •  | 
  •  

سؤال

My entity is a key value pair. 90% of the time i'll be retrieving the entity based on key but 10% of the time I'll also do a reverse lookup i.e. I'll search by value and get the key.

The key and value both are guaranteed to be unique and hence their combination is also guaranteed to be unique.

Is it correct to use Key as PartitionKey and Value as RowKey?

I believe this will also ensure that my data is perfectly load balanced between servers since ParitionKey is unique.

Are there any problems in the above decision? Under any circumstance is it practical to have a hard coded partition key? I.e all rows have same partition key? and keeping the RowKey unique?

هل كانت مفيدة؟

المحلول

Is it doable, yes, but depending on the size of your data, I'm not so sure it's a good idea. When you query on partition key, Table Store can go directly to the exact partition and retrieve all your records. If you query on Rowkey alone, Table store has to check if the row exists in every partition of the table. so if you have 1000 key value pairs, searching by your key will read a single partition/row. If your search via your value alone, it will read all 1000 partitions!

I face a similar problem, I solved it 2 ways:

  1. Have 2 different tables, one with partitionKey as your-key, the other with your-value as partitionKey. Storage is cheap, so duplicating data shouldn't cost much.

  2. (What I finally did) If you're effectively returning single entites based on a unique key, just stick them in blobs(partitioned and pivoted as in point 1), because you don't need to traverse a table, so don't.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top