ruanwenjun commented on code in PR #17153:
URL: 
https://github.com/apache/dolphinscheduler/pull/17153#discussion_r2065575217


##########
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkflowInstanceMapper.xml:
##########
@@ -50,6 +50,22 @@
         </if>
         order by id asc
     </select>
+    <select id="queryMainWorkflowByHostAndStatus" 
resultType="org.apache.dolphinscheduler.dao.entity.WorkflowInstance">
+        select
+        <include refid="baseSql"/>
+        from t_ds_workflow_instance
+        where is_sub_workflow=0
+        <if test="host != null and host != ''">
+            and host=#{host}
+        </if>
+        <if test="states != null and states.length != 0">
+            and state in
+            <foreach collection="states" item="i" open="(" close=")" 
separator=",">
+                #{i}
+            </foreach>
+        </if>
+        order by id asc
+    </select>

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/WorkflowInstanceDaoImpl.java:
##########
@@ -170,7 +170,7 @@ public List<String> queryNeedFailoverMasters() {
 
     @Override
     public List<WorkflowInstance> queryNeedFailoverWorkflowInstances(String 
masterAddress) {
-        return mybatisMapper.queryByHostAndStatus(masterAddress,
+        return mybatisMapper.queryMainWorkflowByHostAndStatus(masterAddress,

Review Comment:
   It's better to  call `queryByHostAndStatus` and filter the parent workflow 
in memory, this can avoid increase index length in `t_ds_workflow_instance`.



##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/WorkflowInstanceMapper.java:
##########
@@ -56,6 +56,15 @@ public interface WorkflowInstanceMapper extends 
BaseMapper<WorkflowInstance> {
     List<WorkflowInstance> queryByHostAndStatus(@Param("host") String host,
                                                 @Param("states") int[] 
stateArray);
 
+    /**
+     * query workflow instance by host and stateArray which is not sub workflow
+     *
+     * @param host       host
+     * @param stateArray stateArray
+     * @return workflow instance list
+     */
+    List<WorkflowInstance> queryMainWorkflowByHostAndStatus(@Param("host") 
String host,
+                                                            @Param("states") 
int[] stateArray);

Review Comment:
   ```suggestion
   ```



##########
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/WorkflowInstanceMapper.java:
##########
@@ -56,6 +56,15 @@ public interface WorkflowInstanceMapper extends 
BaseMapper<WorkflowInstance> {
     List<WorkflowInstance> queryByHostAndStatus(@Param("host") String host,
                                                 @Param("states") int[] 
stateArray);
 
+    /**
+     * query workflow instance by host and stateArray which is not sub workflow
+     *
+     * @param host       host
+     * @param stateArray stateArray
+     * @return workflow instance list
+     */
+    List<WorkflowInstance> queryMainWorkflowByHostAndStatus(@Param("host") 
String host,
+                                                            @Param("states") 
int[] stateArray);

Review Comment:
   ```suggestion
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to