SELECT version();
CREATE OR REPLACE TABLE `a2` (
  `id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `df__acl_tag` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `df__data` mediumblob NOT NULL,
  `version` bigint(20) DEFAULT NULL,
  `org_id` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `deployment_id` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `progress` decimal(20,9) DEFAULT NULL,
  `errors` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`errors`)),
  `activity_type_id` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `activity_type_name` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `activity_type_version` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `activity_type_namespace` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `activity_type_key` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`payload`)),
  `state` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created.user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created.client_id` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created.time` bigint(20) unsigned DEFAULT NULL,
  `updated.user_name` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `updated.client_id` varchar(512) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `updated.time` bigint(20) unsigned DEFAULT NULL,
  `transitions` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`transitions`)),
  `provider` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `submit_on_demand` tinyint(1) DEFAULT NULL,
  `error` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`error`)),
  `output` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`output`)),
  PRIMARY KEY (`id`),
  KEY `IX_activity_type_key_activity` (`activity_type_key`),
  KEY `IX_state_activity` (`state`),
  KEY `IX_org_id_activity` (`org_id`),
  KEY `CIX_org_id_activity_type_key` (`org_id`,`activity_type_key`),
  KEY `CIX_org_id_state` (`org_id`,`state`),
  KEY `CIX_state_updated_time` (`state`,`updated.time`),
  KEY `IX_provider_activity` (`provider`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

SELECT COLUMN_TYPE, COLLATION_NAME, IS_NULLABLE, CHECK_CLAUSE
FROM INFORMATION_SCHEMA.COLUMNS t1
LEFT OUTER JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS t2 USING (TABLE_NAME)
WHERE t1.table_name='a2' AND t1.COLUMN_NAME='output' AND
      t2.table_name='a2' AND t2.CONSTRAINT_NAME='output';

SET profiling = 1;
alter table a2 modify if exists output json;
SELECT COLUMN_TYPE, COLLATION_NAME, IS_NULLABLE, CHECK_CLAUSE
FROM INFORMATION_SCHEMA.COLUMNS t1
LEFT OUTER JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS t2 USING (TABLE_NAME)
WHERE t1.table_name='a2' AND t1.COLUMN_NAME='output' AND
      t2.table_name='a2' AND t2.CONSTRAINT_NAME='output';

alter table a2 modify if exists output longtext DEFAULT NULL CHECK (json_valid(output));
SELECT COLUMN_TYPE, COLLATION_NAME, IS_NULLABLE, CHECK_CLAUSE
FROM INFORMATION_SCHEMA.COLUMNS t1
LEFT OUTER JOIN INFORMATION_SCHEMA.CHECK_CONSTRAINTS t2 USING (TABLE_NAME)
WHERE t1.table_name='a2' AND t1.COLUMN_NAME='output' AND
      t2.table_name='a2' AND t2.CONSTRAINT_NAME='output';

SHOW PROFILES;
SHOW PROFILE FOR QUERY 1;
SHOW PROFILE FOR QUERY 3;
