走進 Redshift 資料倉儲

Redshift 入門

Jason Myers

Principal Architect

議程

  • Redshift 叢集內部
    • 節點類型
    • Leader 專屬函式
    • Redshift 叢集儲存
  • 謂詞
  • Redshift Spectrum
    • 資料庫元件
    • 外部資料表
Redshift 入門

Redshift 叢集架構

Leader 節點

  • 提供連線
  • 建立並分配查詢執行計畫
  • 可執行整個查詢
  • 具專屬函式

Compute 節點

  • 提供資料儲存
  • 在本機資料上執行來自 leader 的程式碼

Redshift 叢集

Redshift 入門

Leader 專屬函式

  • 僅能在 leader 上執行
-- Selecting the substr, starting at 
-- position 11 of 'chocolate chip'
SELECT SUBSTR('chocolate chip', 11);
chip
  • 對資料表欄位使用 SUBSTR 會出錯
-- Selecting the substr from position 1
-- of the column named field on table
SELECT SUBSTR(field, 1) FROM table;
ERROR: SUBSTR() function is not 
supported (Hint: use SUBSTRING 
instead)
Redshift 入門

跨節點檢視資料

SELECT host, 
       -- Calculate the percentage of used space
       -- using the used minus tossed or ready to be reclaimed
       -- divided by the capacity
       (used - tossed) / capacity * 100 as percent_used 
  FROM STV_PARTITIONS;
 host |  percent_used
======+==============
  0   |  24.9
  1   |  24.8
Redshift 入門

謂詞(Predicate)

SELECT table_A.columnX,
       table_B.columnY,
  FROM table_A
       INNER JOIN table_B 
          -- predicate
       ON table_B.foreign_key = table_A.primary_key 
       -- predicate
 WHERE table_B.columnZ = 'value';
  • 通常是布林運算式,出現在 WHERE、HAVING 或 ON 子句中
Redshift 入門

謂詞下推(Predicate push-down)

下推

Redshift 入門

典型資料庫內部元件

資料庫元件

MetaData Catalog(中繼資料目錄)

  • 保存綱要資訊(欄位、鍵等)
  • 參照儲存位置

Query Engine(查詢引擎)

  • 規劃並執行查詢
  • 提供連線

Storage(儲存)

  • 存放資料表資料
  • 支援多種檔案與資料表格式
Redshift 入門

Redshift Spectrum 架構

AWS Glue Data Catalog

  • 儲存「外部」資料表的資訊

AWS S3 Bucket

  • 儲存代表資料表的檔案
  • 支援 CSV、JSON、Text、Parquet 等多種檔案類型

Redshift Spectrum 架構

Redshift 入門

一起來練習吧!

Redshift 入門

Preparing Video For Download...