Pengantar Redshift
Jason Myers
Principal Engineer
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
);

DISTKEY, atau PRIMARY KEY| Name | Description | Usage |
|---|---|---|
| ALL | Seluruh tabel di setiap node | Tabel lookup kecil yang sering dipakai di join |
| KEY | Didistribusikan menurut data pada kolom DISTKEY | Saat agregasi atau join berdasarkan DISTKEY |
| EVEN | Bergiliran antar node per baris | Tabel besar tanpa key |
| AUTO | Menggunakan ALL untuk tabel kecil. Menjadi Key saat membesar jika ada DISTKEY yang cocok, jika tidak kembali ke EVEN | default |
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
-- Mengatur kunci distribusi data
-- ke organization_id
DISTKEY(organization_id);
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
-- Mengatur organization_id sebagai
-- kunci distribusi data
'organization_id' VARCHAR(31) DISTKEY,
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
);
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
DISTKEY(organization_id)
-- Mengatur gaya distribusi ke key
DISTSTYLE KEY;
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
DISTKEY(organization_id)
DISTSTYLE KEY
-- Mengatur sort key data
-- ke fk_monitoringlocation
SORTKEY(fk_monitoringlocation);
CREATE TABLE IDAHO_SITE_ID
(
'pk_siteid' INTEGER PRIMARY KEY,
'fk_monitoringlocation' INTEGER,
'organization_id' VARCHAR(31),
'organizationformalname' VARCHAR(68),
'organization' VARCHAR(16)
)
-- Mengatur fk_monitoringlocation, organization_id sebagai compound sort key
COMPOUND SORTKEY(fk_monitoringlocation, organization_id);
-- Lihat status dist dan sortkey
-- suatu kolom
SELECT column_name,
distkey,
sortkey
FROM SVV_REDSHIFT_COLUMNS
-- Hanya di skema spectrumdb
WHERE schema_name = 'spectrumdb'
-- Untuk tabel ecommerce_sales
AND table_name = 'ecommerce_sales';
Hasil
column | distkey | sortkey
============|=========|========
year_qtr | t | 1
total_sales | f | 2
ecom_sales | f | 0
Kolom Distkey
SVV_TABLE_INFOtable | encoded | diststyle | sortkey1 | skew_sortkey1 | skew_rows
===============|=========|=================|==============|===============|===========
ecommerce_sales| N | KEY(year_qtr) | year_qtr | |
date | N | ALL | dateid | 1.00 |
SELECT table
diststyle
FROM SVV_TABLE_INFO
WHERE schema like 'spectrumdb';
table | diststyle
================|==============
ecommerce_sales | KEY(year_qtr)
Pengantar Redshift