[英]Greenplum distribution
有一張隨機分布的表
CREATE TABLE schema.table (
col1 int4 NULL,
col2 int4 NULL,
col3 int4 NULL
)
WITH (
appendonly=true,
compresstype=zstd,
orientation=column
)
DISTRIBUTED RANDOMLY;
我們需要以最佳方式(以最小的偏斜)將行分布在一個字段上。 為此,我們可以創建測試表
CREATE TABLE schema.test_table (
col_1 int4 NULL,
col_2 int4 NULL,
col_3 int4 NULL
)
WITH (
appendonly=true,
compresstype=zstd,
orientation=column
)
DISTRIBUTED BY (col_i);
INSERT INTO schema.test_table SELECT * FROM schema.table;
然后檢查它們是否傾斜,例如通過
select * from gp_toolkit.gp_skew_coefficient('schema.test_table'::regclass);
問題是我們想在不創建測試表的情況下檢查表是否存在偏斜。 這可以做到嗎?如果可以,怎么做?
如果你真的不想創建一個新表,這樣的事情會起作用,但我不知道沒有實際(重新)分發數據的 model 分發的方法。
foo=# create table foo(a int, b int, c int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
foo=# insert into foo values (generate_series(1,100), generate_series(101,200), generate_series(2001, 2100));
INSERT 0 100
foo=# select * from gp_toolkit.gp_skew_coefficient('public.foo'::regclass);
skcoid | skccoeff
--------+--------------------------
76788 | 18.460769214742921763000
(1 row)
foo=# select gp_segment_id, count(*) from foo group by 1 order by 1;
gp_segment_id | count
---------------+-------
0 | 17
1 | 18
2 | 23
3 | 17
4 | 15
5 | 10
(6 rows)
foo=# ALTER TABLE foo SET
foo-# WITH (REORGANIZE=true)
foo-# DISTRIBUTED BY (a);
ALTER TABLE
foo=# select * from gp_toolkit.gp_skew_coefficient('public.foo'::regclass);
skcoid | skccoeff
--------+--------------------------
76788 | 18.460769214742921763000
(1 row)
foo=# select gp_segment_id, count(*) from foo group by 1 order by 1;
gp_segment_id | count
---------------+-------
0 | 21
1 | 18
2 | 12
3 | 15
4 | 18
5 | 16
(6 rows)
foo=#
foo=# ALTER TABLE foo SET
WITH (REORGANIZE=true)
DISTRIBUTED BY (b);
ALTER TABLE
foo=# select * from gp_toolkit.gp_skew_coefficient('public.foo'::regclass);
skcoid | skccoeff
--------+--------------------------
76788 | 27.011108825814611346000
(1 row)
foo=# select gp_segment_id, count(*) from foo group by 1 order by 1;
gp_segment_id | count
---------------+-------
0 | 12
1 | 14
2 | 20
3 | 24
4 | 16
5 | 14
(6 rows)
foo=#
foo=# ALTER TABLE foo SET
WITH (REORGANIZE=true)
DISTRIBUTED BY (c);
ALTER TABLE
foo=# select * from gp_toolkit.gp_skew_coefficient('public.foo'::regclass);
skcoid | skccoeff
--------+--------------------------
76788 | 30.983866769659334938000
(1 row)
foo=#
foo=# select gp_segment_id, count(*) from foo group by 1 order by 1;
gp_segment_id | count
---------------+-------
0 | 19
1 | 10
2 | 20
3 | 23
4 | 11
5 | 17
(6 rows)
foo=#
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.