create table t_mcv_1(id int, name text, address text);
create table t_mcv_2(id int, name text, address text);
create table t_mcv_3(id int, name text, address text);

drop COLLATION if exists ignore_accent_case;
CREATE COLLATION ignore_accent_case (provider = icu, deterministic = false, locale = 'und-u-ks-level1');
drop COLLATION if exists case_insensitive;
CREATE COLLATION case_insensitive (provider = icu, locale = 'und-u-ks-level2', deterministic = false);
insert into t_mcv_1 
select g, t.*,g::text
FROM generate_series(1, 50) g, 
(values
('À'),
('à'),
('Á'),
('á'),
('Â'),
('â'),
('Ã'),
('ã'),
('Ä'),
('ä'),
('Å'),
('å')) t;
--insert into t_mcv_1 select g, 'A','A' FROM generate_series(1, 20) g;
--insert into t_mcv_1 select g, 'a','a' FROM generate_series(1, 20) g;

--insert into t_mcv_1 select g, g::text,g::text FROM generate_series(1, 10000) g;

--create index idx_t_mcv_1 on t_mcv_1(name,id);

insert into t_mcv_2 select * from t_mcv_1;
insert into t_mcv_3 select * from t_mcv_1;

ALTER TABLE t_mcv_1 ALTER COLUMN name SET STATISTICS 10000;
ALTER TABLE t_mcv_2 ALTER COLUMN name SET STATISTICS 10000;
ALTER TABLE t_mcv_3 ALTER COLUMN name SET STATISTICS 10000;
analyze t_mcv_1, t_mcv_2, t_mcv_3;




--select name,count(*) from t_mcv_1 group by name;
SELECT tablename, attname, correlation, inherited, n_distinct,
       array_to_string(most_common_vals,  E'\n') as most_common_vals
      ,array_to_string(most_common_freqs, E'\n') as most_common_freqs
FROM pg_stats
WHERE tablename in ('t_mcv_1', 't_mcv_2') AND attname = 'name';
select name,count(*) from t_mcv_1
where name = 'a' collate ignore_accent_case 
group by name;
select name collate case_insensitive,count(*) from t_mcv_1
where name = 'a' collate ignore_accent_case 
group by name collate case_insensitive;

select name collate ignore_accent_case,count(*) from t_mcv_1
where name = 'a' collate ignore_accent_case 
group by name collate ignore_accent_case;
