
CREATE TABLE sales (
  user_id INT,
  sales_date DATETIME NOT NULL,
  amount DECIMAL(10, 2), col1 varchar(100),
  col2 varchar(100),
  col3 varchar(100),
  INDEX idx1(user_id, sales_date)
)
PARTITION BY RANGE COLUMNS (sales_date) (
  PARTITION p1 VALUES LESS THAN ('2026-01-25 00:00:00'),
  PARTITION p2 VALUES LESS THAN ('2026-02-25 00:00:00'),
  PARTITION p3 VALUES LESS THAN ('2026-03-25 00:00:00'),
  PARTITION p4 VALUES LESS THAN ('2026-04-25 00:00:00'),
  PARTITION p5 VALUES LESS THAN ('2026-05-25 00:00:00'),
  PARTITION p6 VALUES LESS THAN ('2026-06-25 00:00:00'),
  PARTITION p7 VALUES LESS THAN ('2026-07-25 00:00:00'),
  PARTITION p8 VALUES LESS THAN ('2026-08-25 00:00:00'),
  PARTITION p9 VALUES LESS THAN ('2026-09-25 00:00:00'),
  PARTITION p10 VALUES LESS THAN ('2026-10-25 00:00:00'),
  PARTITION p11 VALUES LESS THAN ('2026-11-25 00:00:00'),
  PARTITION p12 VALUES LESS THAN (MAXVALUE)
);

drop procedure populate_table;
DELIMITER //
CREATE PROCEDURE populate_table(IN numRows BIGINT)
BEGIN
   SET @i = 0;
   START TRANSACTION;
   WHILE @i < numRows DO
    INSERT INTO sales 
    select 
       floor(RAND()*100),
      "2026-01-01 14:19:09" + INTERVAL (select floor(RAND()*365)) DAY,
      ROUND(RAND() * 9, 2),
      UUID(),
      UUID(),
      UUID();
    SET @i = @i + 1;
  END WHILE;
  COMMIT;
END//
DELIMITER ;
CALL populate_table(1000000);
