Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After creating a continuous aggregation view it is no more possibile to insert into a compressed chunk of the source hypertable #3410

Closed
abolognino opened this issue Jul 12, 2021 · 0 comments · Fixed by #3724
Assignees
Labels
feature-request Feature proposal

Comments

@abolognino
Copy link

Relevant system information:

  • OS: Timescale Cloud
  • PostgreSQL version (output of postgres --version): PostgreSQL 13.3
  • TimescaleDB version (output of \dx in psql): 2.3.1
  • Installation method: Timescale Cloud (AWS)

Describe the bug
after defining a continuous aggregation materialized view it is no more possible to insert a row in a compressed chunk of the source hypertable

To Reproduce

-- Create table
CREATE TABLE ee_mis_hh_2gbug
(
  UNIVERSAL_TIME  INT                        NOT NULL,
  POD             TEXT             NOT NULL,
  DT_MISURA       DATE NOT NULL,
  ORA_96          INT,
  Q_EA_RFO        DOUBLE PRECISION,
  Q_ER_RFO        DOUBLE PRECISION,
  TMS_RFO         DATE,
  Q_EA_PDO_EV     DOUBLE PRECISION,
  Q_ER_PDO_EV     DOUBLE PRECISION,
  TMS_PDO_EV      DATE,
  Q_EA_PDO_NE     DOUBLE PRECISION,
  Q_ER_PDO_NE     DOUBLE PRECISION,
  TMS_PDO_NE      DATE,
  FLG_PDO_NE      TEXT,
  Q_EA_SOS        DOUBLE PRECISION,
  Q_ER_SOS        DOUBLE PRECISION,
  TMS_SOS         DATE,
  Q_F_BP          DOUBLE PRECISION,
  TMS_F_BP        DATE,
  ID_MISURA_M2G   TEXT,
  TMS_CREATED     TIMESTAMP WITHOUT TIME ZONE,
  USR_CREATED     TEXT,
  FLG_F_BP        TEXT,
  TMS_UPDATED     TIMESTAMP WITHOUT TIME ZONE
);

-- Create hypertable
SELECT create_hypertable('ee_mis_hh_2gbug', 'dt_misura', chunk_time_interval => INTERVAL '1 day');

-- Insert sample data
INSERT INTO ee_mis_hh_2gbug (universal_time,pod,dt_misura,ora_96,q_ea_rfo,q_er_rfo,tms_rfo,q_ea_pdo_ev,q_er_pdo_ev,tms_pdo_ev,q_ea_pdo_ne,q_er_pdo_ne,tms_pdo_ne,flg_pdo_ne,q_ea_sos,q_er_sos,tms_sos,q_f_bp,tms_f_bp,id_misura_m2g,tms_created,usr_created,flg_f_bp,tms_updated) VALUES
     (1507743900,'OT00XO12345678','2019-10-11',75,NULL,NULL,NULL,0.325,0.0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,0.322,NULL,'0000000000000000000127815598',NULL,'testbug','LT',NULL);

-- Create Continous aggregation
CREATE MATERIALIZED VIEW mv_ee_mis_hh_2gbug
WITH (timescaledb.continuous) AS
SELECT universal_time                    AS universal_time,
         dt_misura                         AS dt_misura,
         ora_96                            AS ora_96,        
         time_bucket(INTERVAL '1 day', dt_misura) AS bucket,
         SUM (COALESCE (m.q_ea_rfo,
                        m.q_ea_pdo_ev,
                        m.q_ea_sos,
                        m.q_ea_pdo_ne,
                        m.q_f_bp))         AS q_bc,
         SUM (COALESCE (m.q_ea_rfo,
                        m.q_ea_pdo_ev,
                        m.q_ea_sos,
                        m.q_ea_pdo_ne))    AS q_meter,
         SUM (m.q_ea_pdo_ne)             AS q_stima,
         SUM (m.q_f_bp)                  AS q_f_bp,
         COUNT (COALESCE (m.q_ea_rfo,
                          m.q_ea_pdo_ev,
                          m.q_ea_sos,
                          m.q_ea_pdo_ne,
                          m.q_f_bp))         AS n_bc,
         COUNT (COALESCE (m.q_ea_rfo,
                          m.q_ea_pdo_ev,
                          m.q_ea_sos,
                          m.q_ea_pdo_ne))    AS n_meter,
         COUNT (m.q_ea_pdo_ne)               AS n_stima,
         COUNT (m.q_f_bp)                    AS n_f_bp
    FROM ee_mis_hh_2gbug m
GROUP BY universal_time,
         dt_misura,
         ora_96,
         bucket;

-- Create policy    
SELECT add_continuous_aggregate_policy('mv_ee_mis_hh_2gbug',
    start_offset => INTERVAL '1 month',
    end_offset => INTERVAL '1 day',
    schedule_interval => INTERVAL '1 hour');    

-- Compress 
ALTER TABLE ee_mis_hh_2gbug SET (
 timescaledb.compress,
 timescaledb.compress_segmentby = 'pod'
);

-- Compress Policy
SELECT add_compression_policy('ee_mis_hh_2gbug', INTERVAL '1 days');

-- Insert row into compressed chunk (ERROR)
insert into ee_mis_hh_2gbug
select 
universal_time, pod || 'W', dt_misura, ora_96, q_ea_rfo, q_er_rfo, tms_rfo, q_ea_pdo_ev, q_er_pdo_ev, tms_pdo_ev, q_ea_pdo_ne, q_er_pdo_ne, tms_pdo_ne, flg_pdo_ne, q_ea_sos, q_er_sos, tms_sos, q_f_bp, tms_f_bp, id_misura_m2g, tms_created, usr_created, flg_f_bp, tms_updated from ee_mis_hh_2gbug where pod = 'OT00XO12345678';

Expected behavior
a row should be inserted and the continuous aggregation materialized view should be updated

Actual behavior
the error "after insert row trigger on compressed chunk not supported" is thrown

Screenshots
N/A

Additional context
N/A

@gayyappan gayyappan self-assigned this Jul 12, 2021
gayyappan added a commit to gayyappan/timescaledb that referenced this issue Oct 21, 2021
After row triggers do not work when we insert into a compressed chunk.
This causes a problem for caggs as invalidations are not recorded.
Explicitly call the function to record invalidations when we
insert into a compressed chunk (if the hypertable has caggs
defined on it)

Fixes timescale#3410.
gayyappan added a commit to gayyappan/timescaledb that referenced this issue Oct 21, 2021
After row triggers do not work when we insert into a compressed chunk.
This causes a problem for caggs as invalidations are not recorded.
Explicitly call the function to record invalidations when we
insert into a compressed chunk (if the hypertable has caggs
defined on it)

Fixes timescale#3410.
gayyappan added a commit that referenced this issue Oct 21, 2021
After row triggers do not work when we insert into a compressed chunk.
This causes a problem for caggs as invalidations are not recorded.
Explicitly call the function to record invalidations when we
insert into a compressed chunk (if the hypertable has caggs
defined on it)

Fixes #3410.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Feature proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants