
create table orders(
  date_created datetime,
  user_id int,
  order_data1 varchar(255),
  order_data2 varchar(255),
  order_data3 varchar(255),
  index(user_id, date_created)
) partition by range columns (date_created) (
  partition p0  VALUES LESS THAN ('2025-02-01 00:00:00'),
  partition p1  VALUES LESS THAN ('2025-03-01 00:00:00'),
  partition p2  VALUES LESS THAN ('2025-04-01 00:00:00'),
  partition p3  VALUES LESS THAN ('2025-05-01 00:00:00'),
  partition p4  VALUES LESS THAN ('2025-06-01 00:00:00'),
  partition p5  VALUES LESS THAN ('2025-07-01 00:00:00'),
  partition p6  VALUES LESS THAN ('2025-08-01 00:00:00'),
  partition p7  VALUES LESS THAN ('2025-09-01 00:00:00'),
  partition p8  VALUES LESS THAN ('2025-10-01 00:00:00'),
  partition p9  VALUES LESS THAN ('2025-11-01 00:00:00'),
  partition p10 VALUES LESS THAN ('2025-12-01 00:00:00'),
  partition p11 VALUES LESS THAN ('2026-01-01 00:00:00'),
  partition p12 VALUES LESS THAN ('2027-01-01 00:00:00'));

insert into orders 
select
  date_add('2025-01-01', interval A.seq day),
  B.seq,
  uuid()
from 
 seq_1_to_364 A, seq_1_to_10000 B;

analyze  format=json 
select * from orders  
where user_id=1234
ORDER BY date_created LIMIT 1;

analyze  format=json 
select * from orders  
where user_id=1234
ORDER BY date_created desc LIMIT 1;

analyze  format=json 
select * from orders  
where user_id=1234 and date_created between '2025-01-01' and '2025-09-01' 
ORDER BY date_created LIMIT 3;

analyze  format=json 
select * from orders  
where user_id=1234 and date_created between '2025-01-01' and '2025-09-01' 
ORDER BY date_created desc LIMIT 3;
