Podcast
Questions and Answers
A DynamoDB table uses customer_id
as the partition key. Frequent queries require sorting customers by order_date
for each customer_id
. Which type of secondary index is most suitable for this scenario?
A DynamoDB table uses customer_id
as the partition key. Frequent queries require sorting customers by order_date
for each customer_id
. Which type of secondary index is most suitable for this scenario?
- Local Secondary Index (LSI) with `order_date` as the sort key. (correct)
- No secondary index is needed; use the primary key for this query.
- Global Secondary Index (GSI) with `customer_id` as the partition key and `order_date` as the sort key.
- Global Secondary Index (GSI) with `order_date` as the partition key.
You need to create a DynamoDB index that allows you to query your products
table by category
and sort the results by price
. The products
table uses product_id
as its primary key. Which type of secondary index should you use?
You need to create a DynamoDB index that allows you to query your products
table by category
and sort the results by price
. The products
table uses product_id
as its primary key. Which type of secondary index should you use?
- Local Secondary Index (LSI) with `category` as the partition key and `price` as the sort key.
- Local Secondary Index (LSI) with `product_id` as the partition key and `price` as the sort key.
- Global Secondary Index (GSI) with `category` as the partition key and `price` as the sort key. (correct)
- Global Secondary Index (GSI) with `product_id` as the partition key and `price` as the sort key.
Which statement accurately describes a key difference between Global Secondary Indexes (GSIs) and Local Secondary Indexes (LSIs) in DynamoDB?
Which statement accurately describes a key difference between Global Secondary Indexes (GSIs) and Local Secondary Indexes (LSIs) in DynamoDB?
- GSIs must have the same partition key as the base table, while LSIs can have a different one.
- LSIs can be created after the table is created, while GSIs must be defined at table creation.
- LSIs support eventual consistency, while GSIs provide strong consistency.
- GSIs can have a different partition key from the base table, while LSIs must have the same partition key. (correct)
A DynamoDB table named game_scores
uses user_id
as the partition key. You want to efficiently query and sort scores based on game_type
for a specific user_id
. Given the need for strong consistency, which index type is most appropriate?
A DynamoDB table named game_scores
uses user_id
as the partition key. You want to efficiently query and sort scores based on game_type
for a specific user_id
. Given the need for strong consistency, which index type is most appropriate?
You are designing a DynamoDB table to store user activity events. The table uses event_type
as the partition key. You now realize the need to query events based on user_id
within each event_type
. You have already created 5 LSIs on the table. What is the recommended approach?
You are designing a DynamoDB table to store user activity events. The table uses event_type
as the partition key. You now realize the need to query events based on user_id
within each event_type
. You have already created 5 LSIs on the table. What is the recommended approach?
Which of the following statements is true regarding the modification of secondary indexes in DynamoDB after table creation?
Which of the following statements is true regarding the modification of secondary indexes in DynamoDB after table creation?
A transactions
table stores financial transactions with transaction_id
as the primary key. There's a need to efficiently query transactions by customer_id
and filter by transaction_amount
. Which indexing strategy would be most effective, assuming you want the index to only contain customer_id
, transaction_amount
and transaction_id
?
A transactions
table stores financial transactions with transaction_id
as the primary key. There's a need to efficiently query transactions by customer_id
and filter by transaction_amount
. Which indexing strategy would be most effective, assuming you want the index to only contain customer_id
, transaction_amount
and transaction_id
?
You have a DynamoDB table with millions of entries and need to perform complex queries that involve filtering and sorting on multiple non-key attributes. You anticipate high read/write traffic. What is the most important consideration when choosing between using multiple Global Secondary Indexes (GSIs) versus performing scans with filters?
You have a DynamoDB table with millions of entries and need to perform complex queries that involve filtering and sorting on multiple non-key attributes. You anticipate high read/write traffic. What is the most important consideration when choosing between using multiple Global Secondary Indexes (GSIs) versus performing scans with filters?
When should you consider using a Global Secondary Index (GSI) over a Local Secondary Index (LSI) in DynamoDB?
When should you consider using a Global Secondary Index (GSI) over a Local Secondary Index (LSI) in DynamoDB?
A DynamoDB table has a partition key CustomerID
and a sort key OrderDate
. You need to frequently query the table to find all orders placed on a specific date for each customer. Which type of secondary index is most suitable, and why?
A DynamoDB table has a partition key CustomerID
and a sort key OrderDate
. You need to frequently query the table to find all orders placed on a specific date for each customer. Which type of secondary index is most suitable, and why?
Your application needs to query a DynamoDB table based on an attribute that is not the primary key. You anticipate a high volume of read requests on this index. Which factor would be MOST important when choosing between a GSI and an LSI?
Your application needs to query a DynamoDB table based on an attribute that is not the primary key. You anticipate a high volume of read requests on this index. Which factor would be MOST important when choosing between a GSI and an LSI?
You're designing a DynamoDB table for an e-commerce application. The table stores customer orders, and you need to support queries based on both CustomerID
(partition key) and OrderDate
. Furthermore, you want to enable queries based on OrderStatus
(e.g., 'Shipped', 'Delivered'). Which indexing strategy offers the most flexible querying options?
You're designing a DynamoDB table for an e-commerce application. The table stores customer orders, and you need to support queries based on both CustomerID
(partition key) and OrderDate
. Furthermore, you want to enable queries based on OrderStatus
(e.g., 'Shipped', 'Delivered'). Which indexing strategy offers the most flexible querying options?
When creating an LSI, which of the following statements is correct regarding its partition key?
When creating an LSI, which of the following statements is correct regarding its partition key?
Consider a scenario where you have a DynamoDB table named Employees
with EmployeeID
as the partition key. You need to frequently query employees based on their Department
. Which of the following approaches is MOST efficient?
Consider a scenario where you have a DynamoDB table named Employees
with EmployeeID
as the partition key. You need to frequently query employees based on their Department
. Which of the following approaches is MOST efficient?
You have a DynamoDB table with a high volume of write operations and frequent queries on a non-key attribute. Which secondary index characteristic is MOST important to consider for optimizing performance and minimizing costs?
You have a DynamoDB table with a high volume of write operations and frequent queries on a non-key attribute. Which secondary index characteristic is MOST important to consider for optimizing performance and minimizing costs?
Which of the following is a limitation of Local Secondary Indexes (LSIs) compared to Global Secondary Indexes (GSIs) in DynamoDB?
Which of the following is a limitation of Local Secondary Indexes (LSIs) compared to Global Secondary Indexes (GSIs) in DynamoDB?
Which of the following scenarios is best suited for using an LSI over a GSI?
Which of the following scenarios is best suited for using an LSI over a GSI?
Referring to the CLI examples provided, what is the primary difference in how a GSI and LSI are created in DynamoDB?
Referring to the CLI examples provided, what is the primary difference in how a GSI and LSI are created in DynamoDB?
Flashcards
Secondary Indexes
Secondary Indexes
Indexes that allow querying data in ways not possible with the primary key alone.
Global Secondary Index (GSI)
Global Secondary Index (GSI)
Index with a partition key and optional sort key different from the table's primary key.
GSI Query Scope
GSI Query Scope
Enables queries on non-primary key attributes, spanning all items in the table.
When to Use GSI
When to Use GSI
Signup and view all the flashcards
Local Secondary Index (LSI)
Local Secondary Index (LSI)
Signup and view all the flashcards
LSI Use Case
LSI Use Case
Signup and view all the flashcards
LSI Limit per Table
LSI Limit per Table
Signup and view all the flashcards
Index Modification
Index Modification
Signup and view all the flashcards
GSI Partition Key
GSI Partition Key
Signup and view all the flashcards
LSI Partition Key
LSI Partition Key
Signup and view all the flashcards
GSI Capacity Mode
GSI Capacity Mode
Signup and view all the flashcards
LSI Capacity Mode
LSI Capacity Mode
Signup and view all the flashcards
GSI Consistency
GSI Consistency
Signup and view all the flashcards
LSI Consistency
LSI Consistency
Signup and view all the flashcards
Study Notes
- Secondary indexes in Amazon DynamoDB enable querying data beyond the primary key.
- There are two types: Global Secondary Index (GSI) and Local Secondary Index (LSI).
Global Secondary Index (GSI)
- It facilitates creating an index with partition and sort keys different from the table's primary key.
- Enables querying on attributes that are not part of the primary key.
- Spans all items in a table, irrespective of the partition key.
- Useful for querying data in multiple ways.
- Any attribute can function as the partition key.
- Any attribute can function as the sort key (optional).
- Projection specifies attributes included in the index like ALL, Keys only, or INCLUDE specific attributes.
- Supports eventual consistency.
- Operates in both provisioned and on-demand capacity modes.
- Can be modified after table creation.
- An example: create a GSI with email as the partition key if the table stores users and queries by email are frequent.
Local Secondary Index (LSI)
- It allows index creation with the same partition key as the base table but with a different sort key.
- Useful when different sorts of queries are needed on data while keeping the same partition key.
- The partition key must match the base table partition key.
- Any other attribute can be the sort key.
- Projection mirrors GSI, which specifies attributes projected.
- Supports eventual and strong consistency.
- Limited to a maximum of 5 LSIs per table.
- It's created when the table created and cannot be modified afterward.
- An example: create an LSI with registration_date as the sort key if the table has users with user_id as the partition key, and querying by registration_date is required.
Key Differences Between GSI and LSI
- GSI's partition key can differ from the base table, but LSI's must be the same.
- A sort key for GSI can be any attribute, while for LSI, it must differ from the base table's sort key.
- GSI supports provisioned or on-demand capacity modes; LSI supports provisioned mode only.
- GSI indexes are virtually unlimited, but LSI is capped at 5 per table.
- GSI uses eventual consistency, whereas LSI supports both eventual and strong consistency.
- GSIs can be modified after table creation, whereas LSIs can't.
Choosing Between GSI and LSI
- Use GSI when: a completely different partition and sort key than the base table is needed.
- Use GSI when: flexible querying pattern spanning all table items is wanted.
- Use GSI when: an application demands scalability, low latency, and high availability.
- Use LSI when: querying requires a different sort key, but the partition key remains the same.
- Use LSI when: strong consistency on queries is needed.
- Use LSI when: the data model necessitates sorting within the same partition key.
Example of Creating a GSI and LSI
- AWS CLI can be used to create both GSI and LSI
- The command utilizes "aws dynamodb update-table"
- The attribute definitions specify your attribute name and type definitions
- The key schema specifies your attribute name and key type (HASH or RANGE)
- The Projection specifies the attributes you want projected, and the type (ALL)
- The throughput needs to be provisioned for GSI (Read and Write Capacity Units)
Summary
- Use GSIs for flexible queries with different partition and sort keys, spanning the entire table.
- Use LSIs for querying within the same partition key but with different sorting, especially when strong consistency is paramount.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Explore secondary indexes in Amazon DynamoDB, including Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI). Learn how to use indexes with partition and sort keys, query attributes, and project specific data. Understand consistency and capacity modes.