iT邦幫忙

2021 iThome 鐵人賽

DAY 11
0
Software Development

SQL / NoSQL的實作與比較系列 第 11

Secondary Index

在SQL Table除了Primary Index, 也可以為其他欄位建立index以加快搜尋速度. NoSQL除了Partition Key & Sort Key之外, 同樣可以為其他欄位新增Index提升效能.

  1. 利用先前的範例程式, 在LoadingDatacs的107行新增一行程式, 加上新的數字欄位屬性再重新執行.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942Hcp0f6Ymbx.png

  2. 確認Movies Table有多一個數字欄位reviewers.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942Y7ygiubuFH.png

  3. Scan搜尋reviewers=1000, 使用了283.5 read capacity units.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942VWYBYFwkdz.png

  4. 再次Scan搜尋reviewers=10, 由於Table Scan, 同樣使用了283.5 read capacity units.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942NYWjNHxJ31.png

  5. 為了加快搜尋效能, 如同SQL的做法, 在reviewers欄位加上Index.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942g3QRTlarcB.png

  6. Index建立完成後, Status=Active即可套用.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942cfGkxnwY6Z.png

  7. 再次使用Scan模式, 但改用Index, 即可看出效能差異.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942lyT7LwlXyf.png

  8. 若套用在Query模式, 差異更明顯.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942Hs6P2HxaWl.png

  9. 需要注意的是, Secondary Index會產生額外的費用.
    https://ithelp.ithome.com.tw/upload/images/20210925/20091942Qxcorl7C01.png


上一篇
DynamoDB匯出至S3
下一篇
NoSQL Transaction
系列文
SQL / NoSQL的實作與比較30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言