iT邦幫忙

2021 iThome 鐵人賽

DAY 7
0
Software Development

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

NoSQL的查詢

NoSQL的查詢有兩種模式, 分別是Scan與Query

  1. Scan會對整個表作掃描. 例如要查詢2013年的七龍珠電影, 輸入相對應的條件做Scan
    https://ithelp.ithome.com.tw/upload/images/20210921/2009194272B8tlDVmG.png

  2. Scan總共花費了275.5 Read Capacity Units找出這筆資料
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942nAVDf5ynFz.png

  3. 但是如果把相同條件下在Partition Key & Sort Key使用Query方式查詢
    https://ithelp.ithome.com.tw/upload/images/20210921/200919422OiomgaM2X.png

  4. 相同的結果只需花費0.5 Read Capacity Units
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942fOAIioUSUt.png

  5. 但是Scan也是有方便之處. 當對搜尋條件不明確時, Scan的搜尋容許成對相對比較大. 例如只搜尋電影名稱包含"Ball Z", 類似SQL Like指令.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942jPW3DpNUOZ.png

  6. Query的搜尋條件就相對有限.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942JlAWfTcaoA.png

  7. 另外無論Scan或Query, 它的屬性型別只有String, Number, Binary, Boolean, Null, 搜尋條件必須符合這些型別.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942ZMZhxf7vAu.png

  8. 例如範例資料的型別是Map, 搜尋條件就無法針對這類型別使用.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942C1fJ6R2L0G.png

  9. 現在新增一筆2021年007的生死交戰, 並將info欄位設成String.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942JU1UodFtUt.png

  10. 再使用Filters功能搜尋, info型別指定為String, 搜尋Daniel即可搜尋到這一筆新增資料.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942au6FW2RGzc.png

  11. 就算其他資料info欄位有Daniel, 但由於型別為Map因此就不會出現在String的搜尋結果.
    https://ithelp.ithome.com.tw/upload/images/20210921/20091942ggk4TBGzDf.png


上一篇
快速新增範例資料
下一篇
PartiSQL簡介
系列文
SQL / NoSQL的實作與比較30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言