使用明细表过程中,建立分区,查看官方的样例,分区字段,都放在key中,并且是第一位比如:
CREATE TABLE site_access1 (
event_day DATETIME NOT NULL,
site_id INT DEFAULT ‘10’,
city_code VARCHAR(100),
user_name VARCHAR(32) DEFAULT ‘’,
pv BIGINT DEFAULT ‘0’
)
DUPLICATE KEY(event_day, site_id, city_code, user_name)
PARTITION BY event_day
DISTRIBUTED BY HASH(event_day, site_id);
但是以下两种方式,可以建表成功:
CREATE TABLE tmp.site_access2 (
site_id INT DEFAULT ‘10’,
city_code VARCHAR(100),
user_name VARCHAR(32) DEFAULT ‘’,
event_day DATE NOT NULL,
pv BIGINT DEFAULT ‘0’
)
DUPLICATE KEY( site_id, city_code, user_name,event_day)
PARTITION BY range(event_day)()
DISTRIBUTED BY HASH(event_day, site_id);
CREATE TABLE site_access3 (
site_id INT DEFAULT ‘10’,
city_code VARCHAR(100),
user_name VARCHAR(32) DEFAULT ‘’,
event_day DATE NOT NULL,
pv BIGINT DEFAULT ‘0’
)
DUPLICATE KEY( site_id, city_code, user_name)
PARTITION BY range(event_day)()
DISTRIBUTED BY HASH(event_day, site_id);
想问下,但我使用 where event_day=xx and site_id=xx时,这3张不同的建表方式,我的分区裁剪+前缀索引命中会有什么区别吗?
如果分区放在duplicate key中,前缀索引会带上分区字段的值吗?