-
Notifications
You must be signed in to change notification settings - Fork 801
Add support of DEPENDS/NO DEPENDS ON EXTENSION for MATERIALIZED VIEW. #6390 #9327
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../server_groups/servers/databases/schemas/views/templates/mviews/pg/13_plus/sql/create.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| {# ===================== Create new view ===================== #} | ||
| {% if display_comments %} | ||
| -- View: {{ data.schema }}.{{ data.name }} | ||
|
|
||
| -- DROP MATERIALIZED VIEW IF EXISTS {{ conn|qtIdent(data.schema, data.name) }}; | ||
|
|
||
| {% endif %} | ||
| {% if data.name and data.schema and data.definition %} | ||
| CREATE MATERIALIZED VIEW{% if add_not_exists_clause %} IF NOT EXISTS{% endif %} {{ conn|qtIdent(data.schema, data.name) }} | ||
| {% if data.default_amname and data.default_amname != data.amname %} | ||
| USING {{data.amname}} | ||
| {% elif not data.default_amname and data.amname %} | ||
| USING {{data.amname}} | ||
| {% endif %} | ||
| {% if(data.fillfactor or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum_enabled in ('t', 'f') or data['vacuum_data']|length > 0) %} | ||
| {% set ns = namespace(add_comma=false) %} | ||
| WITH ( | ||
| {% if data.fillfactor %} | ||
| FILLFACTOR = {{ data.fillfactor }}{% set ns.add_comma = true%}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %} | ||
| {% if ns.add_comma %}, | ||
| {% endif %} | ||
| autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %} | ||
| {% if ns.add_comma %}, | ||
| {% endif %} | ||
| toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %} | ||
| {% for field in data['vacuum_data'] %} | ||
| {% if field.value is defined and field.value != '' and field.value != none %} | ||
| {% if ns.add_comma %}, | ||
| {% endif %} {{ field.name }} = {{ field.value|lower }}{% set ns.add_comma = true%}{% endif %}{% endfor %} | ||
| {{ '\n' }}) | ||
| {% endif %} | ||
| {% if data.spcname %}TABLESPACE {{ data.spcname }} | ||
| {% endif %}AS | ||
| {{ data.definition.rstrip(';') }} | ||
| {% if data.with_data %} | ||
| WITH DATA; | ||
| {% else %} | ||
| WITH NO DATA; | ||
| {% endif %} | ||
| {% if data.owner %} | ||
|
|
||
| ALTER TABLE IF EXISTS {{ conn|qtIdent(data.schema, data.name) }} | ||
| OWNER TO {{ conn|qtIdent(data.owner) }}; | ||
| {% endif %} | ||
| {% if data.dependsonextensions %} | ||
| {% for ext in data.dependsonextensions %} | ||
|
|
||
| ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} | ||
| DEPENDS ON EXTENSION {{ conn|qtIdent(ext) }}; | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% if data.comment %} | ||
|
|
||
| COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} | ||
| IS {{ data.comment|qtLiteral(conn) }}; | ||
| {% endif %} | ||
| {% endif %} |
118 changes: 118 additions & 0 deletions
118
...ver_groups/servers/databases/schemas/views/templates/mviews/pg/13_plus/sql/properties.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| {# ========================== Fetch Materialized View Properties ========================= #} | ||
| {% if (vid and datlastsysoid) or scid %} | ||
| SELECT | ||
| c.oid, | ||
| c.xmin, | ||
| c.relname AS name, | ||
| c.reltablespace AS spcoid, | ||
| c.relispopulated AS with_data, | ||
| CASE WHEN length(spcname::text) > 0 THEN spcname ELSE | ||
| (SELECT sp.spcname FROM pg_catalog.pg_database dtb | ||
| JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid | ||
| WHERE dtb.oid = {{ did }}::oid) | ||
| END as spcname, | ||
| (SELECT st.setting from pg_catalog.pg_show_all_settings() st | ||
| WHERE st.name = 'default_table_access_method') as default_amname, | ||
| c.relacl, | ||
| nsp.nspname as schema, | ||
| pg_catalog.pg_get_userbyid(c.relowner) AS owner, | ||
| description AS comment, | ||
| ( | ||
| SELECT array_agg(DISTINCT e.extname) | ||
| FROM pg_depend d | ||
| JOIN pg_extension e ON d.refobjid = e.oid | ||
| WHERE d.objid = c.oid | ||
| ) AS dependsonextensions, | ||
| pg_catalog.pg_get_viewdef(c.oid, true) AS definition, | ||
| {# ============= Checks if it is system view ================ #} | ||
| {% if vid and datlastsysoid %} | ||
| CASE WHEN {{vid}} <= {{datlastsysoid}} THEN True ELSE False END AS system_view, | ||
| {% endif %} | ||
| pg_catalog.array_to_string(c.relacl::text[], ', ') AS acl, | ||
| (SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=c.oid AND sl1.objsubid=0) AS seclabels, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'fillfactor=([0-9]*)') AS fillfactor, | ||
| (substring(pg_catalog.array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, | ||
| substring(pg_catalog.array_to_string(c.reloptions, ',') | ||
| FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, | ||
| (substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, | ||
| substring(pg_catalog.array_to_string(tst.reloptions, ',') | ||
| FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, | ||
| c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, am.amname, | ||
| (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable | ||
| FROM | ||
| pg_catalog.pg_class c | ||
| LEFT OUTER JOIN pg_catalog.pg_namespace nsp on nsp.oid = c.relnamespace | ||
| LEFT OUTER JOIN pg_catalog.pg_tablespace spc on spc.oid=c.reltablespace | ||
| LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=c.oid and des.objsubid=0 AND des.classoid='pg_class'::regclass) | ||
| LEFT OUTER JOIN pg_catalog.pg_class tst ON tst.oid = c.reltoastrelid | ||
| LEFT OUTER JOIN pg_catalog.pg_am am ON am.oid = c.relam | ||
| WHERE ((c.relhasrules AND (EXISTS ( | ||
| SELECT | ||
| r.rulename | ||
| FROM | ||
| pg_catalog.pg_rewrite r | ||
| WHERE | ||
| ((r.ev_class = c.oid) | ||
| AND (pg_catalog.bpchar(r.ev_type) = '1'::bpchar)) ))) | ||
| AND (c.relkind = 'm'::char) | ||
| ) | ||
| {% if (vid and datlastsysoid) %} | ||
| AND c.oid = {{vid}}::oid | ||
| {% elif scid %} | ||
| AND c.relnamespace = {{scid}}::oid | ||
| ORDER BY | ||
| c.relname | ||
| {% endif %} | ||
|
|
||
| {% elif type == 'roles' %} | ||
| SELECT | ||
| pr.rolname | ||
| FROM | ||
| pg_catalog.pg_roles pr | ||
| WHERE | ||
| pr.rolcanlogin | ||
| ORDER BY | ||
| pr.rolname | ||
|
|
||
| {% elif type == 'schemas' %} | ||
| SELECT | ||
| nsp.nspname | ||
| FROM | ||
| pg_catalog.pg_namespace nsp | ||
| WHERE | ||
| (nsp.nspname NOT LIKE E'pg\\_%' | ||
| AND nsp.nspname != 'information_schema') | ||
| {% endif %} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add dependency type filter to ensure correctness.
The query retrieves all dependencies between the materialized view and extensions, but doesn't filter by dependency type. This could return incorrect results if the materialized view has other dependency relationships with extensions beyond explicit
DEPENDS ON EXTENSIONdeclarations.Apply this diff to filter for extension dependencies only:
( SELECT array_agg(DISTINCT e.extname) FROM pg_depend d JOIN pg_extension e ON d.refobjid = e.oid - WHERE d.objid = c.oid + WHERE d.objid = c.oid + AND d.deptype = 'x' ) AS dependsonextensions,The
deptype = 'x'filter ensures onlyDEPENDS ON EXTENSIONrelationships are captured, not other dependency types.📝 Committable suggestion
🤖 Prompt for AI Agents