-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
drop table if exists t1;
NOTICE:  table "t1" does not exist, skipping
set timescaledb.enable_bool_compression = on;
create table t1 (ts int, b bool);
select create_hypertable('t1','ts');
 create_hypertable 
-------------------
 (1,public,t1,t)

alter table t1 set (timescaledb.compress, timescaledb.compress_orderby = 'ts');
insert into t1 values (1, true);
insert into t1 values (2, false);
insert into t1 values (3, NULL);
insert into t1 values (4, true);
insert into t1 values (5, false);
insert into t1 values (6, NULL);
select compress_chunk(show_chunks('t1'));
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

select * from t1 order by 1;
 ts | b 
----+---
  1 | t
  2 | f
  3 | 
  4 | t
  5 | f
  6 | 

select * from t1 where b is null order by 1;
 ts | b 
----+---
  3 | 
  6 | 

select * from t1 where b = true order by 1;
 ts | b 
----+---
  1 | t
  4 | t

select * from t1 where b = false order by 1;
 ts | b 
----+---
  2 | f
  5 | f

select * from t1 where ts > 3 and b is null order by 1;
 ts | b 
----+---
  6 | 

select * from t1 where ts > 3 and b = true order by 1;
 ts | b 
----+---
  4 | t

select * from t1 where ts > 3 and b = false order by 1;
 ts | b 
----+---
  5 | f

-- delete all null values and compress again
delete from t1 where b is null;
select compress_chunk(show_chunks('t1'));
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

select * from t1 order by 1;
 ts | b 
----+---
  1 | t
  2 | f
  4 | t
  5 | f

select * from t1 where b is null order by 1;
 ts | b 
----+---

select * from t1 where b = true order by 1;
 ts | b 
----+---
  1 | t
  4 | t

select * from t1 where b = false order by 1;
 ts | b 
----+---
  2 | f
  5 | f

select * from t1 where ts > 3 and b is null order by 1;
 ts | b 
----+---

select * from t1 where ts > 3 and b = true order by 1;
 ts | b 
----+---
  4 | t

select * from t1 where ts > 3 and b = false order by 1;
 ts | b 
----+---
  5 | f

