Как разбить таблицу MySQL на два слоя?
Я хочу разделить таблицу, этот код покажет вам структуру таблицы. таблица в настоящее время насчитывает около 5 миллионов записей.
Мне нужен синтаксис раздела MySql эта таблица так
Основной раздел - это поле типа триггера "по году", затем подраздел по полю, называемый статусом.
Как я могу создать раздел / подраздел на этой существующей таблице?
CREATE TABLE `phone_calls` (
`phone_call_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`account_id` int(11) unsigned NOT NULL,
`team_id` int(11) unsigned NOT NULL,
`call_code_id` int(11) unsigned NOT NULL,
`result_code_id` int(11) unsigned NOT NULL DEFAULT '0',
`trigger_on` datetime NOT NULL,
`created_on` datetime NOT NULL,
`first_attempt_on` datetime DEFAULT NULL,
`first_attempt_by` int(11) unsigned DEFAULT NULL,
`call_subject` char(100) NOT NULL,
`status` tinyint(1) NOT NULL COMMENT '0= purge, 1=active, 2 = completed', `workflow_generated` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1= generated by system flow, 0 created by a user',
`last_attempt_on` datetime DEFAULT NULL,
`last_attempt_by` int(11) unsigned DEFAULT NULL,
`total_attempts` tinyint(3) unsigned NOT NULL DEFAULT '0',
`modified_by` int(11) unsigned DEFAULT NULL,
`last_call_id` int(11) unsigned NOT NULL,
`call_direction` enum('INBOUND','OUTBOUND') NOT NULL COMMENT 'INBOUND or OUTBOUND', `call_notes` text NOT NULL,
`owner_id` int(11) NOT NULL,
`call_duration` smallint(5) unsigned NOT NULL DEFAULT '0',
`modified_on` datetime DEFAULT NULL,
PRIMARY KEY (`phone_call_id`),
KEY `owner_id` (`owner_id`),
KEY `call_code_id` (`call_code_id`),
KEY `result_code_id` (`result_code_id`),
KEY `account_id` (`account_id`),
KEY `trigger_on` (`trigger_on`),
KEY `created_on` (`created_on`),
KEY `status` (`status`),
KEY `pcto` (`trigger_on`,`status`,`owner_id`))
ENGINE=InnoDB
AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4
1 ответ
Попробуйте это sql
CREATE TABLE `phone_calls` (
`phone_call_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`account_id` int(11) unsigned NOT NULL,
`team_id` int(11) unsigned NOT NULL,
`call_code_id` int(11) unsigned NOT NULL,
`result_code_id` int(11) unsigned NOT NULL DEFAULT '0',
`trigger_on` datetime NOT NULL,
`created_on` datetime NOT NULL,
`first_attempt_on` datetime DEFAULT NULL,
`first_attempt_by` int(11) unsigned DEFAULT NULL,
`call_subject` char(100) NOT NULL,
`status` tinyint(1) NOT NULL COMMENT '0= purge, 1=active, 2 = completed', `workflow_generated` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1= generated by system flow, 0 created by a user',
`last_attempt_on` datetime DEFAULT NULL,
`last_attempt_by` int(11) unsigned DEFAULT NULL,
`total_attempts` tinyint(3) unsigned NOT NULL DEFAULT '0',
`modified_by` int(11) unsigned DEFAULT NULL,
`last_call_id` int(11) unsigned NOT NULL,
`call_direction` enum('INBOUND','OUTBOUND') NOT NULL COMMENT 'INBOUND or OUTBOUND', `call_notes` text NOT NULL,
`owner_id` int(11) NOT NULL,
`call_duration` smallint(5) unsigned NOT NULL DEFAULT '0',
`modified_on` datetime DEFAULT NULL,
PRIMARY KEY (`phone_call_id`,`trigger_on`,`status`),
KEY `owner_id` (`owner_id`),
KEY `call_code_id` (`call_code_id`),
KEY `result_code_id` (`result_code_id`),
KEY `account_id` (`account_id`),
KEY `trigger_on` (`trigger_on`),
KEY `created_on` (`created_on`),
KEY `status` (`status`),
KEY `pcto` (`trigger_on`,`status`,`owner_id`))
PARTITION BY RANGE( YEAR(`trigger_on`) )
SUBPARTITION BY HASH( `status` )
SUBPARTITIONS 2(
PARTITION p0 VALUES LESS THAN (1990),
PARTITION p1 VALUES LESS THAN MAXVALUE
)