Header Ads

Header ADS

DynamoDB Primary Key Concept

 

DynamoDB Primary Key Concept

DynamoDB এ primary key হলো table এর main identifier
Primary key দুইভাবে হতে পারে:


Option 1 — Simple Primary Key

  1. Partition Key only

  2. প্রতিটি item table এ unique Partition Key দ্বারা uniquely identified হয়

Example: Users table

Partition Key (user_id)nameage
1Ali24
2Sara22

এখানে primary key = Partition Key = user_id

Sort Key নেই → এক Partition Key এ শুধু ১টি item allowed


Option 2 — Composite Primary Key

  1. Partition Key + Sort Key

  2. এখন primary key = combination of Partition Key + Sort Key

  3. একই Partition Key এর multiple items allowed, কিন্তু Sort Key different হতে হবে

Example: Orders table

Partition Key (user_id)Sort Key (order_date)item
120260101Laptop
120260105Mouse
220260102Keyboard

Primary key uniqueness check করে (Partition Key + Sort Key) combination দিয়ে

Partition Key alone unique না → multiple items same user_id allowed


2️⃣ Key Takeaway

ConceptDynamoDB
Partition KeyMain part of primary key, always required
Sort KeyOptional, second part of primary key (for composite key)
Primary KeyEither:
1️⃣ Partition Key only (Simple)
2️⃣ Partition Key + Sort Key (Composite)

💡 মনে রাখো: Partition Key alone defines data distribution / shard,
Sort Key defines ordering inside that partition


Example 

Simple key table:

Primary Key = user_id
Partition Key only

Composite key table:

Primary Key = (user_id + order_date)
Partition Key = user_id
Sort Key = order_date
  • Query efficiency depends on Partition Key

  • Sort Key gives extra flexibility for multiple items per Partition Key

     

     

     

    tar mane primary key er 2 ta part ache primary key = partition key + short key (composite key)

     but main primary key hocche partition key 

     

Powered by Blogger.