DROP DATABASE IF EXISTS testSchema;
CREATE DATABASE testSchema;

use testSchema;

CREATE TABLE testData (
	id INT(10) SIGNED NOT NULL AUTO_INCREMENT,
	groupId INTEGER,
	name varchar(255),
	PRIMARY KEY (id, groupId),
	KEY idx_testData_name (name)
)
ENGINE=InnoDB
CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci
PARTITION BY LIST(groupId)
(
	PARTITION p1 VALUES in (1) ENGINE = InnoDB,
	PARTITION p2 VALUES in (2) ENGINE = InnoDB
);

SELECT * FROM testData;

ALTER TABLE testData TRUNCATE PARTITION p1;

-- SELECT COUNT(*) FROM testData; -- this statement prevents the segfault
-- SELECT COUNT(*) FROM testData PARTITION (p1); -- this one does not

-- this version crashes if it follows the truncate
INSERT INTO testData PARTITION (p1) (groupId, name)
SELECT 1, 'Tamara Smith';

-- this version does not crash
-- INSERT INTO testData (groupId, name) VALUES
-- (1, 'Tamara Smith');

SELECT * FROM testData;
