You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by "avamingli (via GitHub)" <gi...@apache.org> on 2024/12/13 08:49:56 UTC

[PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

avamingli opened a new pull request, #778:
URL: https://github.com/apache/cloudberry/pull/778

   This commit implements changes to the auto-refresh task for Dynamic Tables, specifically:
   
   1. Forbid users from altering the "AS" part of the ALTER TASK command. The SQL must always be a REFRESH command to maintain the integrity of the Dynamic Table design (an auto-refreshing materialized view). Other ALTER TASK subcommands remain allowed, enabling users to control other aspects as needed.
   2. Modify the SQL from "REFRESH DYNAMIC TABLE xxx" to "REFRESH DYNAMIC TABLE xxx CONCURRENTLY" to allow refreshing the materialized view without locking out concurrent selects.
   
   These changes aim to improve the usability and performance of Dynamic Tables in our system.
   
   Authored-by: Zhang Mingli avamingli@gmail.com
   
   <!-- Thank you for your contribution to Apache Cloudberry (Incubating)! -->
   
   Fixes #ISSUE_Number
   
   ### What does this PR do?
   <!-- Brief overview of the changes, including any major features or fixes -->
   
   ### Type of Change
   - [ ] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Breaking Changes
   <!-- Remove if not applicable. If yes, explain impact and migration path -->
   
   ### Test Plan
   <!-- How did you test these changes? -->
   - [ ] Unit tests added/updated
   - [ ] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   ### Impact
   <!-- Remove sections that don't apply -->
   **Performance:**
   <!-- Any performance implications? -->
   
   **User-facing changes:**
   <!-- Any changes visible to users? -->
   
   **Dependencies:**
   <!-- New dependencies or version changes? -->
   
   ### Checklist
   - [ ] Followed [contribution guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [ ] Reviewed code for security implications
   - [ ] Requested review from [cloudberry committers](https://github.com/orgs/apache/teams/cloudberry-committers)
   
   ### Additional Context
   <!-- Any other information that would help reviewers? Remove if none -->
   
   ### CI Skip Instructions
   <!--
   To skip CI builds, add the appropriate CI skip identifier to your PR title.
   The identifier must:
   - Be in square brackets []
   - Include the word "ci" and either "skip" or "no"
   - Only use for documentation-only changes or when absolutely necessary
   -->
   
   ---
   <!-- Join our community:
   - Mailing list: [dev@cloudberry.apache.org](https://lists.apache.org/list.html?dev@cloudberry.apache.org) (subscribe: dev-subscribe@cloudberry.apache.org)
   - Discussions: https://github.com/apache/cloudberry/discussions -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886106388


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   If there is no unique index, adding the CONCURRENTLY option poses no risk. It could improve performance if users decide to create a unique index later, so we should include this option.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886106388


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   If there is no unique index, adding the CONCURRENTLY option poses no risk. It could improve performance if users decide to create a unique index later, so we should include this option.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1884788987


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   normal matview support CONCURRENTLY ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886142208


##########
src/test/regress/expected/dynamic_table.out:
##########
@@ -156,24 +156,24 @@ SELECT * FROM t1 WHERE a = 2;
 (2 rows)
 
 -- test DROP DYNAMIC TABLE
-SELECT schedule, command FROM pg_task WHERE jobname LIKE 'gp_dynamic_table_refresh%' AND command LIKE '%dt0';
- schedule  |                    command                     
------------+------------------------------------------------
- 5 * * * * | REFRESH DYNAMIC TABLE dynamic_table_schema.dt0
+SELECT schedule, command FROM pg_task WHERE jobname LIKE 'gp_dynamic_table_refresh%' AND command LIKE '%dt0%';

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1883706734


##########
src/test/regress/expected/dynamic_table.out:
##########
@@ -156,24 +156,24 @@ SELECT * FROM t1 WHERE a = 2;
 (2 rows)
 
 -- test DROP DYNAMIC TABLE
-SELECT schedule, command FROM pg_task WHERE jobname LIKE 'gp_dynamic_table_refresh%' AND command LIKE '%dt0';
- schedule  |                    command                     
------------+------------------------------------------------
- 5 * * * * | REFRESH DYNAMIC TABLE dynamic_table_schema.dt0
+SELECT schedule, command FROM pg_task WHERE jobname LIKE 'gp_dynamic_table_refresh%' AND command LIKE '%dt0%';

Review Comment:
   add a test case that: insert rows, wait pg_task refresh, then select * from dt0 ;



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1884259830


##########
src/test/regress/expected/dynamic_table.out:
##########
@@ -156,24 +156,24 @@ SELECT * FROM t1 WHERE a = 2;
 (2 rows)
 
 -- test DROP DYNAMIC TABLE
-SELECT schedule, command FROM pg_task WHERE jobname LIKE 'gp_dynamic_table_refresh%' AND command LIKE '%dt0';
- schedule  |                    command                     
------------+------------------------------------------------
- 5 * * * * | REFRESH DYNAMIC TABLE dynamic_table_schema.dt0
+SELECT schedule, command FROM pg_task WHERE jobname LIKE 'gp_dynamic_table_refresh%' AND command LIKE '%dt0%';

Review Comment:
   Thank you for the suggested test case. I'm okay with that.
   
   However, I would like to clarify that there are already cases tested the REFRESH commands in existing cases, and the pg_task executes the same command. If there were any issues with pg_task not executing the command as expected, it would indicate a bug within pg_task, not with the dynamic table functionality itself.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "my-ship-it (via GitHub)" <gi...@apache.org>.
my-ship-it merged PR #778:
URL: https://github.com/apache/cloudberry/pull/778


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886108976


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   You'r right!
   > HINT:  Create a unique index with no WHERE clause on one or more columns of the materialized view.
   
   We should not add this options.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886108592


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   Oh, what if there is no unique index with CONCURRENTLY, I will have a check 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "avamingli (via GitHub)" <gi...@apache.org>.
avamingli commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886068008


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   Yes, normal materialized views do support the CONCURRENTLY option. According to the [PostgreSQL docs](https://www.postgresql.org/docs/14/sql-refreshmaterializedview.html):
   
   > CONCURRENTLY allows the materialized view to be refreshed without locking out concurrent selects. While a standard refresh might block other connections reading from the view, using CONCURRENTLY can be faster, especially when a small number of rows are affected



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org


Re: [PR] Enhance Dynamic Table auto-refresh task. [cloudberry]

Posted by "yjhjstz (via GitHub)" <gi...@apache.org>.
yjhjstz commented on code in PR #778:
URL: https://github.com/apache/cloudberry/pull/778#discussion_r1886102274


##########
src/backend/commands/createas.c:
##########
@@ -1846,7 +1846,7 @@ create_dynamic_table_auto_refresh_task(ParseState *pstate, Relation DynamicTable
 	dtname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(DynamicTableRel)),
 											 RelationGetRelationName(DynamicTableRel));
 	resetStringInfo(&buf);
-	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s", dtname);
+	appendStringInfo(&buf, "REFRESH DYNAMIC TABLE %s CONCURRENTLY", dtname);

Review Comment:
   but gp need UniqueIndex? I checked `ExecRefreshMatView`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org