Skip to content

Latest commit

 

History

History
107 lines (74 loc) · 4.84 KB

20230713_01.md

File metadata and controls

107 lines (74 loc) · 4.84 KB

PostgreSQL 17 preview - Add new parallel message type to progress reporting.

作者

digoal

日期

2023-07-13

标签

PostgreSQL , PolarDB , parallel , progress


背景

增加并行执行worker进程的进度通知消息, 以掌握parallel worker进程的执行进度.

未来也许会支持动态并行调度优化. 类似现在PorlarDB做的epq.

https://apsaradb.github.io/PolarDB-for-PostgreSQL/zh/features/v11/htap/adaptive-scan.html

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=f1889729dd3ab0352dc0ccc2ffcc1b1901f8e39f

Add new parallel message type to progress reporting.  
author	Masahiko Sawada <msawada@postgresql.org>	  
Tue, 11 Jul 2023 03:33:54 +0000 (12:33 +0900)  
committer	Masahiko Sawada <msawada@postgresql.org>	  
Tue, 11 Jul 2023 03:33:54 +0000 (12:33 +0900)  
commit	f1889729dd3ab0352dc0ccc2ffcc1b1901f8e39f  
tree	6c82b614a2f73a9f5ab2a83c32da8cdf832d1079	tree  
parent	26dd0284b98f6bf730dc1f7f7e1f917525d71eda	commit | diff  
Add new parallel message type to progress reporting.  
  
This commit adds a new type of parallel message 'P' to allow a  
parallel worker to poke at a leader to update the progress.  
  
Currently it supports only incremental progress reporting but it's  
possible to allow for supporting of other backend progress APIs in the  
future.  
  
There are no users of this new message type as of this commit. That  
will follow in future commits.  
  
Idea from Andres Freund.  
  
Author: Sami Imseih  
Reviewed by: Michael Paquier, Masahiko Sawada  
Discussion: https://www.postgresql.org/message-id/flat/5478DFCD-2333-401A-B2F0-0D186AB09228@amazon.com  
+/*-----------  
+ * pgstat_progress_parallel_incr_param() -  
+ *  
+ * A variant of pgstat_progress_incr_param to allow a worker to poke at  
+ * a leader to do an incremental progress update.  
+ *-----------  
+ */  
+void  
+pgstat_progress_parallel_incr_param(int index, int64 incr)  
+{  
+   /*  
+    * Parallel workers notify a leader through a 'P' protocol message to  
+    * update progress, passing the progress index and incremented value.  
+    * Leaders can just call pgstat_progress_incr_param directly.  
+    */  
+   if (IsParallelWorker())  
+   {  
+       static StringInfoData progress_message;  
+  
+       initStringInfo(&progress_message);  
+  
+       pq_beginmessage(&progress_message, 'P');  
+       pq_sendint32(&progress_message, index);  
+       pq_sendint64(&progress_message, incr);  
+       pq_endmessage(&progress_message);  
+   }  
+   else  
+       pgstat_progress_incr_param(index, incr);  
+}  

digoal's wechat