Which statement best describes partition key and sort key designs of DynamoDB indexes?
Click on the arrows to vote for the correct answer
A. B. C. D.Answer: B.
Option B is CORRECT because a global secondary index is a DynamoDB index with a partition key and a sort key that can differ from those specified on the base table.
They are generally used to perform scans and queries on the data based on different partition key criteria.
Therefore, Option B is incorrect.
A local secondary index (LSI) must have the same partition key, but can have a different sort key.
Therefore, Options C and D are incorrect.
Reference:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-indexes-general.htmlDynamoDB is a highly scalable and flexible NoSQL database service offered by Amazon Web Services (AWS). It provides support for indexing data using Global Secondary Indexes (GSI) and Local Secondary Indexes (LSI). Both GSI and LSI allow for more efficient querying of data by creating alternate views of the data with different partition keys and/or sort keys.
A partition key is a primary key attribute that is used to distribute data across multiple partitions in a DynamoDB table. It is also used to determine the partition where an item is stored in the table. A sort key is a secondary key attribute that is used to sort items within a partition based on a specific order.
With that in mind, let's look at each answer choice:
A. GSI should have the same partition key as the base table.
This statement is partially correct. A GSI must have a partition key, and it is recommended that the partition key for a GSI should be different from the base table's partition key. However, it is not required that the partition key for a GSI be the same as the base table's partition key.
B. GSI can have a different partition key and sort key compared to the base table.
This statement is correct. GSI allows you to create indexes with different partition and sort keys compared to the base table. This can be useful in cases where you need to query the data in a different way than the base table.
C. LSI can have a different partition key and sort key compared to the base table.
This statement is incorrect. LSI must have the same partition key as the base table, but a different sort key. This is because an LSI is stored within the same partition as its base table, so it must use the same partition key.
D. LSI must have the same sort key compared to the base table.
This statement is incorrect. While an LSI must use the same partition key as the base table, it can have a different sort key. This allows for more efficient querying of data in a different order than the base table.
In conclusion, the correct answer is B. GSI can have a different partition key and sort key compared to the base table.