-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
CREATE TABLE reloptions_test(time integer, temp float8, color integer)
WITH (fillfactor=75, autovacuum_vacuum_threshold=100);
SELECT create_hypertable('reloptions_test', 'time', chunk_time_interval => 3);
      create_hypertable       
------------------------------
 (1,public,reloptions_test,t)

INSERT INTO reloptions_test VALUES (4, 24.3, 1), (9, 13.3, 2);
-- Show that reloptions are inherited by chunks
SELECT relname, reloptions FROM pg_class
WHERE relname ~ '^_hyper.*' AND relkind = 'r';
     relname      |                   reloptions                    
------------------+-------------------------------------------------
 _hyper_1_1_chunk | {fillfactor=75,autovacuum_vacuum_threshold=100}
 _hyper_1_2_chunk | {fillfactor=75,autovacuum_vacuum_threshold=100}

-- Alter reloptions. We support multiple options for the ALTER TABLE
ALTER TABLE reloptions_test SET (fillfactor=80, parallel_workers=8);
ALTER TABLE reloptions_test SET (fillfactor=80), SET (parallel_workers=8);
SELECT relname, reloptions FROM pg_class
WHERE relname ~ '^_hyper.*' AND relkind = 'r';
     relname      |                             reloptions                             
------------------+--------------------------------------------------------------------
 _hyper_1_1_chunk | {autovacuum_vacuum_threshold=100,fillfactor=80,parallel_workers=8}
 _hyper_1_2_chunk | {autovacuum_vacuum_threshold=100,fillfactor=80,parallel_workers=8}

ALTER TABLE reloptions_test RESET (fillfactor);
SELECT relname, reloptions FROM pg_class
WHERE relname ~ '^_hyper.*' AND relkind = 'r';
     relname      |                      reloptions                      
------------------+------------------------------------------------------
 _hyper_1_1_chunk | {autovacuum_vacuum_threshold=100,parallel_workers=8}
 _hyper_1_2_chunk | {autovacuum_vacuum_threshold=100,parallel_workers=8}

-- Test reloptions on a regular table
CREATE TABLE reloptions_test2(time integer, temp float8, color integer);
ALTER TABLE reloptions_test2 SET (fillfactor=80, parallel_workers=8);
ALTER TABLE reloptions_test2 SET (fillfactor=80), SET (parallel_workers=8);
DROP TABLE reloptions_test2;
