I'm creating a table with composite partitioning (RANGE
, then HASH
)
My actual table is enormous, so here's a stripped down dummy table that shows the important parts:
CREATE TABLE table1(
id INT NOT NULL AUTO_INCREMENT,
dtvalue DATETIME NOT NULL, -- Used for RANGE partitions
v1 INT NOT NULL, -- Used for HASH partitions
v2 INT NOT NULL,
CONSTRAINT pk_table1 PRIMARY KEY(id),
CONSTRAINT uk_table1 UNIQUE(v1,v2) -- Unique key for v1 and v2
)
ROW_FORMAT=COMPRESSED
PARTITION BY RANGE(dtvalue)
SUBPARTITION BY HASH(v1,v2) SUBPARTITIONS 32 -- Does this HASH subpartition work?
(PARTITION p20191101 VALUES LESS THAN('2019-11-01'),
PARTITION p20191102 VALUES LESS THAN('2019-11-02'),
PARTITION pMax VALUES LESS THAN MAXVALUE);
This table will frequently be joined by v1
and v2
combined as a unique identifier, so using both columns for the HASH
key is critical.
My question is, can you specify multiple columns as part of the HASH
key?
Or can you specify the unique key itself, for the HASH
key?
e.g. SUBPARTITION BY HASH(uk_table1) SUBPARTITIONS 32
WHERE
and/orORDER BY
clauses, reducing the number of partitions that are scanned. Hence the reasoning behind requiring the hash partition key to be part of the primary key as well. I intend to utilize this properly. But yes, in most fast-paced willy-nilly (badly-designed) database scenarios, hash partitioning would certainly do more harm, than good - Giffyguy