What is a DynamoDB LSI (Local Secondary Index) ?

Поделиться
HTML-код
  • Опубликовано: 28 окт 2024

Комментарии • 100

  • @spider279
    @spider279 2 года назад +1

    You are the hero who saves me for my presentation of dynamoDB at class , such a great explaination

  • @pravinbudage3942
    @pravinbudage3942 2 года назад +1

    You have explained it very smoothly and cleared all the doubts. Thanks

  • @roboprofit2548
    @roboprofit2548 3 года назад +4

    Great video. Keep in mind that more LSI more cost. AWS DOC ==> "A table with many local secondary indexes incurs higher costs for write activity than tables with fewer indexes"
    However, writing to the base table with 2 LSIs still cost 1 WCU IF you don't write to LSIs as well. If you write to 1 LSI then it costs 2 WCUs ( 1 for the table and 1 for LSI)

    • @BeABetterDev
      @BeABetterDev  3 года назад +1

      Great point! Thanks for sharing.

    • @bradw2k
      @bradw2k 3 года назад

      When would a write to a table not result in a write also to its GSI?

    • @tahiraziz193
      @tahiraziz193 2 года назад

      Hi @Robo Profit would be great if you can share any reference please? i have gone through the AWS documentation but couldn't find this. Thanks

    • @roboprofit2548
      @roboprofit2548 2 года назад

      @@bradw2k when you don't write to the index and only write to the base table

  • @SpotCallerzWrestling
    @SpotCallerzWrestling 4 года назад +11

    This is exactly what I needed! Thanks very much. Saved me a lot of money.

  • @mugssyy
    @mugssyy 2 года назад +2

    Hi ! Your videos are great! I had trouble understanding the LSI and GSI for a long time. Thank you . going through more of your content.

  • @yogiHalim
    @yogiHalim 4 года назад +3

    great vid. Thanks.
    First example on 4:00 mins, first approach scan on entire table, should read all data including forum name EC2 and RDS. You stopped at S3 while not entirely wrong but mildly confusing at first as compared to second approach.

    • @yogiHalim
      @yogiHalim 4 года назад +2

      Thanks for the code snippets 7:05 mins (just leaving a shortcut here)

  • @prvinsharma
    @prvinsharma 2 года назад +1

    Well explained! I was going through PluralSight and got lost there with LSI and GSI. Had to hop in here as the first and greatfully the last for LSI. GSI would be next. Thanks

  • @Sami-ec9sd
    @Sami-ec9sd 5 месяцев назад +2

    There is one limitation when using LSI:
    Your Data being stored within the same partition key isn't anymore allowed to exceed 10GB. If you have reached 10GB you wont be able to add more items (you get the error ItemCollectionSizeLimitExceededException).
    You can read about this in the aws doc with the title "Local Secondary Indexes" and the subtitle "Item collections in Local Secondary Indexes"

  • @aamersohail474
    @aamersohail474 3 года назад +2

    Thank you so much for exemplifying it so clearly.

  • @windowcrystal4012
    @windowcrystal4012 4 года назад +5

    Speed: Scan then filter < query on partition key < LSI

  • @krishnasmusicchart4897
    @krishnasmusicchart4897 2 года назад

    Explained excellently, sir

  • @mqtt07
    @mqtt07 Год назад +4

    One other limitation, just to be clear, is that you can change the sort key, not the partition key in an LSI

  • @TomerBenDavid
    @TomerBenDavid 4 года назад +1

    Very clear! Last limitations section was great. I would also suggest to add what are the drawbacks when should you not use it obviously it does not come for free and you might want to use a different db like a mirror in some other place to do these queries based on your intent there is a reason it's a simple kv. Great video many thanks.

  • @JesusAlfredoHernandezOrozco
    @JesusAlfredoHernandezOrozco Год назад

    Great video!
    Really well explained. I recommend it!

  • @worddoc4322
    @worddoc4322 3 года назад +3

    Thank you for the video. I have a question: once a sort key has been set, a table keeps its data sorted by that key. LSI is considered as an extension of the sort key. How the table gets sorted by a pack of sort key + multiple LSI? I think there is something different behind LSI. Could you shed light on it please?

    • @niteshgupta8436
      @niteshgupta8436 2 года назад

      I also have the same doubt. Please explain.

  • @sameeshoncloud9
    @sameeshoncloud9 4 года назад +3

    amazing work buddy

  • @gdemelo
    @gdemelo 9 месяцев назад

    Great explanation. I would recommend providing SDK examples with Javascript/NodeJS or Python, instead of Java, though.

  • @zacsonskaria
    @zacsonskaria 4 года назад +10

    The PartitionKey + SortKey may not be unique, since two subjects in a forum can have same LastPostDateTime. It may not be relevant since it is just an example and the focus is something else, however it can cause confusion in my opinion.

    • @BeABetterDev
      @BeABetterDev  4 года назад +1

      Hi Zacson, thanks for pointing this out. You are absolutely correct.

    • @pikachu5223
      @pikachu5223 2 года назад +1

      There you can use the suffix pattern

    • @rongrongmiao3018
      @rongrongmiao3018 Год назад

      If you use Unix epoch time it would be unique

    • @zacsonskaria
      @zacsonskaria Год назад +1

      @@rongrongmiao3018 Why do you think that the unix epoch time won’t collide when generated at the same time?

  • @ankitgarg568
    @ankitgarg568 4 года назад +1

    Great video. Helped me a lot!!

  • @hejiaji
    @hejiaji 2 года назад +1

    In this example, how can the primary key be assured to be unique? ForumName(Partition key) + LastPostDateTime(SortKey) could definitely be duplicated right?

  • @sunwoojeong9996
    @sunwoojeong9996 2 года назад +2

    Thank you for your lecture. Is LSI sth like a sort key, without having the uniqueness limitation of (partition key, sort key) pair?

    • @BeABetterDev
      @BeABetterDev  2 года назад

      Hi Sunwoo, that's a good way of thinking about it!

    • @sunwoojeong9996
      @sunwoojeong9996 2 года назад

      @@BeABetterDev Got it. Also, for GSI, the whole table (data) is physically replicated to multiple machines. Is LSI also copying some portion of data (the data corresponding to the right partition key) and storing them in different orders?

  • @xamry_
    @xamry_ 4 года назад

    Thanks, to the point and easy to understand.

  • @Viet100
    @Viet100 3 года назад

    I have a question for scan operation. if I scan by PK and Subject="aaa" for example, does dynamodb scan/read "LastPostDateTime"? or it just scan the specified column (not all columns).

    • @BeABetterDev
      @BeABetterDev  3 года назад +1

      Hi Clouder,
      Scans will return the entire row, so all the columns.
      Hope this helps.

    • @Viet100
      @Viet100 3 года назад

      @@BeABetterDev thanks for your effort. keep it up.

  • @juancpgo
    @juancpgo 4 года назад +3

    Great content. 👍 Thank you.

  • @jeffinj7707
    @jeffinj7707 3 года назад +1

    Very helpful. A quick question: I have a large JSON data, how can I create a table with that JSON structure. And can we populate the table with a JSON file?

  • @jwalaivaturi
    @jwalaivaturi 3 года назад +1

    Thanks for the awesome video. Queries or scans on a local secondary index consume read capacity units from the base table and updates consume write capacity units from the base table. What do you mean by no extra cost with LSI?

    • @Xhez2slash
      @Xhez2slash 3 года назад +1

      It is compared to the GSI, where if you create an another GSI for your table that would incur extra cost. (provision extra wcu/rcu for the table created)

  • @_arshadm
    @_arshadm 2 года назад +2

    You left one of the most important questions unanswered. Does the LSI range key attribute also need to be unique in combination with the hash key (i.e. LSI is just another sort key)

    • @renatolimasantos8618
      @renatolimasantos8618 2 года назад +2

      From aws docs:
      "In a DynamoDB table, the combined partition key value and sort key value for each item must be unique. However, in a local secondary index, the sort key value does not need to be unique for a given partition key value. If there are multiple items in the local secondary index that have the same sort key value, a Query operation returns all of the items that have the same partition key value. In the response, the matching items are not returned in any particular order."

    • @_arshadm
      @_arshadm 2 года назад

      @@renatolimasantos8618 Thanks, I was looking for this additional info. This makes the LSI a lot more useful.

  • @karahisarli
    @karahisarli 4 года назад +2

    Great videos and explanation, appreciate the effort, tried couple of blogs/documents but very clearly stated here. Can you please give some tutorials on schema design specially some relations?

    • @BeABetterDev
      @BeABetterDev  4 года назад

      Thanks serdar. I'll look into incorporating relations in an upcoming video!

  • @abhishekpaithane6292
    @abhishekpaithane6292 2 года назад

    great explanation!

  • @MohammadFaizanAli786
    @MohammadFaizanAli786 4 года назад +1

    It's a great video but could you explain how Amazon does it internally? How does it not create more tables and still gives such fast results? If we have local index can we choose to not provide it?

    • @BeABetterDev
      @BeABetterDev  4 года назад

      Hey Mohammad,
      Unfortunately there isn't much documentation in terms of how aws structures LSIs so really its anyone's guess.

  • @arhabersham
    @arhabersham 3 года назад +1

    Well explained ❤️

    • @BeABetterDev
      @BeABetterDev  3 года назад

      Thanks Alfredo! Glad you enjoyed :)

  • @ravisaraswat6519
    @ravisaraswat6519 4 года назад

    You are great , keep up the excellent wok.

  • @ahmedal-shamari414
    @ahmedal-shamari414 4 года назад +1

    thanks for your awesome Video
    can I ask about the brief difference between GSI and LSI? from the 2 videos I think the difference that LSI must be defined at table creation time, no Extra Cost, max 5 LSI per table, it is alternative to range key while GSI can be defined any time, need extra cost, no limitation per table, also GSI= new Partition key + new sort key
    am I correct with the above?
    thanks and best regards

    • @BeABetterDev
      @BeABetterDev  4 года назад

      Hi yes you are correct. Also keep in mind the purpose of the LSI and GSI are fundamentally different. LSI helps you define more range-like queries on a different index. Whereas GSI allows you to perform direct key lookups on the corresponding index.

    • @josecruz2574
      @josecruz2574 4 года назад +1

      @@BeABetterDev so if looking for a specific index - GSI would be more appropriate?

  • @josereneherrerauribe-ceiba8047
    @josereneherrerauribe-ceiba8047 4 года назад +1

    Hello, excellent video! You have any java repository with examples?

    • @BeABetterDev
      @BeABetterDev  4 года назад

      Hi Jose, I unfortunately dont but will look into setting one up. Thanks for watching.

  • @sardesaisantosh
    @sardesaisantosh Год назад

    how can an entire table scan will happen when you have a partition key on forumname in the example for fetching records with s3 and subject = aaa

  • @jeevanthomaskoshy8979
    @jeevanthomaskoshy8979 3 года назад +1

    Won't LSI also duplicate the data like the global secondary index?
    So wouldn't that lead to increased cost ?

    • @sauer.voussoir
      @sauer.voussoir 3 года назад

      same question, if does also create a new table copy like GSI

  • @ognjenaskovic1830
    @ognjenaskovic1830 2 года назад

    Hey, total newbie to Dynamo here. I have a question regarding combination of GSI and LSI. So, if my table has one GSI and one LSI defined, can I do the query which uses GSI as a hash key value and LSI as a range key value ? That would make my life a lot easier, but I'm not sure if it is possible. Will appreciate any help :)

  • @eric19435
    @eric19435 4 года назад

    Nice video. What is the use case of GSI and LSI? What is the different between them?

    • @BeABetterDev
      @BeABetterDev  4 года назад +1

      Hi Eric,
      GSIs allow you to query for specific attributes other than the partition key. LSIs allow you to perform 'range-like' queries on your LSI's range key.

  • @angry740
    @angry740 4 года назад +1

    Excellent!!

  • @ralfrolfen5504
    @ralfrolfen5504 7 месяцев назад

    perfect!

  • @rickfarina9835
    @rickfarina9835 4 года назад

    What is the criteria to use an LSI vs. a GSI? Or, is there now no benefit to using LSIs?

    • @BeABetterDev
      @BeABetterDev  4 года назад +1

      Hi Rick,
      LSIs can unfortuantely only be defined when the table is created and solve a bit of a different purpose than LSIs. LSIs allow you to perform 'range-like' queries on a data field provided you know the partition key. GSIs allow you to perform direct lookups or queries on fields other than the partition key.
      Hoep this helps!

    • @rickfarina9835
      @rickfarina9835 4 года назад

      @@BeABetterDev Hi... First, thank you for this series of AWS videos. Absolutely fantastic!!
      On the LSI/GSI difference, it caused me to re-read the docs and do some testing. I still have the understanding that a GSI can be built over the same Partition Key (PK); and can use either the same or different Sort key (SK) than the base table, which I believe implies a range. For example: "Select PK='x' and SK between 10 and 15".
      I believe this represents a "Range-Query" that you mentioned above. If this is true, doesn't that mean the GSI has essentially the same Query capabilities as the LSI? If so, I'm sill not sure what benefit the LSI has over the GSI, other than it's stored along with the base table rather than creating its own Partitions as the GSI does. Thanks again, so much. Rick

  • @zeretil
    @zeretil Год назад

    This is confusing to me as a rookie -- isn't your partitionkey supposed to be unique? Even when using the Sort Key as part of your partition key, there can be duplicates when two forum posts are updated at the same time?

  • @mhlaskar1991
    @mhlaskar1991 4 года назад +1

    Does LSI doubles the space like GSIs?

    • @BeABetterDev
      @BeABetterDev  4 года назад +1

      Hi Mahbubul,
      LSIs do not take extra space.
      Thanks for watching!

    • @The6thProgrammer
      @The6thProgrammer 3 года назад

      @@BeABetterDev I don't believe this answer is correct. I believe similar to GSIs the LSIs will consume more space and consume WCUs as well. See here docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html where it is mentioned in the AWS documentation "The smaller the index, the less that it costs to store it, and the less your write costs are". This is why there is a trade-off in how many additional attributes you would want to project in your LSI.

    • @warrenjohnson5971
      @warrenjohnson5971 3 года назад

      @@The6thProgrammer No more read units but more space consumed I guess?

  • @LifeDude
    @LifeDude 4 месяца назад

    Awesome

  • @vagifk2864
    @vagifk2864 4 года назад

    Should LSI be unique within the same table?

    • @BeABetterDev
      @BeABetterDev  4 года назад

      It does not necessarily have to be.

  • @leiliu83
    @leiliu83 4 года назад

    So for LSI, hash key + range key does not need to be the same

    • @SurprisedFirzen
      @SurprisedFirzen 3 года назад

      partition key needs to be the same right

  • @__noob__coder__
    @__noob__coder__ Год назад

    Which coding font are you using ?

  • @alekseiborsenkodev
    @alekseiborsenkodev 2 года назад +1

    Nice explanation, but I have a little correction. You CAN NOT search by endsWith. only beginwith

  • @sonny23ization
    @sonny23ization 3 года назад

    why is this strongly consistent?

  • @adamkinsey3139
    @adamkinsey3139 2 года назад +1

    So...let's design and sell a "NoSQL" database, and then add in "fancy" features so that users can pay extra to have a fraction of the SQL features?
    I genuinely don't understand why you would choose to use a "NoSQL" database for any use-case like this....and I would love to know!

    • @BeABetterDev
      @BeABetterDev  2 года назад

      Hi Adam,
      Thank you for the comment. I have a video on RDS vs DynamoDB that attempts to answer your question. You can watch it here: ruclips.net/video/crHwekf0gTA/видео.html
      Hope this helps,
      Daniel

  • @harshjain8823
    @harshjain8823 Год назад +1

    take some break when you finish a sentence.

  • @waytospergtherebro
    @waytospergtherebro Год назад

    This is the single most useless "database" anyone has ever designed.