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

Fix cagg trigger on compat schema layer #6163

Conversation

fabriziomello
Copy link
Contributor

@fabriziomello fabriziomello commented Oct 6, 2023

The trigger continuous_agg_invalidation_trigger receive the hypertable
id as parameter as the following example:

Triggers:
    ts_cagg_invalidation_trigger AFTER INSERT OR DELETE OR UPDATE ON
       _timescaledb_internal._hyper_3_59_chunk
    FOR EACH ROW EXECUTE FUNCTION
       _timescaledb_functions.continuous_agg_invalidation_trigger('3')

The problem is in the compatibility layer using PL/pgSQL code there's no
way to passdown the parameter from the wrapper trigger function created
to the underlying trigger function in another schema.

To solve this we simple create a new function in the deprecated
_timescaledb_internal schema pointing to the function trigger and
inside the C code we emit the WARNING message if the function is called
from the deprecated schema.

Disable-check: force-changelog-file

@fabriziomello fabriziomello self-assigned this Oct 6, 2023
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

Merging #6163 (8702f4e) into main (b514d05) will decrease coverage by 0.06%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #6163      +/-   ##
==========================================
- Coverage   81.46%   81.41%   -0.06%     
==========================================
  Files         246      246              
  Lines       56974    56928      -46     
  Branches    12624    12605      -19     
==========================================
- Hits        46414    46347      -67     
+ Misses       8180     8171       -9     
- Partials     2380     2410      +30     

see 45 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@fabriziomello fabriziomello force-pushed the fix_continuous_agg_trigger_on_schema_compat_layer branch from 7d34107 to 7afecb4 Compare October 6, 2023 17:46
@fabriziomello fabriziomello marked this pull request as ready for review October 6, 2023 17:47
@fabriziomello fabriziomello force-pushed the fix_continuous_agg_trigger_on_schema_compat_layer branch 3 times, most recently from bba749d to 3131231 Compare October 6, 2023 19:31
@svenklemm
Copy link
Member

Not a fan of this, this trigger should never be called through compat layer unless your database is already broken
I think we probably need a check that catalog and schema are in sync and bail if there is mismatch, this will just paper over deeper issue. I would prefer mapping to the C function directly in compat layer over adding more code to deal with this.

@fabriziomello
Copy link
Contributor Author

Not a fan of this, this trigger should never be called through compat layer unless your database is already broken I think we probably need a check that catalog and schema are in sync and bail if there is mismatch, this will just paper over deeper issue. I would prefer mapping to the C function directly in compat layer over adding more code to deal with this.

We're mapping to C function directly already in this PR: https://github.com/timescale/timescaledb/pull/6163/files#diff-8943dabbdc6a8f1b136468c00599f91c6f615869a324b0de70b9c7614a77c9bfR191-R192

The only additional code is just to emit the WARNING message because the current form is wrong: https://github.com/timescale/timescaledb/blob/main/sql/compat.sql#L192-L199

@fabriziomello fabriziomello added this to the TimescaleDB 2.12.1 milestone Oct 7, 2023
@fabriziomello
Copy link
Contributor Author

Chatting with @svenklemm we agreed that is better to don't add extra C code to emit the warning and just point the deprecated schema to the new one and adding regression test to make sure it is working. /cc @jnidzwetzki

@fabriziomello fabriziomello force-pushed the fix_continuous_agg_trigger_on_schema_compat_layer branch 2 times, most recently from d394055 to 3f6ba92 Compare October 7, 2023 14:23
@fabriziomello fabriziomello enabled auto-merge (rebase) October 7, 2023 14:25
The trigger `continuous_agg_invalidation_trigger` receive the hypertable
id as parameter as the following example:

Triggers:
    ts_cagg_invalidation_trigger AFTER INSERT OR DELETE OR UPDATE ON
       _timescaledb_internal._hyper_3_59_chunk
    FOR EACH ROW EXECUTE FUNCTION
       _timescaledb_functions.continuous_agg_invalidation_trigger('3')

The problem is in the compatibility layer using PL/pgSQL code there's no
way to passdown the parameter from the wrapper trigger function created
to the underlying trigger function in another schema.

To solve this we simple create a new function in the deprecated
`_timescaledb_internal` schema pointing to the function trigger and
inside the C code we emit the WARNING message if the function is called
from the deprecated schema.
@fabriziomello fabriziomello force-pushed the fix_continuous_agg_trigger_on_schema_compat_layer branch from 3f6ba92 to 8702f4e Compare October 7, 2023 16:44
@fabriziomello fabriziomello merged commit 586b247 into timescale:main Oct 7, 2023
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants